Skip to content

Commit

Permalink
Get user by id
Browse files Browse the repository at this point in the history
Version 3.0.4
  • Loading branch information
Marc Smith committed Nov 4, 2021
1 parent eac655c commit 99c78c9
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ in your projects as follows:

### Gradle/Grails
```
compile 'com.9ls:myrewards-java-sdk:3.0.4'
compile 'com.9ls:myrewards-java-sdk:3.0.5'
```

### Apache Maven
```
<dependency>
<groupId>com.9ls</groupId>
<artifactId>myrewards-java-sdk</artifactId>
<version>3.0.4</version>
<version>3.0.5</version>
</dependency>
```

### Apache Ivy
```
<dependency org="com.9ls" name="myrewards-java-sdk" rev="3.0.4" />
<dependency org="com.9ls" name="myrewards-java-sdk" rev="3.0.5" />
```

## Custom Configuration
Expand All @@ -49,7 +49,7 @@ from the the api key all the other values have defaults.
.withSecretKey(secretKey)
.withEndpoint("https://api.my-rewards.co.uk")
.withMaxConnectionsPerRoute(20)
.withUserAgent("myrewards-sdk-java 3.0.4")
.withUserAgent("myrewards-sdk-java 3.0.5")
.withBlockTillRateLimitReset(false)
.withRequestsPerSecond(5)
.withRequestBurstSize(20);
Expand Down
1 change: 1 addition & 0 deletions config/checkstyle/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress checks="MethodCount|FileLength" files="com.nls.myrewards.MyRewards.java"/>
<suppress checks="MethodCount" files="com.nls.myrewards.MyRewardsUser.java"/>
<suppress checks="MethodCount" files="com.nls.myrewards.MyRewardsUserRequest.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="com.nls.myrewards.client.HttpClient.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="com.nls.myrewards.client.HttpClient.java"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ abstract class BaseIntegrationSpec extends Specification {

String testSuiteCompany = "Testing Corp (Test Suite)";

MyRewardsRegistrationQuestionValue value = client.getRegistrationQuestionValue(COMPANY_MAGIC_NUMBER, testSuiteCompany);
MyRewardsCompany value = client.companies.find({it -> it.name == testSuiteCompany});
if (value != null) {
testingCompany = value.name
testingCompanyNew = client.getCompany(value.id);
testingCompanyNew = value
return testingCompany
}

testingCompany = client.createRegistrationQuestionValues(COMPANY_MAGIC_NUMBER, testSuiteCompany).name
testingCompanyNew = client.getCompany(value.id);
testingCompanyNew = client.createCompany(testSuiteCompany)
testingCompany = testingCompanyNew.name
return testingCompany
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class UserCreateIntegrationSpec extends BaseIntegrationSpec {
e.message.startsWith('422: Unprocessable Entity')
}

def "I can get a user's details by doing an empty update"() {
def "I can get a user's details"() {
when:
MyRewardsUserRequest request = new MyRewardsUserRequest()
.withUsername(getRandomUsername())
Expand Down Expand Up @@ -181,8 +181,7 @@ class UserCreateIntegrationSpec extends BaseIntegrationSpec {
user.id > 0

when:
MyRewardsUserRequest getRequest = new MyRewardsUserRequest()
MyRewardsUser updateUser = client.updateUser(user.id, getRequest)
MyRewardsUser updateUser = client.getUser(user.id)
println(ObjectMapperFactory.make().writeValueAsString(updateUser))

then:
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/nls/myrewards/MyRewards.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.nls.myrewards;

import com.nls.myrewards.client.HttpClient;
import org.apache.http.HttpStatus;

import java.net.URLEncoder;
import java.util.ArrayList;
Expand Down Expand Up @@ -309,7 +308,10 @@ public List<MyRewardsUserGroupPermission> setUserGroupPermissions(int userGroupI
* @return the user
*/
public MyRewardsUser getUser(int userId) {
return updateUser(userId, new MyRewardsUserRequest());
return client.get(
"/api/v3/users/" + userId,
null,
MyRewardsUser.class);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public final class MyRewardsRegistrationAnswerAttribute {
private String registrationQuestionId;
private String answer;
private MyRewardsRegistrationQuestionAttribute question;

private MyRewardsRegistrationAnswerAttribute() {
}
Expand All @@ -20,6 +21,10 @@ public int getRegistrationQuestionId() {
return Integer.parseInt(registrationQuestionId);
}

public MyRewardsRegistrationQuestionAttribute getQuestion() {
return question;
}

public String getAnswer() {
return answer;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nls.myrewards;

public class MyRewardsRegistrationQuestionAttribute {
private String userLocale;
private String stackLocale;

public String getUserLocale() {
return userLocale;
}

public String getStackLocale() {
return stackLocale;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/nls/myrewards/MyRewardsUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum CompanyType {
private LocalDate dateOfBirth;
private String telephone;
private String mobile;
private String chosenLocale;
private boolean tsandcs;
private Integer userGroupId;
private boolean consented;
Expand Down Expand Up @@ -124,6 +125,10 @@ public String getMobile() {
return mobile;
}

public String getChosenLocale() {
return chosenLocale;
}

public boolean isTsandcs() {
return tsandcs;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/nls/myrewards/MyRewardsUserRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class MyRewardsUserRequest {
private LocalDate dateOfBirth;
private String telephone;
private String mobile;
private String chosenLocale;
private Boolean tsandcs;
private Integer userGroupId;
private Boolean consented;
Expand Down Expand Up @@ -58,6 +59,7 @@ public MyRewardsUserRequest(MyRewardsUser user) {
this.dateOfBirth = user.getDateOfBirth();
this.telephone = user.getTelephone();
this.mobile = user.getMobile();
this.chosenLocale = user.getChosenLocale();
this.tsandcs = user.isTsandcs();
this.userGroupId = user.getUserGroupId();
this.consented = user.isConsented();
Expand Down Expand Up @@ -229,6 +231,15 @@ public MyRewardsUserRequest withMobile(String mobile) {
return this;
}

public String getChosenLocale() {
return chosenLocale;
}

public MyRewardsUserRequest withChosenLocale(String chosenLocale) {
this.chosenLocale = chosenLocale;
return this;
}

public Boolean isTsandcs() {
return tsandcs;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=3.0.4
version=3.0.5
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MyRewardsUserRequestSpec extends Specification {
.withDateOfBirth(LocalDate.parse("1980-02-19"))
.withTelephone("+447876543210")
.withMobile("+447765432101")
.withChosenLocale("en")
.withTsandcs(true)
.withConsented(true)
.withMarketingConsented(true)
Expand Down Expand Up @@ -58,6 +59,7 @@ class MyRewardsUserRequestSpec extends Specification {
request.dateOfBirth == LocalDate.parse('1980-02-19');
request.telephone == '+447876543210'
request.mobile == '+447765432101'
request.chosenLocale == 'en'
request.tsandcs
request.consented
request.marketingConsented
Expand All @@ -84,6 +86,7 @@ class MyRewardsUserRequestSpec extends Specification {
entity.date_of_birth == '1980-02-19'
entity.telephone == '+447876543210'
entity.mobile == '+447765432101'
entity.chosen_locale == 'en'
entity.tsandcs == true
entity.consented == true
entity.marketing_consented == true
Expand Down Expand Up @@ -115,6 +118,7 @@ class MyRewardsUserRequestSpec extends Specification {
result.dateOfBirth == LocalDate.parse('1980-02-19');
result.telephone == '+447876543210'
result.mobile == '+447765432101'
result.chosenLocale == 'en'
result.tsandcs
result.consented
result.marketingConsented
Expand Down Expand Up @@ -145,6 +149,7 @@ class MyRewardsUserRequestSpec extends Specification {
.withDateOfBirth(LocalDate.parse("1980-02-19"))
.withTelephone("+447876543210")
.withMobile("+447765432101")
.withChosenLocale('en')
.withTsandcs(true)
.withConsented(true)
.withMarketingConsented(true)
Expand Down Expand Up @@ -198,6 +203,7 @@ class MyRewardsUserRequestSpec extends Specification {
"date_of_birth" : "1980-02-19",
"telephone" : "+447876543210",
"mobile" : "+447765432101",
"chosen_locale" : "en",
"tsandcs" : "true",
"consented" : "false",
"marketing_consented" : "true",
Expand Down Expand Up @@ -236,6 +242,7 @@ class MyRewardsUserRequestSpec extends Specification {
result.dateOfBirth == LocalDate.parse('1980-02-19');
result.telephone == '+447876543210'
result.mobile == '+447765432101'
result.chosenLocale == 'en'
result.tsandcs
!result.consented
result.marketingConsented
Expand Down Expand Up @@ -272,6 +279,7 @@ class MyRewardsUserRequestSpec extends Specification {
"date_of_birth" : "1980-02-19",
"telephone" : "+447876543210",
"mobile" : "+447765432101",
"chosen_locale" : "en",
"tsandcs" : "true",
"consented" : "false",
"marketing_consented" : "true",
Expand Down Expand Up @@ -312,6 +320,7 @@ class MyRewardsUserRequestSpec extends Specification {
result.dateOfBirth == LocalDate.parse('1980-02-19');
result.telephone == '+447876543210'
result.mobile == '+447765432101'
result.chosenLocale == "en"
result.tsandcs
!result.consented
result.marketingConsented
Expand Down
16 changes: 16 additions & 0 deletions src/test/groovy/com/nls/myrewards/MyRewardsUserSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MyRewardsUserSpec extends Specification {
"date_of_birth" : "1980-02-19",
"telephone" : "+447876543210",
"mobile" : "+447765432101",
"chosen_locale": "en",
"tsandcs" : "true",
"consented" : "false",
"marketing_consented" : "true",
Expand Down Expand Up @@ -67,6 +68,7 @@ class MyRewardsUserSpec extends Specification {
entity.dateOfBirth == LocalDate.parse('1980-02-19');
entity.telephone == '+447876543210'
entity.mobile == '+447765432101'
entity.chosenLocale == "en"
entity.tsandcs
!entity.consented
entity.marketingConsented
Expand Down Expand Up @@ -103,15 +105,24 @@ class MyRewardsUserSpec extends Specification {
"date_of_birth" : "1980-02-19",
"telephone" : "+447876543210",
"mobile" : "+447765432101",
"chosen_locale": "en",
"tsandcs" : "true",
"user_group_id" : "10",
"registration_answers_attributes" : [
{
"registration_question_id" : "2",
"question": {
"user_locale": "Pourquoi?",
"stack_locale": "Why?"
},
"answer" : "Because I'm Batman"
},
{
"registration_question_id" : "16",
"question": {
"user_locale": "Butler Name",
"stack_locale": "Butler Name"
},
"answer" : "Alfred"
}
]
Expand Down Expand Up @@ -141,14 +152,19 @@ class MyRewardsUserSpec extends Specification {
entity.dateOfBirth == LocalDate.parse('1980-02-19');
entity.telephone == '+447876543210'
entity.mobile == '+447765432101'
entity.chosenLocale == 'en'
entity.tsandcs
!entity.consented
!entity.marketingConsented
entity.userGroupId == 10
entity.registrationAnswersAttributes.size() == 2
entity.registrationAnswersAttributes[0].registrationQuestionId == 2
entity.registrationAnswersAttributes[0].question.userLocale == 'Pourquoi?'
entity.registrationAnswersAttributes[0].question.stackLocale == 'Why?'
entity.registrationAnswersAttributes[0].answer == "Because I'm Batman"
entity.registrationAnswersAttributes[1].registrationQuestionId == 16
entity.registrationAnswersAttributes[1].question.userLocale == 'Butler Name'
entity.registrationAnswersAttributes[1].question.stackLocale == 'Butler Name'
entity.registrationAnswersAttributes[1].answer == "Alfred"
}

Expand Down

0 comments on commit 99c78c9

Please sign in to comment.