ruby-box 1.11.1 → 1.12.1

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.
data/.travis.yml ADDED
@@ -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/README.markdown CHANGED
@@ -1,7 +1,9 @@
1
1
  ruby-box
2
2
  ========
3
3
 
4
- Mainted by: [Attachments.me](https://attachments.me)
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)
5
7
 
6
8
  RubyBox provides a simple, chainable, feature-rich client for [Box's 2.0 API](http://developers.box.com/docs/).
7
9
 
@@ -38,7 +40,9 @@ session = RubyBox::Session.new({
38
40
  access_token: 'original-access-token'
39
41
  })
40
42
 
43
+ # you need to persist this somehow. the refresh token will change every time you use it
41
44
  @token = session.refresh_token('your-refresh-token')
45
+ save_me_somehow(@token.refresh_token)
42
46
  ```
43
47
 
44
48
  __3)__ Create a client using a session initialized with the _access\_token_.
@@ -58,7 +62,57 @@ client = RubyBox::Client.new(session)
58
62
  Usage
59
63
  =====
60
64
 
61
- Once you've created a client, you can start interacting with the Box API. What follows are some basic examples of RubyBox's usage:
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
+
62
116
 
63
117
  Folders
64
118
  -------
@@ -66,7 +120,8 @@ Folders
66
120
  * Listing items in a folder:
67
121
 
68
122
  ```ruby
69
- files = client.folder('/image_folder').files # all files in a folder.
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.
70
125
  folders = client.root_folder.folders # all folders in the root directory.
71
126
  files_and_folders = client.folder('files').items # all files and folders in /files
72
127
  ```
@@ -74,13 +129,14 @@ files_and_folders = client.folder('files').items # all files and folders in /fil
74
129
  * Creating a folder:
75
130
 
76
131
  ```ruby
77
- client.folder('image_folder').create_subfolder('subfolder')
132
+ client.folder_by_id(@folder_id).create_subfolder('subfolder') # using an id.
133
+ client.folder('image_folder').create_subfolder('subfolder') # using a path.
78
134
  ```
79
135
 
80
136
  * Setting the description on a folder:
81
137
 
82
138
  ```ruby
83
- folder = client.folder('image_folder')
139
+ folder = client.folder('image_folder') # using a path.
84
140
  folder.description = 'Description on Folder'
85
141
  folder.update
86
142
  ```
@@ -88,7 +144,7 @@ folder.update
88
144
  * Listing the comments in a discussion surrounding a folder.
89
145
 
90
146
  ```ruby
91
- folder = client.folder('image_folder')
147
+ folder = client.folder('image_folder') # lookups by id are more efficient
92
148
  discussion = folder.discussions.first
93
149
  discussion.comments.each {|comment| p comment.message}
94
150
  ```
@@ -96,7 +152,7 @@ discussion.comments.each {|comment| p comment.message}
96
152
  * Creating a shared link for a folder.
97
153
 
98
154
  ```ruby
99
- folder = client.folder('image_folder').create_shared_link
155
+ folder = client.folder('image_folder').create_shared_link # lookups by id are more efficient
100
156
  p folder.shared_link['url'] # https://www.box.com/s/d6de3224958c1755412
101
157
  ```
102
158
 
@@ -106,7 +162,8 @@ Files
106
162
  * Fetching a file's meta information.
107
163
 
108
164
  ```ruby
109
- file = client.file('/image_folder/an-image.jpg')
165
+ file = client.file('/image_folder/an-image.jpg')# lookups by id are more efficient
166
+ file = client.file(@file_id)
110
167
  p file.name
111
168
  p file.created_at
112
169
  ```
@@ -114,7 +171,8 @@ p file.created_at
114
171
  * Uploading a file to a folder.
115
172
 
116
173
  ```ruby
117
- file = client.upload_file('./LICENSE.txt', '/license_folder')
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)
118
176
  ```
119
177
 
120
178
  * Downloading a file.
@@ -123,18 +181,32 @@ file = client.upload_file('./LICENSE.txt', '/license_folder')
123
181
  f = open('./LOCAL.txt', 'w+')
124
182
  f.write( client.file('/license_folder/LICENSE.txt').download )
125
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
126
195
  ```
127
196
 
128
197
  * Deleting a file.
129
198
 
130
199
  ```ruby
200
+ client.file_by_id(@file_id).delete # this
131
201
  client.file('/license_folder/LICENSE.txt').delete
132
202
  ```
133
203
 
134
204
  * Displaying comments on a file.
135
205
 
136
206
  ```ruby
137
- comments = client.file('/image_folder/an-image.jpg').comments
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
+
138
210
  comments.each do |comment|
139
211
  p comment.message
140
212
  end
@@ -144,29 +216,46 @@ end
144
216
 
145
217
  ```ruby
146
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
147
220
  p file.shared_link.url # https://www.box.com/s/d6de3224958c1755412
148
221
  ```
149
222
 
150
223
  * Copying a file to another folder.
151
224
 
152
225
  ```ruby
153
- file = client.file('/image_folder/an-image.jpg')
226
+
227
+ file = client.file('/one_folder/cow_folder/an-image.jpg')
154
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
+
155
235
  file.copy_to(folder)
156
236
  ```
157
237
 
158
238
  * Moving a file to another folder.
159
239
 
160
240
  ```ruby
161
- file = client.file('/image_folder/an-image.jpg')
241
+
242
+ file = client.file('/one_folder/cow_folder/an-image.jpg')
162
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
+
163
251
  file.move_to(folder)
164
252
  ```
165
253
 
166
254
  * Adding a comment to a file.
167
255
 
168
256
  ```ruby
169
- file = client.file('/image_folder/an-image.jpg')
257
+ file = client.file('/image_folder/an-image.jpg') # path
258
+ file = client.file_by_id(@file_id) # id
170
259
  comment = file.create_comment('Hello World!')
171
260
  ```
172
261
 
@@ -196,13 +285,50 @@ eresp.events.each do |ev|
196
285
  end
197
286
  ```
198
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
+
199
328
  Contributors
200
329
  ============
201
330
 
202
- * Benjamin Coe
203
- * Larry Kang
204
- * Dan Reed
205
- * Jesse Miller
331
+ * [full list of contributors](https://github.com/attachmentsme/ruby-box/graphs/contributors)
206
332
 
207
333
  Contributing to ruby-box
208
334
  ========================
@@ -220,4 +346,4 @@ Copyright
220
346
  =========
221
347
 
222
348
  Copyright (c) 2012 Attachments.me. See LICENSE.txt for
223
- further details.
349
+ further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.11.1
1
+ 1.12.1
@@ -12,7 +12,11 @@ module RubyBox
12
12
  end
13
13
 
14
14
  def root_folder
15
- folder = Folder.new(@session, {'id' => '0'})
15
+ folder_by_id('0')
16
+ end
17
+
18
+ def folder_by_id(id)
19
+ folder = Folder.new(@session, {'id' => id})
16
20
  folder.reload_meta
17
21
  end
18
22
 
@@ -22,6 +26,11 @@ module RubyBox
22
26
  folder_from_split_path( split_path(path) )
23
27
  end
24
28
 
29
+ def file_by_id(id)
30
+ file = File.new(@session, {'id' => id})
31
+ file.reload_meta
32
+ end
33
+
25
34
  def file(path)
26
35
  path = split_path( path.sub(/^\.\//, '') )
27
36
  file_name = path.pop
@@ -88,12 +97,13 @@ module RubyBox
88
97
  end
89
98
 
90
99
  def upload_file(local_path, remote_path, overwrite=true)
91
- file_name = local_path.split('/').pop
92
100
  folder = create_folder( remote_path )
93
- return unless folder
94
- ::File.open( local_path ) do |data|
95
- folder.upload_file(file_name, data, overwrite)
96
- end
101
+ upload_file_to_folder(local_path, folder, overwrite)
102
+ end
103
+
104
+ def upload_file_by_folder_id(local_path, folder_id, overwrite=true)
105
+ folder = folder_by_id(folder_id)
106
+ upload_file_to_folder(local_path, folder, overwrite)
97
107
  end
98
108
 
99
109
  def split_path(path)
@@ -113,8 +123,24 @@ module RubyBox
113
123
  User.new(@session, resp)
114
124
  end
115
125
 
126
+ def users(filter_term = "", limit = 100, offset = 0)
127
+ url = "#{RubyBox::API_URL}/users?filter_term=#{URI::encode(filter_term)}&limit=#{limit}&offset=#{offset}"
128
+ resp = @session.get( url )
129
+ resp['entries'].map do |entry|
130
+ RubyBox::Item.factory(@session, entry)
131
+ end
132
+ end
133
+
116
134
  private
117
135
 
136
+ def upload_file_to_folder(local_path, folder, overwrite)
137
+ file_name = local_path.split('/').pop
138
+ return unless folder
139
+ ::File.open(local_path, 'rb') do |data|
140
+ folder.upload_file(file_name, data, overwrite)
141
+ end
142
+ end
143
+
118
144
  def folder_from_split_path(path)
119
145
  folder = root_folder
120
146
  path.each do |folder_name|
@@ -128,7 +154,7 @@ module RubyBox
128
154
  unless stream_position.to_s == 'now'
129
155
  stream_position = stream_position.kind_of?(Numeric) ? stream_position : 0
130
156
  end
131
- stream_type = [:all, :changes, :sync].include?(stream_type) ? stream_type : :all
157
+ stream_type = [:all, :changes, :sync, :admin_logs].include?(stream_type) ? stream_type : :all
132
158
  limit = limit.kind_of?(Fixnum) ? limit : 100
133
159
  "stream_position=#{stream_position}&stream_type=#{stream_type}&limit=#{limit}"
134
160
  end
data/lib/ruby-box/file.rb CHANGED
@@ -7,15 +7,8 @@ module RubyBox
7
7
  resp = stream.read
8
8
  end
9
9
 
10
- def move_to( folder_id, name=nil )
11
- # Allow either a folder_id or a folder object
12
- # to be passed in.
13
- folder_id = folder_id.id if folder_id.instance_of?(RubyBox::Folder)
14
-
15
- self.name = name if name
16
- self.parent = {"id" => folder_id}
17
-
18
- update
10
+ def download_url
11
+ @session.get( file_content_url )["location"]
19
12
  end
20
13
 
21
14
  def copy_to( folder_id, name=nil )
@@ -35,8 +28,7 @@ module RubyBox
35
28
  end
36
29
 
37
30
  def stream( opts={} )
38
- url = "#{RubyBox::API_URL}/#{resource_name}/#{id}/content"
39
- @session.do_stream( url, opts )
31
+ open(download_url, opts)
40
32
  end
41
33
 
42
34
  def upload_content( data )
@@ -83,6 +75,10 @@ module RubyBox
83
75
  end
84
76
 
85
77
  private
78
+ def file_content_url
79
+ "#{RubyBox::API_URL}/#{resource_name}/#{id}/content"
80
+ end
81
+
86
82
 
87
83
  def resource_name
88
84
  'files'
@@ -92,10 +88,6 @@ module RubyBox
92
88
  true
93
89
  end
94
90
 
95
- def update_fields
96
- ['name', 'description', 'parent']
97
- end
98
-
99
91
  def prepare_upload(data, fname)
100
92
  UploadIO.new(data, "application/pdf", fname)
101
93
  end
@@ -77,10 +77,6 @@ module RubyBox
77
77
  true
78
78
  end
79
79
 
80
- def update_fields
81
- ['name', 'description']
82
- end
83
-
84
80
  def items_by_type(type, name, item_limit, offset, fields)
85
81
 
86
82
  # allow paramters to be set via
@@ -95,4 +91,4 @@ module RubyBox
95
91
 
96
92
  end
97
93
  end
98
- end
94
+ end
data/lib/ruby-box/item.rb CHANGED
@@ -20,6 +20,17 @@ module RubyBox
20
20
  keys.each {|key| @@has_many_paginated << key.to_s}
21
21
  end
22
22
 
23
+ def move_to( folder_id, name=nil )
24
+ # Allow either a folder_id or a folder object
25
+ # to be passed in.
26
+ folder_id = folder_id.id if folder_id.instance_of?(RubyBox::Folder)
27
+
28
+ self.name = name if name
29
+ self.parent = {"id" => folder_id}
30
+
31
+ update
32
+ end
33
+
23
34
  def update
24
35
  reload_meta unless etag
25
36
 
@@ -161,5 +172,10 @@ module RubyBox
161
172
  update_fields.inject({}) {|hash, field| hash[field] = @raw_item[field]; hash}
162
173
  end
163
174
 
175
+ def update_fields
176
+ ['name', 'description', 'parent']
177
+ end
178
+
179
+
164
180
  end
165
181
  end
@@ -17,6 +17,7 @@ module RubyBox
17
17
  @oauth2_client = OAuth2::Client.new(opts[:client_id], opts[:client_secret], OAUTH2_URLS.dup)
18
18
  @access_token = OAuth2::AccessToken.new(@oauth2_client, opts[:access_token]) if opts[:access_token]
19
19
  @refresh_token = opts[:refresh_token]
20
+ @as_user = opts[:as_user]
20
21
  else # Support legacy API for historical reasons.
21
22
  @api_key = opts[:api_key]
22
23
  @auth_token = opts[:auth_token]
@@ -66,6 +67,9 @@ module RubyBox
66
67
  request.add_field('Authorization', build_auth_header)
67
68
  end
68
69
 
70
+
71
+ request.add_field('As-User', "#{@as_user}") if @as_user
72
+
69
73
  response = http.request(request)
70
74
 
71
75
  if response.is_a? Net::HTTPNotFound
@@ -80,7 +84,7 @@ module RubyBox
80
84
 
81
85
  sleep(@backoff) # try not to excessively hammer API.
82
86
 
83
- handle_errors( response.code.to_i, response.body, raw )
87
+ handle_errors( response, raw )
84
88
  end
85
89
 
86
90
  def do_stream(url, opts)
@@ -94,11 +98,15 @@ module RubyBox
94
98
  else
95
99
  params['Authorization'] = build_auth_header
96
100
  end
101
+
102
+ params['As-User'] = @as_user if @as_user
97
103
 
98
104
  open(url, params)
99
105
  end
100
106
 
101
- def handle_errors( status, body, raw )
107
+ def handle_errors( response, raw )
108
+ status = response.code.to_i
109
+ body = response.body
102
110
  begin
103
111
  parsed_body = JSON.parse(body)
104
112
  rescue
@@ -111,6 +119,9 @@ module RubyBox
111
119
  parsed_body["status"] = status
112
120
 
113
121
  case status / 100
122
+ when 3
123
+ # 302 Found. We should return the url
124
+ parsed_body["location"] = response["Location"] if status == 302
114
125
  when 4
115
126
  raise(RubyBox::ItemNameInUse.new(parsed_body, status, body), parsed_body["message"]) if parsed_body["code"] == "item_name_in_use"
116
127
  raise(RubyBox::AuthError.new(parsed_body, status, body), parsed_body["message"]) if parsed_body["code"] == "unauthorized" || status == 401
data/ruby-box.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-box"
8
- s.version = "1.11.1"
8
+ s.version = "1.12.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Attachments.me"]
12
- s.date = "2013-09-09"
12
+ s.date = "2013-12-02"
13
13
  s.description = "ruby gem for box.com 2.0 api"
14
14
  s.email = "ben@attachments.me"
15
15
  s.extra_rdoc_files = [
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
+ ".travis.yml",
21
22
  "Gemfile",
22
23
  "Gemfile.lock",
23
24
  "LICENSE.txt",
@@ -46,22 +47,24 @@ Gem::Specification.new do |s|
46
47
  "spec/fixtures/comment_create.json",
47
48
  "spec/fixtures/events.json",
48
49
  "spec/fixtures/me.json",
50
+ "spec/fixtures/users.json",
49
51
  "spec/folder_spec.rb",
50
52
  "spec/helper/account.example",
51
53
  "spec/helper/account.rb",
52
54
  "spec/integration_spec.rb",
53
55
  "spec/item_spec.rb",
54
56
  "spec/me_spec.rb",
55
- "spec/spec_helper.rb"
57
+ "spec/spec_helper.rb",
58
+ "spec/users_spec.rb"
56
59
  ]
57
60
  s.homepage = "http://github.com/attachmentsme/ruby-box"
58
61
  s.licenses = ["MIT"]
59
62
  s.require_paths = ["lib"]
60
- s.rubygems_version = "2.0.3"
63
+ s.rubygems_version = "1.8.24"
61
64
  s.summary = "ruby gem for box.com 2.0 api"
62
65
 
63
66
  if s.respond_to? :specification_version then
64
- s.specification_version = 4
67
+ s.specification_version = 3
65
68
 
66
69
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
67
70
  s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
@@ -0,0 +1,39 @@
1
+ {
2
+ "total_count": 2,
3
+ "entries": [
4
+ {
5
+ "type": "user",
6
+ "id": "181216415",
7
+ "name": "sean rose",
8
+ "login": "sean+awesome@box.com",
9
+ "created_at": "2012-05-03T21:39:11-07:00",
10
+ "modified_at": "2012-08-23T14:57:48-07:00",
11
+ "language": "en",
12
+ "space_amount": 5368709120,
13
+ "space_used": 52947,
14
+ "max_upload_size": 104857600,
15
+ "status": "active",
16
+ "job_title": "",
17
+ "phone": "5555551374",
18
+ "address": "10 Cloud Way Los Altos CA",
19
+ "avatar_url": "https://api.box.com/api/avatar/large/181216415"
20
+ },
21
+ {
22
+ "type": "user",
23
+ "id": "181216416",
24
+ "name": "sean rose",
25
+ "login": "sean+awesomer@box.com",
26
+ "created_at": "2012-05-03T21:39:11-07:00",
27
+ "modified_at": "2012-08-23T14:57:48-07:00",
28
+ "language": "en",
29
+ "space_amount": 5368709120,
30
+ "space_used": 52947,
31
+ "max_upload_size": 104857600,
32
+ "status": "active",
33
+ "job_title": "",
34
+ "phone": "5555551374",
35
+ "address": "10 Cloud Way Los Altos CA",
36
+ "avatar_url": "https://api.box.com/api/avatar/large/181216416"
37
+ }
38
+ ]
39
+ }
@@ -146,7 +146,7 @@ describe RubyBox, :skip => true do
146
146
  end
147
147
  end
148
148
 
149
- describe '#put_data' do
149
+ context 'uploading files' do
150
150
  it "should update an existing file" do
151
151
  utf8_file_name = '遠志教授.jpg'
152
152
  fdata = File.open( 'spec/fixtures/' + utf8_file_name, 'rb' )
@@ -173,6 +173,14 @@ describe RubyBox, :skip => true do
173
173
  file.name.should == '遠志教授.jpg'
174
174
  file.delete
175
175
  end
176
+
177
+ it "should allow a file to be uploaded by a folder id" do
178
+ utf8_file_name = '遠志教授.jpg'
179
+ folder = @client.folder('/ruby-box_gem_testing/cool stuff/')
180
+ file = @client.upload_file_by_folder_id('spec/fixtures/' + utf8_file_name, folder.id)
181
+ file.name.should == '遠志教授.jpg'
182
+ file.delete
183
+ end
176
184
  end
177
185
 
178
186
  describe '#create_folder' do
@@ -183,6 +191,14 @@ describe RubyBox, :skip => true do
183
191
  end
184
192
  end
185
193
 
194
+ describe '#folder_by_id' do
195
+ it "allows a folder to be retrieved by its id" do
196
+ folder = @client.folder('/ruby-box_gem_testing')
197
+ folder_by_id = @client.folder_by_id(folder.id)
198
+ folder_by_id.name.should == folder.name
199
+ end
200
+ end
201
+
186
202
  describe '#delete folder' do
187
203
  it "should be able to recursively delete the contents of a folder" do
188
204
  folder = @client.create_folder('/ruby-box_gem_testing/delete_test')
@@ -191,11 +207,17 @@ describe RubyBox, :skip => true do
191
207
  end
192
208
  end
193
209
 
194
- describe '#get_file_info' do
210
+ context 'retrieving a file' do
195
211
  it "returns meta information for a file" do
196
212
  file = @client.file( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
197
213
  file.size.should == 14
198
214
  end
215
+
216
+ it "a file can be retrieved by its id" do
217
+ file = @client.file( '/ruby-box_gem_testing/cool stuff/кузнецкий_105_а_№2.test' )
218
+ file_by_id = @client.file_by_id( file.id )
219
+ file_by_id.size.should == 14
220
+ end
199
221
  end
200
222
 
201
223
  describe '#stream' do
@@ -0,0 +1,24 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'ruby-box'
4
+ require 'webmock/rspec'
5
+
6
+ describe '/users' do
7
+ before do
8
+ @session = RubyBox::Session.new
9
+ @client = RubyBox::Client.new(@session)
10
+ @users_json = File.read 'spec/fixtures/users.json'
11
+ @users = JSON.load(@users_json)
12
+ stub_request(:get, /#{RubyBox::API_URL}\/users/).to_return(body: @users_json, :status => 200)
13
+ end
14
+
15
+ it 'should return a list of all users in the enterprise' do
16
+ users = @client.users
17
+ users.instance_of?(Array).should be_true
18
+ end
19
+
20
+ it 'should return a list of all users in the enterprise as a user object' do
21
+ users = @client.users
22
+ users.first.instance_of?(RubyBox::User).should be_true
23
+ end
24
+ end
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.12.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Attachments.me
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-09-09 00:00:00.000000000 Z
12
+ date: 2013-12-02 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: multipart-post
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: oauth2
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: json
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :runtime
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: addressable
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :runtime
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rspec
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ! '>='
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ! '>='
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: bundler
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -97,6 +110,7 @@ dependencies:
97
110
  - !ruby/object:Gem::Dependency
98
111
  name: jeweler
99
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
100
114
  requirements:
101
115
  - - ~>
102
116
  - !ruby/object:Gem::Version
@@ -104,6 +118,7 @@ dependencies:
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
107
122
  requirements:
108
123
  - - ~>
109
124
  - !ruby/object:Gem::Version
@@ -111,6 +126,7 @@ dependencies:
111
126
  - !ruby/object:Gem::Dependency
112
127
  name: webmock
113
128
  requirement: !ruby/object:Gem::Requirement
129
+ none: false
114
130
  requirements:
115
131
  - - ! '>='
116
132
  - !ruby/object:Gem::Version
@@ -118,6 +134,7 @@ dependencies:
118
134
  type: :development
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
121
138
  requirements:
122
139
  - - ! '>='
123
140
  - !ruby/object:Gem::Version
@@ -131,6 +148,7 @@ extra_rdoc_files:
131
148
  - README.markdown
132
149
  files:
133
150
  - .document
151
+ - .travis.yml
134
152
  - Gemfile
135
153
  - Gemfile.lock
136
154
  - LICENSE.txt
@@ -159,6 +177,7 @@ files:
159
177
  - spec/fixtures/comment_create.json
160
178
  - spec/fixtures/events.json
161
179
  - spec/fixtures/me.json
180
+ - spec/fixtures/users.json
162
181
  - spec/folder_spec.rb
163
182
  - spec/helper/account.example
164
183
  - spec/helper/account.rb
@@ -166,29 +185,31 @@ files:
166
185
  - spec/item_spec.rb
167
186
  - spec/me_spec.rb
168
187
  - spec/spec_helper.rb
188
+ - spec/users_spec.rb
169
189
  homepage: http://github.com/attachmentsme/ruby-box
170
190
  licenses:
171
191
  - MIT
172
- metadata: {}
173
192
  post_install_message:
174
193
  rdoc_options: []
175
194
  require_paths:
176
195
  - lib
177
196
  required_ruby_version: !ruby/object:Gem::Requirement
197
+ none: false
178
198
  requirements:
179
199
  - - ! '>='
180
200
  - !ruby/object:Gem::Version
181
201
  version: '0'
182
202
  required_rubygems_version: !ruby/object:Gem::Requirement
203
+ none: false
183
204
  requirements:
184
205
  - - ! '>='
185
206
  - !ruby/object:Gem::Version
186
207
  version: '0'
187
208
  requirements: []
188
209
  rubyforge_project:
189
- rubygems_version: 2.0.3
210
+ rubygems_version: 1.8.24
190
211
  signing_key:
191
- specification_version: 4
212
+ specification_version: 3
192
213
  summary: ruby gem for box.com 2.0 api
193
214
  test_files: []
194
215
  has_rdoc:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWRiNTUwYmE4YTFkYzJlN2M4OGQxYTQ2ZDFmZjRhMzEyZTRlMmIwMw==
5
- data.tar.gz: !binary |-
6
- ZDQxMDNjZWYyODc2Njc5MThjNjllYjMzZGE5MmU2OTY5MTc5OGJhNQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YWM3MDRmN2E5M2RmZjYxOWJiOWIwY2ZhNzFlNTA4MzZlM2U3ZTc4ZTNjNGY2
10
- MzkzMDAwZTcyYjY0OWFhNjM3MWQyNTUyZDgxNzNjODViYTM1MGMyNzY4Njcy
11
- ODk1NDNjYzMwZWVjNTJjNTMyMDAwMTY4NTRmOWQ4ZjM3Yzk3ZDI=
12
- data.tar.gz: !binary |-
13
- ZjA4M2UyZDY4OWIzYzU1YjgyMTFhYmI2MTM1Yjk3NzFmZTRmYzQwMGViOGFk
14
- YWQ0Yzg5ODg3NzdhNDE4ODEyNTQzNmVlNTY5YTAyYThlMWY1ZmM0MmQ3ODhk
15
- YmMzMjdhZTU5ZjRkZjNhODFlMTk4Nzg1YzFhMWQ1MTc2NWQ3MzQ=