Skip to content

Commit

Permalink
SDK v3.2.8 | Sample v3.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelskotnicki committed Sep 28, 2018
1 parent 08d56e5 commit a7150c7
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 24 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog
All notable changes to this project will be documented in this file.

## [3.2.8] - 2018-09-28
### Added
- Client method to obtain external client's authorization token

### Fixed
- Profile's `getClientVoucherCodes()` entity
- Profile's `getPromotionsBy(parameter)` entity
- Client's `getAssignedVoucherCodes()` entity

### Changed
- Firebase version incrementation (17.3.2)

## [3.2.7] - 2018-09-26
### Added
- Promotion deactivation by uuid and code
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ apply plugin: 'synerise-plugin'
dependencies {
...
// Synerise Android SDK
implementation 'com.synerise.sdk:synerise-mobile-sdk:3.2.7'
implementation 'com.synerise.sdk:synerise-mobile-sdk:3.2.8'
}
```
Finally, please make sure your `Instant Run` is disabled.
Expand Down Expand Up @@ -641,6 +641,42 @@ private void changePassword(String password) {
}
```

#### Client.createAuthTokenByUuid(uuid)
Use this method to obtain unregistered client's authorization token.
Note, that 401 http status code is returned if you used this method for the client already existing in Synerise database.
Method returns `IApiCall` to execute request.
```
private void createAuthTokenByUuid(String uuid) {
if (createCall != null) createCall.cancel();
createCall = Client.createAuthTokenByUuid(uuid);
createCall.execute(this::onSuccess, this::onError);
}
```

#### Client.createAuthTokenByEmail(email)
Use this method to obtain unregistered client's authorization token.
Note, that 401 http status code is returned if you used this method for the client already existing in Synerise database.
Method returns `IApiCall` to execute request.
```
private void createAuthTokenByEmail(String email) {
if (createCall != null) createCall.cancel();
createCall = Client.createAuthTokenByEmail(email);
createCall.execute(this::onSuccess, this::onError);
}
```

#### Client.createAuthTokenByCustomId(customId)
Use this method to obtain unregistered client's authorization token.
Note, that 401 http status code is returned if you used this method for the client already existing in Synerise database.
Method returns `IApiCall` to execute request.
```
private void createAuthTokenByCustomId(String customId) {
if (createCall != null) createCall.cancel();
createCall = Client.createAuthTokenByCustomId(customId);
createCall.execute(this::onSuccess, this::onError);
}
```

#### Client.getToken()
Get valid JWT login token.<br>
Note, that error is thrown when Client is not logged in or token has expired and cannot be refreshed.<br>
Expand Down
8 changes: 4 additions & 4 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
minSdkVersion 19
targetSdkVersion 27
applicationId "com.synerise.sample"
versionCode 16
versionName "3.0.7"
versionCode 17
versionName "3.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand Down Expand Up @@ -66,8 +66,8 @@ android {

