(feat): add method for get movie info
This commit is contained in:
@@ -11,7 +11,7 @@ public class MovieService {
|
||||
|
||||
private final static String GENRES_URL = "https://moviesapi.ir/api/v1/genres";
|
||||
private static String MOVIES_BY_GENRE_URL = "https://moviesapi.ir/api/v1/genres/";
|
||||
private final static String MOVIE_INFO = "https://moviesapi.ir/api/v1/movies/{movie_id}";//todo fazel
|
||||
private final static String MOVIE_INFO = "https://moviesapi.ir/api/v1/movies/{movie_id}";
|
||||
private final static HttpClient client = HttpClient.newHttpClient();
|
||||
private ArrayList<Movie> moviesList;
|
||||
private ArrayList<Genre> genresList;
|
||||
@@ -61,6 +61,31 @@ public class MovieService {
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getMovieInfo(Long movieId) {
|
||||
try {
|
||||
|
||||
String url = MOVIE_INFO.replace("{movie_id}", movieId.toString());
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(url))
|
||||
.build();
|
||||
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() == 200) {
|
||||
System.out.println("Movie Info received successfully");
|
||||
return response.body();
|
||||
} else {
|
||||
throw new IOException("HTTP error code: " + response.statusCode());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("!!Exception : " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO: Write a method that parses the JSON returned by getGenresList() into a list of Genre objects.
|
||||
// TODO: Write a method that displays the list of genres.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user