Aurum.Coinbase.Client (aurum v0.2.0)
Low(er) level API client. This module isn't particularly intended for user consumption. You are probably looking for the module Aurum.Coinbase
instead.
This module generates the middleware needed to provide a valid client, applies the signature function to generate the correct HMAC signature (see Aurum.Coinbase.Sign
), and performs the actual HTTP requests, and unwraps the interesting part of the response body for consumption in the Coinbase
module.
This module is an implementation of the runtime middlware technique outlined in the Tesla docs. Middlware must be generated at runtime in order to properly sign each request, since the Coinbase API requires a unique signature per request. See the Coinbase API Key Authentication method outlined in the docs for details.
Link to this section Summary
Functions
Generate a signed client struct for a DELETE request to this specific path and make the request. Return the resulting JSON as a map if all goes well.
Generate a signed client struct for a GET request to this specific path and make the request. Return the resulting JSON as a map if all goes well.
Provide a list of headers to be used in the Coinbase request.
Generate a list of required middleware for consumption by Client.new/3
.
Generate a new API client struct. This function is will return a signed %Tesla.Client{}
struct that can be used in later HTTP calls.
Generate a signed client struct for a PATCH request to this specific path and with the provided body, then make the request. Return the resulting JSON as a map if all goes well.
Generate a signed client struct for a POST request to this specific path and with the provided body, then make the request. Return the resulting JSON as a map if all goes well.
Generate a signed client struct for a PUT request to this specific path and with the provided body, then make the request. Return the resulting JSON as a map if all goes well.
Assuming the response was successful and able to connect, return the body or the error message produced by the request. This function essentially strips away response metadata and gets to the meat of the response.
Link to this section Functions
delete(path)
Specs
Generate a signed client struct for a DELETE request to this specific path and make the request. Return the resulting JSON as a map if all goes well.
get(path)
Specs
Generate a signed client struct for a GET request to this specific path and make the request. Return the resulting JSON as a map if all goes well.
headers(method, path, body, key_fun \\ &Fetchers.fetch_key/0, sign_fun \\ &Sign.sign/4, timestamp_fun \\ &Fetchers.fetch_timestamp/0)
Specs
headers( method :: String.t(), path :: String.t(), body :: String.t(), key :: String.t(), sign_fun :: (String.t(), String.t(), String.t() -> String.t()), timestamp :: String.t() ) :: [{String.t(), any()}]
Provide a list of headers to be used in the Coinbase request.
This includes information such as:
- The API key
- The timestamp (required for signature verification)
- The signature to be included with the request
middleware(method, path, body, base_url \\ "https://api.coinbase.com", header_fun \\ &headers/3)
Specs
middleware( method :: String.t(), path :: String.t(), body :: String.t(), base_url :: String.t(), header_fun :: (... -> list()) ) :: list()
Generate a list of required middleware for consumption by Client.new/3
.
new(method, path, body \\ "", middleware_fun \\ &middleware/3)
Specs
new( method :: String.t(), path :: String.t(), body :: String.t(), middlware_fun :: (() -> list()) ) :: %Tesla.Client{adapter: term(), fun: term(), post: term(), pre: term()}
Generate a new API client struct. This function is will return a signed %Tesla.Client{}
struct that can be used in later HTTP calls.
patch(path, body)
Specs
Generate a signed client struct for a PATCH request to this specific path and with the provided body, then make the request. Return the resulting JSON as a map if all goes well.
post(path, body)
Specs
Generate a signed client struct for a POST request to this specific path and with the provided body, then make the request. Return the resulting JSON as a map if all goes well.
put(path, body)
Specs
Generate a signed client struct for a PUT request to this specific path and with the provided body, then make the request. Return the resulting JSON as a map if all goes well.
unwrap_response(resp)
Specs
Assuming the response was successful and able to connect, return the body or the error message produced by the request. This function essentially strips away response metadata and gets to the meat of the response.
In all other cases where it is passed something other than {:error, message}
or {:ok, response}
this function will return {:error, resp}
.