class TogglV8::ReportsV2

Constants

REPORTS_V2_URL

Attributes

conn[R]
workspace_id[RW]

Public Class Methods

new(opts={}) click to toggle source
# File lib/reportsv2.rb, line 13
def initialize(opts={})
  debug(false)

  @user_agent = TogglV8::NAME

  username = opts[:api_token]
  if username.nil?
    toggl_api_file = opts[:toggl_api_file] || File.join(Dir.home, TOGGL_FILE)
    if File.exist?(toggl_api_file) then
      username = IO.read(toggl_api_file)
    else
      raise "Expecting one of:\n" +
        " 1) api_token in file #{toggl_api_file}, or\n" +
        " 2) parameter: (toggl_api_file), or\n" +
        " 3) parameter: (api_token), or\n" +
        "\n\tSee https://github.com/kanet77/togglv8#togglv8reportsv2" +
        "\n\tand https://github.com/toggl/toggl_api_docs/blob/master/reports.md#authentication"
    end
  end

  @conn = TogglV8::Connection.open(username, API_TOKEN, REPORTS_V2_URL, opts)
end

Error (for testing)

↑ top

Public Instance Methods

error400() click to toggle source
# File lib/reportsv2.rb, line 173
def error400
  get "error400"
end

Miscellaneous information

↑ top

Public Instance Methods

env() click to toggle source
# File lib/reportsv2.rb, line 138
def env
  get "env"
end
index() click to toggle source
# File lib/reportsv2.rb, line 134
def index
  get "index"
end
revision() click to toggle source
# File lib/reportsv2.rb, line 130
def revision
  get "revision"
end

Project Dashboard

↑ top

Public Instance Methods

project(project_id, params={}) click to toggle source
# File lib/reportsv2.rb, line 159
def project(project_id, params={})
  raise "workspace_id is required" if @workspace_id.nil?
  get "project", {
    'user_agent': @user_agent,
    'workspace_id': @workspace_id,
    'project_id': project_id,
  }.merge(params)
end

Report

↑ top

Public Instance Methods

details(extension='', params={}) click to toggle source
# File lib/reportsv2.rb, line 87
def details(extension='', params={})
  report('details', extension, params)
end
report(type, extension, params) click to toggle source

extension can be one of ['.pdf', '.csv', '.xls']. Possibly others?

# File lib/reportsv2.rb, line 75
def report(type, extension, params)
  raise "workspace_id is required" if @workspace_id.nil?
  get "#{type}#{extension}", {
    'user_agent': @user_agent,
    'workspace_id': @workspace_id,
  }.merge(params)
end
summary(extension='', params={}) click to toggle source
# File lib/reportsv2.rb, line 91
def summary(extension='', params={})
  report('summary', extension, params)
end
weekly(extension='', params={}) click to toggle source
# File lib/reportsv2.rb, line 83
def weekly(extension='', params={})
  report('weekly', extension, params)
end

Write report to file

↑ top

Public Instance Methods

write_details(filename, params={}) click to toggle source
# File lib/reportsv2.rb, line 113
def write_details(filename, params={})
  write_report(filename) do |extension|
    details(extension, params)
  end
end
write_report(filename) { |extension| ... } click to toggle source
# File lib/reportsv2.rb, line 99
def write_report(filename)
  extension = File.extname(filename)
  report = yield(extension)
  File.open(filename, "wb") do |file|
    file.write(report)
  end
end
write_summary(filename, params={}) click to toggle source
# File lib/reportsv2.rb, line 119
def write_summary(filename, params={})
  write_report(filename) do |extension|
    summary(extension, params)
  end
end
write_weekly(filename, params={}) click to toggle source
# File lib/reportsv2.rb, line 107
def write_weekly(filename, params={})
  write_report(filename) do |extension|
    weekly(extension, params)
  end
end