module Sfctl::Toggl::Client

Constants

DEFAULT_API_PATH
REPORTS_API_PATH

Public Class Methods

conn(token, api = 'default') click to toggle source
# File lib/sfctl/toggl/client.rb, line 10
def self.conn(token, api = 'default')
  raise 'Please set toggl provider before continue.' if token.nil?

  api_path = api == 'reports' ? REPORTS_API_PATH : DEFAULT_API_PATH

  headers = { 'Content-Type' => 'application/json' }
  Faraday.new(url: "https://#{token}:api_token@api.track.toggl.com/#{api_path}", headers: headers) do |builder|
    builder.request :retry
    builder.adapter :net_http
  end
end
parsed_response(response) click to toggle source
# File lib/sfctl/toggl/client.rb, line 22
def self.parsed_response(response)
  [response.status == 200, JSON.parse(response.body)]
end
project_tasks(token, project_id) click to toggle source
# File lib/sfctl/toggl/client.rb, line 36
def self.project_tasks(token, project_id)
  response = conn(token).get("workspaces/#{project_id}/tasks")

  return [] if response.body.length.zero?

  parsed_response(response)
end
time_entries(token, params) click to toggle source
# File lib/sfctl/toggl/client.rb, line 44
def self.time_entries(token, params)
  params[:user_agent] = 'api_test'
  response = conn(token, 'reports').get('details', params)
  parsed_response(response)
end
workspace_projects(token, workspace_id) click to toggle source
# File lib/sfctl/toggl/client.rb, line 31
def self.workspace_projects(token, workspace_id)
  response = conn(token).get("workspaces/#{workspace_id}/projects")
  parsed_response(response)
end
workspaces(token) click to toggle source
# File lib/sfctl/toggl/client.rb, line 26
def self.workspaces(token)
  response = conn(token).get('workspaces')
  parsed_response(response)
end