-
Notifications
You must be signed in to change notification settings - Fork 2
/
API.java
58 lines (54 loc) · 1.83 KB
/
API.java
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package First;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import com.google.gson.Gson;
/**
* API class enables us to use TMDB API’s [] functionalities such as getting movie info, search movies.
* A JFrame class for the LogIn part of the program
* @author Isil Irem TEKES
* @version 4.36
*/
public class API {
public static void main(String[] args) throws IOException {
Movie film = getMovie(121);
System.out.println(film.original_title);
}
/**
*
* @param id get the id of the films to call all of them
* @return
* @throws IOException
*/
public static Movie getMovie(int id) throws IOException{
Gson gson = new Gson();
String line = "";
URL oracle = new URL("http://api.themoviedb.org/3/movie/" + id +"?api_key=9db8f0074c1ed1366f321eceb1d42bf0");
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
line+=inputLine;
Movie m = gson.fromJson(line, Movie.class);
return m;
}
/**
*
* @param m words for search
* @return
* @throws IOException
*/
public static Movies searchMovie(String m) throws IOException{
Gson gson = new Gson();
String line = "";
URL oracle = new URL("http://api.themoviedb.org/3/search/movie?api_key=9db8f0074c1ed1366f321eceb1d42bf0&query=" + m );
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
line+=inputLine;
Movies mov = gson.fromJson(line,Movies.class);
return mov;
}
}