Package net.smoofyuniverse.ore
Class OreAPI
java.lang.Object
net.smoofyuniverse.ore.OreAPI
A wrapper for Ore API.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final URLThe default base URL.final com.google.gson.GsonThe Gson.final SessionManagerThe session manager.final URLThe base URL for endpoints.static final StringThe user agent used when connecting. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidConfigures the URL connection.voidSets the session header of the connection.getUncheckedURL(String path) Gets the URL for the given endpoint.Gets the URL for the given endpoint.openConnection(String path) Opens and configures an HTTP connection to the given endpoint.static InstantparseInstant(String value) Parses an instant from a string in theDateTimeFormatter.ISO_OFFSET_DATE_TIMEformat.static TemporalAccessorparseOffsetDateTime(String value) Parses a temporal accessor from a string in theDateTimeFormatter.ISO_OFFSET_DATE_TIMEformat.
-
Field Details
-
DEFAULT_URL
The default base URL. -
USER_AGENT
The user agent used when connecting.- See Also:
-
urlBase
The base URL for endpoints. -
sessionManager
The session manager. -
gson
public final com.google.gson.Gson gsonThe Gson.
-
-
Constructor Details
-
OreAPI
public OreAPI()Creates a wrapper using default URL and no API key. -
OreAPI
Creates a wrapper.- Parameters:
urlBase- The base URL.apiKey- The API key.
-
OreAPI
Creates a wrapper.- Parameters:
urlBase- The base URL.apiKey- The API key.gson- The Gson.
-
-
Method Details
-
getUncheckedURL
Gets the URL for the given endpoint.MalformedURLExceptionis wrapped in aUncheckedIOException.- Parameters:
path- The path of the endpoint.- Returns:
- The URL.
-
getURL
Gets the URL for the given endpoint.- Parameters:
path- The path of the endpoint.- Returns:
- The URL.
- Throws:
MalformedURLException- if the generated URL is invalid.
-
openConnection
Opens and configures an HTTP connection to the given endpoint.- Parameters:
path- The path of the endpoint.- Returns:
- The HTTP connection.
- Throws:
IOException- if an I/O error occurs.
-
configureSession
Sets the session header of the connection.- Parameters:
co- The connection.- Throws:
IOException- if an I/O error occurs.
-
configureConnection
Configures the URL connection. Disables cache and sets user agent.- Parameters:
co- The URL connection.
-
parseInstant
Parses an instant from a string in theDateTimeFormatter.ISO_OFFSET_DATE_TIMEformat.- Parameters:
value- The string.- Returns:
- The instant.
-
parseOffsetDateTime
Parses a temporal accessor from a string in theDateTimeFormatter.ISO_OFFSET_DATE_TIMEformat.- Parameters:
value- The string.- Returns:
- The temporal accessor.
-