lti-ruby-box 1.14.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9cdfb70e994d4482adeca9ea6fe82dc9ca53d673
4
+ data.tar.gz: d20703c790f5ed46329fc587bc7323aacc3e473b
5
+ SHA512:
6
+ metadata.gz: 368d3ce5239ec743c55c4818d1b932d17ae7ce74347fcecbd2d946945b205fedbd7dd79e7a624edd581bca109735591a59cd337e3ef596da6e49617e3c779dd2
7
+ data.tar.gz: 5373f7b63f522ad526c4f4065abba06363375b6aac16916f4f7c0b397eac7627d993d2fdfdc2cc4c5e75fbf6e15e05922a14ef96a05f4393c3ad6148d2b59313
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ before_install:
5
+ - gem install bundler --pre
6
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "multipart-post"
4
+ gem "oauth2"
5
+ gem "json"
6
+ gem "addressable"
7
+
8
+ group :development do
9
+ gem "rspec"
10
+ gem "bundler"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "webmock"
13
+ end
@@ -0,0 +1,51 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.8)
5
+ crack (0.3.1)
6
+ diff-lcs (1.1.3)
7
+ faraday (0.8.4)
8
+ multipart-post (~> 1.1)
9
+ git (1.2.5)
10
+ httpauth (0.2.0)
11
+ jeweler (1.6.4)
12
+ bundler (~> 1.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ json (1.7.7)
16
+ jwt (0.1.5)
17
+ multi_json (>= 1.0)
18
+ multi_json (1.6.0)
19
+ multipart-post (1.1.5)
20
+ oauth2 (0.8.0)
21
+ faraday (~> 0.8)
22
+ httpauth (~> 0.1)
23
+ jwt (~> 0.1.4)
24
+ multi_json (~> 1.0)
25
+ rack (~> 1.2)
26
+ rack (1.4.5)
27
+ rake (0.9.2.2)
28
+ rspec (2.10.0)
29
+ rspec-core (~> 2.10.0)
30
+ rspec-expectations (~> 2.10.0)
31
+ rspec-mocks (~> 2.10.0)
32
+ rspec-core (2.10.0)
33
+ rspec-expectations (2.10.0)
34
+ diff-lcs (~> 1.1.3)
35
+ rspec-mocks (2.10.1)
36
+ webmock (1.8.7)
37
+ addressable (>= 2.2.7)
38
+ crack (>= 0.1.7)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ addressable
45
+ bundler
46
+ jeweler (~> 1.6.4)
47
+ json
48
+ multipart-post
49
+ oauth2
50
+ rspec
51
+ webmock
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Attachments.me
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,349 @@
1
+ ruby-box
2
+ ========
3
+
4
+ Build Status: [![Build Status](https://travis-ci.org/attachmentsme/ruby-box.png)](https://travis-ci.org/attachmentsme/ruby-box)
5
+
6
+ Mainted by: [Attachments.me](http://attachments.me)
7
+
8
+ RubyBox provides a simple, chainable, feature-rich client for [Box's 2.0 API](http://developers.box.com/docs/).
9
+
10
+ Authorization
11
+ -------------
12
+
13
+ RubyBox uses Box's OAuth2 Implementaton, Here are the steps involved in authorizing a client:
14
+
15
+ __1)__ Get the authorization url.
16
+
17
+ ```ruby
18
+ require 'ruby-box'
19
+
20
+ session = RubyBox::Session.new({
21
+ client_id: 'your-client-id',
22
+ client_secret: 'your-client-secret'
23
+ })
24
+
25
+ authorize_url = session.authorize_url('https://redirect-url-in-app-settings')
26
+ ```
27
+
28
+ __2)__ After redirecting to the authorize_url, exchange the _code_ given for an _access\_token_
29
+
30
+ ```ruby
31
+ @token = session.get_access_token('code-returned-to-redirect_url')
32
+ p '@token.token' # the access token.
33
+ p '@token.refresh_token' # token that can be exchanged for a new access_token once the access_token expires.
34
+
35
+ # refreshing token.
36
+
37
+ session = RubyBox::Session.new({
38
+ client_id: 'your-client-id',
39
+ client_secret: 'your-client-secret',
40
+ access_token: 'original-access-token'
41
+ })
42
+
43
+ # you need to persist this somehow. the refresh token will change every time you use it
44
+ @token = session.refresh_token('your-refresh-token')
45
+ save_me_somehow(@token.refresh_token)
46
+ ```
47
+
48
+ __3)__ Create a client using a session initialized with the _access\_token_.
49
+
50
+ ```ruby
51
+ require 'ruby-box'
52
+
53
+ session = RubyBox::Session.new({
54
+ client_id: 'your-client-id',
55
+ client_secret: 'your-client-secret',
56
+ access_token: 'access-token'
57
+ })
58
+
59
+ client = RubyBox::Client.new(session)
60
+ ```
61
+
62
+ Usage
63
+ =====
64
+
65
+ Once you've created a client, you can start interacting with the Box API. What follows are some basic examples of RubyBox's usage.
66
+
67
+ Warning
68
+ =======
69
+
70
+ Please note that using a file/folder path is extremely inefficient, as it causes the gem to traverse the directory structure recursively querying each folder in turn. Prefer the `_by_id` methods where possible for single-request access.
71
+
72
+ Items
73
+ -----
74
+
75
+ `File`s and `Folder`s are subclasses of `Item`. `Folder` contents (i.e. files and folders inside that folder) are retrieved in a `mini-format` when the `Folder` instance is loaded.
76
+
77
+ There are two caveats to this:
78
+
79
+ ### Only some fields are available
80
+
81
+ a `File` mini looks like this:
82
+
83
+ ```
84
+ {
85
+ "type": "file",
86
+ "id": "5000948880",
87
+ "sequence_id": "3",
88
+ "etag": "3",
89
+ "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
90
+ "name": "tigers.jpeg"
91
+ }
92
+ ```
93
+ a `Folder` mini looks like this:
94
+
95
+ ```
96
+ {
97
+ "type":"folder",
98
+ "id":"301415432",
99
+ "sequence_id":"0",
100
+ "name":"my first sub-folder"
101
+ }
102
+ ```
103
+
104
+ Requests to fields other than the above (e.g. `file.size`) will cause a one-off hit to the api, so take care when iterating over folder contents lest a single application method result in hundreds of api hits and take forever to complete.
105
+
106
+ This can be mitigated by passing a list of extra fields you want to fetch into the `.items` method:
107
+
108
+ ```ruby
109
+ folder = client.folder_by_id(@folder_id)
110
+ # retrieve size, created_at, and description for all items in this directory
111
+ detailed_items = folder.items(@item_limit, @offset, ['size', 'created_at', 'description'])
112
+ ```
113
+
114
+ Note: only the `type` and `id` fields are included in addition to whatever you specify using the above method, so you must be explicit.
115
+
116
+
117
+ Folders
118
+ -------
119
+
120
+ * Listing items in a folder:
121
+
122
+ ```ruby
123
+ files = client.folder('/image_folder').files # all files in a folder using a path.
124
+ files = client.folder(@folder_id).files # all files in a folder using an id.
125
+ folders = client.root_folder.folders # all folders in the root directory.
126
+ files_and_folders = client.folder('files').items # all files and folders in /files
127
+ ```
128
+
129
+ * Creating a folder:
130
+
131
+ ```ruby
132
+ client.folder_by_id(@folder_id).create_subfolder('subfolder') # using an id.
133
+ client.folder('image_folder').create_subfolder('subfolder') # using a path.
134
+ ```
135
+
136
+ * Setting the description on a folder:
137
+
138
+ ```ruby
139
+ folder = client.folder('image_folder') # using a path.
140
+ folder.description = 'Description on Folder'
141
+ folder.update
142
+ ```
143
+
144
+ * Listing the comments in a discussion surrounding a folder.
145
+
146
+ ```ruby
147
+ folder = client.folder('image_folder') # lookups by id are more efficient
148
+ discussion = folder.discussions.first
149
+ discussion.comments.each {|comment| p comment.message}
150
+ ```
151
+
152
+ * Creating a shared link for a folder.
153
+
154
+ ```ruby
155
+ folder = client.folder('image_folder').create_shared_link # lookups by id are more efficient
156
+ p folder.shared_link['url'] # https://www.box.com/s/d6de3224958c1755412
157
+ ```
158
+
159
+ Files
160
+ -----
161
+
162
+ * Fetching a file's meta information.
163
+
164
+ ```ruby
165
+ file = client.file('/image_folder/an-image.jpg')# lookups by id are more efficient
166
+ file = client.file(@file_id)
167
+ p file.name
168
+ p file.created_at
169
+ ```
170
+
171
+ * Uploading a file to a folder.
172
+
173
+ ```ruby
174
+ file = client.upload_file('./LICENSE.txt', '/license_folder') # lookups by id are more efficient
175
+ file = client.upload_file_by_folder_id('./LICENSE.txt', @folder_id)
176
+ ```
177
+
178
+ * Downloading a file.
179
+
180
+ ```ruby
181
+ f = open('./LOCAL.txt', 'w+')
182
+ f.write( client.file('/license_folder/LICENSE.txt').download )
183
+ f.close()
184
+
185
+ # Or you can fetch by file.id, which is more efficient:
186
+ f = open('./LOCAL.txt', 'w+')
187
+ f.write( client.file_by_id(@file_id).download ) # lookups by id are more efficient
188
+ f.close()
189
+
190
+ # You can also grab the raw url with
191
+ client.file_by_id(@file_id).download_url
192
+
193
+ # Note that this URL is not persistent. Clients will need to follow the url immediately in order to
194
+ # actually download the file
195
+ ```
196
+
197
+ * Deleting a file.
198
+
199
+ ```ruby
200
+ client.file_by_id(@file_id).delete # this
201
+ client.file('/license_folder/LICENSE.txt').delete
202
+ ```
203
+
204
+ * Displaying comments on a file.
205
+
206
+ ```ruby
207
+ comments = client.file('/image_folder/an-image.jpg').comments # lookups by id are more efficient
208
+ comments = client.file_by_id(@file_id).comments
209
+
210
+ comments.each do |comment|
211
+ p comment.message
212
+ end
213
+ ```
214
+
215
+ * Creating a shared link for a file.
216
+
217
+ ```ruby
218
+ file = client.file('/image_folder/an-image.jpg').create_shared_link
219
+ file = client.file_by_id(@file_id).create_shared_link # using an id
220
+ p file.shared_link.url # https://www.box.com/s/d6de3224958c1755412
221
+ ```
222
+
223
+ * Copying a file to another folder.
224
+
225
+ ```ruby
226
+
227
+ file = client.file('/one_folder/cow_folder/an-image.jpg')
228
+ folder = client.folder('image_folder')
229
+
230
+ # lookups by id are more efficient
231
+
232
+ file = client.file_by_id(@file_id)
233
+ folder = client.folder_by_id(@folder_id)
234
+
235
+ file.copy_to(folder)
236
+ ```
237
+
238
+ * Moving a file to another folder.
239
+
240
+ ```ruby
241
+
242
+ file = client.file('/one_folder/cow_folder/an-image.jpg')
243
+ folder = client.folder('image_folder')
244
+
245
+ # lookups by id are more efficient
246
+
247
+ file = client.file_by_id(@file_id)
248
+ folder = client.folder_by_id(@folder_id)
249
+
250
+
251
+ file.move_to(folder)
252
+ ```
253
+
254
+ * Adding a comment to a file.
255
+
256
+ ```ruby
257
+ file = client.file('/image_folder/an-image.jpg') # path
258
+ file = client.file_by_id(@file_id) # id
259
+ comment = file.create_comment('Hello World!')
260
+ ```
261
+
262
+ Search
263
+ ------
264
+
265
+ You can use RubyBox's search method to return files and folders that match a given query.
266
+
267
+ ```ruby
268
+ items = client.search('image')
269
+ items.each do |item|
270
+ p "type=#{item.type} name=#{item.name}"
271
+ end
272
+ ```
273
+
274
+ Events
275
+ ------
276
+
277
+ You can use RubyBox's event_response method to return an EventResponse that can be used to process any incoming events.
278
+
279
+ ```ruby
280
+ eresp = client.event_response
281
+ eresp.chunk_size
282
+ eresp.next_stream_position
283
+ eresp.events.each do |ev|
284
+ p "type=#{ev.event_id} type=#{ev.event_type} user=#{ev.created_by.name}"
285
+ end
286
+ ```
287
+
288
+ As-User
289
+ -------
290
+
291
+ * This must be manually enabled for your account by Box Staff. Contact api@box.com for access. [ More Info ] (http://developers.box.com/docs/#users-as-user)
292
+
293
+ ```ruby
294
+ session = RubyBox::Session.new({
295
+ client_id: 'your-client-id',
296
+ client_secret: 'your-client-secret',
297
+ access_token: 'original-access-token' ,
298
+ as_user: 'your-users-box-id'
299
+ })
300
+ ```
301
+ Users
302
+ ------
303
+
304
+ Current User Info
305
+
306
+ ```ruby
307
+ me = client.me
308
+ ```
309
+
310
+ Current User's enterprise
311
+
312
+ ```ruby
313
+ me = client.me.enterprise
314
+ ```
315
+
316
+ An array of Ruby:Box users in an enterprise (Supports Filtering, Limit and Offset)
317
+
318
+ ```ruby
319
+ users = client.users
320
+ ```
321
+
322
+ * Remeber the API filters "name" and "login" by the start of the string. ie: to get "sean+awesome@gmail.com" an approriate filter term would be "sean"
323
+
324
+ ```ruby
325
+ users = client.users("sean" , 10 , 1)
326
+ ```
327
+
328
+ Contributors
329
+ ============
330
+
331
+ * [full list of contributors](https://github.com/attachmentsme/ruby-box/graphs/contributors)
332
+
333
+ Contributing to ruby-box
334
+ ========================
335
+
336
+ RubyBox does not yet support all of Box's API Version 2.0 functionality, be liberal with your contributions.
337
+
338
+ * Rename account.example to account.yml and fill in your Box credentials
339
+ * Type bundle install
340
+ * Type rake.. tests should pass
341
+ * Add a failing test
342
+ * Make it pass
343
+ * Submit a pull request
344
+
345
+ Copyright
346
+ =========
347
+
348
+ Copyright (c) 2012 Attachments.me. See LICENSE.txt for
349
+ further details.