Temporal v0.1.3 Temporal.Api
Download files from the interweb
Summary
Functions
Retrieve data from the interwebs using either :get or :post
Encode the provided hash map for the URL
Build the headers for your API
Download a particular file using GET. Optionally provide any required headers
Download a particular file using POST. Optionally provide any required data and headers
Functions
Retrieve data from the interwebs using either :get or :post
Examples
iex> Temporal.Api.call(:get, %{source: "https://raw.githubusercontent.com/aforward/webfiles/master/x.txt"})
{:ok, "A text file\n"}
iex> Temporal.Api.call(:post, %{source: "https://raw.githubusercontent.com/aforward/webfiles/master/x.txt"})
{:error, "Expected a 200, received 400"}
Encode the provided hash map for the URL.
Examples
iex> Temporal.Api.encode_body(%{a: "one", b: "two"})
"a=one&b=two"
iex> Temporal.Api.encode_body(%{a: "o ne"})
"a=o+ne"
iex> Temporal.Api.encode_body(nil, %{a: "o ne"})
"a=o+ne"
iex> Temporal.Api.encode_body("application/x-www-form-urlencoded", %{a: "o ne"})
"a=o+ne"
iex> Temporal.Api.encode_body("application/json", %{a: "b"})
"{\"a\":\"b\"}"
Build the headers for your API
Examples
iex> Temporal.Api.encode_headers(%{content_type: "application/json", bearer: "abc123"})
[{"Authorization", "Bearer abc123"}, {"Content-Type", "application/json"}]
iex> Temporal.Api.encode_headers(%{bearer: "abc123"})
[{"Authorization", "Bearer abc123"}]
iex> Temporal.Api.encode_headers(%{})
[]
iex> Temporal.Api.encode_headers()
[]
iex> Temporal.Api.encode_headers(nil)
[]
Download a particular file using GET. Optionally provide any required headers
Examples
iex> Temporal.Api.get("https://raw.githubusercontent.com/aforward/webfiles/master/x.txt")
{:ok, "A text file\n"}
iex> Temporal.Api.get("https://raw.githubusercontent.com/aforward/webfiles/master/x.txt", %{content_type: "text/html"})
{:ok, "A text file\n"}
iex> Temporal.Api.get("https://raw.githubusercontent.com/aforward/webfiles/master/missing.txt")
{:error, "Expected a 200, received 404"}
iex> Temporal.Api.get("http://localhost:1")
{:error, :econnrefused}
Download a particular file using POST. Optionally provide any required data and headers
Sorry, the examples suck and only show the :error case.
Examples
iex> Temporal.Api.post("https://raw.githubusercontent.com/aforward/webfiles/master/x.txt")
{:error, "Expected a 200, received 400"}
iex> Temporal.Api.post("https://raw.githubusercontent.com/aforward/webfiles/master/x.txt", %{a: "b"})
{:error, "Expected a 200, received 400"}
iex> Temporal.Api.post("https://raw.githubusercontent.com/aforward/webfiles/master/x.txt", %{}, %{body_type: "application/json"})
{:error, "Expected a 200, received 400"}
iex> Temporal.Api.post("http://localhost:1")
{:error, :econnrefused}