Skip to content

Commit 2a5bc48

Browse files
committed
1. Modified Api service class.
2. Changed the return value for makeApiCall method. 3. Rename method getBitmapData to getBitmapImageFromServer.
1 parent 3d3f854 commit 2a5bc48

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

app/src/main/java/com/amit/api/ApiServices.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.amit.api;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.graphics.Bitmap;
56
import android.graphics.BitmapFactory;
@@ -18,16 +19,16 @@
1819
import java.net.HttpURLConnection;
1920
import java.net.URL;
2021

21-
/*
22-
* Created By AMIT JANGID
23-
* 2018 April 17 - Tuesday - 12:56 PM
22+
/**
23+
* Created By AMIT JANGID
24+
* 2018 April 17 - Tuesday - 12:56 PM
2425
**/
25-
26+
@SuppressWarnings("unused")
27+
@SuppressLint("HardwareIds")
2628
public class ApiServices
2729
{
2830
private static final String TAG = ApiServices.class.getSimpleName();
2931

30-
public int mResponseCode = 0;
3132
private String apiPath, mDeviceID;
3233
private SharedPreferenceData sharedPreferenceData;
3334

@@ -130,13 +131,13 @@ private String capitalizeString(String string)
130131
* - if the api requires token then this has to be true
131132
* - if the api doesn't require token then this has to be false
132133
*
133-
* @return String which contains result from API.
134+
* @return Pair of integer and string which contains response value and response code from the server
134135
*
135136
************************************************************************************************
136137
**/
137-
public String makeAPICall(final String apiName, final String requestMethod,
138-
final boolean parameters, final JSONObject values,
139-
final boolean hasToken)
138+
public Pair<Integer, String> makeAPICall(final String apiName, final String requestMethod,
139+
final boolean parameters, final JSONObject values,
140+
final boolean hasToken)
140141
{
141142
try
142143
{
@@ -155,7 +156,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
155156
Log.e(TAG, "makeAPICall: x-access-token is: " + sharedPreferenceData.getValue("token"));
156157
}
157158

158-
httpURLConnection.setConnectTimeout(10000);
159+
// httpURLConnection.setConnectTimeout(10000);
159160
httpURLConnection.setRequestProperty("Connection", "close");
160161
Log.e(TAG, "makeAPICall: api = " + url + " values = " + values);
161162

@@ -169,8 +170,6 @@ public String makeAPICall(final String apiName, final String requestMethod,
169170
}
170171

171172
int responseCode = httpURLConnection.getResponseCode();
172-
mResponseCode = responseCode;
173-
Log.e(TAG, "makeAPICall: response code from api is: " + mResponseCode);
174173

175174
if (responseCode == 200)
176175
{
@@ -185,6 +184,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
185184

186185
bufferedReader.close();
187186
result = stringBuilder.toString();
187+
httpURLConnection.disconnect();
188188
Log.e(TAG, "makeAPICall: result from server is: " + result);
189189
}
190190
else
@@ -206,7 +206,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
206206
httpURLConnection.disconnect();
207207
}
208208

209-
return result;
209+
return new Pair<>(responseCode, result);
210210
}
211211
catch (Exception e)
212212
{
@@ -217,7 +217,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
217217
}
218218

219219
/**
220-
* Get Bitmap Data
220+
* Get Bitmap Image from Server method
221221
*
222222
* this method gets bitmap image from the server
223223
* this can be used to download the image from server or api
@@ -233,7 +233,7 @@ public String makeAPICall(final String apiName, final String requestMethod,
233233
* and bitmap will be the file uploaded.
234234
*
235235
**/
236-
public Pair<Integer, Bitmap> getBitmapData(String apiPath, String requestType, String parameter)
236+
public Pair<Integer, Bitmap> getBitmapImageFromServer(String apiPath, String requestType, String parameter)
237237
{
238238
Bitmap resultVal = null;
239239
InputStream iStream ;

0 commit comments

Comments
 (0)