Skip to content

Commit

Permalink
Add support for AU tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Serrano committed Jun 1, 2023
1 parent a0617c0 commit 96f176a
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.25.0 (2023-06-01)

- Add support for AU tokens

## 2.24.3 (2023-05-12)

- Fix getScoreColor bug
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ If you use Maven, you can include this library as a dependency:
<dependency>
<groupId>com.wootric</groupId>
<artifactId>wootric-sdk-android</artifactId>
<version>2.24.3</version>
<version>2.25.0</version>
</dependency>
```

### Using Gradle

```xml
implementation 'com.wootric:wootric-sdk-android:2.24.3'
implementation 'com.wootric:wootric-sdk-android:2.25.0'
```

## Initializing Wootric
Expand Down
4 changes: 2 additions & 2 deletions androidsdk/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=2.24.3
VERSION_CODE=2243
VERSION_NAME=2.25.0
VERSION_CODE=2250
GROUP=com.wootric

POM_DESCRIPTION=WootricSDK Android
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ public class Constants {
public static final String CES = "CES";

public static final String CSAT = "CSAT";
public static final String API_BASE_URL = "https://app.wootric.";
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package com.wootric.androidsdk.network.tasks;

import static com.wootric.androidsdk.Constants.API_BASE_URL;

import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
Expand Down Expand Up @@ -49,10 +51,7 @@ public abstract class WootricRemoteRequestTask extends AsyncTask<Void, Void, Str
static final String REQUEST_TYPE_PUT = "PUT";
static final String REQUEST_TYPE_GET = "GET";

protected static final String API_ENDPOINT = "https://api.wootric.com";
protected static final String SURVEY_ENDPOINT = "https://survey.wootric.com";
protected static final String EU_API_ENDPOINT = "https://app.wootric.eu";
protected static final String EU_SURVEY_ENDPOINT = "https://eligibility.wootric.eu";
protected static final String SURVEY_BASE_URL = "https://eligibility.wootric.";
protected static final String END_USERS_PATH = "/api/v1/end_users";
protected static final String OAUTH_PATH = "/oauth/token";
protected static final String ELIGIBLE_PATH = "/eligible.json";
Expand Down Expand Up @@ -169,11 +168,11 @@ protected void onInvalidResponse(String message) {
}

protected String getApiEndpoint() {
return Utils.startsWithEU(this.accountToken) ? EU_API_ENDPOINT : API_ENDPOINT;
return API_BASE_URL + Utils.getTokenTDL(this.accountToken);
}

protected String getSurveyEndpoint() {
return Utils.startsWithEU(this.accountToken) ? EU_SURVEY_ENDPOINT : SURVEY_ENDPOINT;
return SURVEY_BASE_URL + Utils.getTokenTDL(this.accountToken);
}

protected abstract String requestUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.wootric.androidsdk.Constants;

import java.util.Date;
import java.util.regex.Pattern;

/**
* Created by maciejwitowski on 11/24/15.
Expand Down Expand Up @@ -76,7 +77,10 @@ public static byte getByteValue(Boolean bool) {
}
}

public static boolean startsWithEU(String aString) {
return aString.startsWith("NPS-EU");
public static String getTokenTDL(String accountToken) {
if (Pattern.compile("^NPS-(EU-|AU-)[A-Za-z0-9]{8}").matcher(accountToken).matches()) {
return accountToken.substring(4,6).toLowerCase();
}
return "com";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package com.wootric.androidsdk.views;

import static com.wootric.androidsdk.Constants.API_BASE_URL;

import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
Expand Down Expand Up @@ -412,8 +414,8 @@ private void notifySurveyFinished() {
}

private void optOut() {
String tld = Utils.startsWithEU(mUser.getAccountToken()) ? "eu" : "com";
String optOutUrl = "https://app.wootric." + tld + "/opt_out?token=" + mUser.getAccountToken()
String tld = Utils.getTokenTDL(mUser.getAccountToken());
String optOutUrl = API_BASE_URL + tld + "/opt_out?token=" + mUser.getAccountToken()
+ "&metric_type=" + mSettings.getSurveyType()
+ "&end_user_id=" + mEndUser.getId()
+ "&end_user_email=" + mEndUser.getEmail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

package com.wootric.androidsdk.views.support;

import static com.wootric.androidsdk.Constants.API_BASE_URL;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
Expand Down Expand Up @@ -417,8 +419,8 @@ private void notifySurveyFinished() {
}

private void optOut() {
String tld = Utils.startsWithEU(mUser.getAccountToken()) ? "eu" : "com";
String optOutUrl = "https://app.wootric." + tld + "/opt_out?token=" + mUser.getAccountToken()
String tld = Utils.getTokenTDL(mUser.getAccountToken());
String optOutUrl = API_BASE_URL + tld + "/opt_out?token=" + mUser.getAccountToken()
+ "&metric_type=" + mSettings.getSurveyType()
+ "&end_user_id=" + Long.toString(mEndUser.getId())
+ "&end_user_email=" + mEndUser.getEmail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testGet_RequestWithEventName() throws Exception {
public void testGet_RequestWithEuToken() throws Exception {
EndUser endUser = new EndUser();
Settings settings = new Settings();
User user = new User("NPS-EU");
User user = new User("NPS-EU-1234abcd");
SurveyValidator surveyValidator = new SurveyValidator(user, endUser, settings,
wootricRemoteClient, testPreferenceUtils());

Expand All @@ -72,6 +72,21 @@ public void testGet_RequestWithEuToken() throws Exception {
assertThat(asyncTask.requestUrl()).isEqualTo("https://eligibility.wootric.eu/eligible.json");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
EndUser endUser = new EndUser();
Settings settings = new Settings();
User user = new User("NPS-AU-1234abcd");
SurveyValidator surveyValidator = new SurveyValidator(user, endUser, settings,
wootricRemoteClient, testPreferenceUtils());

CheckEligibilityTask asyncTask = new CheckEligibilityTask(user, endUser, settings, testPreferenceUtils(), surveyValidator);
asyncTask.execute();
Robolectric.flushBackgroundThreadScheduler();

assertThat(asyncTask.requestUrl()).isEqualTo("https://eligibility.wootric.au/eligible.json");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
EndUser endUser = new EndUser();
Expand All @@ -84,6 +99,6 @@ public void testGet_RequestWithNormalToken() throws Exception {
asyncTask.execute();
Robolectric.flushBackgroundThreadScheduler();

assertThat(asyncTask.requestUrl()).isEqualTo("https://survey.wootric.com/eligible.json");
assertThat(asyncTask.requestUrl()).isEqualTo("https://eligibility.wootric.com/eligible.json");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ public class CreateDeclineTaskTest {

@Test
public void testGet_RequestWithEuToken() throws Exception {
CreateDeclineTask asyncTask = new CreateDeclineTask(END_USER_ID, USER_ID, ACCOUNT_ID, PRIORITY,ORIGIN_URL, ACCESS_TOKEN, "NPS-EU", offlineDataHandler, UNIQUE_LINK);
CreateDeclineTask asyncTask = new CreateDeclineTask(END_USER_ID, USER_ID, ACCOUNT_ID, PRIORITY,ORIGIN_URL, ACCESS_TOKEN, "NPS-EU-1234abcd", offlineDataHandler, UNIQUE_LINK);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.eu/api/v1/end_users/" + END_USER_ID + "/declines");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
CreateDeclineTask asyncTask = new CreateDeclineTask(END_USER_ID, USER_ID, ACCOUNT_ID, PRIORITY,ORIGIN_URL, ACCESS_TOKEN, "NPS-AU-1234abcd", offlineDataHandler, UNIQUE_LINK);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.au/api/v1/end_users/" + END_USER_ID + "/declines");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
CreateDeclineTask asyncTask = new CreateDeclineTask(END_USER_ID, USER_ID, ACCOUNT_ID, PRIORITY,ORIGIN_URL, ACCESS_TOKEN, "NPS", offlineDataHandler, UNIQUE_LINK);
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users/" + END_USER_ID + "/declines");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users/" + END_USER_ID + "/declines");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ public class CreateEndUserTaskTest {

@Test
public void testGet_RequestWithEuToken() throws Exception {
CreateEndUserTask asyncTask = new CreateEndUserTask(null, ACCESS_TOKEN, "NPS-EU", wootricApiCallback);
CreateEndUserTask asyncTask = new CreateEndUserTask(null, ACCESS_TOKEN, "NPS-EU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.eu/api/v1/end_users");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
CreateEndUserTask asyncTask = new CreateEndUserTask(null, ACCESS_TOKEN, "NPS-AU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.au/api/v1/end_users");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
CreateEndUserTask asyncTask = new CreateEndUserTask(null, ACCESS_TOKEN, "NPS", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,35 @@ public class CreateResponseTaskTest {

@Test
public void testGet_RequestWithEuToken() throws Exception {
CreateResponseTask asyncTask = new CreateResponseTask(END_USER_ID, USER_ID, ACCOUNT_ID, ORIGIN_URL, SCORE, PRIORITY, TEXT, ACCESS_TOKEN, "NPS-EU", offlineDataHandler, UNIQUE_LINK, LANGUAGE, DRIVER_PICKLIST);
CreateResponseTask asyncTask = new CreateResponseTask(END_USER_ID, USER_ID, ACCOUNT_ID, ORIGIN_URL, SCORE, PRIORITY, TEXT, ACCESS_TOKEN, "NPS-EU-1234abcd", offlineDataHandler, UNIQUE_LINK, LANGUAGE, DRIVER_PICKLIST);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.eu/api/v1/end_users/" + END_USER_ID + "/responses");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
CreateResponseTask asyncTask = new CreateResponseTask(END_USER_ID, USER_ID, ACCOUNT_ID, ORIGIN_URL, SCORE, PRIORITY, TEXT, ACCESS_TOKEN, "NPS-AU-1234abcd", offlineDataHandler, UNIQUE_LINK, LANGUAGE, DRIVER_PICKLIST);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.au/api/v1/end_users/" + END_USER_ID + "/responses");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
CreateResponseTask asyncTask = new CreateResponseTask(END_USER_ID, USER_ID, ACCOUNT_ID, ORIGIN_URL, SCORE, PRIORITY, TEXT, ACCESS_TOKEN, "NPS", offlineDataHandler, UNIQUE_LINK, LANGUAGE, DRIVER_PICKLIST);
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users/" + END_USER_ID + "/responses");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users/" + END_USER_ID + "/responses");
}

@Test
public void testPost_RequestWithLanguage() throws Exception {
CreateResponseTask asyncTask = new CreateResponseTask(END_USER_ID, USER_ID, ACCOUNT_ID, ORIGIN_URL, SCORE, PRIORITY, TEXT, ACCESS_TOKEN, "NPS", offlineDataHandler, UNIQUE_LINK, LANGUAGE, DRIVER_PICKLIST);
asyncTask.buildParams();
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users/" + END_USER_ID + "/responses");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users/" + END_USER_ID + "/responses");
assertThat(asyncTask.paramsMap.get("survey[language]")).isEqualTo("es-mx");
}

@Test
public void testPost_RequestWithoutLanguage() throws Exception {
CreateResponseTask asyncTask = new CreateResponseTask(END_USER_ID, USER_ID, ACCOUNT_ID, ORIGIN_URL, SCORE, PRIORITY, TEXT, ACCESS_TOKEN, "NPS", offlineDataHandler, UNIQUE_LINK, null, DRIVER_PICKLIST);
asyncTask.buildParams();
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users/" + END_USER_ID + "/responses");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users/" + END_USER_ID + "/responses");
assertThat(asyncTask.paramsMap.containsKey("survey[language]")).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ public class GetAccessTokenTaskTest {

@Test
public void testGet_RequestWithEuToken() throws Exception {
GetAccessTokenTask asyncTask = new GetAccessTokenTask("clientId1234", "NPS-EU", wootricApiCallback);
GetAccessTokenTask asyncTask = new GetAccessTokenTask("clientId1234", "NPS-EU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.eu/oauth/token");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
GetAccessTokenTask asyncTask = new GetAccessTokenTask("clientId1234", "NPS-AU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.au/oauth/token");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
GetAccessTokenTask asyncTask = new GetAccessTokenTask("clientId1234", "NPS", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/oauth/token");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/oauth/token");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ public class GetEndUserByEmailTaskTest {

@Test
public void testGet_RequestWithEuToken() throws Exception {
GetEndUserByEmailTask asyncTask = new GetEndUserByEmailTask(null, ACCESS_TOKEN, "NPS-EU", wootricApiCallback);
GetEndUserByEmailTask asyncTask = new GetEndUserByEmailTask(null, ACCESS_TOKEN, "NPS-EU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.eu/api/v1/end_users");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
GetEndUserByEmailTask asyncTask = new GetEndUserByEmailTask(null, ACCESS_TOKEN, "NPS-AU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.au/api/v1/end_users");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
GetEndUserByEmailTask asyncTask = new GetEndUserByEmailTask(null, ACCESS_TOKEN, "NPS", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,25 @@ public class GetRegisteredEventsTaskTest {

@Test
public void testGet_RequestWithEuToken() throws Exception {
User user = new User("NPS-EU");
User user = new User("NPS-EU-1234abcd");

GetRegisteredEventsTask asyncTask = new GetRegisteredEventsTask(user, surveyCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://eligibility.wootric.eu/registered_events.json");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
User user = new User("NPS-AU-1234abcd");

GetRegisteredEventsTask asyncTask = new GetRegisteredEventsTask(user, surveyCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://eligibility.wootric.au/registered_events.json");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
User user = new User("NPS");

GetRegisteredEventsTask asyncTask = new GetRegisteredEventsTask(user, surveyCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://survey.wootric.com/registered_events.json");
assertThat(asyncTask.requestUrl()).isEqualTo("https://eligibility.wootric.com/registered_events.json");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,23 @@ public class UpdateEndUserTaskTest {
public void testGet_RequestWithEuToken() throws Exception {
EndUser endUser = testEndUser();
endUser.setId(4321);
UpdateEndUserTask asyncTask = new UpdateEndUserTask(endUser, ACCESS_TOKEN, "NPS-EU", wootricApiCallback);
UpdateEndUserTask asyncTask = new UpdateEndUserTask(endUser, ACCESS_TOKEN, "NPS-EU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.eu/api/v1/end_users/4321");
}

@Test
public void testGet_RequestWithAuToken() throws Exception {
EndUser endUser = testEndUser();
endUser.setId(4321);
UpdateEndUserTask asyncTask = new UpdateEndUserTask(endUser, ACCESS_TOKEN, "NPS-AU-1234abcd", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.au/api/v1/end_users/4321");
}

@Test
public void testGet_RequestWithNormalToken() throws Exception {
EndUser endUser = testEndUser();
endUser.setId(4321);
UpdateEndUserTask asyncTask = new UpdateEndUserTask(endUser, ACCESS_TOKEN, "NPS", wootricApiCallback);
assertThat(asyncTask.requestUrl()).isEqualTo("https://api.wootric.com/api/v1/end_users/4321");
assertThat(asyncTask.requestUrl()).isEqualTo("https://app.wootric.com/api/v1/end_users/4321");
}
}

0 comments on commit 96f176a

Please sign in to comment.