Tornex.API (Tornex v0.1.0)

View Source

Core API functionality.

Tornex.API provides the core Torn API-related functionality to make the API calls.

Configuration

Tornex uses compile-time configuration for certain API-related functionality:

  • base_url (default: "https://api.torn.com") => base of the URL the remainder of the request URL is built off of
  • comment (default: "tex/0.1.0") => Comment used in the API calls

To customize one of these, include the following in a config/*.exs:

config :tornex,
  base_url: "https://tornium.com/api/v1",
  comment: "Tornium"

Summary

Types

Options that may be passed to a request function. See request/2 for detailed descriptions.

Functions

Converts a Tornex.Query to the URL required to make the HTTP request.

Performs a blocking HTTP GET request against the Torn API for the Tornex.Query.

Types

error()

@type error() :: {:error, :timeout | :cf_challenge | :unknown | any()}

option()

@type option() ::
  {:method, Tesla.Env.method()}
  | {:url, Tesla.Env.url()}
  | {:query, Tesla.Env.query()}
  | {:headers, Tesla.Env.headers()}
  | {:body, Tesla.Env.body()}
  | {:opts, Tesla.Env.opts()}

Options that may be passed to a request function. See request/2 for detailed descriptions.

return()

@type return() :: list() | map()

Functions

query_to_url(query)

@spec query_to_url(Tornex.Query.t()) :: String.t()

Converts a Tornex.Query to the URL required to make the HTTP request.

iex> query = %Tornex.Query{
...>   resource: "user",
...>   resource_id: 1,
...>   key: "apikey",
...>   key_owner: "apikey",
...>   nice: 10,
...>   selections: ["basic", "discord"]
...> }
iex> Tornex.API.query_to_url(query)
"https://api.torn.com/user/1?selections=basic,discord&key=apikey&comment=tex/0.1.0"

torn_get(query)

@spec torn_get(Tornex.Query.t()) :: map() | list() | error()

Performs a blocking HTTP GET request against the Torn API for the Tornex.Query.

Examples

iex> query = %Tornex.Query{resource: "user", resource_id: 1, key: "", key_owner: 1, nice: 0}
iex> Tornex.API.torn_get(query)
...