redbooth-ruby 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +429 -0
- data/Rakefile +8 -0
- data/lib/redbooth-ruby/base.rb +43 -0
- data/lib/redbooth-ruby/client.rb +85 -0
- data/lib/redbooth-ruby/conversation.rb +20 -0
- data/lib/redbooth-ruby/me.rb +16 -0
- data/lib/redbooth-ruby/membership.rb +17 -0
- data/lib/redbooth-ruby/operations/base.rb +47 -0
- data/lib/redbooth-ruby/operations/create.rb +25 -0
- data/lib/redbooth-ruby/operations/delete.rb +26 -0
- data/lib/redbooth-ruby/operations/index.rb +49 -0
- data/lib/redbooth-ruby/operations/meta.rb +15 -0
- data/lib/redbooth-ruby/operations/show.rb +25 -0
- data/lib/redbooth-ruby/operations/update.rb +26 -0
- data/lib/redbooth-ruby/organization.rb +34 -0
- data/lib/redbooth-ruby/person.rb +23 -0
- data/lib/redbooth-ruby/project.rb +26 -0
- data/lib/redbooth-ruby/request/base.rb +41 -0
- data/lib/redbooth-ruby/request/collection.rb +105 -0
- data/lib/redbooth-ruby/request/connection.rb +140 -0
- data/lib/redbooth-ruby/request/helpers.rb +36 -0
- data/lib/redbooth-ruby/request/info.rb +41 -0
- data/lib/redbooth-ruby/request/response.rb +34 -0
- data/lib/redbooth-ruby/request/validator.rb +85 -0
- data/lib/redbooth-ruby/session.rb +46 -0
- data/lib/redbooth-ruby/task.rb +37 -0
- data/lib/redbooth-ruby/user.rb +13 -0
- data/lib/redbooth-ruby/version.rb +3 -0
- data/lib/redbooth-ruby.rb +113 -0
- data/redbooth-ruby.gemspec +30 -0
- metadata +37 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c965740525e418665ebed6cdfc26ab17a67fb5e
|
4
|
+
data.tar.gz: 76bd8e60f6b972b540b23feb613e7e1cb2241544
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6280ee42271771c0c17d57107084382b841f14e44976426b62eb7da0964214eb4ab8dd42bb3b90d743bd807bfa65218e4b809e217cce5f71acedb4e0303ccfe5
|
7
|
+
data.tar.gz: 46075bd7b3d79e78762958021e89d38363fb1be2d7a73c94ac7dad71dceaa3e8a1f35f30555aa5ede4bbcb1abd3fce359ce00798df7eca1a29db4b6617c96583
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Redbooth
|
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 NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
21
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
22
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,429 @@
|
|
1
|
+
[![Build Status](https://magnum.travis-ci.com/teambox/redbooth-ruby.svg?token=DytWKainUGNzXxdrekWH&branch=feature/tasks)](https://magnum.travis-ci.com/teambox/redbooth-ruby) [![Code Climate](https://codeclimate.com/repos/5461c4f6e30ba075bc0a0ab0/badges/11031f420440e8a9f525/gpa.svg)](https://codeclimate.com/repos/5461c4f6e30ba075bc0a0ab0/feed) [![Test Coverage](https://codeclimate.com/repos/5461c4f6e30ba075bc0a0ab0/badges/11031f420440e8a9f525/coverage.svg)](https://codeclimate.com/repos/5461c4f6e30ba075bc0a0ab0/feed) [![Inline docs](http://inch-ci.org/github/teambox/redbooth-ruby.svg?branch=master)](http://inch-ci.org/github/teambox/redbooth-ruby)
|
2
|
+
|
3
|
+
Redbooth-Ruby
|
4
|
+
======
|
5
|
+
|
6
|
+
This is a Ruby wrapper for redbooth's API.
|
7
|
+
|
8
|
+
Documentation
|
9
|
+
=====
|
10
|
+
|
11
|
+
We use YARD for documentation.
|
12
|
+
|
13
|
+
Usage
|
14
|
+
======
|
15
|
+
|
16
|
+
First, you've to install the gem
|
17
|
+
|
18
|
+
```Ruby
|
19
|
+
gem install redbooth-ruby
|
20
|
+
```
|
21
|
+
|
22
|
+
and require it
|
23
|
+
|
24
|
+
```Ruby
|
25
|
+
require 'redbooth-ruby'
|
26
|
+
```
|
27
|
+
|
28
|
+
and set up your app credentials
|
29
|
+
|
30
|
+
|
31
|
+
```Ruby
|
32
|
+
RedboothRuby.config do |configuration|
|
33
|
+
configuration[:consumer_key] = '_your_consumer_key_'
|
34
|
+
configuration[:consumer_secret] = '_your_consumer_secret_'
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
in fact this last step is optional (yes! we support multiple applications) but if as most fo the humans you use only one redbooth app, this is the easyest way to go.
|
39
|
+
|
40
|
+
|
41
|
+
Oauth
|
42
|
+
=====
|
43
|
+
|
44
|
+
*[Redbooth oauth2 API documentation](https://www.redbooth.com/developer/documentation#authentication)*
|
45
|
+
|
46
|
+
using omniauth? :+1: good choice, just try this gem
|
47
|
+
|
48
|
+
*[teambox/omniauth-redbooth](https://github.com/teambox/omniauth-redbooth)*
|
49
|
+
|
50
|
+
not using omniauth,? no prob oauth implementation comming soon
|
51
|
+
|
52
|
+
...
|
53
|
+
|
54
|
+
|
55
|
+
Client
|
56
|
+
======
|
57
|
+
|
58
|
+
Everything starts with the client, once you have the user credentials you should create a session and a client to start interaction with the API
|
59
|
+
|
60
|
+
```Ruby
|
61
|
+
session = RedboothRuby::Session.new(
|
62
|
+
token: '_your_user_token_'
|
63
|
+
)
|
64
|
+
client = RedboothRuby::Client.new(session)
|
65
|
+
```
|
66
|
+
|
67
|
+
Now you can perform any user api call inside the clien wrapper
|
68
|
+
|
69
|
+
```Ruby
|
70
|
+
client.me(:show)
|
71
|
+
```
|
72
|
+
|
73
|
+
If you have multiple applications or you just want to ve explicit use the application credentials inside the session creation
|
74
|
+
|
75
|
+
```Ruby
|
76
|
+
session = RedboothRuby::Session.new(
|
77
|
+
token: '_your_user_token_',
|
78
|
+
consumer_key: '_your_app_key_',
|
79
|
+
consumer_secret: '_your_app_secret'
|
80
|
+
)
|
81
|
+
client = RedboothRuby::Client.new(session)
|
82
|
+
```
|
83
|
+
|
84
|
+
Async Endpoints
|
85
|
+
======
|
86
|
+
|
87
|
+
Redbooth API is ready to transform any endpoint to async performing in order to optimize the API response time. When this happens the response will contain:
|
88
|
+
|
89
|
+
* `202` status code
|
90
|
+
|
91
|
+
* `Retry-After` header with the time in seconds to wait until retry the same request
|
92
|
+
|
93
|
+
To know the real response of this request you just need to perform the same request once the retry-after time passed.
|
94
|
+
|
95
|
+
In the client we handle this work for you by waiting and repeating the request if needed, but if you want to perform the retry method in any other way (renqueue the job for instance) you should declare it in the client initialize process:
|
96
|
+
|
97
|
+
```Ruby
|
98
|
+
client = RedboothRuby::Client.new(session, retry: -> { |time| YourFancyJob.enque_in(time, params) })
|
99
|
+
```
|
100
|
+
|
101
|
+
Collections
|
102
|
+
======
|
103
|
+
|
104
|
+
Index methods always return a `RedboothRuby::Request::Collection` object to handle the pagination and ordering.
|
105
|
+
|
106
|
+
ie:
|
107
|
+
```Ruby
|
108
|
+
tasks_collection = client.task(:index, project_id: 2)
|
109
|
+
tasks_collection.class # => RedboothRuby::Request::Collection
|
110
|
+
tasks = tasks_collection.all
|
111
|
+
|
112
|
+
tasks_collection.current_page # => 1
|
113
|
+
tasks_collection.total_pages # => 7
|
114
|
+
tasks_collection.per_page # => 30
|
115
|
+
tasks_collection.count # => 208
|
116
|
+
|
117
|
+
next_page_collection = tasks_collection.next_page
|
118
|
+
next_page_collection.class # => RedboothRuby::Request::Collection
|
119
|
+
|
120
|
+
prev_page_collection = tasks_collection.prev_page
|
121
|
+
prev_page_collection.class # => RedboothRuby::Request::Collection
|
122
|
+
```
|
123
|
+
|
124
|
+
## Collection Methods
|
125
|
+
|
126
|
+
* `all` : `Array` of elements in the current page
|
127
|
+
|
128
|
+
* `count` : `Integer` number of the total elements
|
129
|
+
|
130
|
+
* `current_page`: `Integer` current page number (nil if the resource is not paginated)
|
131
|
+
|
132
|
+
* `total_pages`: `Integer` total pages number (nil if the resource is not paginated)
|
133
|
+
|
134
|
+
* `next_page`: `RedboothRuby::Request::Collection` Collection object pointing to the next page (nil if the resource is not paginated or there is no next page)
|
135
|
+
|
136
|
+
* `prev_page`: `RedboothRuby::Request::Collection` Collection object pointing to the prev page (nil if the resource is not paginated or there is no next page)
|
137
|
+
|
138
|
+
## Examples
|
139
|
+
|
140
|
+
Iterating thought all the pages
|
141
|
+
|
142
|
+
```Ruby
|
143
|
+
tasks_collection = client.task(:index, project_id: 2)
|
144
|
+
tasks = tasks_collection.all
|
145
|
+
|
146
|
+
while task_collection = tasks_collection.next_page do
|
147
|
+
tasks << task_collection.all
|
148
|
+
end
|
149
|
+
|
150
|
+
tasks.flatten!
|
151
|
+
```
|
152
|
+
|
153
|
+
Users
|
154
|
+
=====
|
155
|
+
|
156
|
+
List users in your network
|
157
|
+
|
158
|
+
```Ruby
|
159
|
+
users_collection = client.user(:index)
|
160
|
+
users = users_collection.all
|
161
|
+
```
|
162
|
+
|
163
|
+
Fetch a especific user
|
164
|
+
|
165
|
+
```Ruby
|
166
|
+
user = client.user(:show, id: 123)
|
167
|
+
```
|
168
|
+
|
169
|
+
Tasks
|
170
|
+
=====
|
171
|
+
|
172
|
+
Lists tasks in your visibility scope
|
173
|
+
|
174
|
+
```Ruby
|
175
|
+
tasks_collection = client.task(:index)
|
176
|
+
tasks = tasks_collection.all
|
177
|
+
```
|
178
|
+
|
179
|
+
You can also filter by multiple params (see docs [here](https://redbooth.com/api/api-docs/#page:tasks,header:tasks-task-list) )
|
180
|
+
|
181
|
+
```Ruby
|
182
|
+
filtered_tasks = client.task(:index, order: 'id-DESC',
|
183
|
+
per_page: 50,
|
184
|
+
project_id: 123)
|
185
|
+
```
|
186
|
+
|
187
|
+
Fetch a especific task
|
188
|
+
|
189
|
+
```Ruby
|
190
|
+
task = client.task(:show, id: 123)
|
191
|
+
```
|
192
|
+
|
193
|
+
Update a especific task
|
194
|
+
|
195
|
+
```Ruby
|
196
|
+
task = client.task(:update, id: 123, name: 'new name')
|
197
|
+
```
|
198
|
+
|
199
|
+
Delete a especific task
|
200
|
+
|
201
|
+
```Ruby
|
202
|
+
client.task(:delete, id: 123)
|
203
|
+
```
|
204
|
+
|
205
|
+
Organizations
|
206
|
+
=====
|
207
|
+
|
208
|
+
Lists organizations in your visibility scope
|
209
|
+
|
210
|
+
```Ruby
|
211
|
+
organization_collection = client.organization(:index)
|
212
|
+
organizations = organization_collection.all
|
213
|
+
```
|
214
|
+
|
215
|
+
You can also filter by multiple params (see docs [here](https://redbooth.com/api/api-docs/#page:organizations,header:organizations-organization-list) )
|
216
|
+
|
217
|
+
```Ruby
|
218
|
+
filtered_organizations = client.organization(:index, order: 'id-DESC',
|
219
|
+
per_page: 50)
|
220
|
+
```
|
221
|
+
|
222
|
+
Fetch a especific organization
|
223
|
+
|
224
|
+
```Ruby
|
225
|
+
organization = client.organization(:show, id: 123)
|
226
|
+
```
|
227
|
+
|
228
|
+
Create a organization
|
229
|
+
|
230
|
+
```Ruby
|
231
|
+
organization = client.organization(:create, name: 'New Organization')
|
232
|
+
```
|
233
|
+
|
234
|
+
Update a especific organization
|
235
|
+
|
236
|
+
```Ruby
|
237
|
+
organization = client.organization(:update, id: 123, name: 'new name')
|
238
|
+
```
|
239
|
+
|
240
|
+
Delete a especific organization
|
241
|
+
|
242
|
+
```Ruby
|
243
|
+
client.organization(:delete, id: 123)
|
244
|
+
```
|
245
|
+
|
246
|
+
Projects
|
247
|
+
=====
|
248
|
+
|
249
|
+
Lists projects in your visibility scope
|
250
|
+
|
251
|
+
```Ruby
|
252
|
+
project_collection = client.project(:index)
|
253
|
+
projects = project_collection.all
|
254
|
+
```
|
255
|
+
|
256
|
+
You can also filter by multiple params (see docs [here](https://redbooth.com/api/api-docs/#page:projects,header:projects-project-list) )
|
257
|
+
|
258
|
+
```Ruby
|
259
|
+
filtered_projects = client.project(:index, order: 'id-DESC',
|
260
|
+
per_page: 50)
|
261
|
+
```
|
262
|
+
|
263
|
+
Fetch a especific project
|
264
|
+
|
265
|
+
```Ruby
|
266
|
+
project = client.project(:show, id: 123)
|
267
|
+
```
|
268
|
+
|
269
|
+
Create a project
|
270
|
+
|
271
|
+
```Ruby
|
272
|
+
project = client.project(:create, name: 'New Project')
|
273
|
+
```
|
274
|
+
|
275
|
+
Update a especific project
|
276
|
+
|
277
|
+
```Ruby
|
278
|
+
project = client.project(:update, id: 123, name: 'new name')
|
279
|
+
```
|
280
|
+
|
281
|
+
Delete a especific project
|
282
|
+
|
283
|
+
```Ruby
|
284
|
+
client.project(:delete, id: 123)
|
285
|
+
```
|
286
|
+
|
287
|
+
People
|
288
|
+
=====
|
289
|
+
|
290
|
+
People is the redbooth relation between projects and users containing the role
|
291
|
+
information
|
292
|
+
|
293
|
+
```
|
294
|
+
|-------| |--------| |---------|
|
295
|
+
| User | ==> | Person | ==> | Project |
|
296
|
+
|-------| |--------| |---------|
|
297
|
+
\
|
298
|
+
{role}
|
299
|
+
```
|
300
|
+
|
301
|
+
Lists People in your visibility scope
|
302
|
+
|
303
|
+
```Ruby
|
304
|
+
people_collection = client.person(:index)
|
305
|
+
people = people_collection.all
|
306
|
+
```
|
307
|
+
|
308
|
+
You can also filter by multiple params (see docs [here](https://redbooth.com/api/api-docs/#page:people,header:people-people-list) )
|
309
|
+
|
310
|
+
```Ruby
|
311
|
+
filtered_people = client.person(:index, order: 'id-DESC',
|
312
|
+
per_page: 50)
|
313
|
+
```
|
314
|
+
|
315
|
+
Fetch a especific person
|
316
|
+
|
317
|
+
```Ruby
|
318
|
+
people = client.person(:show, id: 123)
|
319
|
+
```
|
320
|
+
|
321
|
+
Create a person
|
322
|
+
|
323
|
+
```Ruby
|
324
|
+
person = client.person(:create, project_id: 123, user_id: 123, role: 'participant')
|
325
|
+
```
|
326
|
+
|
327
|
+
Update a especific person
|
328
|
+
|
329
|
+
```Ruby
|
330
|
+
person = client.person(:update, id: 123, role: 'admin')
|
331
|
+
```
|
332
|
+
|
333
|
+
Delete a especific person
|
334
|
+
|
335
|
+
```Ruby
|
336
|
+
client.person(:delete, id: 123)
|
337
|
+
```
|
338
|
+
|
339
|
+
Memberships
|
340
|
+
=====
|
341
|
+
|
342
|
+
Memberships is the redbooth relation between organization and users containing the role information
|
343
|
+
|
344
|
+
```
|
345
|
+
|-------| |------------| |--------------|
|
346
|
+
| User | ==> | Membership | ==> | Organization |
|
347
|
+
|-------| |------------| |--------------|
|
348
|
+
\
|
349
|
+
{role}
|
350
|
+
```
|
351
|
+
|
352
|
+
Lists Memberships in your visibility scope
|
353
|
+
|
354
|
+
```Ruby
|
355
|
+
membership_collection = client.membership(:index)
|
356
|
+
memberships = membership_collection.all
|
357
|
+
```
|
358
|
+
|
359
|
+
You can also filter by multiple params (see docs [here](https://redbooth.com/api/api-docs/#page:memberships,header:memberships-memberships-list) )
|
360
|
+
|
361
|
+
```Ruby
|
362
|
+
filtered_memberships = client.membership(:index, order: 'id-DESC',
|
363
|
+
per_page: 50)
|
364
|
+
```
|
365
|
+
|
366
|
+
Fetch a especific membership
|
367
|
+
|
368
|
+
```Ruby
|
369
|
+
memberships = client.membership(:show, id: 123)
|
370
|
+
```
|
371
|
+
|
372
|
+
Create a membership
|
373
|
+
|
374
|
+
```Ruby
|
375
|
+
membership = client.membership(:create, organization_id: 123, user_id: 123, role: 'participant')
|
376
|
+
```
|
377
|
+
|
378
|
+
Update a especific membership
|
379
|
+
|
380
|
+
```Ruby
|
381
|
+
membership = client.membership(:update, id: 123, role: 'admin')
|
382
|
+
```
|
383
|
+
|
384
|
+
Delete a especific membership
|
385
|
+
|
386
|
+
```Ruby
|
387
|
+
client.membership(:delete, id: 123)
|
388
|
+
```
|
389
|
+
|
390
|
+
Conversations
|
391
|
+
=====
|
392
|
+
|
393
|
+
Lists conversations in your visibility scope
|
394
|
+
|
395
|
+
```Ruby
|
396
|
+
conversation_collection = client.conversation(:index)
|
397
|
+
conversations = conversation_collection.all
|
398
|
+
```
|
399
|
+
|
400
|
+
You can also filter by multiple params (see docs [here](https://redbooth.com/api/api-docs/#page:conversations,header:conversations-conversations-list) )
|
401
|
+
|
402
|
+
```Ruby
|
403
|
+
filtered_conversations = client.conversation(:index, order: 'id-DESC',
|
404
|
+
per_page: 50,
|
405
|
+
project_id: 123)
|
406
|
+
```
|
407
|
+
|
408
|
+
Fetch a especific conversation
|
409
|
+
|
410
|
+
```Ruby
|
411
|
+
conversation = client.conversation(:show, id: 123)
|
412
|
+
```
|
413
|
+
|
414
|
+
Update a especific conversation
|
415
|
+
|
416
|
+
```Ruby
|
417
|
+
conversation = client.conversation(:update, id: 123, name: 'new name')
|
418
|
+
```
|
419
|
+
|
420
|
+
Delete a especific conversation
|
421
|
+
|
422
|
+
```Ruby
|
423
|
+
client.conversation(:delete, id: 123)
|
424
|
+
```
|
425
|
+
|
426
|
+
License
|
427
|
+
=====
|
428
|
+
|
429
|
+
Copyright (c) 2012-2013 Redbooth. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module RedboothRuby
|
2
|
+
class Base
|
3
|
+
include RedboothRuby::Operations::Base
|
4
|
+
|
5
|
+
attr_accessor :created_time
|
6
|
+
|
7
|
+
# Initializes the object using the given attributes
|
8
|
+
#
|
9
|
+
# @param [Hash] attributes The attributes to use for initialization
|
10
|
+
def initialize(attributes = {})
|
11
|
+
set_attributes(attributes)
|
12
|
+
parse_timestamps
|
13
|
+
end
|
14
|
+
|
15
|
+
# Model validations
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
def valid?
|
19
|
+
errors.empty?
|
20
|
+
end
|
21
|
+
|
22
|
+
# Accesor for the errors
|
23
|
+
#
|
24
|
+
def errors
|
25
|
+
@errors || []
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sets the attributes
|
29
|
+
#
|
30
|
+
# @param [Hash] attributes The attributes to initialize
|
31
|
+
def set_attributes(attributes)
|
32
|
+
attributes.each_pair do |key, value|
|
33
|
+
instance_variable_set("@#{key}", value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Parses UNIX timestamps and creates Time objects.
|
38
|
+
def parse_timestamps
|
39
|
+
@created_time = created_time.to_i if created_time.is_a? String
|
40
|
+
@created_time = Time.at(created_time) if created_time
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module RedboothRuby
|
2
|
+
class Client
|
3
|
+
RESOURCES = [:me, :user, :task, :organization, :person, :project, :conversation, :membership]
|
4
|
+
|
5
|
+
attr_reader :session, :options
|
6
|
+
|
7
|
+
# Creates an client object using the given Redbooth session.
|
8
|
+
# existing account.
|
9
|
+
#
|
10
|
+
# @param [String] client object to use the redbooth api.
|
11
|
+
def initialize(session, options={})
|
12
|
+
raise RedboothRuby::AuthenticationError unless session.valid?
|
13
|
+
@session = session
|
14
|
+
@options = options
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
# Metaprograming of every resource to execute it over the perform!
|
19
|
+
# method just to add session tho the resource
|
20
|
+
#
|
21
|
+
# @param [String||Symbol] action name of the action to execute over
|
22
|
+
# @param [Hash] options for the execution
|
23
|
+
# @returns the execution return or nil
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# session = RedboothRuby::Session.new(api_key: '_your_api_key_', auth_token: '_aut_token_for_the_user')
|
27
|
+
# client = RedboothRuby::Client.new(session)
|
28
|
+
# client.user.show # returns user profile
|
29
|
+
# client.files.all
|
30
|
+
#
|
31
|
+
RESOURCES.each do |resource|
|
32
|
+
eval %{
|
33
|
+
def #{resource.to_s}(action, options={})
|
34
|
+
perform!(:#{resource.to_s}, action, options)
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
# Executes block with the access token
|
42
|
+
#
|
43
|
+
# @param [String||Symbol] resource_name name of the resource to execute over
|
44
|
+
# @param [String||Symbol] action name of the action to execute over
|
45
|
+
# @param [Hash] options for the execution
|
46
|
+
# @returns the execution return or nil
|
47
|
+
def perform!(resource_name, action, options = {})
|
48
|
+
fail RedboothRuby::AuthenticationError unless session
|
49
|
+
resource(resource_name).send(action, options_with_session(options))
|
50
|
+
rescue Processing => processing
|
51
|
+
delay = processing.response.data["retry_after"] || 10
|
52
|
+
retry_in(delay, resource_name, action, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Retryes the request in the given time
|
56
|
+
# either calls the given proc options[:retry]
|
57
|
+
# or executes it in this thread
|
58
|
+
#
|
59
|
+
def retry_in(delay, *args)
|
60
|
+
if options[:retry]
|
61
|
+
options[:retry].call(delay)
|
62
|
+
else
|
63
|
+
sleep(delay)
|
64
|
+
perform!(*args)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Merge the given options with the session for use the api
|
69
|
+
#
|
70
|
+
# @param [Hash] options options to merge with session
|
71
|
+
# @return [Hash]
|
72
|
+
def options_with_session(options={})
|
73
|
+
options.merge(session: @session)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Gest the api resource model class by his name
|
77
|
+
#
|
78
|
+
# @param [String||Symbol] name name of the resource
|
79
|
+
# @return [Copy::Base] resource to use the api
|
80
|
+
def resource(name)
|
81
|
+
eval('RedboothRuby::' + name.to_s.capitalize) rescue nil
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RedboothRuby
|
2
|
+
class Conversation < Base
|
3
|
+
include RedboothRuby::Operations::Index
|
4
|
+
include RedboothRuby::Operations::Create
|
5
|
+
include RedboothRuby::Operations::Update
|
6
|
+
include RedboothRuby::Operations::Show
|
7
|
+
include RedboothRuby::Operations::Delete
|
8
|
+
|
9
|
+
attr_accessor :id,
|
10
|
+
:name,
|
11
|
+
:project_id,
|
12
|
+
:user_id,
|
13
|
+
:comments_count,
|
14
|
+
:is_private,
|
15
|
+
:last_activity_id,
|
16
|
+
:created_at,
|
17
|
+
:updated_at
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RedboothRuby
|
2
|
+
class Me < Base
|
3
|
+
include RedboothRuby::Operations::Show
|
4
|
+
include RedboothRuby::Operations::Update
|
5
|
+
include RedboothRuby::Operations::Delete
|
6
|
+
|
7
|
+
attr_accessor :id, :email, :first_name, :last_name
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def api_member_url(id = nil, method = nil)
|
11
|
+
'me'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RedboothRuby
|
2
|
+
class Membership < Base
|
3
|
+
include RedboothRuby::Operations::Index
|
4
|
+
include RedboothRuby::Operations::Create
|
5
|
+
include RedboothRuby::Operations::Update
|
6
|
+
include RedboothRuby::Operations::Show
|
7
|
+
include RedboothRuby::Operations::Delete
|
8
|
+
|
9
|
+
attr_accessor :id,
|
10
|
+
:user_id,
|
11
|
+
:organization_id,
|
12
|
+
:role,
|
13
|
+
:created_at,
|
14
|
+
:updated_at
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|