boxr 0.18.0 → 0.19.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 +4 -4
- data/README.md +8 -5
- data/boxr.gemspec +1 -0
- data/lib/boxr.rb +2 -1
- data/lib/boxr/auth.rb +10 -4
- data/lib/boxr/client.rb +16 -4
- data/lib/boxr/collaborations.rb +19 -2
- data/lib/boxr/files.rb +1 -1
- data/lib/boxr/version.rb +1 -1
- data/spec/boxr_spec.rb +14 -6
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b149bf857a1d64b35578d649c769792c9569e1c2
|
4
|
+
data.tar.gz: 1cba489db37903b1ceea8f90508687baf76521da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a9ff438d8b6a582d3e52bdea63457b874377b5c7290b945a3430241d308aa051cf6c9e0b4c8d929c273f411582d343f1c3ff7f79b3e217fccd27d61fe882e3b
|
7
|
+
data.tar.gz: b6ffbfe77e2060e9d7a01d60eec9aca993181f22353282da8df4e86185d357f96eb4b0edff5af74adfb924bc5768a81dc20f61c2cf2e21882ebd8ba547d336f1
|
data/README.md
CHANGED
@@ -3,7 +3,10 @@ Boxr is a Ruby client library for the Box V2 Content API that covers 100% of the
|
|
3
3
|
|
4
4
|
The purpose of this gem is to provide a clear, efficient, and intentional method of interacting with the Box Content API. As with any SDK that wraps a REST API, it is important to fully understand the Box Content API at the REST endpoint level. You are strongly encouraged to read through the Box documentation located [here](https://developers.box.com/docs/).
|
5
5
|
|
6
|
-
The full RubyDocs for Boxr can be found [here](http://www.rubydoc.info/gems/boxr/Boxr/Client). You are also encouraged to rely heavily on the source code found in the [lib/boxr](https://github.com/cburnette/boxr/tree/master/lib/boxr) directory of this gem, as well as on the integration
|
6
|
+
The full RubyDocs for Boxr can be found [here](http://www.rubydoc.info/gems/boxr/Boxr/Client). You are also encouraged to rely heavily on the source code found in the [lib/boxr](https://github.com/cburnette/boxr/tree/master/lib/boxr) directory of this gem, as well as on the integration tests found [here](https://github.com/cburnette/boxr/blob/master/spec/boxr_spec.rb).
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
This gem requires Ruby 2.0.0 or higher. The integration tests are currently being run using MRI Ruby 2.0.0-p643 and MRI Ruby 2.2.0.
|
7
10
|
|
8
11
|
## Installation
|
9
12
|
Add this line to your application's Gemfile:
|
@@ -103,7 +106,7 @@ puts "Shared Link: #{file.shared_link.url}"
|
|
103
106
|
```ruby
|
104
107
|
#NOTE: these are all module methods
|
105
108
|
|
106
|
-
Boxr::oauth_url(state, response_type: "code", scope: nil, folder_id: nil, box_client_id: ENV['BOX_CLIENT_ID'])
|
109
|
+
Boxr::oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, box_client_id: ENV['BOX_CLIENT_ID'])
|
107
110
|
|
108
111
|
Boxr::get_tokens(code, grant_type: "authorization_code", username: nil, box_client_id: ENV['BOX_CLIENT_ID'], box_client_secret: ENV['BOX_CLIENT_SECRET'])
|
109
112
|
|
@@ -221,11 +224,11 @@ pending_collaborations()
|
|
221
224
|
```
|
222
225
|
#### [Events](https://developers.box.com/docs/#events)
|
223
226
|
```ruby
|
224
|
-
user_events(stream_position, stream_type: :all, limit:
|
227
|
+
user_events(stream_position, stream_type: :all, limit: 800)
|
225
228
|
|
226
|
-
enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit:
|
229
|
+
enterprise_events(created_after: nil, created_before: nil, stream_position: 0, event_type: nil, limit: 500)
|
227
230
|
|
228
|
-
enterprise_events_stream(initial_stream_position, event_type: nil, limit:
|
231
|
+
enterprise_events_stream(initial_stream_position, event_type: nil, limit: 500, refresh_period: 300)
|
229
232
|
```
|
230
233
|
#### [Shared Items](https://developers.box.com/docs/#shared-items)
|
231
234
|
```ruby
|
data/boxr.gemspec
CHANGED
data/lib/boxr.rb
CHANGED
data/lib/boxr/auth.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
module Boxr
|
2
2
|
|
3
|
-
def self.oauth_url(state, response_type: "code", scope: nil, folder_id: nil, box_client_id: ENV['BOX_CLIENT_ID'])
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
def self.oauth_url(state, host: "app.box.com", response_type: "code", scope: nil, folder_id: nil, box_client_id: ENV['BOX_CLIENT_ID'])
|
4
|
+
template = Addressable::Template.new("https://{host}/api/oauth2/authorize{?query*}")
|
5
|
+
|
6
|
+
query = {"response_type" => "#{response_type}", "state" => "#{state}", "client_id" => "#{box_client_id}"}
|
7
|
+
query["scope"] = "#{scope}" unless scope.nil?
|
8
|
+
query["folder_id"] = "#{folder_id}" unless folder_id.nil?
|
9
|
+
|
10
|
+
uri = template.expand({"host" => "#{host}", "query" => query})
|
7
11
|
uri
|
8
12
|
end
|
9
13
|
|
@@ -32,6 +36,8 @@ module Boxr
|
|
32
36
|
private
|
33
37
|
|
34
38
|
def self.auth_post(uri, body)
|
39
|
+
uri = Addressable::URI.encode(uri)
|
40
|
+
|
35
41
|
res = BOX_CLIENT.post(uri, body: body)
|
36
42
|
|
37
43
|
if(res.status==200)
|
data/lib/boxr/client.rb
CHANGED
@@ -49,6 +49,8 @@ module Boxr
|
|
49
49
|
|
50
50
|
GROUP_FIELDS = [:type, :id, :name, :created_at, :modified_at]
|
51
51
|
GROUP_FIELDS_QUERY = GROUP_FIELDS.join(',')
|
52
|
+
|
53
|
+
VALID_COLLABORATION_ROLES = ['editor','viewer','previewer','uploader','previewer uploader','viewer uploader','co-owner','owner']
|
52
54
|
|
53
55
|
|
54
56
|
def initialize(access_token=ENV['BOX_DEVELOPER_TOKEN'], refresh_token: nil, box_client_id: ENV['BOX_CLIENT_ID'], box_client_secret: ENV['BOX_CLIENT_SECRET'],
|
@@ -67,13 +69,15 @@ module Boxr
|
|
67
69
|
|
68
70
|
private
|
69
71
|
|
70
|
-
def get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil)
|
72
|
+
def get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil, follow_redirect: true)
|
73
|
+
uri = Addressable::URI.encode(uri)
|
74
|
+
|
71
75
|
res = with_auto_token_refresh do
|
72
76
|
headers = standard_headers
|
73
77
|
headers['If-Match'] = if_match unless if_match.nil?
|
74
78
|
headers['BoxApi'] = box_api_header unless box_api_header.nil?
|
75
79
|
|
76
|
-
BOX_CLIENT.get(uri, query: query, header: headers)
|
80
|
+
BOX_CLIENT.get(uri, query: query, header: headers, follow_redirect: follow_redirect)
|
77
81
|
end
|
78
82
|
|
79
83
|
check_response_status(res, success_codes)
|
@@ -85,7 +89,8 @@ module Boxr
|
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
|
-
def get_all_with_pagination(uri, query: {}, offset: 0, limit: DEFAULT_LIMIT)
|
92
|
+
def get_all_with_pagination(uri, query: {}, offset: 0, limit: DEFAULT_LIMIT, follow_redirect: true)
|
93
|
+
uri = Addressable::URI.encode(uri)
|
89
94
|
entries = []
|
90
95
|
|
91
96
|
begin
|
@@ -93,7 +98,7 @@ module Boxr
|
|
93
98
|
query[:offset] = offset
|
94
99
|
res = with_auto_token_refresh do
|
95
100
|
headers = standard_headers
|
96
|
-
BOX_CLIENT.get(uri, query: query, header: headers)
|
101
|
+
BOX_CLIENT.get(uri, query: query, header: headers, follow_redirect: follow_redirect)
|
97
102
|
end
|
98
103
|
|
99
104
|
if (res.status==200)
|
@@ -111,6 +116,7 @@ module Boxr
|
|
111
116
|
end
|
112
117
|
|
113
118
|
def post(uri, body, query: nil, success_codes: [201], process_body: true, content_md5: nil, content_type: nil, if_match: nil)
|
119
|
+
uri = Addressable::URI.encode(uri)
|
114
120
|
body = Oj.dump(body) if process_body
|
115
121
|
|
116
122
|
res = with_auto_token_refresh do
|
@@ -128,6 +134,8 @@ module Boxr
|
|
128
134
|
end
|
129
135
|
|
130
136
|
def put(uri, body, query: nil, success_codes: [200], content_type: nil, if_match: nil)
|
137
|
+
uri = Addressable::URI.encode(uri)
|
138
|
+
|
131
139
|
res = with_auto_token_refresh do
|
132
140
|
headers = standard_headers
|
133
141
|
headers['If-Match'] = if_match unless if_match.nil?
|
@@ -142,6 +150,8 @@ module Boxr
|
|
142
150
|
end
|
143
151
|
|
144
152
|
def delete(uri, query: nil, success_codes: [204], if_match: nil)
|
153
|
+
uri = Addressable::URI.encode(uri)
|
154
|
+
|
145
155
|
res = with_auto_token_refresh do
|
146
156
|
headers = standard_headers
|
147
157
|
headers['If-Match'] = if_match unless if_match.nil?
|
@@ -155,6 +165,8 @@ module Boxr
|
|
155
165
|
end
|
156
166
|
|
157
167
|
def options(uri, body, success_codes: [200])
|
168
|
+
uri = Addressable::URI.encode(uri)
|
169
|
+
|
158
170
|
res = with_auto_token_refresh do
|
159
171
|
headers = standard_headers
|
160
172
|
BOX_CLIENT.options(uri, body: Oj.dump(body), header: headers)
|
data/lib/boxr/collaborations.rb
CHANGED
@@ -18,7 +18,7 @@ module Boxr
|
|
18
18
|
|
19
19
|
attributes = {item: {id: folder_id, type: :folder}}
|
20
20
|
attributes[:accessible_by] = accessible_by
|
21
|
-
attributes[:role] = role
|
21
|
+
attributes[:role] = validate_role(role)
|
22
22
|
|
23
23
|
collaboration, response = post(COLLABORATIONS_URI, attributes, query: query)
|
24
24
|
collaboration
|
@@ -28,7 +28,7 @@ module Boxr
|
|
28
28
|
collaboration_id = ensure_id(collaboration)
|
29
29
|
uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
|
30
30
|
attributes = {}
|
31
|
-
attributes[:role] = role unless role.nil?
|
31
|
+
attributes[:role] = validate_role(role) unless role.nil?
|
32
32
|
attributes[:status] = status unless status.nil?
|
33
33
|
|
34
34
|
updated_collaboration, response = put(uri, attributes)
|
@@ -62,5 +62,22 @@ module Boxr
|
|
62
62
|
end
|
63
63
|
|
64
64
|
|
65
|
+
private
|
66
|
+
|
67
|
+
def validate_role(role)
|
68
|
+
case role
|
69
|
+
when :previewer_uploader
|
70
|
+
role = 'previewer uploader'
|
71
|
+
when :viewer_uploader
|
72
|
+
role = 'viewer uploader'
|
73
|
+
when :co_owner
|
74
|
+
role = 'co-owner'
|
75
|
+
end
|
76
|
+
|
77
|
+
role = role.to_s
|
78
|
+
raise BoxrError.new(boxr_message: "Invalid collaboration role: '#{role}'") unless VALID_COLLABORATION_ROLES.include?(role)
|
79
|
+
|
80
|
+
role
|
81
|
+
end
|
65
82
|
end
|
66
83
|
end
|
data/lib/boxr/files.rb
CHANGED
@@ -52,7 +52,7 @@ module Boxr
|
|
52
52
|
uri = "#{FILES_URI}/#{file_id}/content"
|
53
53
|
query = {}
|
54
54
|
query[:version] = version unless version.nil?
|
55
|
-
body_json, response = get(uri, query: query, success_codes: [302,202])
|
55
|
+
body_json, response = get(uri, query: query, success_codes: [302,202], follow_redirect: false) #we don't want httpclient to automatically follow the redirect; we need to grab it
|
56
56
|
|
57
57
|
if(response.status==302)
|
58
58
|
location = response.header['Location'][0]
|
data/lib/boxr/version.rb
CHANGED
data/spec/boxr_spec.rb
CHANGED
@@ -61,6 +61,8 @@ describe Boxr::Client do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
#use this command to just execute this scenario
|
65
|
+
#rake spec SPEC_OPTS="-e \"invokes folder operations"\"
|
64
66
|
it 'invokes folder operations' do
|
65
67
|
puts "get folder using path"
|
66
68
|
folder = BOX_CLIENT.folder_from_path(TEST_FOLDER_NAME)
|
@@ -125,6 +127,7 @@ describe Boxr::Client do
|
|
125
127
|
expect(result).to eq({})
|
126
128
|
end
|
127
129
|
|
130
|
+
#rake spec SPEC_OPTS="-e \"invokes file operations"\"
|
128
131
|
it "invokes file operations" do
|
129
132
|
puts "upload a file"
|
130
133
|
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
@@ -216,6 +219,7 @@ describe Boxr::Client do
|
|
216
219
|
expect(result).to eq({})
|
217
220
|
end
|
218
221
|
|
222
|
+
#rake spec SPEC_OPTS="-e \"invokes user operations"\"
|
219
223
|
it "invokes user operations" do
|
220
224
|
puts "inspect current user"
|
221
225
|
user = BOX_CLIENT.current_user
|
@@ -244,6 +248,7 @@ describe Boxr::Client do
|
|
244
248
|
expect(result).to eq({})
|
245
249
|
end
|
246
250
|
|
251
|
+
#rake spec SPEC_OPTS="-e \"invokes group operations"\"
|
247
252
|
it "invokes group operations" do
|
248
253
|
puts "create group"
|
249
254
|
group = BOX_CLIENT.create_group(TEST_GROUP_NAME)
|
@@ -305,6 +310,7 @@ describe Boxr::Client do
|
|
305
310
|
expect(response).to eq({})
|
306
311
|
end
|
307
312
|
|
313
|
+
#rake spec SPEC_OPTS="-e \"invokes comment operations"\"
|
308
314
|
it "invokes comment operations" do
|
309
315
|
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
310
316
|
test_file = new_file
|
@@ -335,9 +341,10 @@ describe Boxr::Client do
|
|
335
341
|
expect(result).to eq({})
|
336
342
|
end
|
337
343
|
|
344
|
+
#rake spec SPEC_OPTS="-e \"invokes collaborations operations"\"
|
338
345
|
it "invokes collaborations operations" do
|
339
346
|
puts "add collaboration"
|
340
|
-
collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :
|
347
|
+
collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :viewer_uploader)
|
341
348
|
expect(collaboration.accessible_by.id).to eq(@test_user.id)
|
342
349
|
COLLABORATION = collaboration
|
343
350
|
|
@@ -363,8 +370,12 @@ describe Boxr::Client do
|
|
363
370
|
puts "inspect pending collaborations"
|
364
371
|
pending_collaborations = BOX_CLIENT.pending_collaborations
|
365
372
|
expect(pending_collaborations).to eq([])
|
373
|
+
|
374
|
+
puts "add invalid collaboration"
|
375
|
+
expect { BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :invalid_role)}.to raise_error
|
366
376
|
end
|
367
377
|
|
378
|
+
#rake spec SPEC_OPTS="-e \"invokes task operations"\"
|
368
379
|
it "invokes task operations" do
|
369
380
|
test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
370
381
|
collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :editor)
|
@@ -419,9 +430,9 @@ describe Boxr::Client do
|
|
419
430
|
expect(result).to eq({})
|
420
431
|
end
|
421
432
|
|
433
|
+
#rake spec SPEC_OPTS="-e \"invokes metadata operations"\"
|
422
434
|
it "invokes metadata operations" do
|
423
435
|
test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
424
|
-
#test_file_id = new_file.id
|
425
436
|
|
426
437
|
puts "create metadata"
|
427
438
|
meta = {"a" => "hello", "b" => "world"}
|
@@ -441,6 +452,7 @@ describe Boxr::Client do
|
|
441
452
|
expect(result).to eq({})
|
442
453
|
end
|
443
454
|
|
455
|
+
#rake spec SPEC_OPTS="-e \"invokes search operations"\"
|
444
456
|
it "invokes search operations" do
|
445
457
|
#the issue with this test is that Box can take between 5-10 minutes to index any content uploaded; this is just a smoke test
|
446
458
|
#so we are searching for something that should return zero results
|
@@ -449,8 +461,4 @@ describe Boxr::Client do
|
|
449
461
|
expect(results).to eq([])
|
450
462
|
end
|
451
463
|
|
452
|
-
it "invokes a Boxr error" do
|
453
|
-
expect { BOX_CLIENT.folder(1)}.to raise_error
|
454
|
-
end
|
455
|
-
|
456
464
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Burnette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,6 +150,20 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '3.3'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: addressable
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.3'
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '2.3'
|
153
167
|
description: ''
|
154
168
|
email:
|
155
169
|
- chadburnette@me.com
|