Home

Awesome

Build Status Coverage Status Inline docs

Togglex

Simple Elixir wrapper for the Toggl API.

Heavily based on ExTracker and Tentacat.

Installation

The package can be installed as:

  1. Add togglex to your list of dependencies in mix.exs:
def deps do
  [{:togglex, "~> 0.1.0"}]
end
  1. Ensure togglex is started before your application:
def application do
  [applications: [:togglex]]
end

Usage

All calls to Toggl APIs must use a Client which contains the access token and the endpoint. The API is splitted in two different parts. The first one is called Toggl API which is essentially a RESTful API that you can use to create, update, delete and get most of the resources from Toggl service. On the other hand there is a read-only Reports API which you can use to obtain aggregated data based on more or less complex queries.

Toggl API examples

Initializing the client for the Toggl API endpoint:

client = Togglex.Client.new(%{access_token: "YOU_ACCESS_TOKEN"}, :api)

Get workspace projects:

Togglex.Api.Workspaces.projects(client, "YOUR_WORKSPACE_ID")

Reports API examples

Initializing the client for the Reports API endpoint:

client = Togglex.Client.new(%{access_token: "YOU_ACCESS_TOKEN"}, :reports)

Getting a detailed report based on some parameters:

Togglex.Reports.detailed(client, %{workspace_id: "YOUR_WORKSPACE_ID", project_ids: "COMMA_SEPARATED_PROJECT_IDS"})

Getting a summarized report based on some parameters:

Togglex.Reports.summary(client, %{workspace_id: "YOUR_WORKSPACE_ID", project_ids: "COMMA_SEPARATED_PROJECT_IDS"})

PDF Reports

Toggl allows you to retrieve reports in PDF format. To do that you only need to call a report function passing :pdf atom as last parameter. The value returned is a binary you can use to write a file:

pdf = Togglex.Reports.summary(client, %{workspace_id: "YOUR_WORKSPACE_ID", project_ids: "COMMA_SEPARATED_PROJECT_IDS"}, :pdf)
File.write!(path, pdf)

Check out in the next section which API calls are already implemented in this wrapper.

Features

Toggl API

Reports API