Tornex.API (Tornex v0.1.1)
View SourceCore 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 ofcomment
(default: "tex/0.1.1") => 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
@type error() :: {:error, :timeout | :cf_challenge | :unknown | any()}
@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.
Functions
@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.1"
@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)
...