Class OreAPI

java.lang.Object
net.smoofyuniverse.ore.OreAPI

public class OreAPI extends Object
A wrapper for Ore API.
  • Field Details

    • DEFAULT_URL

      public static final URL DEFAULT_URL
      The default base URL.
    • USER_AGENT

      public static final String USER_AGENT
      The user agent used when connecting.
      See Also:
    • urlBase

      public final URL urlBase
      The base URL for endpoints.
    • sessionManager

      public final SessionManager sessionManager
      The session manager.
    • gson

      public final com.google.gson.Gson gson
      The Gson.
  • Constructor Details

    • OreAPI

      public OreAPI()
      Creates a wrapper using default URL and no API key.
    • OreAPI

      public OreAPI(URL urlBase, String apiKey)
      Creates a wrapper.
      Parameters:
      urlBase - The base URL.
      apiKey - The API key.
    • OreAPI

      public OreAPI(URL urlBase, String apiKey, com.google.gson.Gson gson)
      Creates a wrapper.
      Parameters:
      urlBase - The base URL.
      apiKey - The API key.
      gson - The Gson.
  • Method Details

    • getUncheckedURL

      public URL getUncheckedURL(String path)
      Gets the URL for the given endpoint. MalformedURLException is wrapped in a UncheckedIOException.
      Parameters:
      path - The path of the endpoint.
      Returns:
      The URL.
    • getURL

      public URL getURL(String path) throws MalformedURLException
      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

      public HttpURLConnection openConnection(String path) throws IOException
      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

      public void configureSession(URLConnection co) throws IOException
      Sets the session header of the connection.
      Parameters:
      co - The connection.
      Throws:
      IOException - if an I/O error occurs.
    • configureConnection

      public static void configureConnection(URLConnection co)
      Configures the URL connection. Disables cache and sets user agent.
      Parameters:
      co - The URL connection.
    • parseInstant

      public static Instant parseInstant(String value)
      Parses an instant from a string in the DateTimeFormatter.ISO_OFFSET_DATE_TIME format.
      Parameters:
      value - The string.
      Returns:
      The instant.
    • parseOffsetDateTime

      public static TemporalAccessor parseOffsetDateTime(String value)
      Parses a temporal accessor from a string in the DateTimeFormatter.ISO_OFFSET_DATE_TIME format.
      Parameters:
      value - The string.
      Returns:
      The temporal accessor.