doex v0.1.1 Doex.Api View Source

Make generic HTTP calls a web service. Please update (or remove) the tests to a sample service in the examples below.

Link to this section Summary

Functions

Retrieve data from the API using either :get or :post

Encode the provided hash map for the URL

Build the headers for your API

Make an API call using GET. Optionally provide any required headers

Make an API call using POST. Optionally provide any required data and headers

Provided the relative path of the Digital Ocean API, resolve the full URL

Link to this section Functions

Retrieve data from the API using either :get or :post

Encode the provided hash map for the URL.

Examples

iex> Doex.Api.encode_body(%{a: "one", b: "two"})
"{\"b\":\"two\",\"a\":\"one\"}"

iex> Doex.Api.encode_body(%{a: "o ne"})
"{\"a\":\"o ne\"}"

iex> Doex.Api.encode_body(nil, %{a: "o ne"})
"{\"a\":\"o ne\"}"

iex> Doex.Api.encode_body("application/x-www-form-urlencoded", %{a: "o ne"})
"a=o+ne"

iex> Doex.Api.encode_body("application/json", %{a: "b"})
"{\"a\":\"b\"}"

Build the headers for your API

Examples

iex> Doex.Api.encode_headers(%{content_type: "application/json", bearer: "abc123"})
[{"Authorization", "Bearer abc123"}, {"Content-Type", "application/json"}]

iex> Doex.Api.encode_headers(%{bearer: "abc123"})
[{"Authorization", "Bearer abc123"}, {"Content-Type", "application/json"}]

iex> Doex.Api.encode_headers(%{})
[{"Authorization", "Bearer FILL_ME_IN"}, {"Content-Type", "application/json"}]

iex> Doex.Api.encode_headers()
[{"Authorization", "Bearer FILL_ME_IN"}, {"Content-Type", "application/json"}]

iex> Doex.Api.encode_headers(nil)
[{"Authorization", "Bearer FILL_ME_IN"}, {"Content-Type", "application/json"}]

Make an API call using GET. Optionally provide any required headers

Link to this macro invoke(piped_in_argument, expr) View Source (macro)

Make an API call using POST. Optionally provide any required data and headers

Link to this function post(source, body, headers) View Source

Provided the relative path of the Digital Ocean API, resolve the full URL

Examples

iex> Doex.Api.resolve_url("/accounts")
"https://api.digitalocean.com/v2/accounts"