Created
March 15, 2017 05:46
-
-
Save JaydipZala/e242a55be1881a03cc5167a4568039e9 to your computer and use it in GitHub Desktop.
Okhttp Soap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Soap { | |
private static final String BASE_URL = "base_url"; | |
private static String RESULT_OK = "200"; | |
private static String getAbsiluteURL(String postFixUrl) { | |
return BASE_URL + postFixUrl; | |
} | |
private static String getConnectionErrorResponse(Context context) | |
throws JSONException { | |
JSONObject objRes = new JSONObject(); | |
objRes.put("status", "401"); | |
objRes.put("message", context.getString(R.string.err_network)); | |
return objRes.toString(); | |
} | |
private static String getSoapResponse(Context context, String postFixUrl) | |
throws IOException, JSONException { | |
if (Utils.connectionAvailable(context)) { | |
String url = getAbsiluteURL(postFixUrl); | |
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() | |
.url(url) | |
.build(); | |
Response response = client.newCall(request).execute(); | |
return response.body().string(); | |
} else { | |
return getConnectionErrorResponse(context); | |
} | |
} | |
private static String postSoapResponse(Context context, String postFixUrl, RequestBody formBody) | |
throws IOException, JSONException { | |
if (Utils.connectionAvailable(context)) { | |
String url = getAbsiluteURL(postFixUrl); | |
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() | |
.url(url) | |
.post(formBody) | |
.build(); | |
Response response = client.newCall(request).execute(); | |
String res = response.body().string(); | |
Log.e("res", res); | |
return res; | |
} else { | |
return getConnectionErrorResponse(context); | |
} | |
} | |
public static ParsedResponse apiDrawPath(Context context, String google_map_api_url) | |
throws IOException, JSONException { | |
ParsedResponse p = new ParsedResponse(); | |
if (Utils.connectionAvailable(context)) { | |
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() | |
.url(google_map_api_url) | |
.build(); | |
Response response = client.newCall(request).execute(); | |
String res = response.body().string(); | |
p.error = false; | |
p.o = res; | |
} else { | |
p.error = true; | |
p.o = context.getString(R.string.err_network); | |
} | |
return p; | |
} | |
public static ParsedResponse apiGetLatLng(Context context, String google_geocode_url) | |
throws IOException, JSONException { | |
ParsedResponse p = new ParsedResponse(); | |
if (Utils.connectionAvailable(context)) { | |
OkHttpClient client = new OkHttpClient(); | |
Request request = new Request.Builder() | |
.url(google_geocode_url) | |
.build(); | |
Response response = client.newCall(request).execute(); | |
String res = response.body().string(); | |
p.error = false; | |
p.o = new JSONObject(res).getJSONArray("results").getJSONObject(0).getString("formatted_address"); | |
} else { | |
p.error = true; | |
p.o = context.getString(R.string.err_network); | |
} | |
return p; | |
} | |
public static ParsedResponse selectestimate(Context context, String api_key, String api_secret, String id_user, String dista, String requets) | |
throws IOException, JSONException { | |
ParsedResponse p = new ParsedResponse(); | |
if (Utils.connectionAvailable(context)) { | |
RequestBody formBody = new FormBody.Builder() | |
.add("api_key", api_key) | |
.add("api_secret", api_secret) | |
.add("id_user", id_user) | |
.add("distance_to_customer", dista) | |
.add("requested_services", requets) | |
.build(); | |
String res = postSoapResponse(context, "get-estimate", formBody); | |
p.error = false; | |
p.o = res; | |
} else { | |
p.error = true; | |
p.o = context.getString(R.string.err_network); | |
} | |
return p; | |
} | |
public static ParsedResponse selectinvoice(Context context, String api_key, String api_secret, String id_user, String requets) | |
throws IOException, JSONException { | |
ParsedResponse p = new ParsedResponse(); | |
if (Utils.connectionAvailable(context)) { | |
RequestBody formBody = new FormBody.Builder() | |
.add("api_key", api_key) | |
.add("api_secret", api_secret) | |
.add("id_user", id_user) | |
.add("id_request", requets) | |
.build(); | |
String res = postSoapResponse(context, "get-invoice", formBody); | |
p.error = false; | |
p.o = res; | |
} else { | |
p.error = true; | |
p.o = context.getString(R.string.err_network); | |
} | |
return p; | |
} | |
public static ParsedResponse payment(Context context, String api_key, String api_secret, String id_user, String requets, String payment) | |
throws IOException, JSONException { | |
ParsedResponse p = new ParsedResponse(); | |
if (Utils.connectionAvailable(context)) { | |
RequestBody formBody = new FormBody.Builder() | |
.add("api_key", api_key) | |
.add("api_secret", api_secret) | |
.add("id_user", id_user) | |
.add("id_request", requets) | |
.add("payment_method", payment) | |
.build(); | |
String res = postSoapResponse(context, "add-payment", formBody); | |
p.error = false; | |
p.o = res; | |
} else { | |
p.error = true; | |
p.o = context.getString(R.string.err_network); | |
} | |
return p; | |
} | |
public static ParsedResponse rating(Context context, String api_key, String api_secret, String id_user, String id_driver, String id_request, String rating, String message) | |
throws IOException, JSONException { | |
ParsedResponse p = new ParsedResponse(); | |
if (Utils.connectionAvailable(context)) { | |
RequestBody formBody = new FormBody.Builder() | |
.add("api_key", api_key) | |
.add("api_secret", api_secret) | |
.add("id_user", id_user) | |
.add("id_driver", id_driver) | |
.add("id_request", id_request) | |
.add("rating",rating) | |
.add("rating_notes",message) | |
.build(); | |
String res = postSoapResponse(context, "rate-driver", formBody); | |
p.error = false; | |
p.o = res; | |
} else { | |
p.error = true; | |
p.o = context.getString(R.string.err_network); | |
} | |
return p; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment