You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* refactor request logic
* move the retry logic to the http client
* small cleanup + tests
* remove invalid comment
* add integration test support + IT for TmdbHttpClient
* update comment
It's available via [Maven Central](https://central.sonatype.com/artifact/uk.co.conoregan/themoviedbapi). Just add it as dependency to your project.
36
13
37
14
## Usage
38
15
To register for a TMdB API key, click the [API link](https://www.themoviedb.org/settings/api) from within your account settings page. There are two types of API keys currently provided by TMdB, please ensure you are using the `API Read Access Token` key.
@@ -42,6 +19,9 @@ With this you can instantiate `info.movito.themoviedbapi.TmdbApi`, which has get
42
19
TmdbApi tmdbApi =newTmdbApi("<apikey>");
43
20
```
44
21
22
+
By default this uses the library's built-in HTTP client. If you would rather plug in your own, see
23
+
[Using your own HTTP client](#using-your-own-http-client).
24
+
45
25
### Examples
46
26
#### Get movie details
47
27
```java
@@ -78,7 +58,7 @@ MovieDb movie = tmdbMovies.getDetails(5353, "en-US", MovieAppendToResponse.value
78
58
To find all methods that use append to response, see the `info.movito.themoviedbapi.tools.appendtoresponse.AppendToResponse` interface
79
59
implementations.
80
60
81
-
### Exception Handling
61
+
### Exception handling
82
62
Every API method can throw a `info.movito.themoviedbapi.tools.TmdbException` if the request fails for any reason. You should catch this
We chose to throw exceptions rather than returning `null`, so you have more control over what you do with each failure case. E.g. with the
107
87
example above, you may want to display an error message to the user about failing authentication.
108
88
89
+
### Using your own HTTP client
90
+
By default, `TmdbApi` uses the built-in `info.movito.themoviedbapi.tools.TmdbHttpClient`, which is backed by the JDK's
91
+
`java.net.http.HttpClient`. If you would rather use a different HTTP client, you can provide your own
92
+
implementation of the `info.movito.themoviedbapi.tools.TmdbRequestExecutor` interface.
93
+
94
+
Your implementation only has to make the call and hand back the raw response. If the request fails (e.g. an `IOException`), wrap it in a
95
+
`info.movito.themoviedbapi.tools.TmdbException`. Interpreting TMdB status codes (e.g. mapping unsuccessful responses to exceptions) is handled by the library on top of your executor, so
96
+
you do not need to deal with that (see `info.movito.themoviedbapi.tools.TmdbApiClient` for more information).
97
+
98
+
Then, simply pass your implementation to `TmdbApi` instead of the API key:
0 commit comments