-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImdbApiClient.java
More file actions
41 lines (33 loc) · 1.17 KB
/
ImdbApiClient.java
File metadata and controls
41 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ImdbApiClient implements APIClient {
private static final String IMDB_API_URL = "https://imdb-api.com/API/";
private final String apiKey;
public ImdbApiClient(String apiKey) {
this.apiKey = apiKey;
}
public String getBody() {
try {
HttpRequest request = HttpRequest
.newBuilder()
.uri(new URI(IMDB_API_URL + "Top250Movies/" + this.apiKey))
.GET()
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
return response.body();
} catch (URISyntaxException | InterruptedException | IOException e) {
System.out.println("ERROR: " + e.getMessage());
e.printStackTrace();
return "";
}
}
@Override
public Class<? extends Content> type() {
return Movie.class;
}
}