Last active
August 1, 2021 09:22
-
-
Save whoisprakhar/ef41748486d2aa67407933febedfe8ed to your computer and use it in GitHub Desktop.
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
package ddev.yobo.app.api; | |
import android.util.Log; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import com.google.gson.reflect.TypeToken; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
import retrofit.Callback; | |
import retrofit.RestAdapter; | |
import retrofit.RetrofitError; | |
import retrofit.client.Response; | |
import retrofit.http.GET; | |
import retrofit.http.QueryMap; | |
import retrofit.mime.TypedByteArray; | |
/** | |
* Created by Ddev on 6/25/2016. | |
*/ | |
public class TestEndpoint { | |
public final String BaseEndpoint = "http://108.healthifyme.com"; | |
public final String QueryParams = "username=alok@x.coz&api_key=a4aeb4e27f27b5786828f6cdf0" + | |
"0d8d2cb44fe6d7&vc=276&expert_username=neha@healthifyme.com&format=json"; | |
private Map<String, String> params = new HashMap<>(); | |
TestService service; | |
public TestEndpoint() { | |
for (String pair : QueryParams.split("&")) { | |
String[] kv = pair.split("="); | |
params.put(kv[0], kv[1]); | |
} | |
service = new RestAdapter.Builder().setEndpoint(BaseEndpoint) | |
.setLogLevel(RestAdapter.LogLevel.FULL) | |
.build().create(TestService.class); | |
service.getSlots(params, new Callback<Response>() { | |
@Override | |
public void success(Response cb, Response response) { | |
String payload = new String(((TypedByteArray) response.getBody()).getBytes()); | |
try { | |
JSONObject slots = new JSONObject(payload).getJSONObject("slots"); | |
Iterator<String> keys = slots.keys(); | |
Gson gson = new Gson(); | |
Map<String, Map<String, List<SlotDetail>>> result = new HashMap<>(); | |
while (keys.hasNext()) { | |
String date = keys.next(); | |
JSONObject slot = slots.getJSONObject(date); | |
Iterator<String> slot_keys = slot.keys(); | |
HashMap<String, List<SlotDetail>> data = new HashMap<>(); | |
while (slot_keys.hasNext()) { | |
String time = slot_keys.next(), | |
timings = slot.getJSONArray(time).toString(); | |
List<SlotDetail> slot_details = gson.fromJson(timings, | |
new TypeToken<List<SlotDetail>>(){}.getType()); | |
data.put(time, slot_details); | |
} | |
result.put(date, data); | |
} | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public void failure(RetrofitError error) { | |
} | |
}); | |
} | |
private interface TestService { | |
@GET("/api/v1/booking/slots/all") | |
void getSlots(@QueryMap Map<String, String> qp, | |
Callback<SlotsCallback> cb); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment