Last active
August 29, 2015 14:15
-
-
Save silmood/5de9971d241a0da6a9fa to your computer and use it in GitHub Desktop.
Retrofit for Eventful example
This file contains hidden or 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 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; | |
| } | |
| } | |
| } |
This file contains hidden or 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 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; | |
| } | |
| } |
This file contains hidden or 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
| 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) { | |
| } | |
| }); |
This file contains hidden or 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
| @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