togglv8 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a10237427eb728d8536f6276c84e0e83a051695c
4
+ data.tar.gz: bb81c9c5d1c9a2f1d17b943eefdc1682565da2eb
5
+ SHA512:
6
+ metadata.gz: 944c4db8f611b45f210a53aba3ad3de9b5ea2c1237d982e4f06fe24637c0e5c6caaacf96ad936d59255d7bc8cb3e03e76a6d66851fbd33a205105f1d9e5cd23b
7
+ data.tar.gz: a5b4cdc752d55441db098753d4f578d68f7888118686dad90f1fbf79991fab5ffc80f4998ed0d07df81234176077f1511300cb472ab78e41c1123717e0dedb13
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: D1ZrNoAoVUgrr8B1KvO8ky8jUpFftVJfH
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ coverage/
3
+ doc/
4
+ pkg/
data/.rdoc_options ADDED
@@ -0,0 +1,23 @@
1
+ --- !ruby/object:RDoc::Options
2
+ encoding: UTF-8
3
+ static_path: []
4
+ rdoc_include:
5
+ - "."
6
+ - "/Users/tk/src/togglv8"
7
+ charset: UTF-8
8
+ exclude:
9
+ hyperlink_all: false
10
+ line_numbers: false
11
+ locale:
12
+ locale_dir: locale
13
+ locale_name:
14
+ main_page: README.md
15
+ markup: tomdoc
16
+ output_decoration: true
17
+ page_dir:
18
+ show_hash: false
19
+ tab_width: 8
20
+ template_stylesheets: []
21
+ title: Toggl V8
22
+ visibility: :protected
23
+ webcvs:
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ script: bundle exec rspec
5
+ cache: bundler
6
+ branches:
7
+ only:
8
+ - master
9
+ addons:
10
+ code_climate:
11
+ repo_token: eb44970f9efc497fb68c6ec1ce051dea530776b6a5bbe75e57734625f761ac86
data/API calls.md ADDED
@@ -0,0 +1,330 @@
1
+ # Toggl v8 API calls
2
+
3
+ These API calls with [curl](http://curl.haxx.se/) were useful when prototyping togglv8.
4
+
5
+ The calls have since been converted to use [resty](https://github.com/micha/resty) (a wrapper for curl). They are included here only for reference.
6
+
7
+ See [Toggl API Documentation](https://github.com/toggl/toggl_api_docs) for more authoritative, comprehensive, and up-to-date information.
8
+
9
+ As of 2013-08-11, the calls listed here cover almost the entire [Toggl API](https://github.com/toggl/toggl_api_docs/blob/master/toggl_api.md) section. The following calls are not yet supported by [togglv8](/):
10
+ * [Add multiple users to a project](/API%20calls.md#add-multiple-users-to-a-project)
11
+ * [Update multiple project users](/API%20calls.md#update-multiple-project-users)
12
+ * [Delete multiple project users](/API%20calls.md#delete-multiple-project-users)
13
+ * [Sign up new user](/API%20calls.md#sign-up-new-user) (Will increase the cost of your Toggl account.)
14
+ * [Invite users to workspace](/API%20calls.md#invite-users-to-workspace)
15
+ * [Delete workspace user](/API%20calls.md#delete-workspace-user)
16
+ * [Get workspace users for a workspace](/API%20calls.md#get-workspace-users-for-a-workspace)
17
+
18
+ # Authentication
19
+
20
+ Toggl API uses Basic Auth. Resty is initialized with basic auth info (-u), as well as headers (-H).
21
+
22
+ ### HTTP Basic Auth with API token
23
+ The user API Token for an account is available under [My Profile](https://www.toggl.com/user/edit) after logging into [Toggl.com](https://www.toggl.com).
24
+
25
+ When using an API Token, the user is your API Token and the password is "api_token".
26
+ ```
27
+ resty https://www.toggl.com/api/v8 -u 1971800d4d82861d8f2c1651fea4d212:api_token -H "Content-type: application/json"
28
+ ```
29
+
30
+ ### (Alternative method) HTTP Basic Auth with e-mail and password
31
+ It is also possible to use your email address and Toggl password.
32
+ ```
33
+ resty https://www.toggl.com/api/v8 -u your.email@example.com:SuperSecretPassword -H "Content-type: application/json"
34
+ ```
35
+
36
+ # Displaying JSON
37
+ It is helpful to use a JSON parsing tool such as [Jazor](https://github.com/mconigliaro/jazor).
38
+
39
+ For example, ```GET /me | jazor -c``` outputs
40
+
41
+ ```
42
+ {
43
+ since: 1370938972,
44
+ data: {
45
+ id: {<user_id>},
46
+ api_token: "<api_token>",
47
+ default_wid: <wid>,
48
+ email: "<email_address>",
49
+ fullname: "<fullname>",
50
+ jquery_timeofday_format: H:i,
51
+ jquery_date_format: "m/d/Y",
52
+ timeofday_format: H:mm,
53
+ date_format: "MM/DD/YYYY",
54
+ store_start_and_stop_time: true,
55
+ beginning_of_week: 1,
56
+ language: "en_US",
57
+ image_url: https://www.toggl.com/system/avatars/<image.jpg>,
58
+ sidebar_piechart: false,
59
+ at: "2013-06-11T07:00:44+00:00",
60
+ created_at: "2012-08-01T12:41:56+00:00",
61
+ retention: 9,
62
+ record_timeline: true,
63
+ render_timeline: true,
64
+ timeline_enabled: true,
65
+ timeline_experiment: true,
66
+ manual_mode: true,
67
+ new_blog_post: {
68
+ },
69
+ invitation: {
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ rather than
76
+
77
+ ```
78
+ {"since":1370938972,"data":{"id":<user_id>},"api_token":"<api_token>","default_wid":<wid>,"email":"<email_address>","fullname":"<fullname>","jquery_timeofday_format":"H:i","jquery_date_format":"m/d/Y","timeofday_format":"H:mm","date_format":"MM/DD/YYYY","store_start_and_stop_time":true,"beginning_of_week":1,"language":"en_US","image_url":"https://www.toggl.com/system/avatars/<image.jpg>","sidebar_piechart":false,"at":"2013-06-11T07:00:44+00:00","created_at":"2012-08-01T12:41:56+00:00","retention":9,"record_timeline":true,"render_timeline":true,"timeline_enabled":true,"timeline_experiment":true,"manual_mode":true,"new_blog_post":{},"invitation":{}}}
79
+ ```
80
+
81
+ ---
82
+
83
+ # Clients
84
+
85
+ ### Create client
86
+ ```
87
+ POST /clients -d '{"client":{"name":"Very Big Company","wid":282224}}'
88
+ ```
89
+
90
+ ### Read client
91
+ ```
92
+ GET /clients/1101632
93
+ ```
94
+
95
+ ### Update client
96
+ ```
97
+ PUT /clients/1150638 -d '{"client":{"notes":"this client must go!"}}'
98
+ ```
99
+
100
+ ### Delete client
101
+ ```
102
+ DELETE /clients/1150758
103
+ ```
104
+
105
+ ### Get clients visible to user
106
+ ```
107
+ GET /clients
108
+ ```
109
+
110
+ ### Get client projects
111
+ ```
112
+ GET /clients/1150488/projects
113
+ ```
114
+
115
+ # Projects
116
+
117
+ ### Create project
118
+ ```
119
+ POST /projects -d '{"project":{"name":"TEST project","wid":282224,"is_private":true}}'
120
+ ```
121
+
122
+ ### Read project
123
+ ```
124
+ GET /projects/2882160
125
+ ```
126
+
127
+ ### Update project
128
+ ```
129
+ PUT /projects/2931253 -d '{"project":{"name":"Changed the name","is_private":false,"template":true}}'
130
+ ```
131
+
132
+ ### Get project users
133
+ ```
134
+ GET /projects/2883126/project_users
135
+ ```
136
+
137
+ # Project users
138
+
139
+ ### Create project user
140
+ ```
141
+ POST /project_users -d '{"project_user":{"pid":2931296,"uid":509726,"rate":30.0,"manager":true}}'
142
+ ```
143
+
144
+ ### Update project user
145
+ ```
146
+ PUT /project_users/8310314 -d '{"project_user":{"manager":false,"rate":15,"fields":"fullname"}}'
147
+ ```
148
+
149
+ ### Delete project user
150
+ ```
151
+ DELETE /project_users/8310314
152
+ ```
153
+ ### Add multiple users to a project
154
+ **Note:** Not yet supported by [togglv8](/)
155
+
156
+ ### Update multiple project users
157
+ **Note:** Not yet supported by [togglv8](/)
158
+
159
+ ### Delete multiple project users
160
+ **Note:** Not yet supported by [togglv8](/)
161
+
162
+ # Tags
163
+
164
+ ### Create tag
165
+ ```
166
+ POST /tags -d '{"tag":{"name":"tag"}}'
167
+ ```
168
+
169
+ ### Update tag
170
+ ```
171
+ PUT /tags/294414 -d '{"tag":{"name":"taggggg"}}'
172
+ ```
173
+
174
+ ### Delete tag
175
+ ```
176
+ DELETE /tags/294414
177
+ ```
178
+
179
+ # Tasks
180
+
181
+ ### Create task
182
+ ```
183
+ POST /tasks -d '{"task":{"name":"A new task","pid":2883129}}'
184
+ ```
185
+
186
+ ### Get task details
187
+ ```
188
+ GET /tasks/1894675
189
+ ```
190
+
191
+ ### Update task
192
+ ```
193
+ PUT /tasks/1894675 -d '{"task":{"id": 1894675, "active": true, "estimated_seconds": 7200, "fields": "done_seconds,uname"}}'
194
+ ```
195
+
196
+ ### Delete task
197
+ ```
198
+ DELETE /tasks/1893464
199
+ ```
200
+
201
+ ### Update multiple tasks
202
+ ```
203
+ PUT /tasks/1894758,1894751 -d '{"task":{"active":false,"fields":"done_seconds,uname"}}'
204
+ ```
205
+
206
+ ### Delete multiple Tasks
207
+ ```
208
+ DELETE /tasks/1922656,1922683,1922684
209
+ ```
210
+
211
+ # Time entries
212
+
213
+ ### Create time entry
214
+ ```
215
+ POST /time_entries -d '{"time_entry":{"description":"Meeting with possible clients","tags":["billed"],"duration":1200,"start":"2013-03-05T07:58:58.000Z","pid":2931296}}'
216
+ ```
217
+
218
+ ### Get time entry details
219
+ ```
220
+ GET /time_entries/77628973
221
+ ```
222
+
223
+ ### Start a time entry
224
+ ```
225
+ POST /time_entries/start -d '{"time_entry":{"description":"New time entry","wid":282224}}'
226
+ ```
227
+
228
+ ### Stop a time entry
229
+ ```
230
+ PUT /time_entries/86229778/stop
231
+ ```
232
+
233
+ ### Update time entry
234
+ ```
235
+ PUT /time_entries/86229778 -d '{"time_entry":{"description":"Renamed new time entry","duration":180}}'
236
+ ```
237
+
238
+ ### Delete time entry
239
+ ```
240
+ DELETE /time_entries/86229778
241
+ ```
242
+
243
+ ### Get time entries started in a specific time range
244
+ **Note:**
245
+
246
+ - `start_date` and `end_date` are in [ISO 8601 date and time format](http://en.wikipedia.org/wiki/ISO_8601#Combined_date_and_time_representations), (e.g. "2013-03-10T15:42:46+02:00")
247
+ - It is necessary to use the encoded value %2B for '+' in order to avoid JSON parsing error. (Using %3A for ':' is not strictly necessary.)
248
+
249
+ ```
250
+ GET /time_entries -q 'start_date=2013-05-22T15:42:46%2B02:00&end_date=2013-05-22T16:42:46%2B02:00'
251
+ ```
252
+
253
+ ```
254
+ GET /time_entries -q 'start_date=2013-06-04T18:32:12%2B00:00'
255
+ ```
256
+
257
+ # Users
258
+
259
+ ### Get current user data
260
+ ```
261
+ GET /me
262
+ ```
263
+
264
+ ### Get current user with related data
265
+ ```
266
+ GET /me?with_related_data=true -Q
267
+ ```
268
+ or
269
+ ```
270
+ GET /me -q 'with_related_data=true'
271
+ ```
272
+
273
+ ### Sign up new user
274
+ **Note:** This is not implemented in [togglv8](/) wrapper because it will increase the cost of your Toggl account. See [Toggl Pricing and Payments](http://support.toggl.com/pricing-and-payments/) for details.
275
+ ```
276
+ POST /signups -d '{"user":{"email":"<email_address>","password":"<password>"}}'
277
+ ```
278
+
279
+ # Workspaces
280
+
281
+ ### Get user workspaces
282
+ ```
283
+ GET /workspaces
284
+ ```
285
+
286
+ ### Get workspace users
287
+ ```
288
+ GET /workspaces/282224/users
289
+ ```
290
+
291
+ ### Get workspace clients
292
+ ```
293
+ GET /workspaces/282224/clients
294
+ ```
295
+
296
+ ### Get workspace projects
297
+ ```
298
+ GET /workspaces/282224/projects
299
+ ```
300
+
301
+ ### Get workspace tasks
302
+ ```
303
+ GET /workspaces/282224/tasks
304
+ ```
305
+ ```
306
+ GET /workspaces/282224/tasks?active=true
307
+ ```
308
+ ```
309
+ GET /workspaces/282224/tasks?active=false
310
+ ```
311
+ ```
312
+ GET /workspaces/282224/tasks?active=both
313
+ ```
314
+
315
+ # Workspace Users
316
+
317
+ ### Invite users to workspace
318
+ **Note:** Not yet supported by [togglv8](/)
319
+
320
+ ### Update workspace user (can only update admin flag)
321
+ **Note:** Call fails with error message "Cannot access workspace users"
322
+ ```
323
+ PUT /workspace_users/282224 -d '{"workspace_user":{"admin":true}}'
324
+ ```
325
+
326
+ ### Delete workspace user
327
+ **Note:** Not yet supported by [togglv8](/)
328
+
329
+ ### Get workspace users for a workspace
330
+ **Note:** Not yet supported by [togglv8](/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in togglv8.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013-2015 Tom Kane
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.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+
2
+ # Toggl API v8
3
+
4
+ [![Build Status](https://api.travis-ci.org/kanet77/togglv8.svg "Build Status")](https://travis-ci.org/kanet77/togglv8) [![Coverage Status](https://coveralls.io/repos/kanet77/togglv8/badge.svg?branch=master&service=github)](https://coveralls.io/github/kanet77/togglv8?branch=master)
5
+
6
+ [Toggl](http://www.toggl.com) is a time tracking tool.
7
+
8
+ [togglv8](/) is a Ruby Wrapper for [Toggl API v8](https://github.com/toggl/toggl_api_docs). It is designed to mirror the Toggl API as closely as possible.
9
+
10
+ **Note:** Currently togglv8 only includes calls to [Toggl API](https://github.com/toggl/toggl_api_docs/blob/master/toggl_api.md), not the [Reports API](https://github.com/toggl/toggl_api_docs/blob/master/reports.md)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'togglv8'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install togglv8
27
+
28
+ ## Usage
29
+
30
+ This short example shows one way to create a time entry for the first workspace of the user identified by `<API_TOKEN>`:
31
+
32
+ ```ruby
33
+ require 'togglv8'
34
+
35
+ toggl_api = TogglV8::API.new(<API_TOKEN>)
36
+ user = toggl_api.me(all=true)
37
+ workspaces = toggl_api.my_workspaces(user)
38
+ workspace_id = workspaces.first['id']
39
+ toggl_api.create_time_entry({description: "Workspace time entry",
40
+ wid: workspace_id,
41
+ duration: 1200,
42
+ start: "2015-08-18T01:13:40.000Z",
43
+ created_with: "My awesome Ruby application"})
44
+ ```
45
+
46
+ See specs for more examples.
47
+
48
+ ## Documentation
49
+
50
+ Run `rdoc` to generate documentation. Open `doc/index.html` in your browser.
51
+
52
+ Also available on [DocumentUp](https://documentup.com/kanet77/togglv8)
53
+
54
+ ## Test Coverage
55
+
56
+ Open `coverage/index.html` to see test coverage.
57
+
58
+ As of 2015-08-21, coverage is "90.39% covered at 6.16 hits/line" according to [SimpleCov](https://rubygems.org/gems/simplecov).
59
+
60
+ ## Acknowledgements
61
+
62
+ - Thanks to [Koen Van der Auwera](https://github.com/atog) for the [Ruby Wrapper for Toggl API v6](https://github.com/atog/toggl)
63
+ - Thanks to the Toggl team for exposing the API.
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/[my-github-username]/togglv8/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
72
+
73
+ ## License
74
+
75
+ Copyright (c) 2013-2015 Tom Kane. Released under the [MIT License](http://opensource.org/licenses/mit-license.php). See [LICENSE.txt](LICENSE.txt) for details.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'fileutils'
3
+
4
+ task :clean do
5
+ FileUtils.remove_dir('coverage', force=true)
6
+ FileUtils.remove_dir('doc', force=true)
7
+ FileUtils.remove_dir('pkg', force=true)
8
+ end
@@ -0,0 +1,37 @@
1
+ module TogglV8
2
+ class API
3
+
4
+ ##
5
+ # ---------
6
+ # :section: Clients
7
+ #
8
+ # name : The name of the client (string, required, unique in workspace)
9
+ # wid : workspace ID, where the client will be used (integer, required)
10
+ # notes : Notes for the client (string, not required)
11
+ # hrate : The hourly rate for this client (float, not required, available only for pro workspaces)
12
+ # cur : The name of the client's currency (string, not required, available only for pro workspaces)
13
+ # at : timestamp that is sent in the response, indicates the time client was last updated
14
+
15
+ def create_client(params)
16
+ requireParams(params, ['name', 'wid'])
17
+ post "clients", {client: params}
18
+ end
19
+
20
+ def get_client(client_id)
21
+ get "clients/#{client_id}"
22
+ end
23
+
24
+ def update_client(client_id, params)
25
+ put "clients/#{client_id}", { 'client' => params }
26
+ end
27
+
28
+ def delete_client(client_id)
29
+ delete "clients/#{client_id}"
30
+ end
31
+
32
+ def get_client_projects(client_id, params={})
33
+ active = params.has_key?('active') ? "?active=#{params['active']}" : ""
34
+ get "clients/#{client_id}/projects#{active}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ module TogglV8
2
+ class API
3
+
4
+ ##
5
+ # ---------
6
+ # :section: Dashboard
7
+ #
8
+ # See https://github.com/toggl/toggl_api_docs/blob/master/chapters/dashboard.md
9
+
10
+ def dashboard(workspace_id)
11
+ get "dashboard/#{workspace_id}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module TogglV8
2
+ class API
3
+
4
+ ##
5
+ # ---------
6
+ # :section: Project Users
7
+ #
8
+ # pid : project ID (integer, required)
9
+ # uid : user ID, who is added to the project (integer, required)
10
+ # wid : workspace ID, where the project belongs to (integer, not-required, project's workspace id is used)
11
+ # manager : admin rights for this project (boolean, default false)
12
+ # 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.
13
+ # at : timestamp that is sent in the response, indicates when the project user was last updated
14
+ # -- Additional fields --
15
+ # fullname : full name of the user, who is added to the project
16
+
17
+ def create_project_user(params)
18
+ requireParams(params, ['pid', 'uid'])
19
+ params[:fields] = "fullname" # for simplicity, always request fullname field
20
+ post "project_users", { 'project_user' => params }
21
+ end
22
+
23
+ def update_project_user(project_user_id, params)
24
+ params[:fields] = "fullname" # for simplicity, always request fullname field
25
+ put "project_users/#{project_user_id}", { 'project_user' => params }
26
+ end
27
+
28
+ def delete_project_user(project_user_id)
29
+ delete "project_users/#{project_user_id}"
30
+ end
31
+ end
32
+ end