Skip to content

Commit c4c1148

Browse files
authored
Release 1.0.0-beta05 (#90)
Added support to List user balance Updated documentation Enhancements
1 parent 28ed676 commit c4c1148

File tree

216 files changed

+6376
-4218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+6376
-4218
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
[1.0.0-beta05](https://github.com/hyperwallet/hyperwallet-android-sdk/releases/tag/1.0.0-beta05)
5+
-------------------
6+
* Added support to list User Balance
7+
* Updated documentation
8+
49
[1.0.0-beta04](https://github.com/hyperwallet/hyperwallet-android-sdk/releases/tag/1.0.0-beta04)
510
-------------------
611
* Added support to create transfers

README.md

Lines changed: 92 additions & 70 deletions
Large diffs are not rendered by default.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ allprojects {
2121
mavenLocal()
2222
}
2323

24-
project.version = "1.0.0-beta04"
24+
project.version = "1.0.0-beta05"
2525
}
2626

2727
task clean(type: Delete) {

core/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ task javadocs(type: Javadoc) {
5151
source = android.sourceSets.main.java.srcDirs
5252
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
5353
failOnError false
54+
options.addStringOption 'Xdoclint:none', '-quiet'
55+
options.addStringOption 'Xmaxwarns', '1'
56+
options.addStringOption 'Xmaxerrs', '1'
57+
options.links "https://docs.oracle.com/javase/8/docs/api"
5458
}
5559

5660
task javadocsJar(type: Jar, dependsOn: javadocs) {

core/src/main/java/com/hyperwallet/android/Configuration.java

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@
3838
import java.util.Date;
3939
import java.util.concurrent.TimeUnit;
4040

41-
class Configuration {
41+
/**
42+
* Authorized user's session {@code Configuration}
43+
*/
44+
public class Configuration {
4245

46+
private static final String INSIGHT_API_URI = "insights-uri";
47+
private static final String ENVIRONMENT = "environment";
4348
private static final String JWT_EXP = "exp";
4449
private static final String JWT_IAT = "iat";
4550
private static final String JWT_ISS = "iss";
@@ -57,7 +62,14 @@ class Configuration {
5762
private String mRestUri;
5863
private String mUserToken;
5964
private long mExpireOnBootTime;
60-
65+
private String mInsightApiUri;
66+
private String mEnvironment;
67+
68+
/**
69+
* Construct {@Configuration} with Authentication token specified
70+
*
71+
* @param token authentication token
72+
*/
6173
public Configuration(@NonNull final String token) throws JSONException {
6274
if (token.isEmpty()) {
6375
throw new IllegalArgumentException();
@@ -66,34 +78,72 @@ public Configuration(@NonNull final String token) throws JSONException {
6678
parseAuthenticationToken();
6779
}
6880

81+
/**
82+
* @return authentication token assigned to this {@code Configuration}
83+
*/
6984
public String getAuthenticationToken() {
7085
return mAuthenticationToken;
7186
}
7287

88+
/**
89+
* @return creation {@link Date} of this {@code Configuration}
90+
*/
7391
public Date getCreatedOn() {
7492
return new Date(mCreatedOn);
7593
}
7694

95+
/**
96+
* @return expiration {@link Date} of this {@code Configuration}
97+
*/
7798
public Date getExpiresOn() {
7899
return new Date(mExpiresOn);
79100
}
80101

102+
/**
103+
* @return GraphQL Api Uri
104+
*/
81105
public String getGraphQlUri() {
82106
return mGraphQlUri;
83107
}
84108

109+
/**
110+
* @return Program token that this {@code Configuration} is linked
111+
*/
85112
public String getProgramToken() {
86113
return mProgramToken;
87114
}
88115

116+
/**
117+
* @return Rest Api Uri
118+
*/
89119
public String getRestUri() {
90120
return mRestUri;
91121
}
92122

123+
/**
124+
* @return User token that this {@code Configuration} is linked
125+
*/
93126
public String getUserToken() {
94127
return mUserToken;
95128
}
96129

130+
/**
131+
* @return Insight Api Uri
132+
*/
133+
public String getInsightApiUri() {
134+
return mInsightApiUri;
135+
}
136+
137+
/**
138+
* @return Platform environment information
139+
*/
140+
public String getEnvironment() {
141+
return mEnvironment;
142+
}
143+
144+
/**
145+
* @return {@code True} if and only if this {@code Configuration} is not stale; otherwise {@code False}
146+
*/
97147
public boolean isStale() {
98148
return SystemClock.elapsedRealtime() >= mExpireOnBootTime - STALE_PERIOD;
99149
}
@@ -129,6 +179,7 @@ private void parsePayload(String payload) throws JSONException {
129179
mUserToken = jsonObject.getString(JWT_SUB);
130180
long tokenLifespan = mExpiresOn - mCreatedOn;
131181
mExpireOnBootTime = SystemClock.elapsedRealtime() + tokenLifespan;
182+
mEnvironment = jsonObject.optString(ENVIRONMENT);
183+
mInsightApiUri = jsonObject.optString(INSIGHT_API_URI);
132184
}
133-
134185
}

core/src/main/java/com/hyperwallet/android/ExceptionMapper.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
import androidx.annotation.RestrictTo;
2121
import androidx.annotation.StringRes;
2222

23-
import com.hyperwallet.android.exception.AuthenticationTokenProviderException;
23+
import com.hyperwallet.android.exception.HyperwalletAuthenticationTokenProviderException;
2424
import com.hyperwallet.android.exception.HyperwalletException;
2525
import com.hyperwallet.android.exception.HyperwalletGqlException;
2626
import com.hyperwallet.android.exception.HyperwalletJsonParseException;
2727
import com.hyperwallet.android.exception.HyperwalletRestException;
28-
import com.hyperwallet.android.model.HyperwalletError;
29-
import com.hyperwallet.android.model.HyperwalletErrors;
28+
import com.hyperwallet.android.model.Error;
29+
import com.hyperwallet.android.model.Errors;
3030
import com.hyperwallet.android.sdk.R;
3131

3232
import org.json.JSONException;
@@ -53,14 +53,14 @@ public final class ExceptionMapper {
5353
public static final String EC_UNEXPECTED_EXCEPTION = "EC_UNEXPECTED_EXCEPTION";
5454

5555
/**
56-
* Converts a {@code HyperwalletException} containing a {@link HyperwalletErrors} object that is derived from the
56+
* Converts a {@code HyperwalletException} containing a {@link Errors} object that is derived from the
5757
* {@code Exception} parameter or the REST/GraphQL response.
5858
*
5959
* <p>If an exception does not have a mapping defined the exception is created with the default error code,
6060
* {@code "EC_UNEXPECTED_EXCEPTION"}.</p>
6161
*
6262
* @param exception the {@code Exception} to be converted
63-
* @return a {@code HyperwalletException} containing a {code HyperwalletErrors} object
63+
* @return a {@code HyperwalletException} containing a {code Errors} object
6464
*/
6565
public static HyperwalletException toHyperwalletException(@NonNull final Exception exception) {
6666
if (exception instanceof HyperwalletGqlException) {
@@ -75,7 +75,7 @@ public static HyperwalletException toHyperwalletException(@NonNull final Excepti
7575
return initHyperwalletException(R.string.json_exception, EC_JSON_EXCEPTION, exception);
7676
} else if (exception instanceof HyperwalletJsonParseException) {
7777
return initHyperwalletException(R.string.json_parse_exception, EC_JSON_PARSE_EXCEPTION, exception);
78-
} else if (exception instanceof AuthenticationTokenProviderException) {
78+
} else if (exception instanceof HyperwalletAuthenticationTokenProviderException) {
7979
return initHyperwalletException(R.string.authentication_token_provider_exception,
8080
EC_AUTHENTICATION_TOKEN_PROVIDER_EXCEPTION, exception);
8181
} else {
@@ -85,10 +85,10 @@ public static HyperwalletException toHyperwalletException(@NonNull final Excepti
8585

8686
private static HyperwalletException initHyperwalletException(@StringRes int stringResourceId,
8787
@NonNull final String code, @NonNull final Throwable throwable) {
88-
HyperwalletError error = new HyperwalletError(stringResourceId, code);
89-
List<HyperwalletError> errorList = new ArrayList<>();
88+
Error error = new Error(stringResourceId, code);
89+
List<Error> errorList = new ArrayList<>();
9090
errorList.add(error);
91-
HyperwalletErrors errors = new HyperwalletErrors(errorList);
91+
Errors errors = new Errors(errorList);
9292
return new HyperwalletException(throwable, errors);
9393
}
9494
}

core/src/main/java/com/hyperwallet/android/GqlTransaction.java

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.hyperwallet.android.listener.HyperwalletListener;
2424
import com.hyperwallet.android.model.TypeReference;
2525
import com.hyperwallet.android.model.graphql.error.GqlErrors;
26-
import com.hyperwallet.android.model.graphql.query.HyperwalletGqlQuery;
26+
import com.hyperwallet.android.model.graphql.query.GqlQuery;
2727
import com.hyperwallet.android.util.HttpClient;
2828
import com.hyperwallet.android.util.HttpMethod;
2929
import com.hyperwallet.android.util.JsonUtils;
@@ -33,19 +33,41 @@
3333
import java.io.IOException;
3434
import java.lang.reflect.InvocationTargetException;
3535

36+
/**
37+
* {@code GqlTransaction} HTTP transaction service that sends request
38+
* to Hyperwallet GQL platform api
39+
*/
3640
class GqlTransaction extends HttpTransaction {
3741

42+
/**
43+
* Construct a {@code GqlTransaction} object based on specified required parameters
44+
*
45+
* @param uri GQL uri
46+
* @param body request query information
47+
* @param authenticationToken authentication token assigned during authentication flow
48+
* @param hyperwalletListener callback information please refer to {@link HyperwalletListener}
49+
* @param typeReference The class type reference to use in order to deserialize response into Hyperwallet SDK
50+
* object
51+
*/
3852
private GqlTransaction(@NonNull final String uri, @NonNull final String body,
39-
@NonNull final HyperwalletListener hyperwalletListener, @NonNull final TypeReference typeReference) {
53+
@NonNull final String authenticationToken, @NonNull final HyperwalletListener hyperwalletListener,
54+
@NonNull final TypeReference typeReference) {
4055
super(HttpMethod.POST, uri, typeReference, hyperwalletListener);
56+
addHeader(HTTP_HEADER_AUTHORIZATION, AUTHENTICATION_STRATEGY + authenticationToken);
4157
setPayload(body);
4258
}
4359

60+
/**
61+
* Refer to {@link HttpTransaction#performRequest(HttpClient)}
62+
*/
4463
@Override
4564
protected int performRequest(final @NonNull HttpClient client) throws IOException {
4665
return client.post(getPayload());
4766
}
4867

68+
/**
69+
* Refer to {@link HttpTransaction#handleErrors(int, String)}
70+
*/
4971
@Override
5072
protected void handleErrors(final int responseCode, @NonNull final String response) throws JSONException,
5173
InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
@@ -54,22 +76,33 @@ protected void handleErrors(final int responseCode, @NonNull final String respon
5476
onFailure(new HyperwalletGqlException(gqlErrors));
5577
}
5678

57-
protected final static class Builder<T> {
58-
private final HyperwalletGqlQuery gqlQuery;
79+
/**
80+
* Builder for {@link GqlTransaction}
81+
*/
82+
protected static final class Builder<T> {
83+
private final GqlQuery gqlQuery;
5984
private final TypeReference<T> typeReference;
6085
private final HyperwalletListener listener;
6186

62-
protected Builder(@NonNull final HyperwalletGqlQuery gqlQuery,
87+
/**
88+
* Construct a builder based on parameters
89+
*
90+
* @param gqlQuery GQL query information
91+
* @param typeReference Response type generator result
92+
* @param listener callback object; refer to {@link HyperwalletListener}
93+
*/
94+
protected Builder(@NonNull final GqlQuery gqlQuery,
6395
@NonNull final TypeReference<T> typeReference,
6496
@NonNull final HyperwalletListener listener) {
6597
this.gqlQuery = gqlQuery;
6698
this.typeReference = typeReference;
6799
this.listener = listener;
68100
}
69101

70-
protected GqlTransaction build(@NonNull final String uri, @NonNull final String userToken) {
102+
protected GqlTransaction build(@NonNull final String uri, @NonNull final String userToken,
103+
@NonNull final String authenticationToken) {
71104
String query = gqlQuery.toQuery(userToken);
72-
return new GqlTransaction(uri, query, listener, typeReference);
105+
return new GqlTransaction(uri, query, authenticationToken, listener, typeReference);
73106
}
74107
}
75108
}

core/src/main/java/com/hyperwallet/android/HttpTransaction.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
*/
1717
package com.hyperwallet.android;
1818

19+
import android.os.Build;
20+
1921
import androidx.annotation.NonNull;
2022
import androidx.annotation.VisibleForTesting;
2123

2224
import com.hyperwallet.android.listener.HyperwalletListener;
2325
import com.hyperwallet.android.model.TypeReference;
26+
import com.hyperwallet.android.sdk.BuildConfig;
2427
import com.hyperwallet.android.util.HttpClient;
2528
import com.hyperwallet.android.util.HttpMethod;
2629
import com.hyperwallet.android.util.JsonUtils;
@@ -32,13 +35,19 @@
3235
import java.util.HashMap;
3336
import java.util.Map;
3437

38+
/**
39+
* {@code HttpTransaction} HTTP transaction service that sends request
40+
* to Hyperwallet API platforms
41+
*/
3542
public abstract class HttpTransaction implements Runnable {
3643

3744
protected static final String AUTHENTICATION_STRATEGY = "Bearer ";
3845
protected static final String HTTP_HEADER_AUTHORIZATION = "Authorization";
3946
private static final String APPLICATION_JSON = "application/json";
4047
private static final String HTTP_HEADER_ACCEPT_KEY = "Accept";
4148
private static final String HTTP_HEADER_CONTENT_TYPE_KEY = "Content-Type";
49+
private static final String HTTP_HEADER_USER_AGENT_KEY = "User-Agent";
50+
private static final String HTTP_HEADER_USER_AGENT = "HyperwalletSDK/Android/%s; App: HyperwalletSDK; Android: %s";
4251
private Map<String, String> mHeaderMap;
4352
private HyperwalletListener mListener;
4453
private HttpMethod mMethod;
@@ -48,6 +57,14 @@ public abstract class HttpTransaction implements Runnable {
4857
private String mUri;
4958
private TypeReference mTypeReference;
5059

60+
/**
61+
* Construct a {@code HttpTransaction} object based from specified required parameters
62+
*
63+
* @param httpMethod Http method to use; refer to {@link HttpMethod}
64+
* @param uri location of api
65+
* @param typeReference Response type generator result
66+
* @param httpListener callback object; refer to {@link HyperwalletListener}
67+
*/
5168
public HttpTransaction(@NonNull final HttpMethod httpMethod, @NonNull final String uri,
5269
@NonNull final TypeReference typeReference,
5370
@NonNull final HyperwalletListener httpListener) {
@@ -60,8 +77,12 @@ public HttpTransaction(@NonNull final HttpMethod httpMethod, @NonNull final Stri
6077

6178
addHeader(HTTP_HEADER_ACCEPT_KEY, APPLICATION_JSON);
6279
addHeader(HTTP_HEADER_CONTENT_TYPE_KEY, APPLICATION_JSON);
80+
addHeader(HTTP_HEADER_USER_AGENT_KEY, getUserAgent());
6381
}
6482

83+
/**
84+
* Background execution
85+
*/
6586
public void run() {
6687
try {
6788
HttpClient client = new HttpClient.Builder(mUri).path(mPath).putHeaders(getHeaders()).putQueries(
@@ -80,9 +101,27 @@ public void run() {
80101
}
81102
}
82103

104+
/**
105+
* Process errors, if available, from the resulting HTTP request
106+
*
107+
* @param responseCode HTTP response code
108+
* @param response Serialized HTTP response
109+
* @throws JSONException
110+
* @throws InvocationTargetException
111+
* @throws NoSuchMethodException
112+
* @throws InstantiationException
113+
* @throws IllegalAccessException
114+
*/
83115
protected abstract void handleErrors(int responseCode, String response) throws JSONException,
84116
InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException;
85117

118+
/**
119+
* Perform HTTP request
120+
*
121+
* @param client Http client to use for this operation {@link HttpClient}
122+
* @return HTTP response code
123+
* @throws IOException
124+
*/
86125
protected abstract int performRequest(HttpClient client) throws IOException;
87126

88127
public HyperwalletListener getListener() {
@@ -166,4 +205,8 @@ public void run() {
166205
});
167206
}
168207
}
208+
209+
private String getUserAgent() {
210+
return String.format(HTTP_HEADER_USER_AGENT, BuildConfig.VERSION_NAME, Build.VERSION.RELEASE);
211+
}
169212
}

0 commit comments

Comments
 (0)