Last active
June 29, 2017 20:07
-
-
Save rohans-doordash/c63033d011bd498317d68378d0753504 to your computer and use it in GitHub Desktop.
Fetch restaurant list at a user's default address using Retrofit
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
/** | |
* Fetch the current user's default address | |
*/ | |
public void getUserInfo(int userId) { | |
ddApi.getUserInfo(userId, new Callback<User>() { | |
@Override | |
public void onResponse(@NonNull Call<User> call, | |
@NonNull Response<User> response) { | |
if (response.isSuccessful() && response.body() != null) { | |
User user = response.body(); | |
getRestaurants(user.defaultAddress.lat, user.defaultAddress.lng); | |
} else { | |
// display the error message contained in response.errorBody() | |
} | |
} | |
@Override | |
public void onFailure(@NonNull Call<User> call, @NonNull Throwable t) { | |
// display a network error message | |
} | |
}); | |
} | |
/** | |
* Fetch restaurants at the given location | |
*/ | |
public void getRestaurants(double lat, double lng) { | |
ddApi.getRestaurants(lat, lng, new Callback<List<Restaurant>>() { | |
@Override | |
public void onResponse(@NonNull Call<List<Restaurant>> call, | |
@NonNull Response<List<Restaurant>> response) { | |
if (response.isSuccessful() && response.body() != null) { | |
// update adapter with restaurants | |
} else { | |
// display the error message contained in response.errorBody() | |
} | |
} | |
@Override | |
public void onFailure(@NonNull Call<List<Restaurant>> call, @NonNull Throwable t) { | |
// display a network error message | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment