diff --git a/README.md b/README.md index 8887b81..e3f4d6c 100644 --- a/README.md +++ b/README.md @@ -137,14 +137,18 @@ user.getCards().then(new PromiseAction>() { ### Create new card ```java +// You can create a simple card request with just the label and the currency. CardRequest cardRequest = new CardRequest("label", "USD"); user.createCard(cardRequest); + +// Or a card request with the label, currency, position and whether it is starred or not. +CardRequest cardRequest = new CardRequest("label", "USD", new Settings(1, true)); +user.createCard(cardRequest); ``` Handling the success and error flow: ```java -CardRequest cardRequest = new CardRequest("label", "USD"); user.createCard(cardRequest).then(new PromiseAction() { @Override public void call(Card card) { diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java index 2ec6ee7..90a2649 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/UserTest.java @@ -12,6 +12,7 @@ import com.uphold.uphold_android_sdk.model.balance.Currency; import com.uphold.uphold_android_sdk.model.balance.UserBalance; import com.uphold.uphold_android_sdk.model.card.CardRequest; +import com.uphold.uphold_android_sdk.model.card.Settings; import com.uphold.uphold_android_sdk.model.user.Contact; import com.uphold.uphold_android_sdk.model.user.Phone; import com.uphold.uphold_android_sdk.paginator.Paginator; @@ -70,7 +71,7 @@ public Promise call(UpholdRestAdapter adapter) { user.setUpholdRestAdapter(adapter); - return user.createCard(new CardRequest("foo", "BTC")); + return user.createCard(new CardRequest("foo", "BTC", new Settings(7, true))); } }); diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/card/CardRequestTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/card/CardRequestTest.java index 250a432..e813410 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/card/CardRequestTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/model/card/CardRequestTest.java @@ -1,14 +1,16 @@ package com.uphold.uphold_android_sdk.test.integration.model.card; -import junit.framework.Assert; +import android.support.test.runner.AndroidJUnit4; +import android.test.suitebuilder.annotation.SmallTest; import com.uphold.uphold_android_sdk.model.card.CardRequest; +import com.uphold.uphold_android_sdk.model.card.Settings; + +import junit.framework.Assert; + import org.junit.Test; import org.junit.runner.RunWith; -import android.support.test.runner.AndroidJUnit4; -import android.test.suitebuilder.annotation.SmallTest; - /** * CardRequest integration tests. */ @@ -31,4 +33,18 @@ public void getCurrencyShouldReturnTheCurrency() { Assert.assertEquals(cardRequest.getCurrency(), "bar"); } + @Test + public void getSettingsPositionShouldReturnTheSettingsPosition() { + CardRequest cardRequest = new CardRequest("foo", "bar", new Settings(0, true)); + + Assert.assertEquals((int) cardRequest.getSettings().getPosition(), 0); + } + + @Test + public void getSettingsStarredShouldReturnTheSettingsStarred() { + CardRequest cardRequest = new CardRequest("foo", "bar", new Settings(0, true)); + + Assert.assertEquals((boolean) cardRequest.getSettings().getStarred(), true); + } + } diff --git a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java index 24fd942..3ed4110 100644 --- a/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java +++ b/src/app/src/androidTest/java/com/uphold/uphold_android_sdk/test/integration/service/UserCardServiceTest.java @@ -11,6 +11,7 @@ import com.uphold.uphold_android_sdk.model.Card; import com.uphold.uphold_android_sdk.model.Transaction; import com.uphold.uphold_android_sdk.model.card.CardRequest; +import com.uphold.uphold_android_sdk.model.card.Settings; import com.uphold.uphold_android_sdk.model.transaction.TransactionCardDepositRequest; import com.uphold.uphold_android_sdk.model.transaction.TransactionCommitRequest; import com.uphold.uphold_android_sdk.model.transaction.TransactionDenominationRequest; @@ -181,6 +182,28 @@ public Promise call(UpholdRestAdapter upholdRestAdapter) { Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/cards", BuildConfig.API_SERVER_URL)); } + @Test + public void createUserCardWithSettingsShouldReturnTheRequest() throws Exception { + final MockRestAdapter adapter = new MockRestAdapter<>(null, null, null); + + adapter.request(new RepromiseFunction() { + @Override + public Promise call(UpholdRestAdapter upholdRestAdapter) { + UserCardService userCardService = adapter.getRestAdapter().create(UserCardService.class); + RetrofitPromise promise = new RetrofitPromise<>(); + + userCardService.createUserCard(new CardRequest("foo", "bar", new Settings(0, true)), promise); + + return promise; + } + }); + + Request request = adapter.getRequest(); + + Assert.assertEquals(request.getMethod(), "POST"); + Assert.assertEquals(request.getUrl(), String.format("%s/v0/me/cards", BuildConfig.API_SERVER_URL)); + } + @Test public void getUserCardByIdShouldReturnTheRequest() throws Exception { final MockRestAdapter adapter = new MockRestAdapter<>(null, null, null); diff --git a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/card/CardRequest.java b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/card/CardRequest.java index 1c167f3..38aa5fe 100644 --- a/src/app/src/main/java/com/uphold/uphold_android_sdk/model/card/CardRequest.java +++ b/src/app/src/main/java/com/uphold/uphold_android_sdk/model/card/CardRequest.java @@ -10,6 +10,7 @@ public class CardRequest implements Serializable { private final String label; private final String currency; + private final Settings settings; /** * Constructor. @@ -21,6 +22,21 @@ public class CardRequest implements Serializable { public CardRequest(String label, String currency) { this.label = label; this.currency = currency; + this.settings = null; + } + + /** + * Constructor. + * + * @param label The label of the card. + * @param currency The currency of the card. + * @param settings The settings of the card. + */ + + public CardRequest(String label, String currency, Settings settings) { + this.label = label; + this.currency = currency; + this.settings = settings; } /** @@ -43,4 +59,14 @@ public String getCurrency() { return currency; } + /** + * Gets the settings of the card. + * + * @return the settings of the card + */ + + public Settings getSettings() { + return settings; + } + } diff --git a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/card/CardRequestTest.java b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/card/CardRequestTest.java index 6392f6f..f825c82 100644 --- a/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/card/CardRequestTest.java +++ b/src/app/src/test/java/com/uphold/uphold_android_sdk/test/unit/model/card/CardRequestTest.java @@ -1,9 +1,11 @@ package com.uphold.uphold_android_sdk.test.unit.model.card; +import com.uphold.uphold_android_sdk.model.card.CardRequest; +import com.uphold.uphold_android_sdk.model.card.Settings; + import junit.framework.Assert; import org.apache.commons.lang3.SerializationUtils; -import com.uphold.uphold_android_sdk.model.card.CardRequest; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -16,7 +18,7 @@ public class CardRequestTest { @Test - public void shouldBeSerializable() { + public void cardRequestShouldBeSerializable() { CardRequest cardRequest = new CardRequest("foo", "bar"); byte[] serializedCardRequest = SerializationUtils.serialize(cardRequest); CardRequest deserializedCardRequest = SerializationUtils.deserialize(serializedCardRequest); @@ -25,4 +27,16 @@ public void shouldBeSerializable() { Assert.assertEquals(cardRequest.getLabel(), deserializedCardRequest.getLabel()); } + @Test + public void cardRequestWithSettingsshouldBeSerializable() { + CardRequest cardRequest = new CardRequest("foo", "bar", new Settings(0, true)); + byte[] serializedCardRequest = SerializationUtils.serialize(cardRequest); + CardRequest deserializedCardRequest = SerializationUtils.deserialize(serializedCardRequest); + + Assert.assertEquals(cardRequest.getCurrency(), deserializedCardRequest.getCurrency()); + Assert.assertEquals(cardRequest.getLabel(), deserializedCardRequest.getLabel()); + Assert.assertEquals(cardRequest.getSettings().getPosition(), deserializedCardRequest.getSettings().getPosition()); + Assert.assertEquals(cardRequest.getSettings().getStarred(), deserializedCardRequest.getSettings().getStarred()); + } + }