Package se.michaelthelin.spotify
Class SpotifyHttpManager
java.lang.Object
se.michaelthelin.spotify.SpotifyHttpManager
- All Implemented Interfaces:
IHttpManager
Default implementation of the
IHttpManager
interface.
Manages HTTP requests to the Spotify Web API using Apache HttpClient.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder class for creatingSpotifyHttpManager
instances. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new SpotifyHttpManager instance. -
Method Summary
Modifier and TypeMethodDescriptiondelete
(URI uri, org.apache.hc.core5.http.Header[] headers, org.apache.hc.core5.http.HttpEntity body) Perform an HTTP DELETE request to the specified URL.Perform an HTTP GET request to the specified URL.Gets the maximum number of cache entries.Gets the maximum size of cached objects.Gets whether the cache is shared between multiple HTTP clients.org.apache.hc.client5.http.io.HttpClientConnectionManager
Gets the HTTP client connection manager.Gets the connection request timeout in milliseconds.org.apache.hc.core5.http.HttpHost
getProxy()
Gets the HTTP proxy configuration.org.apache.hc.client5.http.auth.UsernamePasswordCredentials
Gets the proxy authentication credentials.Gets the socket timeout in milliseconds.static URI
Creates a URI from a string, handling any syntax exceptions.Perform an HTTP POST request to the specified URL.Perform an HTTP PUT request to the specified URL.
-
Constructor Details
-
SpotifyHttpManager
Construct a new SpotifyHttpManager instance.- Parameters:
builder
- The builder.
-
-
Method Details
-
makeUri
Creates a URI from a string, handling any syntax exceptions.- Parameters:
uriString
- the URI string to parse- Returns:
- the parsed URI, or null if the string is invalid
-
getConnectionManager
public org.apache.hc.client5.http.io.HttpClientConnectionManager getConnectionManager()Gets the HTTP client connection manager.- Returns:
- the connection manager
-
getProxy
public org.apache.hc.core5.http.HttpHost getProxy()Gets the HTTP proxy configuration.- Returns:
- the HTTP proxy host, or null if no proxy is configured
-
getProxyCredentials
public org.apache.hc.client5.http.auth.UsernamePasswordCredentials getProxyCredentials()Gets the proxy authentication credentials.- Returns:
- the proxy credentials, or null if no credentials are configured
-
getCacheMaxEntries
Gets the maximum number of cache entries.- Returns:
- the maximum cache entries
-
getCacheMaxObjectSize
Gets the maximum size of cached objects.- Returns:
- the maximum cache object size
-
getConnectionRequestTimeout
Gets the connection request timeout in milliseconds.- Returns:
- the connection request timeout
-
getSocketTimeout
Gets the socket timeout in milliseconds.- Returns:
- the socket timeout
-
get
public String get(URI uri, org.apache.hc.core5.http.Header[] headers) throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException Description copied from interface:IHttpManager
Perform an HTTP GET request to the specified URL.- Specified by:
get
in interfaceIHttpManager
- Parameters:
uri
- The GET request'sURI
.headers
- The GET request'sHeader
s.- Returns:
- A string containing the GET request's response body.
- Throws:
IOException
- In case of networking issues.SpotifyWebApiException
- The Web API returned an error further specified in this exception's root cause.org.apache.hc.core5.http.ParseException
- The response could not be parsed as a string.
-
post
public String post(URI uri, org.apache.hc.core5.http.Header[] headers, org.apache.hc.core5.http.HttpEntity body) throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException Description copied from interface:IHttpManager
Perform an HTTP POST request to the specified URL.- Specified by:
post
in interfaceIHttpManager
- Parameters:
uri
- The POST request'sURI
.headers
- The POST request'sHeader
s.body
- The PUT request's body as aHttpEntity
.- Returns:
- A string containing the POST request's response body.
- Throws:
IOException
- In case of networking issues.SpotifyWebApiException
- The Web API returned an error further specified in this exception's root cause.org.apache.hc.core5.http.ParseException
- The response could not be parsed as a string.
-
put
public String put(URI uri, org.apache.hc.core5.http.Header[] headers, org.apache.hc.core5.http.HttpEntity body) throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException Description copied from interface:IHttpManager
Perform an HTTP PUT request to the specified URL.- Specified by:
put
in interfaceIHttpManager
- Parameters:
uri
- The PUT request'sURI
.headers
- The PUT request'sHeader
s.body
- The PUT request's body as aHttpEntity
.- Returns:
- A string containing the PUT request's response body.
- Throws:
IOException
- In case of networking issues.SpotifyWebApiException
- The Web API returned an error further specified in this exception's root cause.org.apache.hc.core5.http.ParseException
- The response could not be parsed as a string.
-
delete
public String delete(URI uri, org.apache.hc.core5.http.Header[] headers, org.apache.hc.core5.http.HttpEntity body) throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException Description copied from interface:IHttpManager
Perform an HTTP DELETE request to the specified URL.- Specified by:
delete
in interfaceIHttpManager
- Parameters:
uri
- The DELETE request'sURI
.headers
- The DELETE request'sHeader
s.body
- The DELETE request's body as aHttpEntity
.- Returns:
- A string containing the DELETE request's response body.
- Throws:
IOException
- In case of networking issues.SpotifyWebApiException
- The Web API returned an error further specified in this exception's root cause.org.apache.hc.core5.http.ParseException
- The response could not be parsed as a string.
-