Last active
May 30, 2018 09:25
-
-
Save rmxsantiago/122c7b9fcd89f7bab84778d684f66881 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
{ | |
"genres": [ | |
{ | |
"id": 28, | |
"name": "Action" | |
}, | |
{ | |
"id": 12, | |
"name": "Adventure" | |
}, | |
{ | |
"id": 16, | |
"name": "Animation" | |
}, | |
{ | |
"id": 35, | |
"name": "Comedy" | |
}, | |
{ | |
"id": 80, | |
"name": "Crime" | |
}, | |
{ | |
"id": 99, | |
"name": "Documentary" | |
}, | |
{ | |
"id": 18, | |
"name": "Drama" | |
}, | |
{ | |
"id": 10751, | |
"name": "Family" | |
}, | |
{ | |
"id": 14, | |
"name": "Fantasy" | |
}, | |
{ | |
"id": 36, | |
"name": "History" | |
}, | |
{ | |
"id": 27, | |
"name": "Horror" | |
}, | |
{ | |
"id": 10402, | |
"name": "Music" | |
}, | |
{ | |
"id": 9648, | |
"name": "Mystery" | |
}, | |
{ | |
"id": 10749, | |
"name": "Romance" | |
}, | |
{ | |
"id": 878, | |
"name": "Science Fiction" | |
}, | |
{ | |
"id": 10770, | |
"name": "TV Movie" | |
}, | |
{ | |
"id": 53, | |
"name": "Thriller" | |
}, | |
{ | |
"id": 10752, | |
"name": "War" | |
}, | |
{ | |
"id": 37, | |
"name": "Western" | |
} | |
] | |
} |
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
import retrofit2.Call; | |
import retrofit2.Callback; | |
import retrofit2.Response; | |
import retrofit2.Retrofit; | |
import retrofit2.converter.gson.GsonConverterFactory; | |
import retrofit2.http.GET; | |
import retrofit2.http.Query; | |
import java.util.List; | |
public class Networking implements Callback<Networking.GenreResponse> { | |
private static String BASE_URL = "https://api.themoviedb.org/3/"; | |
private static String API_KEY = "3661f054fd66a3f8a97df3940ff9e3b0"; | |
private static String LANGUAGE = "en-US"; | |
public static void main(String[] args) { | |
Networking networking = new Networking(); | |
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl(BASE_URL) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); | |
TMDBService service = retrofit.create(TMDBService.class); | |
Call<GenreResponse> genreCall = service.listGenre(API_KEY, LANGUAGE); | |
genreCall.enqueue(networking); | |
} | |
@Override | |
public void onResponse(Call<Networking.GenreResponse> call, Response<Networking.GenreResponse> response) { | |
if(response.isSuccessful()) { | |
GenreResponse genreResponse = response.body(); | |
genreResponse.genres.forEach(genre -> System.out.println(genre.getName())); | |
} else { | |
System.out.println(response.errorBody()); | |
} | |
System.exit(0); | |
} | |
@Override | |
public void onFailure(Call<GenreResponse> call, Throwable t) { | |
t.printStackTrace(); | |
System.exit(0); | |
} | |
public interface TMDBService{ | |
@GET("genre/movie/list") | |
Call<GenreResponse> listGenre(@Query("api_key") String api, @Query("language") String lang); | |
} | |
public class GenreResponse{ | |
List<Genre> genres; | |
} | |
public class Genre{ | |
int id; | |
String name; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment