Skip to content

Instantly share code, notes, and snippets.

@silmood
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save silmood/5de9971d241a0da6a9fa to your computer and use it in GitHub Desktop.

Select an option

Save silmood/5de9971d241a0da6a9fa to your computer and use it in GitHub Desktop.
Retrofit for Eventful example
public class EventsRequestModel {
public class EventsModelResponse {
@SerializedName(EventfulApiKeys.JSON_KEY_EVENTS)
EventsMainSection eventsMainSection;
public List<EventGson> getListEvents (){
return eventsMainSection.eventsPackage.listEvents;
}
}
private class EventsMainSection {
@SerializedName(EventfulApiKeys.JSON_KEY_PACKAGE_EVENTS)
EventsPackage eventsPackage;
}
private class EventsPackage {
@SerializedName(EventfulApiKeys.JSON_KEY_EVENTS)
List<EventGson> listEvents;
}
public class EventGson {
@SerializedName(EventfulApiKeys.JSON_KEY_TITLE_EVENT)
String title;
@SerializedName(EventfulApiKeys.JSON_KEY_DATE_EVENT)
String date;
@SerializedName(EventfulApiKeys.JSON_KEY_DESCRIPTION_EVENT)
String description;
public String getTitle() {
return title;
}
public String getDate() {
return date;
}
public String getDescription() {
return description;
}
}
}
public class EventfulApiClient {
private EventfulApiContract apiContract;
public EventfulApiClient() {
RestAdapter restAdapter = new RestAdapter.Builder()
.setLogLevel(RestAdapter.LogLevel.BASIC)
.setEndpoint(EventfulApiKeys.BASE_URL)
.build();
apiContract = restAdapter.create(EventfulApiContract.class);
}
public EventfulApiContract getApiContract() {
return apiContract;
}
}
EventfulApiClient retrofitClient = new EventfulApiClient();
retrofitClient.getApiContract().findEvents(EventfulApiKeys.APP_KEY , EventfulApiKeys.VALUE_THIS_WEEK , location,
new Callback<EventsRequestModel.EventsModelResponse>() {
@Override
public void success(EventsRequestModel.EventsModelResponse eventsModelResponse,
retrofit.client.Response response) {
EventsRequestModel.EventGson randomEvent = eventsModelResponse.getListEvents().get(0);
changeEventUI(randomEvent.getTitle(), randomEvent.getDate(), randomEvent.getDescription());
}
@Override
public void failure(RetrofitError error) {
}
});
@GET(EventfulApiKeys.URL_EVENTS_SEARCH)
public void findEvents(@Query(EventfulApiKeys.PARAM_APP_KEY) String appKey ,
@Query(EventfulApiKeys.PARAM_DATE) String date,
@Query(EventfulApiKeys.PARAM_LOCATION) String location,
retrofit.Callback<EventsRequestModel.EventsModelResponse> eventsCallback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment