forked from kanet77/togglv8
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Roy Mumaw <roy@mudbugmedia.com>
- Loading branch information
Roy Mumaw
committed
Oct 9, 2015
1 parent
3e1fc2e
commit 36113d2
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'faraday' | ||
require 'oj' | ||
|
||
require 'logger' | ||
require 'awesome_print' # for debug output | ||
|
||
require_relative 'reportsv2/summary' | ||
require_relative 'reportsv2/details' | ||
require_relative 'reportsv2/weekly' | ||
|
||
require_relative 'toggl_base_api' | ||
|
||
|
||
# mode: :compat will convert symbols to strings | ||
Oj.default_options = { mode: :compat } | ||
|
||
module ReportsV2 | ||
TOGGL_API_BASE_URL = 'https://www.toggl.com/reports/api/' | ||
|
||
class API | ||
attr_accessor :user_agent | ||
|
||
# Because reports can contain information outside of the 'data' field | ||
# We need to explicitly request the full response for reports | ||
FULL_RESPONSE = true | ||
|
||
def self.toggl_api_url | ||
TOGGL_API_BASE_URL + 'v2/' | ||
end | ||
|
||
def user_agent | ||
@user_agent || super | ||
end | ||
|
||
def get_report(report_type, workspace_id, params={}) | ||
params_string = params.map do |key, value| | ||
if value.is_a? Array | ||
value = value.join('%') | ||
end | ||
"#{key}=#{value}" | ||
end.join('&') | ||
get "#{report_type}?user_agent=#{user_agent}&workspace_id=#{workspace_id}&#{params_string}", FULL_RESPONSE | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ReportsV2 | ||
class API < TogglBaseApi | ||
|
||
def details(workspace_id, params={}) | ||
get_report('details', workspace_id, params) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ReportsV2 | ||
class API < TogglBaseApi | ||
|
||
def summary(workspace_id, params={}) | ||
get_report('summary', workspace_id, params) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module TogglV8 | ||
# :section: | ||
VERSION = "0.2.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ReportsV2 | ||
class API < TogglBaseApi | ||
|
||
def weekly(workspace_id, params={}) | ||
get_report('weekly', workspace_id, params) | ||
end | ||
|
||
end | ||
end |