Class: TogglV8::ReportsV2
- Inherits:
-
Object
- Object
- TogglV8::ReportsV2
- Includes:
- Connection
- Defined in:
- lib/reportsv2.rb
Constant Summary collapse
- REPORTS_V2_URL =
TOGGL_REPORTS_URL + 'v2/'
Constants included from Connection
Connection::API_TOKEN, Connection::DELAY_SEC, Connection::MAX_RETRIES, Connection::TOGGL_FILE
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#workspace_id ⇒ Object
Returns the value of attribute workspace_id.
Instance Method Summary collapse
- #details(extension = '', params = {}) ⇒ Object
- #env ⇒ Object
-
#error400 ⇒ Object
——— :section: Error (for testing).
- #index ⇒ Object
-
#initialize(opts = {}) ⇒ ReportsV2
constructor
A new instance of ReportsV2.
-
#project(project_id, params = {}) ⇒ Object
——— :section: Project Dashboard.
-
#report(type, extension, params) ⇒ Object
extension can be one of [‘.pdf’, ‘.csv’, ‘.xls’].
-
#revision ⇒ Object
——— :section: Miscellaneous information.
- #summary(extension = '', params = {}) ⇒ Object
- #weekly(extension = '', params = {}) ⇒ Object
- #write_details(filename, params = {}) ⇒ Object
-
#write_report(filename) ⇒ Object
——— :section: Write report to file.
- #write_summary(filename, params = {}) ⇒ Object
- #write_weekly(filename, params = {}) ⇒ Object
Methods included from Connection
#_call_api, #delete, #get, open, #post, #put, #requireParams
Methods included from Logging
#debug, included, logger, #logger, logger=
Constructor Details
#initialize(opts = {}) ⇒ ReportsV2
Returns a new instance of ReportsV2.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
9 10 11 |
# File 'lib/reportsv2.rb', line 9 def conn @conn end |
#workspace_id ⇒ Object
Returns the value of attribute workspace_id.
11 12 13 |
# File 'lib/reportsv2.rb', line 11 def workspace_id @workspace_id end |
Instance Method Details
#details(extension = '', params = {}) ⇒ Object
87 88 89 |
# File 'lib/reportsv2.rb', line 87 def details(extension='', params={}) report('details', extension, params) end |
#env ⇒ Object
138 139 140 |
# File 'lib/reportsv2.rb', line 138 def env get "env" end |
#error400 ⇒ Object
:section: Error (for testing)
excludes endpoints ‘error500’ and ‘division_by_zero_error’
173 174 175 |
# File 'lib/reportsv2.rb', line 173 def error400 get "error400" end |
#index ⇒ Object
134 135 136 |
# File 'lib/reportsv2.rb', line 134 def index get "index" end |
#project(project_id, params = {}) ⇒ Object
:section: Project Dashboard
Project dashboard returns at-a-glance information for a single project. This feature is only available with Toggl pro.
user_agent : email, or other way to contact client application developer
(string, *required*)
workspace_id : The workspace whose data you want to access
(integer, *required*)
project_id : The project whose data you want to access
(integer, *required*)
page : number of ‘tasks_page’ you want to fetch
(integer, optional)
order_field string : name/assignee/duration/billable_amount/estimated_seconds order_desc string : on/off, on for descending and off for ascending order
159 160 161 162 163 164 165 166 |
# 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(type, extension, params) ⇒ Object
extension can be one of [‘.pdf’, ‘.csv’, ‘.xls’]. Possibly others?
75 76 77 78 79 80 81 |
# 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 |
#revision ⇒ Object
:section: Miscellaneous information
130 131 132 |
# File 'lib/reportsv2.rb', line 130 def revision get "revision" end |
#summary(extension = '', params = {}) ⇒ Object
91 92 93 |
# File 'lib/reportsv2.rb', line 91 def summary(extension='', params={}) report('summary', extension, params) end |
#weekly(extension = '', params = {}) ⇒ Object
83 84 85 |
# File 'lib/reportsv2.rb', line 83 def weekly(extension='', params={}) report('weekly', extension, params) end |
#write_details(filename, params = {}) ⇒ Object
113 114 115 116 117 |
# File 'lib/reportsv2.rb', line 113 def write_details(filename, params={}) write_report(filename) do |extension| details(extension, params) end end |
#write_report(filename) ⇒ Object
:section: Write report to file
99 100 101 102 103 104 105 |
# 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 = {}) ⇒ Object
119 120 121 122 123 |
# 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 = {}) ⇒ Object
107 108 109 110 111 |
# File 'lib/reportsv2.rb', line 107 def write_weekly(filename, params={}) write_report(filename) do |extension| weekly(extension, params) end end |