toggl_api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +20 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +48 -0
  7. data/Rakefile +1 -0
  8. data/lib/toggl_api.rb +7 -0
  9. data/lib/toggl_api/api/client.rb +42 -0
  10. data/lib/toggl_api/api/project.rb +46 -0
  11. data/lib/toggl_api/api/project_user.rb +38 -0
  12. data/lib/toggl_api/api/tag.rb +24 -0
  13. data/lib/toggl_api/api/task.rb +38 -0
  14. data/lib/toggl_api/api/time_entry.rb +73 -0
  15. data/lib/toggl_api/api/user.rb +46 -0
  16. data/lib/toggl_api/api/workspace.rb +36 -0
  17. data/lib/toggl_api/api/workspace_user.rb +32 -0
  18. data/lib/toggl_api/base.rb +39 -0
  19. data/lib/toggl_api/error.rb +8 -0
  20. data/lib/toggl_api/report.rb +30 -0
  21. data/lib/toggl_api/request.rb +100 -0
  22. data/lib/toggl_api/version.rb +3 -0
  23. data/test/base_test.rb +38 -0
  24. data/test/fixtures/authentication.json +44 -0
  25. data/test/fixtures/bulk_update_tasks.json +24 -0
  26. data/test/fixtures/bulk_update_time_entries.json +29 -0
  27. data/test/fixtures/client.json +11 -0
  28. data/test/fixtures/client_projects.json +21 -0
  29. data/test/fixtures/clients.json +15 -0
  30. data/test/fixtures/create_client.json +8 -0
  31. data/test/fixtures/create_project.json +13 -0
  32. data/test/fixtures/create_project_user.json +0 -0
  33. data/test/fixtures/create_tag.json +7 -0
  34. data/test/fixtures/create_task.json +10 -0
  35. data/test/fixtures/create_time_entry.json +13 -0
  36. data/test/fixtures/invite_users_to_workspace.json +12 -0
  37. data/test/fixtures/project.json +13 -0
  38. data/test/fixtures/project_users.json +18 -0
  39. data/test/fixtures/relations_of_workspace_and_user.json +22 -0
  40. data/test/fixtures/report_failure.json +8 -0
  41. data/test/fixtures/report_success.json +6 -0
  42. data/test/fixtures/reset_api_token.json +2 -0
  43. data/test/fixtures/signup.json +19 -0
  44. data/test/fixtures/start_time_entry.json +13 -0
  45. data/test/fixtures/stop_time_entry.json +13 -0
  46. data/test/fixtures/task.json +10 -0
  47. data/test/fixtures/time_entries.json +24 -0
  48. data/test/fixtures/time_entry.json +15 -0
  49. data/test/fixtures/update_client.json +9 -0
  50. data/test/fixtures/update_project.json +12 -0
  51. data/test/fixtures/update_project_user.json +0 -0
  52. data/test/fixtures/update_tag.json +7 -0
  53. data/test/fixtures/update_task.json +13 -0
  54. data/test/fixtures/update_time_entry.json +15 -0
  55. data/test/fixtures/update_user.json +31 -0
  56. data/test/fixtures/update_workspace_user.json +9 -0
  57. data/test/fixtures/workspace_clients.json +19 -0
  58. data/test/fixtures/workspace_projects.json +21 -0
  59. data/test/fixtures/workspace_tasks.json +29 -0
  60. data/test/fixtures/workspace_users.json +47 -0
  61. data/test/fixtures/workspaces.json +12 -0
  62. data/test/helper.rb +10 -0
  63. data/test/test_client.rb +51 -0
  64. data/test/test_project.rb +94 -0
  65. data/test/test_report.rb +53 -0
  66. data/test/test_tag.rb +30 -0
  67. data/test/test_task.rb +51 -0
  68. data/test/test_time_entry.rb +69 -0
  69. data/test/test_user.rb +53 -0
  70. data/test/test_workspace.rb +72 -0
  71. data/toggl_api.gemspec +30 -0
  72. metadata +260 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c85d613997879ceca21022bec6c8cf78a0e9938
4
+ data.tar.gz: 463fdeecfe329b23d3a1a742db36f75df98fbe55
5
+ SHA512:
6
+ metadata.gz: 8acad8db1ca172e743b2b21e50374b5b4fe226ea39165c89ce71b548471533849e6910a7f6600c5b2cf3b3d8b23a77e64539c407b7e14882c82ecf80371f19a5
7
+ data.tar.gz: 6c0d282164bc046e159c4ce1e6f8eacbdc9f41594ca5a64037ff77f131b6f98a6b7d319a711a60727c6124091d7fd0c3d5ed19b296e82139b848995fec940ba9
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://ruby.taobao.org'
2
+
3
+ # Specify your gem's dependencies in toggl_api.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Kang Wen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kang Wen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ Toggl API Ruby Client
2
+ =======
3
+ # TogglApi
4
+
5
+ A Ruby interface to the [Toggl](https://github.com/toggl/toggl_api_docs/blob/master/toggl_api.md) and [Reports](https://github.com/toggl/toggl_api_docs/blob/master/reports.md) API
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'toggl_api'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install toggl_api
20
+
21
+ ## Usage
22
+
23
+ ### Base Api
24
+
25
+ base = Toggl::Base.new "2a9800b95ef1d8d2b61d630f5df448f8"
26
+
27
+ base.me(true) ##will return current user data with related data, default is false
28
+
29
+ base.time_entries(Date.today) ##return today's entries
30
+
31
+ entries = base.time_entries(Date.today - 1, Date.today) ##return yesterday's entries
32
+ entries.first.description ##get description for the first entry
33
+
34
+ ### Report Api
35
+
36
+ report = Toggl::Report.new "2a9800b95ef1d8d2b61d630f5df448f8"
37
+
38
+ report.weekly('wid')
39
+ report.details('wid')
40
+ report.summary('wid')
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ require 'multi_json'
2
+ require 'faraday'
3
+ require 'hashie'
4
+
5
+ require "toggl_api/version"
6
+ require 'toggl_api/base'
7
+ require 'toggl_api/report'
@@ -0,0 +1,42 @@
1
+ module Toggl
2
+ module Api
3
+ module Client
4
+
5
+ #*name*: The name of the client (string, required, unique in workspace)
6
+ #*wid*: workspace ID, where the client will be used (integer, required)
7
+ # notes: Notes for the client (string, not required)
8
+ # hrate: The hourly rate for this client (float, not required, available only for pro workspaces)
9
+ # cur: The name of the client's currency (string, not required, available only for pro workspaces)
10
+ # at: timestamp that is sent in the response, indicates the time client was last updated
11
+
12
+ def create_client(name, wid,options={})
13
+ post "/clients", {"client" => {"name"=>name,"wid"=>wid}.merge(options)}
14
+ end
15
+
16
+ def get_client(cid)
17
+ get "/clients/#{cid}"
18
+ end
19
+ alias :client :get_client
20
+
21
+ def get_clients
22
+ get "/clients"
23
+ end
24
+ alias :clients :get_clients
25
+
26
+ def get_client_projects(cid,active=true)
27
+ get "clients/#{cid}/projects",{:active => active}
28
+ end
29
+ alias :client_projects :get_client_projects
30
+
31
+ def update_client(cid,options)
32
+ options = Hashie::Mash.new options
33
+ put "/clients/#{cid}", (options.key?(:client) ? options : {:client => options})
34
+ end
35
+
36
+ def delete_client(cid)
37
+ delete "/clients/#{cid}"
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,46 @@
1
+ module Toggl
2
+ module Api
3
+ module Project
4
+
5
+ # *name*: The name of the project (string, required, unique for client and workspace)
6
+ # *wid*: workspace ID, where the project will be saved (integer, required)
7
+ # cid: client ID(integer, not required)
8
+ # active: whether the project is archived or not (boolean, by default true)
9
+ # is_private: whether project is accessible for only project users or for all workspace users (boolean, default true)
10
+ # template: whether the project can be used as a template (boolean, not required)
11
+ # template_id: id of the template project used on current project's creation
12
+ # billable: whether the project is billable or not (boolean, default true, available only for pro workspaces)
13
+ # auto_estimates: whether the esitamated hours is calculated based on task esimations or is fixed manually(boolean, default false, not required, premium functionality)
14
+ # estimated_hours: if auto_estimates is true then the sum of task estimations is returned, otherwise user inserted hours (integer, not required, premium functionality)
15
+ # at: timestamp that is sent in the response for PUT, indicates the time task was last updated
16
+
17
+ def create_project(name, wid, options={})
18
+ post "/projects", {"project" =>{"name"=>name,"wid"=>wid}.merge(options)}
19
+ end
20
+
21
+ def update_project(pid, option)
22
+ options = Hashie::Mash.new options
23
+ put "/projects/#{pid}", (options.key?(:project) ? options : {:project => options})
24
+ end
25
+
26
+ def get_project(pid)
27
+ get "/projects/#{pid}"
28
+ end
29
+
30
+ alias :project :get_project
31
+
32
+ def get_project_users(pid)
33
+ get "/projects/#{pid}/project_users"
34
+ end
35
+ alias :project_users :get_project_users
36
+
37
+ def delete_project(pid)
38
+ pid = pid.join(',') if pid.is_a?(Array)
39
+ delete "/projects/#{pid}"
40
+ end
41
+
42
+ alias :bulk_delete_projects :delete_project
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ module Toggl
2
+ module Api
3
+ module ProjectUser
4
+
5
+ # *pid*: project ID (integer, required)
6
+ # *uid*: user ID, who is added to the project (integer, required)
7
+ # wid: workspace ID, where the project belongs to (integer, not-required, project's workspace id is used)
8
+ # manager: admin rights for this project (boolean, default false)
9
+ # rate: hourly rate for the project user (float, not-required, only for pro workspaces) in the currency of the project's client or in workspace default currency.
10
+ # at: timestamp that is sent in the response, indicates when the project user was last updated
11
+ #
12
+ # #Workspace id (wid), project id (pid) and user id (uid) can't be changed on update.
13
+
14
+ def create_project_user(pid,uids,options={})
15
+ uids = uids.join(',') if uids.is_a? Array
16
+ post "/project_users", {"project_user"=>{"pid"=>pid,"uid"=>uids,"fields"=>"fullname"}.merge(options)}
17
+ end
18
+
19
+ alias :bulk_create_project_users :create_project_user
20
+
21
+ def update_project_user(uids, options)
22
+ options = Hashie::Mash.new options
23
+ options.merge!({"fields" => "fullname"})
24
+ uids = uids.join(',') if uids.is_a? Array
25
+ put "/project_users/#{uids}", (options.key?(:project_user) ? options : {:project_user => options})
26
+ end
27
+
28
+ alias :bulk_update_project_users :update_project_user
29
+
30
+ def delete_project_user(uids)
31
+ uids = uids.join(',') if uids.is_a? Array
32
+ delete "/project_users/#{uids}"
33
+ end
34
+
35
+ alias :bulk_delete_project_users :delete_project_user
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ module Toggl
2
+ module Api
3
+ module Tag
4
+
5
+ # *name*: The name of the tag (string, required, unique in workspace)
6
+ # *wid*: workspace ID, where the tag will be used (integer, required)
7
+
8
+ def create_tag(name,wid)
9
+ post "/tags", {"tag" => {"name" => name,"wid" =>wid}}
10
+ end
11
+
12
+ #tag wid can't be changed.
13
+ #only name can be updated
14
+ def update_tag_name(tag_id, name)
15
+ put "/tags/#{tag_id}", {"tag" => {"name" => name}}
16
+ end
17
+
18
+ def delete_tag(tag_id)
19
+ delete "/tags/#{tag_id}"
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ module Toggl
2
+ module Api
3
+ module Task
4
+
5
+ # *name*: The name of the task (string, required, unique in project)
6
+ # *pid*: project ID for the task (integer, required)
7
+ # wid: workspace ID, where the task will be saved (integer, project's workspace id is used when not supplied)
8
+ # uid: user ID, to whom the task is assigned to (integer, not required)
9
+ # estimated_seconds: estimated duration of task in seconds (integer, not required)
10
+ # active: whether the task is done or not (boolean, by default true)
11
+ # at: timestamp that is sent in the response for PUT, indicates the time task was last updated
12
+
13
+ def create_task(name, pid, options={})
14
+ post "/tasks", {"tag" => {"name" => name,"pid" =>pid}.merge(options)}
15
+ end
16
+
17
+ def get_task(tid)
18
+ get "/tasks/#{tid}"
19
+ end
20
+ alias :task :get_task
21
+
22
+ def update_task(tids, options)
23
+ options = Hashie::Mash.new options
24
+ tids = tids.join(',') if tids.is_a?(Array)
25
+ put "/tasks/#{tids}",(options.key?(:task) ? options : {:task => options})
26
+ end
27
+
28
+ alias :bulk_update_tasks :update_task
29
+
30
+ def delete_task(tid)
31
+ tids = tids.join(',') if tids.is_a?(Array)
32
+ delete "/tasks/#{tids}"
33
+ end
34
+ alias :bulk_delete_tasks :delete_task
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,73 @@
1
+ module Toggl
2
+ module Api
3
+ module TimeEntry
4
+
5
+ # *description*: (string, required)
6
+ # *wid*: workspace ID (integer, required if pid or tid not supplied)
7
+ # *pid*: project ID (integer, not required)
8
+ # *tid*: task ID (integer, not required)
9
+ # *start*: time entry start time (string, required, ISO 8601 date and time)
10
+ # *duration*: time entry duration in seconds. If the time entry is currently running, the duration attribute contains a negative value, denoting the start of the time entry in seconds since epoch (Jan 1 1970). The correct duration can be calculated as current_time + duration, where current_time is the current time in seconds since epoch. (integer, required)
11
+ # *created_with*: the name of your client app (string, required)
12
+ # stop: time entry stop time (string, not required, ISO 8601 date and time)
13
+ # billable: (boolean, not required, default false, available for pro workspaces)
14
+ # tags: a list of tag names (array of strings, not required)
15
+ # duronly: should Toggl show the start and stop time of this time entry? (boolean, not required)
16
+ # at: timestamp that is sent in the response, indicates the time item was last updated
17
+
18
+ def create_time_entry(options)
19
+ options = options.merge({:created_with => "Toggl Api Ruby Gem #{Toggl::VERSION}"})
20
+ post "/time_entries", (options.key?(:time_entry) ? options : {:time_entry => options})
21
+ end
22
+
23
+ def start_time_entry(options)
24
+ options = Hashie::Mash.new options
25
+ post "/time_entries/start", (options.key?(:time_entry) ? options : {:time_entry => options})
26
+ end
27
+
28
+ def stop_time_entry(tid)
29
+ put "/time_entries/#{tid}/stop"
30
+ end
31
+
32
+ def get_time_entry(tid)
33
+ get "/time_entries/#{tid}"
34
+ end
35
+ alias :time_entry :get_time_entry
36
+
37
+ def iso8601_date(date)
38
+ case date
39
+ when Time,Date
40
+ iso = date.to_datetime.iso8601
41
+ when String
42
+ iso = DateTime.parse(date).iso8601
43
+ else
44
+ raise ArgumentError, "Can't convert #{date.class} to ISO-8601 Date/Time"
45
+ end
46
+ end
47
+
48
+ #default return last 9 days time entries
49
+ def get_time_entries(start_date=nil, end_date=nil)
50
+ options = Hash.new
51
+ options["start_date"] = iso8601_date(start_date) if start_date
52
+ options["end_date"] = iso8601_date(end_date) if end_date
53
+ get "/time_entries", options
54
+ end
55
+
56
+ alias :time_entries :get_time_entries
57
+
58
+ def update_time_entry(tid,options)
59
+ tid = tid.join(",") if tid.is_a? Array
60
+ options = Hashie::Mash.new options
61
+ put "/time_entries/#{tid}", (options.key?(:time_entry) ? options : {:time_entry => options})
62
+ end
63
+
64
+ alias :bulk_update_time_entries :update_time_entry
65
+
66
+ def delete_time_entry(tid)
67
+ delete "/time_entries/#{tid}"
68
+ end
69
+
70
+ end
71
+ end
72
+ end
73
+
@@ -0,0 +1,46 @@
1
+ module Toggl
2
+ module Api
3
+ module User
4
+
5
+ #pass related_data as true to all related data
6
+ def me(related_data=false)
7
+ get "/me",{:with_related_data => related_data }
8
+ end
9
+
10
+ # You can update the following user fields:
11
+ # fullname: string
12
+ # email: string, valid email
13
+ # send_product_emails: boolean
14
+ # send_weekly_report: boolean
15
+ # send_timer_notifications: boolean
16
+ # store_start_and_stop_time: boolean
17
+ # beginning_of_week: integer, in the range of 0-6
18
+ # timezone: string, IANA TZ timezones
19
+ # timeofday_format: string, two formats are supported:
20
+ # "H:mm" for 24-hour format
21
+ # "h:mm A" for 12-hour format (AM/PM)
22
+ # date_format: string, possible values: "YYYY-MM-DD", "DD.MM.YYYY", "DD-MM-YYYY", "MM/DD/YYYY", "DD/MM/YYYY", "MM-DD-YYYY"
23
+ #
24
+ # To change password you have to have the following fields:
25
+ # current_password: string
26
+ # password: string
27
+ def update_me(options={})
28
+ options = Hashie::Mash.new options
29
+ put "/me", (options.key?(:user) ? options : {:user => options})
30
+ end
31
+
32
+ # *email*: a valid email for the user whose account is created (string, required)
33
+ # *password*: password at least 6 characters long (string, required)
34
+ # *timezone*: for example "Etc/UTC" (string, required)
35
+ # *created_with*: in free form, name of the app that signed the user app (string, required)
36
+ def signup(email, password, timezone, created_with="Toggl Api Ruby Gem #{Toggl::VERSION}")
37
+ post "/signups",{"user" => {"email" => email,"password" => "password","timezone" => timezone,"created_with" => created_with}}
38
+ end
39
+
40
+ def reset_token
41
+ post "/reset_token"
42
+ end
43
+
44
+ end
45
+ end
46
+ end