Skip to content

Commit 9ad6ac0

Browse files
committed
more code style fixes
1 parent 13c7558 commit 9ad6ac0

15 files changed

+508
-211
lines changed

src/main/java/ug/sparkpl/momoapi/ImproperlyConfiguredException.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
package ug.sparkpl.momoapi;
22

33
public class ImproperlyConfiguredException extends Exception {
4+
/**
5+
* ImproperlyConfiguredException.
6+
*
7+
* @param errorMessage String
8+
*/
49
public ImproperlyConfiguredException(String errorMessage) {
510

611
super(errorMessage);

src/main/java/ug/sparkpl/momoapi/network/BaseClient.java

+34-14
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,21 @@
1010
import com.google.gson.GsonBuilder;
1111

1212
import lombok.NonNull;
13-
import okhttp3.HttpUrl;
1413
import okhttp3.OkHttpClient;
1514
import okhttp3.logging.HttpLoggingInterceptor;
1615
import retrofit2.Retrofit;
1716
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
1817
import retrofit2.converter.gson.GsonConverterFactory;
19-
import rx.Scheduler;
20-
import rx.schedulers.Schedulers;
2118

2219

2320
class BaseClient {
2421

25-
BaseClient() {
26-
27-
}
28-
29-
30-
Scheduler getScheduler() {
31-
return Schedulers.computation();
32-
}
33-
3422

23+
/**
24+
* getGson.
25+
*
26+
* @return Gson
27+
*/
3528
Gson getGson() {
3629
return new GsonBuilder()
3730
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
@@ -40,7 +33,15 @@ Gson getGson() {
4033
}
4134

4235

43-
Retrofit createRetrofit(final @NonNull HttpUrl apiEndpoint, final @NonNull Gson gson,
36+
/**
37+
* create Retrofit.
38+
*
39+
* @param apiEndpoint String
40+
* @param gson Gson
41+
* @param okHttpClient OkHttpClient
42+
* @return Retrofit
43+
*/
44+
Retrofit createRetrofit(final String apiEndpoint, final Gson gson,
4445
final @NonNull OkHttpClient okHttpClient) {
4546
return new Retrofit.Builder()
4647
.client(okHttpClient)
@@ -51,19 +52,38 @@ Retrofit createRetrofit(final @NonNull HttpUrl apiEndpoint, final @NonNull Gson
5152
}
5253

5354

55+
/**
56+
* get Http Logging Interceptor.
57+
*
58+
* @return HttpLoggingInterceptor
59+
*/
5460
HttpLoggingInterceptor getHttpLoggingInterceptor() {
5561
final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
5662
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
5763
return interceptor;
5864
}
5965

6066

67+
/**
68+
* get collections Api Service.
69+
*
70+
* @param apiRetrofit Retrofit.
71+
* @return CollectionsApiService
72+
*/
6173
CollectionsApiService provideCollectionsApiService(final @NonNull Retrofit apiRetrofit) {
6274
return apiRetrofit.create(CollectionsApiService.class);
6375
}
6476

6577

66-
Retrofit getApiRetrofit(final @NonNull HttpUrl apiEndpoint,
78+
/**
79+
* Get Api Retrofit.
80+
*
81+
* @param apiEndpoint String
82+
* @param gson Gson
83+
* @param okHttpClient OkHttpClient
84+
* @return Retrofit
85+
*/
86+
Retrofit getApiRetrofit(final @NonNull String apiEndpoint,
6787
final @NonNull Gson gson,
6888
final @NonNull OkHttpClient okHttpClient) {
6989
return createRetrofit(apiEndpoint, gson, okHttpClient);

src/main/java/ug/sparkpl/momoapi/network/BaseResponse.java

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
public class BaseResponse {
44
private String error = null;
55

6+
/**
7+
* get Error.
8+
*
9+
* @return String
10+
*/
611
public String getError() {
712
return error;
813
}

src/main/java/ug/sparkpl/momoapi/network/MomoApiException.java

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
public final class MomoApiException extends IOException {
99

1010

11+
/**
12+
* MomoApiException.
13+
*
14+
* @param response String
15+
*/
1116
public MomoApiException(String response) {
1217
super(response);
1318

src/main/java/ug/sparkpl/momoapi/network/ResponseException.java

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public ResponseException(final Response response) {
1414
this.response = response;
1515
}
1616

17+
/**
18+
* response.
19+
*
20+
* @return
21+
*/
1722
public Response response() {
1823
return response;
1924
}

src/main/java/ug/sparkpl/momoapi/network/collections/CollectionsApiService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ Call<AccessToken> getToken(@Header("Authorization") String credentials,
6969
/**
7070
* Get Transaction Status.
7171
*
72-
* @param transaction_id String
72+
* @param transactionId String
7373
* @return Transaction object
7474
*/
75-
@GET("/collection/v1_0/requesttopay/{transaction_id}")
75+
@GET("/collection/v1_0/requesttopay/{transactionId}")
7676
@Headers("Content-Type: application/json")
77-
Call<Transaction> getTransactionStatus(@Path("transaction_id") String transaction_id);
77+
Call<Transaction> getTransactionStatus(@Path("transactionId") String transactionId);
7878

7979

8080
/**

src/main/java/ug/sparkpl/momoapi/network/collections/CollectionsAuthorizationInterceptor.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public CollectionsAuthorizationInterceptor(CollectionSession session, RequestOpt
4646
this.opts = opts;
4747
this.logger = Logger.getLogger(CollectionsAuthorizationInterceptor.class.getName());
4848

49-
Gson gson = new GsonBuilder()
49+
final Gson gson = new GsonBuilder()
5050
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
5151
.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter())
5252
.create();
@@ -86,7 +86,7 @@ public CollectionsAuthorizationInterceptor(CollectionSession session, RequestOpt
8686
* request wrapper.
8787
*
8888
* @param initialRequest Request
89-
* @return
89+
* @return Request
9090
*/
9191
private Request request(final Request initialRequest) {
9292

@@ -124,7 +124,8 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
124124
this.logger.log(Level.INFO, "<<<<<<<<<<<<<<<Getting Fresh Token");
125125

126126

127-
String credentials = Credentials.basic(this.opts.getCollectionUserId(), this.opts.getCollectionApiSecret());
127+
String credentials = Credentials.basic(this.opts.getCollectionUserId(),
128+
this.opts.getCollectionApiSecret());
128129
Response<AccessToken> loginResponse = this.apiService
129130
.getToken(credentials, this.opts.getCollectionPrimaryKey()).execute();
130131

@@ -135,15 +136,17 @@ public okhttp3.Response intercept(Chain chain) throws IOException {
135136
this.session.saveToken(token.getToken());
136137
// retry the 'mainRequest' which encountered an authentication error
137138
// add new token into 'mainRequest' header and request again
138-
Request.Builder builder = mainRequest.newBuilder().addHeader("Authorization", "Bearer " + this.session.getToken())
139+
Request.Builder builder = mainRequest.newBuilder().addHeader("Authorization",
140+
"Bearer " + this.session.getToken())
139141
.addHeader("Ocp-Apim-Subscription-Key", this.opts.getCollectionPrimaryKey())
140-
.addHeader("X-Target-Environment", this.opts.getTargetEnvironment()).
141-
method(mainRequest.method(), mainRequest.body());
142+
.addHeader("X-Target-Environment", this.opts.getTargetEnvironment())
143+
.method(mainRequest.method(), mainRequest.body());
142144
mainResponse = chain.proceed(builder.build());
143145
}
144146
} else if (!mainResponse.isSuccessful()) {
145147

146-
this.logger.log(Level.INFO, "<<<<<<<<<<<<<<< ETETETET " + mainResponse.code() + " .." + mainResponse.body().string());
148+
this.logger.log(Level.INFO, "<<<<<<<<<<<<<<< ETETETET "
149+
+ mainResponse.code() + " .." + mainResponse.body().string());
147150

148151

149152
throw new MomoApiException(mainResponse.body().string());

src/main/java/ug/sparkpl/momoapi/network/collections/CollectionsClient.java

+81-30
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
package ug.sparkpl.momoapi.network.collections;
22

3+
import java.io.IOException;
4+
import java.util.HashMap;
5+
import java.util.UUID;
6+
import java.util.concurrent.TimeUnit;
7+
8+
import ug.sparkpl.momoapi.models.AccessToken;
9+
import ug.sparkpl.momoapi.models.Balance;
10+
import ug.sparkpl.momoapi.models.RequestToPay;
11+
import ug.sparkpl.momoapi.models.Transaction;
12+
import ug.sparkpl.momoapi.network.RequestOptions;
13+
import ug.sparkpl.momoapi.utils.DateTimeTypeConverter;
14+
15+
import org.joda.time.DateTime;
16+
317
import com.google.gson.FieldNamingPolicy;
418
import com.google.gson.Gson;
519
import com.google.gson.GsonBuilder;
20+
621
import okhttp3.Credentials;
722
import okhttp3.OkHttpClient;
823
import okhttp3.logging.HttpLoggingInterceptor;
9-
import org.joda.time.DateTime;
1024
import retrofit2.Response;
1125
import retrofit2.Retrofit;
1226
import retrofit2.converter.gson.GsonConverterFactory;
1327
import retrofit2.converter.scalars.ScalarsConverterFactory;
14-
import ug.sparkpl.momoapi.models.AccessToken;
15-
import ug.sparkpl.momoapi.models.Balance;
16-
import ug.sparkpl.momoapi.models.RequestToPay;
17-
import ug.sparkpl.momoapi.models.Transaction;
18-
import ug.sparkpl.momoapi.network.RequestOptions;
19-
import ug.sparkpl.momoapi.utils.DateTimeTypeConverter;
20-
21-
import java.io.IOException;
22-
import java.util.HashMap;
23-
import java.util.UUID;
24-
import java.util.concurrent.TimeUnit;
2528

2629
public class CollectionsClient {
2730

@@ -35,12 +38,17 @@ public class CollectionsClient {
3538
private Retrofit client;
3639

3740

41+
/**
42+
* CollectionsClient.
43+
*
44+
* @param opts RequestOptions
45+
*/
3846
public CollectionsClient(RequestOptions opts) {
3947
this.opts = opts;
4048
this.gson = new GsonBuilder()
41-
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
42-
.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter())
43-
.create();
49+
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
50+
.registerTypeAdapter(DateTime.class, new DateTimeTypeConverter())
51+
.create();
4452

4553
this.session = new CollectionSession();
4654

@@ -64,58 +72,101 @@ public CollectionsClient(RequestOptions opts) {
6472

6573

6674
this.httpClient = okhttpbuilder
67-
.build();
75+
.build();
6876

6977

7078
this.retrofitClient = new Retrofit.Builder()
71-
.client(this.httpClient)
72-
.baseUrl(opts.getBaseUrl())
73-
.addConverterFactory(GsonConverterFactory.create(gson))
74-
.addConverterFactory(ScalarsConverterFactory.create())
75-
.build();
79+
.client(this.httpClient)
80+
.baseUrl(opts.getBaseUrl())
81+
.addConverterFactory(GsonConverterFactory.create(gson))
82+
.addConverterFactory(ScalarsConverterFactory.create())
83+
.build();
7684

7785
this.apiService = this.retrofitClient.create(CollectionsApiService.class);
7886

7987

8088
}
8189

8290

91+
/**
92+
* get access Token.
93+
*
94+
* @return AccessToken
95+
* @throws IOException when there is a network error
96+
*/
8397
public AccessToken getToken() throws IOException {
84-
String credentials = Credentials.basic(this.opts.getCollectionUserId(), this.opts.getCollectionApiSecret());
98+
String credentials = Credentials.basic(this.opts.getCollectionUserId(),
99+
this.opts.getCollectionApiSecret());
85100
Response<AccessToken> token = this.apiService
86-
.getToken(credentials, this.opts.getCollectionPrimaryKey()).execute();
101+
.getToken(credentials, this.opts.getCollectionPrimaryKey()).execute();
87102

88103
return token.body();
89104
}
90105

91106

107+
/**
108+
* get Account Balance.
109+
*
110+
* @return Balance
111+
* @throws IOException when there is a network error
112+
*/
92113
public Balance getBalance() throws IOException {
93114
Response<Balance> balance = this.apiService
94-
.getBalance().execute();
115+
.getBalance().execute();
95116
return balance.body();
96117

97118
}
98119

120+
/**
121+
* get Transaction.
122+
*
123+
* @param ref String
124+
* @return Transaction
125+
* @throws IOException when there is a network error
126+
*/
99127
public Transaction getTransaction(String ref) throws IOException {
100128
Response<Transaction> transaction = this.apiService
101-
.getTransactionStatus(ref).execute();
129+
.getTransactionStatus(ref).execute();
102130
return transaction.body();
103131

104132
}
105133

106134

107-
public String requestToPay(String mobile, String amount, String external_id, String payee_note, String payer_message, String currency) throws IOException {
108-
RequestToPay rBody = new RequestToPay(mobile, amount, external_id, payee_note, payer_message, currency);
135+
/**
136+
* Request To Pay.
137+
*
138+
* @param mobile String
139+
* @param amount String
140+
* @param externalId String
141+
* @param payeeNote String
142+
* @param payerMessage String
143+
* @param currency String
144+
* @return String
145+
* @throws IOException when there is a network error
146+
*/
147+
public String requestToPay(String mobile, String amount, String externalId, String payeeNote,
148+
String payerMessage, String currency) throws IOException {
149+
RequestToPay rbody = new RequestToPay(mobile, amount, externalId,
150+
payeeNote, payerMessage, currency);
109151
String ref = UUID.randomUUID().toString();
110-
this.apiService.requestToPay(rBody, ref).execute();
152+
this.apiService.requestToPay(rbody, ref).execute();
111153
return ref;
112154

113155
}
114156

157+
/**
158+
* Request To Pay.
159+
*
160+
* @param opts HashMap
161+
* @return String
162+
* @throws IOException when there is a network error
163+
*/
115164
public String requestToPay(HashMap<String, String> opts) throws IOException {
116-
RequestToPay rBody = new RequestToPay(opts.get("mobile"), opts.get("amount"), opts.get("externalId"), opts.get("payeeNote"), opts.get("payerMessage"), this.opts.getCurrency());
165+
RequestToPay rbody = new RequestToPay(opts.get("mobile"), opts.get("amount"),
166+
opts.get("externalId"), opts.get("payeeNote"), opts.get("payerMessage"),
167+
this.opts.getCurrency());
117168
String ref = UUID.randomUUID().toString();
118-
this.apiService.requestToPay(rBody, ref).execute();
169+
this.apiService.requestToPay(rbody, ref).execute();
119170
return ref;
120171

121172
}

0 commit comments

Comments
 (0)