Skip to content

Commit ad54983

Browse files
committed
Inject Gson in NetworkRequestImpl Class
1 parent 56bbd86 commit ad54983

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

raveandroid/src/main/java/com/flutterwave/raveandroid/data/NetworkRequestImpl.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@ public class NetworkRequestImpl implements DataRequest.NetworkRequest {
3737

3838
Retrofit retrofit;
3939
ApiService service;
40+
Gson gson;
4041
private String errorParsingError = "An error occurred parsing the error response";
4142

4243
@Inject
43-
public NetworkRequestImpl(Retrofit retrofit, ApiService service) {
44+
public NetworkRequestImpl(Retrofit retrofit, ApiService service, Gson gson) {
4445
this.retrofit = retrofit;
4546
this.service = service;
47+
this.gson = gson;
4648
}
4749

4850
public NetworkRequestImpl() {
@@ -52,7 +54,6 @@ public NetworkRequestImpl() {
5254
private ErrorBody parseErrorJson(String errorStr) {
5355

5456
try {
55-
Gson gson = new Gson();
5657
Type type = new TypeToken<ErrorBody>() {
5758
}.getType();
5859
return gson.fromJson(errorStr, type);
@@ -75,7 +76,6 @@ public void chargeCard(ChargeRequestBody body, final Callbacks.OnChargeRequestCo
7576
public void onResponse(Call<String> call, Response<String> response) {
7677

7778
if (response.isSuccessful()) {
78-
Gson gson = new Gson();
7979
Type type = new TypeToken<ChargeResponse>() {}.getType();
8080
ChargeResponse chargeResponse = gson.fromJson(response.body(), type);
8181
callback.onSuccess(chargeResponse, response.body());
@@ -111,7 +111,6 @@ public void chargeMobileMoneyWallet(ChargeRequestBody body, final Callbacks.OnGh
111111
public void onResponse(Call<String> call, Response<String> response) {
112112

113113
if (response.isSuccessful()) {
114-
Gson gson = new Gson();
115114
Type type = new TypeToken<MobileMoneyChargeResponse>() {
116115
}.getType();
117116
MobileMoneyChargeResponse chargeResponse = gson.fromJson(response.body(), type);
@@ -147,7 +146,6 @@ public void validateChargeCard(ValidateChargeBody body, final Callbacks.OnValida
147146
@Override
148147
public void onResponse(Call<String> call, Response<String> response) {
149148
if (response.isSuccessful()) {
150-
Gson gson = new Gson();
151149
Type type = new TypeToken<ChargeResponse>() {}.getType();
152150
ChargeResponse chargeResponse = gson.fromJson(response.body(), type);
153151
callback.onSuccess(chargeResponse, response.body());
@@ -182,7 +180,6 @@ public void validateAccountCard(ValidateChargeBody body, final Callbacks.OnValid
182180
@Override
183181
public void onResponse(Call<String> call, Response<String> response) {
184182
if (response.isSuccessful()) {
185-
Gson gson = new Gson();
186183
Type type = new TypeToken<ChargeResponse>() {}.getType();
187184
ChargeResponse chargeResponse = gson.fromJson(response.body(), type);
188185
callback.onSuccess(chargeResponse, response.body()); }
@@ -228,7 +225,6 @@ public void onResponse(Call<String> call, Response<String> response) {
228225
} catch (JSONException e) {
229226
e.printStackTrace();
230227
}
231-
Gson gson = new Gson();
232228
Type type = new TypeToken<RequeryResponsev2>() {}.getType();
233229
RequeryResponsev2 requeryResponse = gson.fromJson(jsonResponse, type);
234230
callback.onSuccess(requeryResponse, jsonResponse);
@@ -273,7 +269,6 @@ public void onResponse(Call<String> call, Response<String> response) {
273269
} catch (JSONException e) {
274270
e.printStackTrace();
275271
}
276-
Gson gson = new Gson();
277272
Type type = new TypeToken<RequeryResponse>() {}.getType();
278273
RequeryResponse requeryResponse = gson.fromJson(jsonResponse, type);
279274
callback.onSuccess(requeryResponse, jsonResponse);
@@ -318,7 +313,6 @@ public void onResponse(Call<String> call, Response<String> response) {
318313
} catch (JSONException e) {
319314
e.printStackTrace();
320315
}
321-
Gson gson = new Gson();
322316
Type type = new TypeToken<RequeryResponse>() {}.getType();
323317
RequeryResponse requeryResponse = gson.fromJson(jsonResponse, type);
324318
callback.onSuccess(requeryResponse, jsonResponse);
@@ -384,7 +378,6 @@ public void chargeAccount(ChargeRequestBody body, final Callbacks.OnChargeReques
384378
@Override
385379
public void onResponse(Call<String> call, Response<String> response) {
386380
if (response.isSuccessful()) {
387-
Gson gson = new Gson();
388381
Type type = new TypeToken<ChargeResponse>() {}.getType();
389382
ChargeResponse chargeResponse = gson.fromJson(response.body(), type);
390383
callback.onSuccess(chargeResponse, response.body());
@@ -420,7 +413,7 @@ public void chargeToken(Payload payload, final Callbacks.OnChargeRequestComplete
420413
public void onResponse(Call<String> call, Response<String> response) {
421414

422415
if (response.isSuccessful()) {
423-
Gson gson = new Gson();
416+
424417
Type type = new TypeToken<ChargeResponse>() {}.getType();
425418
ChargeResponse chargeResponse = gson.fromJson(response.body(), type);
426419
callback.onSuccess(chargeResponse, response.body());

0 commit comments

Comments
 (0)