ex_metra v0.1.1 ExMetra.Web

This is the module that interacts with the Metra JSON API. It uses HTTPoison as the base in order to make the actual calls. It will use the same functions as HTTPoison. Because of the fact that it uses the @endpoint as the base of the url, it will only be able to be used to call the Metra API. Do not use this if you are looking to make calls to other websites or services. Do note that basic authorization will already be present in the web calls so it is not necessary to add the headers when making a request. Because Basic Authorization is already included it is important to set the necessary values in your config.exs. The following values must be present in your config.exs for any web calls to be successful:

config :ex_metra, access_key: ““, secret_key: “

Usage: ExMetra.Web.get(url)

Link to this section Summary

Functions

Issues a DELETE request to the given url

Issues a DELETE request to the given url, raising an exception in case of failure

Issues a GET request to the given url

Issues a GET request to the given url, raising an exception in case of failure

Issues a HEAD request to the given url

Issues a HEAD request to the given url, raising an exception in case of failure

Issues an OPTIONS request to the given url

Issues a OPTIONS request to the given url, raising an exception in case of failure

Issues a PATCH request to the given url

Issues a PATCH request to the given url, raising an exception in case of failure

Issues a POST request to the given url

Issues a POST request to the given url, raising an exception in case of failure

Processes the request headers before the actual web call. This is a callback from the HTTPoison.Base. It adds basic authorization into the headers so that it isn’t needed to be entered in any other get calls using this module. It only adds to the headers and does not remove any extra header values so it will not affect any headers that are actually passed in

Processes the url before the actual web call. This is a callback from the HTTPoison.Base. It is used in order to prepend the base url common to all API calls

Issues a PUT request to the given url

Issues a PUT request to the given url, raising an exception in case of failure

Issues an HTTP request with the given method to the given url

Issues an HTTP request with the given method to the given url, raising an exception in case of failure

Starts HTTPoison and its dependencies

Requests the next message to be streamed for a given HTTPoison.AsyncResponse

Link to this section Types

Link to this section Functions

Link to this function delete(url, headers \\ [], options \\ [])
delete(binary(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues a DELETE request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function delete!(url, headers \\ [], options \\ [])

Issues a DELETE request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function get(url, headers \\ [], options \\ [])
get(binary(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues a GET request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function get!(url, headers \\ [], options \\ [])

Issues a GET request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function head(url, headers \\ [], options \\ [])
head(binary(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues a HEAD request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function head!(url, headers \\ [], options \\ [])

Issues a HEAD request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function options(url, headers \\ [], options \\ [])
options(binary(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues an OPTIONS request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function options!(url, headers \\ [], options \\ [])

Issues a OPTIONS request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function patch(url, body, headers \\ [], options \\ [])
patch(binary(), any(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues a PATCH request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function patch!(url, body, headers \\ [], options \\ [])
patch!(binary(), any(), headers(), Keyword.t()) ::
  HTTPoison.Response.t() |
  HTTPoison.AsyncResponse.t()

Issues a PATCH request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function post(url, body, headers \\ [], options \\ [])
post(binary(), any(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues a POST request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function post!(url, body, headers \\ [], options \\ [])
post!(binary(), any(), headers(), Keyword.t()) ::
  HTTPoison.Response.t() |
  HTTPoison.AsyncResponse.t()

Issues a POST request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function process_headers(headers)
Link to this function process_request_body(body)
process_request_body(any()) :: body()
Link to this function process_request_headers(headers)
process_request_headers(Keyword.t()) :: Keyword.t()
process_request_headers(headers()) :: headers()

Processes the request headers before the actual web call. This is a callback from the HTTPoison.Base. It adds basic authorization into the headers so that it isn’t needed to be entered in any other get calls using this module. It only adds to the headers and does not remove any extra header values so it will not affect any headers that are actually passed in

Link to this function process_request_options(options)
Link to this function process_response_body(body)
process_response_body(binary()) :: any()
Link to this function process_response_chunk(chunk)
Link to this function process_status_code(status_code)
Link to this function process_url(url)
process_url(String.t()) :: String.t()

Processes the url before the actual web call. This is a callback from the HTTPoison.Base. It is used in order to prepend the base url common to all API calls

Link to this function put(url, body \\ "", headers \\ [], options \\ [])
put(binary(), any(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues a PUT request to the given url.

Returns {:ok, response} if the request is successful, {:error, reason} otherwise.

See request/5 for more detailed information.

Link to this function put!(url, body \\ "", headers \\ [], options \\ [])

Issues a PUT request to the given url, raising an exception in case of failure.

If the request does not fail, the response is returned.

See request!/5 for more detailed information.

Link to this function request(method, url, body \\ "", headers \\ [], options \\ [])
request(atom(), binary(), any(), headers(), Keyword.t()) ::
  {:ok, HTTPoison.Response.t() | HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Issues an HTTP request with the given method to the given url.

This function is usually used indirectly by get/3, post/4, put/4, etc

Args:

  • method - HTTP method as an atom (:get, :head, :post, :put, :delete, etc.)
  • url - target url as a binary string or char list
  • body - request body. See more below
  • headers - HTTP headers as an orddict (e.g., [{"Accept", "application/json"}])
  • options - Keyword list of options

Body:

  • binary, char list or an iolist
  • {:form, [{K, V}, ...]} - send a form url encoded
  • {:file, "/path/to/file"} - send a file
  • {:stream, enumerable} - lazily send a stream of binaries/charlists

Options:

  • :timeout - timeout to establish a connection, in milliseconds. Default is 8000
  • :recv_timeout - timeout used when receiving a connection. Default is 5000
  • :stream_to - a PID to stream the response to
  • :async - if given :once, will only stream one message at a time, requires call to stream_next
  • :proxy - a proxy to be used for the request; it can be a regular url or a {Host, Port} tuple
  • :proxy_auth - proxy authentication {User, Password} tuple
  • :ssl - SSL options supported by the ssl erlang module
  • :follow_redirect - a boolean that causes redirects to be followed
  • :max_redirect - an integer denoting the maximum number of redirects to follow
  • :params - an enumerable consisting of two-item tuples that will be appended to the url as query string parameters

Timeouts can be an integer or :infinity

This function returns {:ok, response} or {:ok, async_response} if the request is successful, {:error, reason} otherwise.

Examples

request(:post, "https://my.website.com", "{\"foo\": 3}", [{"Accept", "application/json"}])
Link to this function request!(method, url, body \\ "", headers \\ [], options \\ [])
request!(atom(), binary(), any(), headers(), Keyword.t()) :: HTTPoison.Response.t()

Issues an HTTP request with the given method to the given url, raising an exception in case of failure.

request!/5 works exactly like request/5 but it returns just the response in case of a successful request, raising an exception in case the request fails.

Starts HTTPoison and its dependencies.

Link to this function stream_next(resp)
stream_next(HTTPoison.AsyncResponse.t()) ::
  {:ok, HTTPoison.AsyncResponse.t()} |
  {:error, HTTPoison.Error.t()}

Requests the next message to be streamed for a given HTTPoison.AsyncResponse.

See request!/5 for more detailed information.