boxr 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +18 -3
- data/Rakefile +2 -0
- data/boxr.gemspec +4 -1
- data/examples/enterprise_events.rb +21 -0
- data/examples/user_events.rb +24 -0
- data/lib/boxr.rb +3 -2
- data/lib/boxr/client.rb +13 -11
- data/lib/boxr/collaborations.rb +7 -1
- data/lib/boxr/comments.rb +8 -1
- data/lib/boxr/events.rb +22 -0
- data/lib/boxr/exceptions.rb +18 -13
- data/lib/boxr/files.rb +38 -27
- data/lib/boxr/folders.rb +26 -12
- data/lib/boxr/groups.rb +2 -0
- data/lib/boxr/search.rb +1 -1
- data/lib/boxr/tasks.rb +9 -1
- data/lib/boxr/users.rb +5 -1
- data/lib/boxr/version.rb +1 -1
- data/lib/tasks/oauth.rake +22 -0
- data/spec/boxr_spec.rb +437 -5
- data/spec/spec_helper.rb +3 -1
- data/spec/test_files/test file.txt +1 -0
- metadata +52 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67e27a5d8aa317d4f5367ca297a6effba37f940c
|
4
|
+
data.tar.gz: b3541ffde249148cbdde2f1666479c1377993b7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9837ce765c7cf63b3df57ab8fbf513b2e9f6745d447291bcedfd7a9bdc672028b185b93b52797c1fc9e36600f931fe6f40f0824122f659eff96ca052d3a3ae0d
|
7
|
+
data.tar.gz: bd84a9467ad8df991be52c8832cd63e0e5bb112352e20d7d1418b3ad7ddc77d98d4dbbb6c71eee253eeeb5d70a926fe10b4d1188ec4ec7df45c31aad7d536e01
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Boxr
|
2
2
|
|
3
|
-
|
3
|
+
PLEASE NOTE: I need to complete this README with much more detailed instructions. However, feel free to try it out. The integration test suite is achieving 95% code coverage. Thanks!
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,11 +20,26 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
Super-fast instructions for now (much more to come):
|
24
|
+
|
25
|
+
1. go to https://developers.box.com
|
26
|
+
2. find or create your Box Content API app for testing
|
27
|
+
3. click 'Edit Application'
|
28
|
+
4. check the boxes for 'Read and write all files and folders' and 'Manage an enterprise'
|
29
|
+
5. click 'Create a developer token'
|
30
|
+
6. copy the token and use it in the code below in place of {BOX_DEVELOPER_TOKEN}
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'boxr'
|
34
|
+
|
35
|
+
client = Boxr::Client.new({BOX_DEVELOPER_TOKEN})
|
36
|
+
items = client.folder_items(Boxr::ROOT)
|
37
|
+
items.each {|i| puts i.name}
|
38
|
+
```
|
24
39
|
|
25
40
|
## Contributing
|
26
41
|
|
27
|
-
1. Fork it ( https://github.com/
|
42
|
+
1. Fork it ( https://github.com/cburnette/boxr/fork )
|
28
43
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
44
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
45
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
data/boxr.gemspec
CHANGED
@@ -20,10 +20,13 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '~> 2.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
spec.add_development_dependency "rspec", "~> 3.1"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.9"
|
26
27
|
spec.add_development_dependency "dotenv", "~> 0.11"
|
28
|
+
spec.add_development_dependency "awesome_print"
|
29
|
+
spec.add_development_dependency "lru_redux"
|
27
30
|
|
28
31
|
spec.add_runtime_dependency "oj", "~> 2.11"
|
29
32
|
spec.add_runtime_dependency "httpclient", "~> 2.5"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'dotenv'; Dotenv.load("../.env")
|
2
|
+
require 'boxr'
|
3
|
+
require 'awesome_print'
|
4
|
+
|
5
|
+
client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
|
6
|
+
|
7
|
+
now = Time.now
|
8
|
+
start_date = now - (60*60*24*30) #three days ago
|
9
|
+
end_date = now - (60*60*24) #one day ago
|
10
|
+
|
11
|
+
stream_position = 0
|
12
|
+
puts "fetching enterprise events..."
|
13
|
+
loop do
|
14
|
+
event_response = client.enterprise_events(stream_position: stream_position, created_after: start_date.utc, created_before: end_date.utc)
|
15
|
+
event_response.events.each do |event|
|
16
|
+
ap event
|
17
|
+
end
|
18
|
+
stream_position = event_response.next_stream_position
|
19
|
+
|
20
|
+
break if event_response.events.empty?
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'dotenv'; Dotenv.load("../.env")
|
2
|
+
require 'boxr'
|
3
|
+
require 'awesome_print'
|
4
|
+
require 'lru_redux'
|
5
|
+
|
6
|
+
client = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
|
7
|
+
cache = LruRedux::Cache.new(1000)
|
8
|
+
|
9
|
+
stream_position = :now
|
10
|
+
loop do
|
11
|
+
puts "fetching events..."
|
12
|
+
event_response = client.user_events(stream_position: stream_position)
|
13
|
+
event_response.events.each do |event|
|
14
|
+
key = "/box-event/id/#{event.event_id}"
|
15
|
+
|
16
|
+
#we need to de-dupe the events because we will receive multiple events with the same event_id; this is to ensure that we get the event
|
17
|
+
if (cache.fetch(event.event_id)==nil)
|
18
|
+
cache[event.event_id] = true
|
19
|
+
puts event.event_type
|
20
|
+
end
|
21
|
+
end
|
22
|
+
stream_position = event_response.next_stream_position
|
23
|
+
sleep 2
|
24
|
+
end
|
data/lib/boxr.rb
CHANGED
@@ -2,9 +2,10 @@ require 'oj'
|
|
2
2
|
require 'httpclient'
|
3
3
|
require 'hashie'
|
4
4
|
|
5
|
-
require
|
5
|
+
require 'boxr/version'
|
6
6
|
require 'boxr/exceptions'
|
7
7
|
require 'boxr/client'
|
8
|
+
require 'boxr/shared_items'
|
8
9
|
require 'boxr/folders'
|
9
10
|
require 'boxr/files'
|
10
11
|
require 'boxr/comments'
|
@@ -13,8 +14,8 @@ require 'boxr/groups'
|
|
13
14
|
require 'boxr/collaborations'
|
14
15
|
require 'boxr/search'
|
15
16
|
require 'boxr/tasks'
|
16
|
-
require 'boxr/shared_items'
|
17
17
|
require 'boxr/metadata'
|
18
|
+
require 'boxr/events'
|
18
19
|
|
19
20
|
module Enumerable
|
20
21
|
def files
|
data/lib/boxr/client.rb
CHANGED
@@ -17,6 +17,7 @@ module Boxr
|
|
17
17
|
TASK_ASSIGNMENTS_URI = "#{API_URI}/task_assignments"
|
18
18
|
SHARED_ITEMS_URI = "#{API_URI}/shared_items"
|
19
19
|
METADATA_URI = "#{API_URI}/files"
|
20
|
+
EVENTS_URI = "#{API_URI}/events"
|
20
21
|
|
21
22
|
DEFAULT_LIMIT = 100
|
22
23
|
FOLDER_ITEMS_LIMIT = 1000
|
@@ -50,6 +51,7 @@ module Boxr
|
|
50
51
|
#All instances of Boxr::Client will use this one class instance of HTTPClient; that way persistent HTTPS connections work.
|
51
52
|
#Plus, httpclient is thread-safe so we can use the same class instance with multiple instances of Boxr::Client
|
52
53
|
BOX_CLIENT = HTTPClient.new
|
54
|
+
BOX_CLIENT.send_timeout = 3600 #one hour; needed for lengthy uploads
|
53
55
|
BOX_CLIENT.transparent_gzip_decompression = true
|
54
56
|
|
55
57
|
def initialize(token, as_user_id: nil)
|
@@ -103,7 +105,7 @@ module Boxr
|
|
103
105
|
|
104
106
|
entries << body_json["entries"]
|
105
107
|
else
|
106
|
-
raise BoxrException.new(res.status, res.body, res.header)
|
108
|
+
raise BoxrException.new(status: res.status, body: res.body, header: res.header)
|
107
109
|
end
|
108
110
|
end until offset - total_count >= 0
|
109
111
|
|
@@ -161,7 +163,7 @@ module Boxr
|
|
161
163
|
end
|
162
164
|
|
163
165
|
def check_response_status(res, success_codes)
|
164
|
-
raise BoxrException.new(res.status, res.body, res.header) unless success_codes.include?(res.status)
|
166
|
+
raise BoxrException.new(status: res.status, body: res.body, header: res.header) unless success_codes.include?(res.status)
|
165
167
|
end
|
166
168
|
|
167
169
|
def processed_response(res)
|
@@ -179,6 +181,15 @@ module Boxr
|
|
179
181
|
end
|
180
182
|
end
|
181
183
|
|
184
|
+
def restore_trashed_item(uri, name, parent_id)
|
185
|
+
attributes = {}
|
186
|
+
attributes[:name] = name unless name.nil?
|
187
|
+
attributes[:parent] = {id: parent_id} unless parent_id.nil?
|
188
|
+
|
189
|
+
restored_item, response = post uri, attributes
|
190
|
+
restored_item
|
191
|
+
end
|
192
|
+
|
182
193
|
def create_shared_link(uri, item_id, access, unshared_at, can_download, can_preview)
|
183
194
|
if access.nil?
|
184
195
|
attributes = {shared_link: {}}
|
@@ -201,15 +212,6 @@ module Boxr
|
|
201
212
|
updated_item
|
202
213
|
end
|
203
214
|
|
204
|
-
def restore_trashed_item(uri, name, parent_id)
|
205
|
-
attributes = {}
|
206
|
-
attributes[:name] = name if name
|
207
|
-
attributes[:parent] = {id: parent_id} if parent_id
|
208
|
-
|
209
|
-
restored_item, response = post uri, attributes
|
210
|
-
restored_item
|
211
|
-
end
|
212
|
-
|
213
215
|
end
|
214
216
|
|
215
217
|
end
|
data/lib/boxr/collaborations.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
+
def folder_collaborations(folder_id)
|
5
|
+
uri = "#{FOLDERS_URI}/#{folder_id}/collaborations"
|
6
|
+
collaborations, response = get(uri)
|
7
|
+
collaborations['entries']
|
8
|
+
end
|
9
|
+
|
4
10
|
#make sure 'role' value is a string as Box has role values with spaces and dashes; e.g. 'previewer uploader'
|
5
11
|
def add_collaboration(folder_id, accessible_by, role, fields: [], notify: nil)
|
6
12
|
query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
|
@@ -40,7 +46,7 @@ module Boxr
|
|
40
46
|
collaboration
|
41
47
|
end
|
42
48
|
|
43
|
-
#these are pending collaborations for the current
|
49
|
+
#these are pending collaborations for the current user; use the As-User Header to request for different users
|
44
50
|
def pending_collaborations
|
45
51
|
query = {status: :pending}
|
46
52
|
pending_collaborations, response = get(COLLABORATIONS_URI, query: query)
|
data/lib/boxr/comments.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
+
def file_comments(file_id, fields: [])
|
5
|
+
uri = "#{FILES_URI}/#{file_id}/comments"
|
6
|
+
query = build_fields_query(fields, COMMENT_FIELDS_QUERY)
|
7
|
+
|
8
|
+
comments = get_with_pagination uri, query: query
|
9
|
+
end
|
10
|
+
|
4
11
|
def add_comment_to_file(file_id, message: nil, tagged_message: nil)
|
5
12
|
add_comment(:file, file_id, message, tagged_message)
|
6
13
|
end
|
@@ -16,7 +23,7 @@ module Boxr
|
|
16
23
|
updated_comment
|
17
24
|
end
|
18
25
|
|
19
|
-
def
|
26
|
+
def comment(comment_id, fields: [])
|
20
27
|
uri ="#{COMMENTS_URI}/#{comment_id}"
|
21
28
|
comment, response = get uri
|
22
29
|
comment
|
data/lib/boxr/events.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Boxr
|
2
|
+
class Client
|
3
|
+
|
4
|
+
def user_events(stream_position: 0, stream_type: :all, limit: 100)
|
5
|
+
query = {stream_position: stream_position, stream_type: stream_type, limit: limit}
|
6
|
+
|
7
|
+
events, response = get(EVENTS_URI, query: query)
|
8
|
+
Hashie::Mash.new({events: events["entries"], chunk_size: events["chunk_size"], next_stream_position: events["next_stream_position"]})
|
9
|
+
end
|
10
|
+
|
11
|
+
def enterprise_events(stream_position: 0, limit: 100, event_type: nil, created_after: nil, created_before: nil)
|
12
|
+
query = {stream_position: stream_position, stream_type: :admin_logs, limit: limit}
|
13
|
+
query['event_type'] = event_type unless event_type.nil?
|
14
|
+
query['created_after'] = created_after.to_datetime.rfc3339 unless created_after.nil?
|
15
|
+
query['created_before'] = created_before.to_datetime.rfc3339 unless created_before.nil?
|
16
|
+
|
17
|
+
events, response = get(EVENTS_URI, query: query)
|
18
|
+
Hashie::Mash.new({events: events["entries"], chunk_size: events["chunk_size"], next_stream_position: events["next_stream_position"]})
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/boxr/exceptions.rb
CHANGED
@@ -2,30 +2,35 @@ module Boxr
|
|
2
2
|
|
3
3
|
class BoxrException < Exception
|
4
4
|
|
5
|
-
attr_reader :response_body, :type, :status, :code, :help_uri, :box_message, :request_id
|
5
|
+
attr_reader :response_body, :type, :status, :code, :help_uri, :box_message, :boxr_message, :request_id
|
6
6
|
|
7
|
-
def initialize(status,body,header)
|
7
|
+
def initialize(status: nil, body: nil, header: nil, boxr_message: nil)
|
8
8
|
@status = status
|
9
9
|
@response_body = body
|
10
10
|
@header = header
|
11
|
+
@boxr_message = boxr_message
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
if(body)
|
14
|
+
body_json = Oj.load(body)
|
15
|
+
if body_json
|
16
|
+
@type = body_json["type"]
|
17
|
+
@box_status = body_json["status"]
|
18
|
+
@code = body_json["code"]
|
19
|
+
@help_uri = body_json["help_uri"]
|
20
|
+
@box_message = body_json["message"]
|
21
|
+
@request_id = body_json["request_id"]
|
22
|
+
end
|
20
23
|
end
|
21
24
|
end
|
22
25
|
|
23
26
|
def message
|
24
|
-
auth_header = @header['WWW-Authenticate']
|
25
|
-
if(auth_header)
|
27
|
+
auth_header = @header['WWW-Authenticate'] unless @header.nil?
|
28
|
+
if(auth_header && auth_header != [])
|
26
29
|
"#{@status}: #{auth_header}"
|
27
|
-
elsif(
|
30
|
+
elsif(@box_message)
|
28
31
|
"#{@status}: #{@box_message}"
|
32
|
+
elsif(@boxr_message)
|
33
|
+
@boxr_message
|
29
34
|
else
|
30
35
|
"#{@status}: #{@response_body}"
|
31
36
|
end
|
data/lib/boxr/files.rb
CHANGED
@@ -1,14 +1,33 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
-
def
|
4
|
+
def file_id(path)
|
5
|
+
if(path.start_with?('/'))
|
6
|
+
path = path.slice(1..-1)
|
7
|
+
end
|
8
|
+
|
9
|
+
path_items = path.split('/')
|
10
|
+
file_name = path_items.slice!(-1)
|
11
|
+
|
12
|
+
folder_id = folder_id(path_items.join('/'))
|
13
|
+
|
14
|
+
files = folder_items(folder_id, fields: [:id, :name])
|
15
|
+
|
16
|
+
begin
|
17
|
+
files.select{|f| f.name == file_name}.first.id
|
18
|
+
rescue
|
19
|
+
raise BoxrException.new(boxr_message: "File not found: '#{file_name}'")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def file(file_id, fields: [])
|
5
24
|
uri = "#{FILES_URI}/#{file_id}"
|
6
25
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
7
26
|
file, response = get uri, query: query
|
8
27
|
file
|
9
28
|
end
|
10
29
|
|
11
|
-
def
|
30
|
+
def update_file(file_id, name: nil, description: nil, parent_id: nil, shared_link: nil, tags: nil, if_match: nil)
|
12
31
|
uri = "#{FILES_URI}/#{file_id}"
|
13
32
|
|
14
33
|
attributes = {}
|
@@ -22,7 +41,7 @@ module Boxr
|
|
22
41
|
updated_file
|
23
42
|
end
|
24
43
|
|
25
|
-
def download_file(file_id, version: nil)
|
44
|
+
def download_file(file_id, version: nil, follow_redirect: true)
|
26
45
|
begin
|
27
46
|
uri = "#{FILES_URI}/#{file_id}/content"
|
28
47
|
query = {}
|
@@ -31,7 +50,12 @@ module Boxr
|
|
31
50
|
|
32
51
|
if(response.status==302)
|
33
52
|
location = response.header['Location'][0]
|
34
|
-
|
53
|
+
|
54
|
+
if(follow_redirect)
|
55
|
+
file, response = get location, process_response: false
|
56
|
+
else
|
57
|
+
return location #simply return the url
|
58
|
+
end
|
35
59
|
elsif(response.status==202)
|
36
60
|
retry_after_seconds = response.header['Retry-After'][0]
|
37
61
|
sleep retry_after_seconds.to_i
|
@@ -41,6 +65,10 @@ module Boxr
|
|
41
65
|
file
|
42
66
|
end
|
43
67
|
|
68
|
+
def download_url(file_id, version: nil)
|
69
|
+
download_file(file_id, version: version, follow_redirect: false)
|
70
|
+
end
|
71
|
+
|
44
72
|
def upload_file(path_to_file, parent_id, content_created_at: nil, content_modified_at: nil,
|
45
73
|
preflight_check: true, send_content_md5: true)
|
46
74
|
|
@@ -91,10 +119,6 @@ module Boxr
|
|
91
119
|
versions["entries"]
|
92
120
|
end
|
93
121
|
|
94
|
-
def download_old_version_of_file
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
122
|
def promote_old_version_of_file(file_id, file_version_id)
|
99
123
|
uri = "#{FILES_URI}/#{file_id}/versions/current"
|
100
124
|
attributes = {:type => 'file_version', :id => file_version_id}
|
@@ -104,8 +128,8 @@ module Boxr
|
|
104
128
|
|
105
129
|
def delete_old_version_of_file(file_id, file_version_id, if_match: nil)
|
106
130
|
uri = "#{FILES_URI}/#{file_id}/versions/#{file_version_id}"
|
107
|
-
|
108
|
-
|
131
|
+
result, response = delete uri, if_match: if_match
|
132
|
+
result
|
109
133
|
end
|
110
134
|
|
111
135
|
def copy_file(file_id, parent_id, name: nil)
|
@@ -145,9 +169,11 @@ module Boxr
|
|
145
169
|
disable_shared_link(uri, file_id)
|
146
170
|
end
|
147
171
|
|
148
|
-
def trashed_file(file_id)
|
172
|
+
def trashed_file(file_id, fields: [])
|
149
173
|
uri = "#{FILES_URI}/#{file_id}/trash"
|
150
|
-
|
174
|
+
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
175
|
+
|
176
|
+
trashed_file, response = get uri, query: query
|
151
177
|
trashed_file
|
152
178
|
end
|
153
179
|
|
@@ -163,21 +189,6 @@ module Boxr
|
|
163
189
|
restore_trashed_item(uri, name, parent_id)
|
164
190
|
end
|
165
191
|
|
166
|
-
def file_comments(file_id, fields: [])
|
167
|
-
uri = "#{FILES_URI}/#{file_id}/comments"
|
168
|
-
query = build_fields_query(fields, COMMENT_FIELDS_QUERY)
|
169
|
-
|
170
|
-
comments = get_with_pagination uri, query: query
|
171
|
-
end
|
172
|
-
|
173
|
-
def file_tasks(file_id, fields: [])
|
174
|
-
uri = "#{FILES_URI}/#{file_id}/tasks"
|
175
|
-
query = build_fields_query(fields, TASK_FIELDS_QUERY)
|
176
|
-
|
177
|
-
tasks, response = get uri, query: query
|
178
|
-
tasks["entries"]
|
179
|
-
end
|
180
|
-
|
181
192
|
|
182
193
|
private
|
183
194
|
|
data/lib/boxr/folders.rb
CHANGED
@@ -1,6 +1,24 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
+
def folder_id(path)
|
5
|
+
if(path.start_with?('/'))
|
6
|
+
path = path.slice(1..-1)
|
7
|
+
end
|
8
|
+
|
9
|
+
path_folders = path.split('/')
|
10
|
+
|
11
|
+
folder_id = path_folders.inject(Boxr::ROOT) do |parent_id, folder_name|
|
12
|
+
folders = folder_items(parent_id, fields: [:id, :name]).folders
|
13
|
+
|
14
|
+
begin
|
15
|
+
folders.select{|f| f.name == folder_name}.first.id
|
16
|
+
rescue
|
17
|
+
raise BoxrException.new(boxr_message: "Folder not found: '#{folder_name}'")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
4
22
|
def folder_items(folder_id, fields: [])
|
5
23
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
6
24
|
uri = "#{FOLDERS_URI}/#{folder_id}/items"
|
@@ -16,7 +34,7 @@ module Boxr
|
|
16
34
|
created_folder
|
17
35
|
end
|
18
36
|
|
19
|
-
def
|
37
|
+
def folder(folder_id, fields: [])
|
20
38
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
21
39
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
22
40
|
|
@@ -24,7 +42,7 @@ module Boxr
|
|
24
42
|
folder
|
25
43
|
end
|
26
44
|
|
27
|
-
def
|
45
|
+
def update_folder(folder_id, name: nil, description: nil, parent_id: nil, shared_link: nil,
|
28
46
|
folder_upload_email: nil, owned_by_id: nil, sync_state: nil, tags: nil,
|
29
47
|
can_non_owners_invite: nil, if_match: nil)
|
30
48
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
@@ -48,7 +66,7 @@ module Boxr
|
|
48
66
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
49
67
|
query = {:recursive => recursive}
|
50
68
|
|
51
|
-
result, response = delete uri, query, if_match: if_match
|
69
|
+
result, response = delete uri, query: query, if_match: if_match
|
52
70
|
result
|
53
71
|
end
|
54
72
|
|
@@ -71,12 +89,6 @@ module Boxr
|
|
71
89
|
disable_shared_link(uri, folder_id)
|
72
90
|
end
|
73
91
|
|
74
|
-
def folder_collaborations(folder_id)
|
75
|
-
uri = "#{FOLDERS_URI}/#{folder_id}/collaborations"
|
76
|
-
collaborations, response = get uri
|
77
|
-
collaborations
|
78
|
-
end
|
79
|
-
|
80
92
|
def trash(fields: [])
|
81
93
|
uri = "#{FOLDERS_URI}/trash/items"
|
82
94
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
@@ -84,10 +96,12 @@ module Boxr
|
|
84
96
|
items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
|
85
97
|
end
|
86
98
|
|
87
|
-
def trashed_folder(folder_id)
|
99
|
+
def trashed_folder(folder_id, fields: [])
|
88
100
|
uri = "#{FOLDERS_URI}/#{folder_id}/trash"
|
89
|
-
|
90
|
-
|
101
|
+
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
102
|
+
|
103
|
+
folder, response = get uri, query: query
|
104
|
+
folder
|
91
105
|
end
|
92
106
|
|
93
107
|
def delete_trashed_folder(folder_id)
|
data/lib/boxr/groups.rb
CHANGED
data/lib/boxr/search.rb
CHANGED
data/lib/boxr/tasks.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module Boxr
|
2
2
|
class Client
|
3
3
|
|
4
|
+
def file_tasks(file_id, fields: [])
|
5
|
+
uri = "#{FILES_URI}/#{file_id}/tasks"
|
6
|
+
query = build_fields_query(fields, TASK_FIELDS_QUERY)
|
7
|
+
|
8
|
+
tasks, response = get uri, query: query
|
9
|
+
tasks["entries"]
|
10
|
+
end
|
11
|
+
|
4
12
|
def create_task(file_id, action: :review, message: nil, due_at: nil)
|
5
13
|
attributes = {item: {type: :file, id: file_id}}
|
6
14
|
attributes[:action] = action unless action.nil?
|
@@ -69,7 +77,7 @@ module Boxr
|
|
69
77
|
attributes[:message] = message unless message.nil?
|
70
78
|
attributes[:resolution_state] = resolution_state unless resolution_state.nil?
|
71
79
|
|
72
|
-
updated_task,
|
80
|
+
updated_task, response = put uri, attributes
|
73
81
|
updated_task
|
74
82
|
end
|
75
83
|
|
data/lib/boxr/users.rb
CHANGED
@@ -8,6 +8,10 @@ module Boxr
|
|
8
8
|
user
|
9
9
|
end
|
10
10
|
|
11
|
+
def me(fields: [])
|
12
|
+
current_user(fields: fields)
|
13
|
+
end
|
14
|
+
|
11
15
|
def user(user_id, fields: [])
|
12
16
|
uri = "#{USERS_URI}/#{user_id}"
|
13
17
|
query = build_fields_query(fields, USER_FIELDS_QUERY)
|
@@ -19,7 +23,7 @@ module Boxr
|
|
19
23
|
uri = USERS_URI
|
20
24
|
query = build_fields_query(fields, USER_FIELDS_QUERY)
|
21
25
|
query[:filter_term] = filter_term unless filter_term.nil?
|
22
|
-
users
|
26
|
+
users = get_with_pagination(uri, query: query)
|
23
27
|
end
|
24
28
|
|
25
29
|
def create_user(login, name, role: nil, language: nil, is_sync_enabled: nil, job_title: nil,
|
data/lib/boxr/version.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'dotenv/tasks'
|
2
|
+
require 'boxr'
|
3
|
+
|
4
|
+
#to call this from bash, etc. use: rake oauth:get_tokens[YOUR_CLIENT_ID, YOUR CLIENT_SECRET]
|
5
|
+
|
6
|
+
#however, if you use zsh you must call as such: rake 'oauth:get_tokens[YOUR_CLIENT_ID, YOUR CLIENT_SECRET]'
|
7
|
+
#the single quotes are important for zsh!
|
8
|
+
|
9
|
+
|
10
|
+
namespace :oauth do
|
11
|
+
desc "some stuff"
|
12
|
+
task :get_tokens, [:client_id, :client_secret] => :environment do |task, args|
|
13
|
+
puts args.client_id, args.client_secret
|
14
|
+
|
15
|
+
# print "Whoa! Pushing to production. Type 'pushitrealgood' to continue: "
|
16
|
+
# if STDIN.gets.chomp == 'pushitrealgood'
|
17
|
+
# system "heroku pgbackups:capture -e -a zenph-production" or abort "aborted backing up production database"
|
18
|
+
# else
|
19
|
+
# abort 'task aborted'
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
end
|
data/spec/boxr_spec.rb
CHANGED
@@ -1,15 +1,447 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Boxr do
|
3
|
+
describe Boxr::Client do
|
4
|
+
|
5
|
+
#PLEASE NOTE
|
6
|
+
#This test is intentionally NOT a series of unit tests. The goal is to smoke test the entire code base
|
7
|
+
#against an actual Box account, making real calls to the Box API. The Box API is subject to frequent
|
8
|
+
#changes and it is not sufficient to mock responses as those responses will change over time. Successfully
|
9
|
+
#running this test suite shows that the code base works with the current Box API. The main premise here
|
10
|
+
#is that an exception will be thrown if anything unexpected happens.
|
11
|
+
|
12
|
+
#REQUIRED BOX SETTINGS
|
13
|
+
# 1. The developer token used must have admin or co-admin priviledges
|
14
|
+
# 2. Enterprise settings must allow Admin and Co-admins to permanently delete content in Trash
|
4
15
|
|
5
16
|
#follow the directions in .env.example to set up your BOX_DEVELOPER_TOKEN
|
17
|
+
#keep in mind it is only valid for 60 minutes
|
6
18
|
BOX_CLIENT = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'])
|
7
19
|
|
8
|
-
#uncomment this line to see the HTTP request and response debug info
|
20
|
+
#uncomment this line to see the HTTP request and response debug info in the rspec output
|
9
21
|
#BOX_CLIENT.debug_device = STDOUT
|
10
22
|
|
11
|
-
|
12
|
-
|
13
|
-
|
23
|
+
BOX_SERVER_SLEEP = 5
|
24
|
+
TEST_FOLDER_NAME = 'Boxr Test'
|
25
|
+
SUB_FOLDER_NAME = 'sub_folder_1'
|
26
|
+
SUB_FOLDER_DESCRIPTION = 'This was created by the Boxr test suite'
|
27
|
+
TEST_FILE_NAME = 'test file.txt'
|
28
|
+
DOWNLOADED_TEST_FILE_NAME = 'downloaded test file.txt'
|
29
|
+
COMMENT_MESSAGE = 'this is a comment'
|
30
|
+
REPLY_MESSAGE = 'this is a comment reply'
|
31
|
+
CHANGED_COMMENT_MESSAGE = 'this comment has been changed'
|
32
|
+
TEST_USER_LOGIN = "test-boxr-user@example.com"
|
33
|
+
TEST_USER_NAME = "Test Boxr User"
|
34
|
+
TEST_GROUP_NAME= "Test Boxr Group"
|
35
|
+
TEST_TASK_MESSAGE = "Please review"
|
36
|
+
|
37
|
+
before(:each) do
|
38
|
+
puts "-----> Resetting Box Environment"
|
39
|
+
sleep BOX_SERVER_SLEEP
|
40
|
+
root_folders = BOX_CLIENT.folder_items(Boxr::ROOT).folders
|
41
|
+
test_folder = root_folders.find{|f| f.name == TEST_FOLDER_NAME}
|
42
|
+
if(test_folder)
|
43
|
+
BOX_CLIENT.delete_folder(test_folder.id, recursive: true)
|
44
|
+
end
|
45
|
+
new_folder = BOX_CLIENT.create_folder(TEST_FOLDER_NAME, Boxr::ROOT)
|
46
|
+
@test_folder_id = new_folder.id
|
47
|
+
|
48
|
+
all_users = BOX_CLIENT.all_users
|
49
|
+
test_user = all_users.find{|u| u.login == TEST_USER_LOGIN}
|
50
|
+
if(test_user)
|
51
|
+
BOX_CLIENT.delete_user(test_user.id, force: true)
|
52
|
+
end
|
53
|
+
sleep BOX_SERVER_SLEEP
|
54
|
+
test_user = BOX_CLIENT.create_user(TEST_USER_LOGIN, TEST_USER_NAME)
|
55
|
+
@test_user_id = test_user.id
|
56
|
+
|
57
|
+
all_groups = BOX_CLIENT.groups
|
58
|
+
test_group = all_groups.find{|g| g.name == TEST_GROUP_NAME}
|
59
|
+
if(test_group)
|
60
|
+
BOX_CLIENT.delete_group(test_group.id)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'invokes folder operations' do
|
65
|
+
puts "get folder id using path"
|
66
|
+
folder_id = BOX_CLIENT.folder_id(TEST_FOLDER_NAME)
|
67
|
+
expect(folder_id).to eq(@test_folder_id)
|
68
|
+
|
69
|
+
puts "get folder info"
|
70
|
+
folder = BOX_CLIENT.folder(@test_folder_id)
|
71
|
+
expect(folder.id).to eq(@test_folder_id)
|
72
|
+
|
73
|
+
puts "create new folder"
|
74
|
+
new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder_id)
|
75
|
+
expect(new_folder).to be_a Hashie::Mash
|
76
|
+
SUB_FOLDER_ID = new_folder.id
|
77
|
+
|
78
|
+
puts "update folder"
|
79
|
+
updated_folder = BOX_CLIENT.update_folder(SUB_FOLDER_ID, description: SUB_FOLDER_DESCRIPTION)
|
80
|
+
expect(updated_folder.description).to eq(SUB_FOLDER_DESCRIPTION)
|
81
|
+
|
82
|
+
puts "copy folder"
|
83
|
+
new_folder = BOX_CLIENT.copy_folder(SUB_FOLDER_ID,@test_folder_id, name: 'copy of sub_folder_1')
|
84
|
+
expect(new_folder).to be_a Hashie::Mash
|
85
|
+
SUB_FOLDER_COPY_ID = new_folder.id
|
86
|
+
|
87
|
+
puts "create shared link for folder"
|
88
|
+
updated_folder = BOX_CLIENT.create_shared_link_for_folder(@test_folder_id, access: :open)
|
89
|
+
expect(updated_folder.shared_link.access).to eq("open")
|
90
|
+
shared_link = updated_folder.shared_link.url
|
91
|
+
|
92
|
+
puts "inspect shared link"
|
93
|
+
shared_item = BOX_CLIENT.shared_item(shared_link)
|
94
|
+
expect(shared_item.id).to eq(@test_folder_id)
|
95
|
+
|
96
|
+
puts "disable shared link for folder"
|
97
|
+
updated_folder = BOX_CLIENT.disable_shared_link_for_folder(@test_folder_id)
|
98
|
+
expect(updated_folder.shared_link).to be_nil
|
99
|
+
|
100
|
+
puts "delete folder"
|
101
|
+
result = BOX_CLIENT.delete_folder(SUB_FOLDER_COPY_ID, recursive: true)
|
102
|
+
expect(result).to eq ({})
|
103
|
+
|
104
|
+
puts "inspect the trash"
|
105
|
+
trash = BOX_CLIENT.trash()
|
106
|
+
expect(trash).to be_a Array
|
107
|
+
|
108
|
+
puts "inspect trashed folder"
|
109
|
+
trashed_folder = BOX_CLIENT.trashed_folder(SUB_FOLDER_COPY_ID)
|
110
|
+
expect(trashed_folder.item_status).to eq("trashed")
|
111
|
+
|
112
|
+
puts "restore trashed folder"
|
113
|
+
restored_folder = BOX_CLIENT.restore_trashed_folder(SUB_FOLDER_COPY_ID)
|
114
|
+
expect(restored_folder.item_status).to eq("active")
|
115
|
+
|
116
|
+
puts "trash and permanently delete folder"
|
117
|
+
BOX_CLIENT.delete_folder(SUB_FOLDER_COPY_ID, recursive: true)
|
118
|
+
result = BOX_CLIENT.delete_trashed_folder(SUB_FOLDER_COPY_ID)
|
119
|
+
expect(result).to eq({})
|
120
|
+
end
|
121
|
+
|
122
|
+
it "invokes file operations" do
|
123
|
+
puts "upload a file"
|
124
|
+
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder_id)
|
125
|
+
expect(new_file.name).to eq(TEST_FILE_NAME)
|
126
|
+
test_file_id = new_file.id
|
127
|
+
|
128
|
+
puts "get file id using path"
|
129
|
+
file_id = BOX_CLIENT.file_id("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
|
130
|
+
expect(file_id).to eq(test_file_id)
|
131
|
+
|
132
|
+
puts "get file download url"
|
133
|
+
download_url = BOX_CLIENT.download_url(test_file_id)
|
134
|
+
expect(download_url).to start_with("https://")
|
135
|
+
|
136
|
+
puts "get file info"
|
137
|
+
file_info = BOX_CLIENT.file(test_file_id)
|
138
|
+
expect(file_info.id).to eq(test_file_id)
|
139
|
+
|
140
|
+
puts "update file"
|
141
|
+
new_description = 'this file is used to test Boxr'
|
142
|
+
updated_file_info = BOX_CLIENT.update_file(test_file_id, description: new_description)
|
143
|
+
expect(updated_file_info.description).to eq(new_description)
|
144
|
+
|
145
|
+
puts "download file"
|
146
|
+
file = BOX_CLIENT.download_file(test_file_id)
|
147
|
+
f = open("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}", 'w+')
|
148
|
+
f.write(file)
|
149
|
+
f.close
|
150
|
+
expect(FileUtils.identical?("./spec/test_files/#{TEST_FILE_NAME}","./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")).to eq(true)
|
151
|
+
File.delete("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")
|
152
|
+
|
153
|
+
puts "upload new version of file"
|
154
|
+
new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}", test_file_id)
|
155
|
+
expect(new_version.id).to eq(test_file_id)
|
156
|
+
|
157
|
+
puts "inspect versions of file"
|
158
|
+
versions = BOX_CLIENT.versions_of_file(test_file_id)
|
159
|
+
expect(versions.count).to eq(1) #the reason this is 1 instead of 2 is that Box considers 'versions' to be a versions other than 'current'
|
160
|
+
v1_id = versions.first.id
|
161
|
+
|
162
|
+
puts "promote old version of file"
|
163
|
+
newer_version = BOX_CLIENT.promote_old_version_of_file(test_file_id, v1_id)
|
164
|
+
versions = BOX_CLIENT.versions_of_file(test_file_id)
|
165
|
+
expect(versions.count).to eq(2)
|
166
|
+
|
167
|
+
puts "delete old version of file"
|
168
|
+
result = BOX_CLIENT.delete_old_version_of_file(test_file_id,v1_id)
|
169
|
+
versions = BOX_CLIENT.versions_of_file(test_file_id)
|
170
|
+
expect(versions.count).to eq(2) #this is still 2 because with Box you can restore a trashed old version
|
171
|
+
|
172
|
+
puts "get file thumbnail"
|
173
|
+
thumb = BOX_CLIENT.thumbnail(test_file_id)
|
174
|
+
expect(thumb).not_to be_nil
|
175
|
+
|
176
|
+
puts "create shared link for file"
|
177
|
+
updated_file = BOX_CLIENT.create_shared_link_for_file(test_file_id, access: :open)
|
178
|
+
expect(updated_file.shared_link.access).to eq("open")
|
179
|
+
|
180
|
+
puts "disable shared link for file"
|
181
|
+
updated_file = BOX_CLIENT.disable_shared_link_for_file(test_file_id)
|
182
|
+
expect(updated_file.shared_link).to be_nil
|
183
|
+
|
184
|
+
puts "copy file"
|
185
|
+
new_file_name = "copy of #{TEST_FILE_NAME}"
|
186
|
+
new_file = BOX_CLIENT.copy_file(test_file_id, @test_folder_id, name: new_file_name)
|
187
|
+
expect(new_file.name).to eq(new_file_name)
|
188
|
+
NEW_FILE_ID = new_file.id
|
189
|
+
|
190
|
+
puts "delete file"
|
191
|
+
result = BOX_CLIENT.delete_file(NEW_FILE_ID)
|
192
|
+
expect(result).to eq({})
|
193
|
+
|
194
|
+
puts "get trashed file info"
|
195
|
+
trashed_file = BOX_CLIENT.trashed_file(NEW_FILE_ID)
|
196
|
+
expect(trashed_file.item_status).to eq("trashed")
|
197
|
+
|
198
|
+
puts "restore trashed file"
|
199
|
+
restored_file = BOX_CLIENT.restore_trashed_file(NEW_FILE_ID)
|
200
|
+
expect(restored_file.item_status).to eq("active")
|
201
|
+
|
202
|
+
puts "trash and permanently delete file"
|
203
|
+
BOX_CLIENT.delete_file(NEW_FILE_ID)
|
204
|
+
result = BOX_CLIENT.delete_trashed_file(NEW_FILE_ID)
|
205
|
+
expect(result).to eq({})
|
206
|
+
end
|
207
|
+
|
208
|
+
it "invokes user operations" do
|
209
|
+
puts "inspect current user"
|
210
|
+
user = BOX_CLIENT.current_user
|
211
|
+
expect(user.status).to eq('active')
|
212
|
+
user = BOX_CLIENT.me(fields: [:role])
|
213
|
+
expect(user.role).to_not be_nil
|
214
|
+
|
215
|
+
puts "inspect a user"
|
216
|
+
user = BOX_CLIENT.user(@test_user_id)
|
217
|
+
expect(user.id).to eq(@test_user_id)
|
218
|
+
|
219
|
+
puts "inspect all users"
|
220
|
+
all_users = BOX_CLIENT.all_users()
|
221
|
+
test_user = all_users.find{|u| u.id == @test_user_id}
|
222
|
+
expect(test_user).to_not be_nil
|
223
|
+
|
224
|
+
puts "update user"
|
225
|
+
new_name = "Chuck Nevitt"
|
226
|
+
user = BOX_CLIENT.update_user(@test_user_id, name: new_name)
|
227
|
+
expect(user.name).to eq(new_name)
|
228
|
+
|
229
|
+
#create user is tested in the before method
|
230
|
+
|
231
|
+
puts "delete user"
|
232
|
+
result = BOX_CLIENT.delete_user(@test_user_id, force: true)
|
233
|
+
expect(result).to eq({})
|
234
|
+
end
|
235
|
+
|
236
|
+
it "invokes group operations" do
|
237
|
+
puts "create group"
|
238
|
+
group = BOX_CLIENT.create_group(TEST_GROUP_NAME)
|
239
|
+
expect(group.name).to eq(TEST_GROUP_NAME)
|
240
|
+
test_group_id = group.id
|
241
|
+
|
242
|
+
puts "inspect groups"
|
243
|
+
groups = BOX_CLIENT.groups
|
244
|
+
test_group = groups.find{|g| g.name == TEST_GROUP_NAME}
|
245
|
+
expect(test_group).to_not be_nil
|
246
|
+
|
247
|
+
puts "update group"
|
248
|
+
new_name = "Test Boxr Group Renamed"
|
249
|
+
group = BOX_CLIENT.update_group(test_group_id, new_name)
|
250
|
+
expect(group.name).to eq(new_name)
|
251
|
+
group = BOX_CLIENT.rename_group(test_group_id,TEST_GROUP_NAME)
|
252
|
+
expect(group.name).to eq(TEST_GROUP_NAME)
|
253
|
+
|
254
|
+
puts "add user to group"
|
255
|
+
group_membership = BOX_CLIENT.add_user_to_group(@test_user_id, test_group_id)
|
256
|
+
expect(group_membership.user.id).to eq(@test_user_id)
|
257
|
+
expect(group_membership.group.id).to eq(test_group_id)
|
258
|
+
membership_id = group_membership.id
|
259
|
+
|
260
|
+
puts "inspect group membership"
|
261
|
+
group_membership = BOX_CLIENT.group_membership(membership_id)
|
262
|
+
expect(group_membership.id).to eq(membership_id)
|
263
|
+
|
264
|
+
puts "inspect group memberships"
|
265
|
+
group_memberships = BOX_CLIENT.group_memberships(test_group_id)
|
266
|
+
expect(group_memberships.count).to eq(1)
|
267
|
+
expect(group_memberships.first.id).to eq(membership_id)
|
268
|
+
|
269
|
+
puts "inspect group memberships for a user"
|
270
|
+
group_memberships = BOX_CLIENT.group_memberships_for_user(@test_user_id)
|
271
|
+
expect(group_memberships.count).to eq(1)
|
272
|
+
expect(group_memberships.first.id).to eq(membership_id)
|
273
|
+
|
274
|
+
puts "inspect group memberships for me"
|
275
|
+
#this is whatever user your developer token is tied to
|
276
|
+
group_memberships = BOX_CLIENT.group_memberships_for_me
|
277
|
+
expect(group_memberships).to be_a(Array)
|
278
|
+
|
279
|
+
puts "update group membership"
|
280
|
+
group_membership = BOX_CLIENT.update_group_membership(membership_id, :admin)
|
281
|
+
expect(group_membership.role).to eq("admin")
|
282
|
+
|
283
|
+
puts "delete group membership"
|
284
|
+
result = BOX_CLIENT.delete_group_membership(membership_id)
|
285
|
+
expect(result).to eq({})
|
286
|
+
group_memberships = BOX_CLIENT.group_memberships_for_user(@test_user_id)
|
287
|
+
expect(group_memberships.count).to eq(0)
|
288
|
+
|
289
|
+
puts "inspect group collaborations"
|
290
|
+
group_collaboration = BOX_CLIENT.add_collaboration(@test_folder_id, {id: test_group_id, type: :group}, :editor)
|
291
|
+
expect(group_collaboration.accessible_by.id).to eq(test_group_id)
|
292
|
+
|
293
|
+
puts "delete group"
|
294
|
+
response = BOX_CLIENT.delete_group(test_group_id)
|
295
|
+
expect(response).to eq({})
|
296
|
+
end
|
297
|
+
|
298
|
+
it "invokes comment operations" do
|
299
|
+
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder_id)
|
300
|
+
test_file_id = new_file.id
|
301
|
+
|
302
|
+
puts "add comment to file"
|
303
|
+
comment = BOX_CLIENT.add_comment_to_file(test_file_id, message: COMMENT_MESSAGE)
|
304
|
+
expect(comment.message).to eq(COMMENT_MESSAGE)
|
305
|
+
COMMENT_ID = comment.id
|
306
|
+
|
307
|
+
puts "reply to comment"
|
308
|
+
reply = BOX_CLIENT.reply_to_comment(COMMENT_ID, message: REPLY_MESSAGE)
|
309
|
+
expect(reply.message).to eq(REPLY_MESSAGE)
|
310
|
+
|
311
|
+
puts "get file comments"
|
312
|
+
comments = BOX_CLIENT.file_comments(test_file_id)
|
313
|
+
expect(comments.count).to eq(2)
|
314
|
+
|
315
|
+
puts "update a comment"
|
316
|
+
comment = BOX_CLIENT.change_comment(COMMENT_ID, CHANGED_COMMENT_MESSAGE)
|
317
|
+
expect(comment.message).to eq(CHANGED_COMMENT_MESSAGE)
|
318
|
+
|
319
|
+
puts "get comment info"
|
320
|
+
comment = BOX_CLIENT.comment(COMMENT_ID)
|
321
|
+
expect(comment.id).to eq(COMMENT_ID)
|
322
|
+
|
323
|
+
puts "delete comment"
|
324
|
+
result = BOX_CLIENT.delete_comment(COMMENT_ID)
|
325
|
+
expect(result).to eq({})
|
326
|
+
end
|
327
|
+
|
328
|
+
it "invokes collaborations operations" do
|
329
|
+
puts "add collaboration"
|
330
|
+
collaboration = BOX_CLIENT.add_collaboration(@test_folder_id, {id: @test_user_id, type: :user}, :editor)
|
331
|
+
expect(collaboration.accessible_by.id).to eq(@test_user_id)
|
332
|
+
collaboration_id = collaboration.id
|
333
|
+
|
334
|
+
puts "inspect collaboration"
|
335
|
+
collaboration = BOX_CLIENT.collaboration(collaboration_id)
|
336
|
+
expect(collaboration.id).to eq(collaboration_id)
|
337
|
+
|
338
|
+
puts "edit collaboration"
|
339
|
+
collaboration = BOX_CLIENT.edit_collaboration(collaboration_id, role: "viewer uploader")
|
340
|
+
expect(collaboration.role).to eq("viewer uploader")
|
341
|
+
|
342
|
+
puts "inspect folder collaborations"
|
343
|
+
collaborations = BOX_CLIENT.folder_collaborations(@test_folder_id)
|
344
|
+
expect(collaborations.count).to eq(1)
|
345
|
+
expect(collaborations[0].id).to eq(collaboration_id)
|
346
|
+
|
347
|
+
puts "remove collaboration"
|
348
|
+
result = BOX_CLIENT.remove_collaboration(collaboration_id)
|
349
|
+
expect(result).to eq({})
|
350
|
+
collaborations = BOX_CLIENT.folder_collaborations(@test_folder_id)
|
351
|
+
expect(collaborations.count).to eq(0)
|
352
|
+
|
353
|
+
puts "inspect pending collaborations"
|
354
|
+
pending_collaborations = BOX_CLIENT.pending_collaborations
|
355
|
+
expect(pending_collaborations).to eq([])
|
356
|
+
end
|
357
|
+
|
358
|
+
it "invokes task operations" do
|
359
|
+
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder_id)
|
360
|
+
test_file_id = new_file.id
|
361
|
+
collaboration = BOX_CLIENT.add_collaboration(@test_folder_id, {id: @test_user_id, type: :user}, :editor)
|
362
|
+
|
363
|
+
puts "create task"
|
364
|
+
new_task = BOX_CLIENT.create_task(test_file_id, message: TEST_TASK_MESSAGE)
|
365
|
+
expect(new_task.message).to eq(TEST_TASK_MESSAGE)
|
366
|
+
TEST_TASK_ID = new_task.id
|
367
|
+
|
368
|
+
puts "inspect file tasks"
|
369
|
+
tasks = BOX_CLIENT.file_tasks(test_file_id)
|
370
|
+
expect(tasks.first.id).to eq(TEST_TASK_ID)
|
371
|
+
|
372
|
+
puts "inspect task"
|
373
|
+
task = BOX_CLIENT.task(TEST_TASK_ID)
|
374
|
+
expect(task.id).to eq(TEST_TASK_ID)
|
375
|
+
|
376
|
+
puts "update task"
|
377
|
+
NEW_TASK_MESSAGE = "new task message"
|
378
|
+
updated_task = BOX_CLIENT.update_task(TEST_TASK_ID, message: NEW_TASK_MESSAGE)
|
379
|
+
expect(updated_task.message).to eq(NEW_TASK_MESSAGE)
|
380
|
+
|
381
|
+
puts "create task assignment"
|
382
|
+
task_assignment = BOX_CLIENT.create_task_assignment(TEST_TASK_ID, assign_to_id: @test_user_id)
|
383
|
+
expect(task_assignment.assigned_to.id).to eq(@test_user_id)
|
384
|
+
task_assignment_id = task_assignment.id
|
385
|
+
|
386
|
+
puts "inspect task assignment"
|
387
|
+
task_assignment = BOX_CLIENT.task_assignment(task_assignment_id)
|
388
|
+
expect(task_assignment.id).to eq(task_assignment_id)
|
389
|
+
|
390
|
+
puts "inspect task assignments"
|
391
|
+
task_assignments = BOX_CLIENT.task_assignments(TEST_TASK_ID)
|
392
|
+
expect(task_assignments.count).to eq(1)
|
393
|
+
expect(task_assignments[0].id).to eq(task_assignment_id)
|
394
|
+
|
395
|
+
#TODO: can't do this test yet because the test user needs to confirm their email address before you can do this
|
396
|
+
puts "update task assignment"
|
397
|
+
expect {
|
398
|
+
box_client_as_test_user = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'], as_user_id: @test_user_id)
|
399
|
+
new_message = "Updated task message"
|
400
|
+
task_assignment = box_client_as_test_user.update_task_assignment(TEST_TASK_ID, resolution_state: :completed)
|
401
|
+
expect(task_assignment.resolution_state).to eq('completed')
|
402
|
+
}.to raise_error
|
403
|
+
|
404
|
+
puts "delete task assignment"
|
405
|
+
result = BOX_CLIENT.delete_task_assignment(task_assignment_id)
|
406
|
+
expect(result).to eq({})
|
407
|
+
|
408
|
+
puts "delete task"
|
409
|
+
result = BOX_CLIENT.delete_task(TEST_TASK_ID)
|
410
|
+
expect(result).to eq({})
|
411
|
+
end
|
412
|
+
|
413
|
+
it "invokes metadata operations" do
|
414
|
+
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder_id)
|
415
|
+
test_file_id = new_file.id
|
416
|
+
|
417
|
+
puts "create metadata"
|
418
|
+
meta = {"a" => "hello", "b" => "world"}
|
419
|
+
metadata = BOX_CLIENT.create_metadata(test_file_id, meta)
|
420
|
+
expect(metadata.a).to eq("hello")
|
421
|
+
|
422
|
+
puts "update metadata"
|
423
|
+
metadata = BOX_CLIENT.update_metadata(test_file_id, [{op: :replace, path: "/b", value: "there"}])
|
424
|
+
expect(metadata.b).to eq("there")
|
425
|
+
|
426
|
+
puts "get metadata"
|
427
|
+
metadata = BOX_CLIENT.metadata(test_file_id)
|
428
|
+
expect(metadata.a).to eq("hello")
|
429
|
+
|
430
|
+
puts "delete metadata"
|
431
|
+
result = BOX_CLIENT.delete_metadata(test_file_id)
|
432
|
+
expect(result).to eq({})
|
433
|
+
end
|
434
|
+
|
435
|
+
it "invokes search operations" do
|
436
|
+
#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
|
437
|
+
#so we are searching for something that should return zero results
|
438
|
+
puts "perform search"
|
439
|
+
results = BOX_CLIENT.search("sdlfjuwnsljsdfuqpoiqweouyvnnadsfkjhiuweruywerbjvhvkjlnasoifyukhenlwdflnsdvoiuawfydfjh")
|
440
|
+
expect(results).to eq([])
|
14
441
|
end
|
442
|
+
|
443
|
+
it "invokes a Boxr exception" do
|
444
|
+
expect { BOX_CLIENT.folder(1)}.to raise_error
|
445
|
+
end
|
446
|
+
|
15
447
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
This is a test file for the Boxr Gem RSpec smoke test.
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chad Burnette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: dotenv
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,34 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0.11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: awesome_print
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: lru_redux
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
112
|
name: oj
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,10 +164,13 @@ files:
|
|
122
164
|
- README.md
|
123
165
|
- Rakefile
|
124
166
|
- boxr.gemspec
|
167
|
+
- examples/enterprise_events.rb
|
168
|
+
- examples/user_events.rb
|
125
169
|
- lib/boxr.rb
|
126
170
|
- lib/boxr/client.rb
|
127
171
|
- lib/boxr/collaborations.rb
|
128
172
|
- lib/boxr/comments.rb
|
173
|
+
- lib/boxr/events.rb
|
129
174
|
- lib/boxr/exceptions.rb
|
130
175
|
- lib/boxr/files.rb
|
131
176
|
- lib/boxr/folders.rb
|
@@ -136,8 +181,10 @@ files:
|
|
136
181
|
- lib/boxr/tasks.rb
|
137
182
|
- lib/boxr/users.rb
|
138
183
|
- lib/boxr/version.rb
|
184
|
+
- lib/tasks/oauth.rake
|
139
185
|
- spec/boxr_spec.rb
|
140
186
|
- spec/spec_helper.rb
|
187
|
+
- spec/test_files/test file.txt
|
141
188
|
homepage: https://github.com/cburnette/boxr
|
142
189
|
licenses:
|
143
190
|
- MIT
|
@@ -166,3 +213,4 @@ summary: A Ruby client library for the Box V2 Content API that covers 100% of th
|
|
166
213
|
test_files:
|
167
214
|
- spec/boxr_spec.rb
|
168
215
|
- spec/spec_helper.rb
|
216
|
+
- spec/test_files/test file.txt
|