ext {
daggerVersion = '2.16'
syneriseVersion = '3.2.7'
playServicesVersion = '17.3.1'
syneriseVersion = '3.2.8'
playServicesVersion = '17.3.2'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,13 @@ private List<Pair<Promotion, CartItem>> filterPromotions(List<Promotion> promoti
List<CartItem> cartItems = accountManager.getCartItems();
for (Promotion promotion : promotions) {
List<String> catalogIndexItems = promotion.getCatalogIndexItems();
if (catalogIndexItems != null) {
if (catalogIndexItems.isEmpty()) {
results.add(new Pair<>(promotion, null));
} else if (!cartItems.isEmpty()) {
for (String catalogIndexItem : catalogIndexItems) {
for (CartItem cartItem : cartItems) {
if (catalogIndexItem.equals(cartItem.getProduct().getSKU()))
results.add(new Pair<>(promotion, cartItem));
}
if (catalogIndexItems.isEmpty()) {
results.add(new Pair<>(promotion, null));
} else if (!cartItems.isEmpty()) {
for (String catalogIndexItem : catalogIndexItems) {
for (CartItem cartItem : cartItems) {
if (catalogIndexItem.equals(cartItem.getProduct().getSKU()))
results.add(new Pair<>(promotion, cartItem));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ protected void onSuccess() {
protected void onFailure(ApiError apiError) {
Snackbar.make(view, getErrorMessage(apiError), Snackbar.LENGTH_SHORT).show();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientConfirmPhoneUpdateFragment;
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientDeleteAccountFragment;
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientGetAccountFragment;
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientGetExternalTokenFragment;
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientGetTokenFragment;
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientRequestPhoneUpdateFragment;
import com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client.ClientUpdateAccountFragment;
Expand Down Expand Up @@ -141,6 +142,8 @@ private Fragment getDevProfileFragment(SyneriseSdkApi syneriseSdkApi) {
return ClientChangePasswordFragment.newInstance();
case CLIENT_GET_TOKEN:
return ClientGetTokenFragment.newInstance();
case CLIENT_GET_EXTERNAL_TOKEN:
return ClientGetExternalTokenFragment.newInstance();
case REQUEST_PHONE_UPDATE:
return ClientRequestPhoneUpdateFragment.newInstance();
case CONFIRM_PHONE_UPDATE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public enum SyneriseSdkApi {
DELETE_ACCOUNT(R.string.delete_account),
CHANGE_PASSWORD(R.string.client_change_password),
CLIENT_GET_TOKEN(R.string.get_token),
CLIENT_PROMOTIONS(R.string.default_promotion_apis, true),
CLIENT_VOUCHERS(R.string.default_vouchers_api, true),
CLIENT_GET_EXTERNAL_TOKEN(R.string.get_external_token),
REQUEST_PHONE_UPDATE(R.string.client_phone_update),
CLIENT_PROMOTIONS(R.string.default_promotion_apis, true),
CONFIRM_PHONE_UPDATE(R.string.client_confirm_phone_update),
CLIENT_VOUCHERS(R.string.default_vouchers_api, true),

// CLIENT PROMOTION API
CLIENT_GET_PROMOTIONS(R.string.client_get_promotions),
Expand Down Expand Up @@ -81,6 +82,8 @@ public int getTitle() {
return title;
}

// ****************************************************************************************************************************************

public boolean isGroup() {
return isGroup;
}
Expand Down Expand Up @@ -119,6 +122,7 @@ public static List<SyneriseSdkApi> getClientApis() {
DELETE_ACCOUNT,
CHANGE_PASSWORD,
CLIENT_GET_TOKEN,
CLIENT_GET_EXTERNAL_TOKEN,
REQUEST_PHONE_UPDATE,
CONFIRM_PHONE_UPDATE,
CLIENT_PROMOTIONS,
Expand All @@ -128,7 +132,9 @@ public static List<SyneriseSdkApi> getClientApis() {
public static List<SyneriseSdkApi> getClientPromotionApis() {
return Arrays.asList(CLIENT_GET_PROMOTIONS,
ACTIVATE_PROMOTION_BY_UUID,
ACTIVATE_PROMOTION_BY_CODE);
ACTIVATE_PROMOTION_BY_CODE,
DEACTIVATE_PROMOTION_BY_CODE,
DEACTIVATE_PROMOTION_BY_UUID);
}

public static List<SyneriseSdkApi> getClientVoucherApis() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.synerise.sdk.sample.ui.dev.apiAdapter.fragments.client;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;

import com.synerise.sdk.client.Client;
import com.synerise.sdk.core.listeners.DataActionListener;
import com.synerise.sdk.core.net.IApiCall;
import com.synerise.sdk.core.utils.ValidationUtils;
import com.synerise.sdk.error.ApiError;
import com.synerise.sdk.sample.R;
import com.synerise.sdk.sample.ui.dev.BaseDevFragment;

public class ClientGetExternalTokenFragment extends BaseDevFragment {

private IApiCall apiCall;
private TextInputLayout inputValue;
private RadioButton radioUuid, radioEmail, radioCustomId;

public static ClientGetExternalTokenFragment newInstance() { return new ClientGetExternalTokenFragment(); }

// ****************************************************************************************************************************************

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_client_get_external_token, container, false);
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

inputValue = view.findViewById(R.id.input_value);
radioUuid = view.findViewById(R.id.radio_uuid);
radioEmail = view.findViewById(R.id.radio_email);
radioCustomId = view.findViewById(R.id.radio_custom_id);
view.findViewById(R.id.create_token_button).setOnClickListener(v -> getPromotions());
}

@Override
public void onStop() {
super.onStop();
if (apiCall != null) apiCall.cancel();
}

// ****************************************************************************************************************************************

@SuppressWarnings("ConstantConditions")
private void getPromotions() {

boolean isValid = true;
inputValue.setError(null);

String value = inputValue.getEditText().getText().toString();

if (ValidationUtils.isEmpty(value)) {
isValid = false;
inputValue.setError(getString(R.string.error_empty));
}

if (isValid) {
if (apiCall != null) apiCall.cancel();
if (radioUuid.isChecked()) {
apiCall = Client.createAuthTokenByUuid(value);
} else if (radioEmail.isChecked()) {
apiCall = Client.createAuthTokenByEmail(value);
} else if (radioCustomId.isChecked()) {
apiCall = Client.createAuthTokenByCustomId(value);
}
apiCall.execute(this::onSuccess, new DataActionListener<ApiError>() {
@Override
public void onDataAction(ApiError apiError) {
ClientGetExternalTokenFragment.this.onFailure(apiError);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/input_uuid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/provide_uuid"
android:hint="@string/default_uuid"
app:errorEnabled="true"
app:hintAnimationEnabled="true">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/input_uuid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/provide_uuid"
android:hint="@string/default_uuid"
app:errorEnabled="true"
app:hintAnimationEnabled="true">

Expand Down
60 changes: 60 additions & 0 deletions sample/src/main/res/layout/fragment_client_get_external_token.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="@dimen/space_large">

<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkedButton="@id/radio_uuid"
android:orientation="vertical">

<RadioButton
android:id="@+id/radio_uuid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_uuid" />

<RadioButton
android:id="@+id/radio_custom_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_custom_id" />

<RadioButton
android:id="@+id/radio_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_email" />

</RadioGroup>

<android.support.design.widget.TextInputLayout
android:id="@+id/input_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_medium"
android:hint="@string/default_client_value"
app:errorEnabled="true"
app:hintAnimationEnabled="true">

<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />

</android.support.design.widget.TextInputLayout>

<Button
android:id="@+id/create_token_button"
style="@style/ButtonPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_medium"
android:text="@string/create_token_button" />

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/input_uuid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/provide_uuid"
android:hint="@string/default_uuid"
app:errorEnabled="true"
app:hintAnimationEnabled="true">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:id="@+id/input_custom_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/provide_custom_id"
android:hint="@string/default_custom_id"
app:errorEnabled="true"
app:hintAnimationEnabled="true">

Expand Down
7 changes: 5 additions & 2 deletions sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -366,12 +366,12 @@
<string name="profile_get_promotions_by_uuid">Promotion by UUID</string>
<string name="provide_external_id">External id</string>
<string name="provide_phone_number">Phone number</string>
<string name="provide_uuid">Uuid</string>
<string name="default_uuid">UUID</string>
<string name="provide_code">Code</string>
<string name="provide_email">Email</string>
<string name="profile_redeem_promotions_by_phone">Redeem by phone</string>
<string name="profile_redeem_promotions_by_client_id">Redeem client id</string>
<string name="provide_custom_id">Custom id</string>
<string name="default_custom_id">Custom ID</string>
<string name="profile_redeem_promotions_by_custom_id">Redeem custom id</string>
<string name="profile_redeem_promotions_by_email">Redeem Email</string>
<string name="provide_promotion_code">Promotion code</string>
Expand Down Expand Up @@ -414,4 +414,7 @@
<string name="default_refreshing_promotions">Refreshing promotions…</string>
<string name="default_activating">Activating…</string>
<string name="available_promotions">Available promotions</string>
<string name="get_external_token">Get external token</string>
<string name="create_token_button">Get external token</string>
<string name="default_client_value">Client value</string>
</resources>

0 comments on commit a7150c7

Please sign in to comment.