ex_gecko v0.0.3 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 fields with the same uniqueId 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 ::
  binary |
  {:form, [{atom, any}]} |
  {:file, binary}
headers ::
  [{binary, binary}] |
  %{optional(binary) => binary}

Functions

append(id, data)

Specs

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

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

Example

auth_header()

Add header with username and also the user agent

build_url(id)

Specs

build_url(String.t) :: String.t

Builds URL based on the resource, id and parameters

build_url(id, arg2)
create_dataset(id, type \\ "reqs")

Specs

create_dataset(String.t, String.t) :: ExGecko.response
create_reqs_dataset(id)

Specs

create_reqs_dataset(String.t) :: ExGecko.response
delete(id)

Specs

delete(String.t) :: Brighterx.response

Wrapper for DELETE requests

Examples

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

Specs

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.

delete!(url, headers \\ [], options \\ [])

Specs

delete!(binary, headers, Keyword.t) ::
  HTTPoison.Response.t |
  HTTPoison.AsyncResponse.t

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)

Specs

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

Specs

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.

get!(url, headers \\ [], options \\ [])

Specs

get!(binary, headers, Keyword.t) ::
  HTTPoison.Response.t |
  HTTPoison.AsyncResponse.t

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 \\ [])

Specs

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.

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

Specs

head!(binary, headers, Keyword.t) ::
  HTTPoison.Response.t |
  HTTPoison.AsyncResponse.t

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)

Specs

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 \\ [])

Specs

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.

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

Specs

options!(binary, headers, Keyword.t) ::
  HTTPoison.Response.t |
  HTTPoison.AsyncResponse.t

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 \\ [])

Specs

patch(binary, body, 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.

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

Specs

patch!(binary, body, 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.

ping()

Specs

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 \\ [])

Specs

post(binary, body, 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.

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

Specs

post!(binary, body, 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.

post_request(id, data, has_data \\ false)

Specs

post_request(String.t, map, boolean) :: ExGecko.response

Wrapper for POST requests

Examples

process_url(path)

Specs

process_url(String.t) :: String.t

Creating URL based on url from config and resources paths

push(widget_key, data)

Specs

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)

Specs

put(String.t, list) :: ExGecko.response
put(url, body, headers \\ [], options \\ [])

Specs

put(binary, body, 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.

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

Specs

put!(binary, body, headers, Keyword.t) ::
  HTTPoison.Response.t |
  HTTPoison.AsyncResponse.t

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 \\ [])

Specs

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 \\ [])

Specs

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)

Specs

update(String.t, map, boolean) :: ExGecko.response

Wrapper for PUT requests

Examples