ex_gecko v0.1.0 ExGecko.Api

API interface to communicate with geckoboard’s api

Todo: refactor code so that we can move auth part to single place

Summary

Functions

Appends data to an existing dataset. If the dataset contains a unique id field, then any existing records in the dataset with the same unique id will be updated

Add header with username and also the user agent

Builds URL based on the resource, id and parameters

Wrapper for DELETE requests

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

Convenience function to manage datasets. Follows similar syntax as this https://developer-beta.geckoboard.com/nodejs/

Issues a POST request to the given url

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

Wrapper for POST requests

Creating URL based on url from config and resources paths

Push API to Geckoboard, which is a POST with this data format

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

Wrapper for PUT requests

Types

body()
body() :: binary | {:form, [{atom, any}]} | {:file, binary}
headers()
headers ::
  [{binary, binary}] |
  %{optional(binary) => binary}

Functions

append(id, data)
append(String.t, map) :: ExGecko.response

Appends data to an existing dataset. If the dataset contains a unique id field, then any existing records in the dataset with the same unique id will be updated.

Example

auth_header()

Add header with username and also the user agent

build_url(id)
build_url(String.t) :: String.t

Builds URL based on the resource, id and parameters

build_url(id, arg2)
create_dataset(id, type \\ "reqs")
create_dataset(String.t, String.t) :: ExGecko.response
create_reqs_dataset(id)
create_reqs_dataset(String.t) :: ExGecko.response
delete(id)
delete(String.t) :: Brighterx.response

Wrapper for DELETE requests

Examples

  • ExGecko.Api.delete(“mydataset”)
delete(url, headers \\ [], options \\ [])

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.

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.

find_or_create(id, fields)
find_or_create(String.t, map) :: ExGecko.response
format_status(status)
get(url, headers \\ [], options \\ [])

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.

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.

head(url, headers \\ [], options \\ [])

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.

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.

limit_data(events)
limit_data(list) :: list

Examples

iex> Mix.Tasks.LoadData.limit_data(Enum.to_list(1..500)) === Enum.to_list(101..500)
true
options(url, headers \\ [], options \\ [])

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.

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.

patch(url, body, headers \\ [], options \\ [])

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.

patch!(url, body, headers \\ [], options \\ [])

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.

ping()
ping() :: ExGecko.response

Convenience function to manage datasets. Follows similar syntax as this https://developer-beta.geckoboard.com/nodejs/

Examples

  • ExGecko.Api.find_or_create - finds or creates the dataset
  • ExGecko.Api.put - replaces all data in the dataset
  • ExGecko.Api.delete - deletes the dataset and data therein
post(url, body, headers \\ [], options \\ [])

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.

post!(url, body, headers \\ [], options \\ [])

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.

post_request(id, data, has_data \\ false)
post_request(String.t, map, boolean) :: ExGecko.response

Wrapper for POST requests

Examples

process_url(path)
process_url(String.t) :: String.t

Creating URL based on url from config and resources paths

push(widget_key, data)
push(String.t, map) :: ExGecko.response

Push API to Geckoboard, which is a POST with this data format

{
  "api_key": "222f66ab58130a8ece8ccd7be57f12e2",
  "data": {
     "item": [
        { "text": "Visitors", "value": 4223 },
        { "text": "", "value": 238 }
      ]
  }
}
push_monitor(widget_key, status, down_time \\ "", response_time \\ "")

Monitor format expected from geckoboard

{
  "status": "Up",
  "downTime": "9 days ago",
  "responseTime": "593 ms"
}

{
  "status": "Down",
  "downTime": "2 days ago",
  "responseTime": "593 ms"
}
put(id, data)
put(String.t, list) :: ExGecko.response
put(url, body, headers \\ [], options \\ [])

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.

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.

request(method, url, body \\ "", headers \\ [], options \\ [])
request(atom, binary, body, 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

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
  • :proxy - a proxy to be used for the request; it can be a regular url or a {Host, Proxy} 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"}])
request!(method, url, body \\ "", headers \\ [], options \\ [])
request!(atom, binary, body, 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.

request_header()
request_header_content_type()
start()

Starts HTTPoison and its dependencies.

update(id, put_data, data \\ false)
update(String.t, map, boolean) :: ExGecko.response

Wrapper for PUT requests

Examples