boxr 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/boxr/client.rb +6 -0
- data/lib/boxr/collaborations.rb +5 -0
- data/lib/boxr/comments.rb +6 -0
- data/lib/boxr/files.rb +22 -1
- data/lib/boxr/folders.rb +13 -0
- data/lib/boxr/groups.rb +11 -0
- data/lib/boxr/metadata.rb +4 -0
- data/lib/boxr/tasks.rb +10 -0
- data/lib/boxr/users.rb +3 -0
- data/lib/boxr/version.rb +1 -1
- data/spec/boxr_spec.rb +116 -118
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ecd063a6d71a477dc1aa7d50d53b2f649354599
|
4
|
+
data.tar.gz: 16fbb18c677d990d8dba2071226d1ce8f59ee145
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 657845370199ea7d468ea248c06038febfa0e58ba126b2bfb35cc6b7140262b0f078485ad4de83cf9b8bf8a8a7944831a498d6315cfc95e71dc706e10259cde7
|
7
|
+
data.tar.gz: 4dd7d41e230f9729cbb9ff2a90ecbca5e31cf7116800e034e9f9e4a3dc1195f15dd4e45aca0d0840c9dbf5e5d66ca13d512bca46a51fbf7533ea9ac52b764dd0
|
data/README.md
CHANGED
@@ -83,8 +83,8 @@ require 'boxr'
|
|
83
83
|
client = Boxr::Client.new #using ENV['BOX_DEVELOPER_TOKEN']
|
84
84
|
|
85
85
|
folder = client.folder_from_path('/some/directory/structure')
|
86
|
-
file = client.upload_file('test.txt', folder
|
87
|
-
file = client.create_shared_link_for_file(file
|
86
|
+
file = client.upload_file('test.txt', folder)
|
87
|
+
file = client.create_shared_link_for_file(file, access: :open)
|
88
88
|
puts "Shared Link: #{file.shared_link.url}"
|
89
89
|
```
|
90
90
|
|
data/lib/boxr/client.rb
CHANGED
@@ -222,6 +222,12 @@ module Boxr
|
|
222
222
|
end
|
223
223
|
end
|
224
224
|
|
225
|
+
def ensure_id(item)
|
226
|
+
return item if item.class == String || item.class == Fixnum
|
227
|
+
return item.id if item.respond_to?(:id)
|
228
|
+
raise BoxrException.new(boxr_message: "Expecting an id of class String or Fixnum, or object that responds to :id")
|
229
|
+
end
|
230
|
+
|
225
231
|
def restore_trashed_item(uri, name, parent_id)
|
226
232
|
attributes = {}
|
227
233
|
attributes[:name] = name unless name.nil?
|
data/lib/boxr/collaborations.rb
CHANGED
@@ -2,6 +2,7 @@ module Boxr
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
def folder_collaborations(folder_id)
|
5
|
+
folder_id = ensure_id(folder_id)
|
5
6
|
uri = "#{FOLDERS_URI}/#{folder_id}/collaborations"
|
6
7
|
collaborations, response = get(uri)
|
7
8
|
collaborations['entries']
|
@@ -9,6 +10,7 @@ module Boxr
|
|
9
10
|
|
10
11
|
#make sure 'role' value is a string as Box has role values with spaces and dashes; e.g. 'previewer uploader'
|
11
12
|
def add_collaboration(folder_id, accessible_by, role, fields: [], notify: nil)
|
13
|
+
folder_id = ensure_id(folder_id)
|
12
14
|
query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
|
13
15
|
query[:notify] = :notify unless notify.nil?
|
14
16
|
|
@@ -21,6 +23,7 @@ module Boxr
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def edit_collaboration(collaboration_id, role: nil, status: nil)
|
26
|
+
collaboration_id = ensure_id(collaboration_id)
|
24
27
|
uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
|
25
28
|
attributes = {}
|
26
29
|
attributes[:role] = role unless role.nil?
|
@@ -31,12 +34,14 @@ module Boxr
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def remove_collaboration(collaboration_id)
|
37
|
+
collaboration_id = ensure_id(collaboration_id)
|
34
38
|
uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
|
35
39
|
result, response = delete(uri)
|
36
40
|
result
|
37
41
|
end
|
38
42
|
|
39
43
|
def collaboration(collaboration_id, fields: [], status: nil)
|
44
|
+
collaboration_id = ensure_id(collaboration_id)
|
40
45
|
uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
|
41
46
|
|
42
47
|
query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
|
data/lib/boxr/comments.rb
CHANGED
@@ -2,6 +2,7 @@ module Boxr
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
def file_comments(file_id, fields: [])
|
5
|
+
file_id = ensure_id(file_id)
|
5
6
|
uri = "#{FILES_URI}/#{file_id}/comments"
|
6
7
|
query = build_fields_query(fields, COMMENT_FIELDS_QUERY)
|
7
8
|
|
@@ -9,14 +10,17 @@ module Boxr
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def add_comment_to_file(file_id, message: nil, tagged_message: nil)
|
13
|
+
file_id = ensure_id(file_id)
|
12
14
|
add_comment(:file, file_id, message, tagged_message)
|
13
15
|
end
|
14
16
|
|
15
17
|
def reply_to_comment(comment_id, message: nil, tagged_message: nil)
|
18
|
+
comment_id = ensure_id(comment_id)
|
16
19
|
add_comment(:comment, comment_id, message, tagged_message)
|
17
20
|
end
|
18
21
|
|
19
22
|
def change_comment(comment_id, message)
|
23
|
+
comment_id = ensure_id(comment_id)
|
20
24
|
uri = "#{COMMENTS_URI}/#{comment_id}"
|
21
25
|
attributes = {message: message}
|
22
26
|
updated_comment, response = put uri, attributes
|
@@ -24,12 +28,14 @@ module Boxr
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def comment(comment_id, fields: [])
|
31
|
+
comment_id = ensure_id(comment_id)
|
27
32
|
uri ="#{COMMENTS_URI}/#{comment_id}"
|
28
33
|
comment, response = get uri
|
29
34
|
comment
|
30
35
|
end
|
31
36
|
|
32
37
|
def delete_comment(comment_id)
|
38
|
+
comment_id = ensure_id(comment_id)
|
33
39
|
uri = "#{COMMENTS_URI}/#{comment_id}"
|
34
40
|
result, response = delete uri
|
35
41
|
result
|
data/lib/boxr/files.rb
CHANGED
@@ -18,6 +18,7 @@ module Boxr
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def file(file_id, fields: [])
|
21
|
+
file_id = ensure_id(file_id)
|
21
22
|
uri = "#{FILES_URI}/#{file_id}"
|
22
23
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
23
24
|
file, response = get uri, query: query
|
@@ -25,6 +26,7 @@ module Boxr
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def update_file(file_id, name: nil, description: nil, parent_id: nil, shared_link: nil, tags: nil, if_match: nil)
|
29
|
+
file_id = ensure_id(file_id)
|
28
30
|
uri = "#{FILES_URI}/#{file_id}"
|
29
31
|
|
30
32
|
attributes = {}
|
@@ -39,6 +41,7 @@ module Boxr
|
|
39
41
|
end
|
40
42
|
|
41
43
|
def download_file(file_id, version: nil, follow_redirect: true)
|
44
|
+
file_id = ensure_id(file_id)
|
42
45
|
begin
|
43
46
|
uri = "#{FILES_URI}/#{file_id}/content"
|
44
47
|
query = {}
|
@@ -69,6 +72,7 @@ module Boxr
|
|
69
72
|
def upload_file(path_to_file, parent_id, content_created_at: nil, content_modified_at: nil,
|
70
73
|
preflight_check: true, send_content_md5: true)
|
71
74
|
|
75
|
+
parent_id = ensure_id(parent_id)
|
72
76
|
preflight_check(path_to_file, parent_id) if preflight_check
|
73
77
|
|
74
78
|
file_info = nil
|
@@ -86,6 +90,7 @@ module Boxr
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def delete_file(file_id, if_match: nil)
|
93
|
+
file_id = ensure_id(file_id)
|
89
94
|
uri = "#{FILES_URI}/#{file_id}"
|
90
95
|
result, response = delete uri, if_match: if_match
|
91
96
|
result
|
@@ -93,7 +98,7 @@ module Boxr
|
|
93
98
|
|
94
99
|
def upload_new_version_of_file(path_to_file, file_id, content_modified_at: nil, send_content_md5: true,
|
95
100
|
preflight_check: true, if_match: nil)
|
96
|
-
|
101
|
+
file_id = ensure_id(file_id)
|
97
102
|
preflight_check_new_version_of_file(path_to_file, file_id) if preflight_check
|
98
103
|
|
99
104
|
uri = "#{UPLOAD_URI}/files/#{file_id}/content"
|
@@ -111,12 +116,16 @@ module Boxr
|
|
111
116
|
end
|
112
117
|
|
113
118
|
def versions_of_file(file_id)
|
119
|
+
file_id = ensure_id(file_id)
|
114
120
|
uri = "#{FILES_URI}/#{file_id}/versions"
|
115
121
|
versions, response = get uri
|
116
122
|
versions["entries"]
|
117
123
|
end
|
118
124
|
|
119
125
|
def promote_old_version_of_file(file_id, file_version_id)
|
126
|
+
file_id = ensure_id(file_id)
|
127
|
+
file_version_id = ensure_id(file_version_id)
|
128
|
+
|
120
129
|
uri = "#{FILES_URI}/#{file_id}/versions/current"
|
121
130
|
attributes = {:type => 'file_version', :id => file_version_id}
|
122
131
|
new_version, res = post uri, attributes
|
@@ -124,12 +133,18 @@ module Boxr
|
|
124
133
|
end
|
125
134
|
|
126
135
|
def delete_old_version_of_file(file_id, file_version_id, if_match: nil)
|
136
|
+
file_id = ensure_id(file_id)
|
137
|
+
file_version_id = ensure_id(file_version_id)
|
138
|
+
|
127
139
|
uri = "#{FILES_URI}/#{file_id}/versions/#{file_version_id}"
|
128
140
|
result, response = delete uri, if_match: if_match
|
129
141
|
result
|
130
142
|
end
|
131
143
|
|
132
144
|
def copy_file(file_id, parent_id, name: nil)
|
145
|
+
file_id = ensure_id(file_id)
|
146
|
+
parent_id = ensure_id(parent_id)
|
147
|
+
|
133
148
|
uri = "#{FILES_URI}/#{file_id}/copy"
|
134
149
|
attributes = {:parent => {:id => parent_id}}
|
135
150
|
attributes[:name] = name unless name.nil?
|
@@ -138,6 +153,7 @@ module Boxr
|
|
138
153
|
end
|
139
154
|
|
140
155
|
def thumbnail(file_id, min_height: nil, min_width: nil, max_height: nil, max_width: nil)
|
156
|
+
file_id = ensure_id(file_id)
|
141
157
|
uri = "#{FILES_URI}/#{file_id}/thumbnail.png"
|
142
158
|
query = {}
|
143
159
|
query[:min_height] = min_height unless min_height.nil?
|
@@ -157,16 +173,19 @@ module Boxr
|
|
157
173
|
end
|
158
174
|
|
159
175
|
def create_shared_link_for_file(file_id, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
|
176
|
+
file_id = ensure_id(file_id)
|
160
177
|
uri = "#{FILES_URI}/#{file_id}"
|
161
178
|
create_shared_link(uri, file_id, access, unshared_at, can_download, can_preview)
|
162
179
|
end
|
163
180
|
|
164
181
|
def disable_shared_link_for_file(file_id)
|
182
|
+
file_id = ensure_id(file_id)
|
165
183
|
uri = "#{FILES_URI}/#{file_id}"
|
166
184
|
disable_shared_link(uri, file_id)
|
167
185
|
end
|
168
186
|
|
169
187
|
def trashed_file(file_id, fields: [])
|
188
|
+
file_id = ensure_id(file_id)
|
170
189
|
uri = "#{FILES_URI}/#{file_id}/trash"
|
171
190
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
172
191
|
|
@@ -175,6 +194,7 @@ module Boxr
|
|
175
194
|
end
|
176
195
|
|
177
196
|
def delete_trashed_file(file_id)
|
197
|
+
file_id = ensure_id(file_id)
|
178
198
|
uri = "#{FILES_URI}/#{file_id}/trash"
|
179
199
|
|
180
200
|
result, response = delete uri
|
@@ -182,6 +202,7 @@ module Boxr
|
|
182
202
|
end
|
183
203
|
|
184
204
|
def restore_trashed_file(file_id, name: nil, parent_id: nil)
|
205
|
+
file_id = ensure_id(file_id)
|
185
206
|
uri = "#{FILES_URI}/#{file_id}"
|
186
207
|
restore_trashed_item(uri, name, parent_id)
|
187
208
|
end
|
data/lib/boxr/folders.rb
CHANGED
@@ -18,6 +18,7 @@ module Boxr
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def folder_items(folder_id, fields: [])
|
21
|
+
folder_id = ensure_id(folder_id)
|
21
22
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
22
23
|
uri = "#{FOLDERS_URI}/#{folder_id}/items"
|
23
24
|
|
@@ -29,6 +30,7 @@ module Boxr
|
|
29
30
|
end
|
30
31
|
|
31
32
|
def create_folder(name, parent_id)
|
33
|
+
parent_id = ensure_id(parent_id)
|
32
34
|
uri = "#{FOLDERS_URI}"
|
33
35
|
attributes = {:name => name, :parent => {:id => parent_id}}
|
34
36
|
|
@@ -37,6 +39,7 @@ module Boxr
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def folder(folder_id, fields: [])
|
42
|
+
folder_id = ensure_id(folder_id)
|
40
43
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
41
44
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
42
45
|
|
@@ -47,6 +50,7 @@ module Boxr
|
|
47
50
|
def update_folder(folder_id, name: nil, description: nil, parent_id: nil, shared_link: nil,
|
48
51
|
folder_upload_email_access: nil, owned_by_id: nil, sync_state: nil, tags: nil,
|
49
52
|
can_non_owners_invite: nil, if_match: nil)
|
53
|
+
folder_id = ensure_id(folder_id)
|
50
54
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
51
55
|
|
52
56
|
attributes = {}
|
@@ -65,6 +69,7 @@ module Boxr
|
|
65
69
|
end
|
66
70
|
|
67
71
|
def delete_folder(folder_id, recursive: false, if_match: nil)
|
72
|
+
folder_id = ensure_id(folder_id)
|
68
73
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
69
74
|
query = {:recursive => recursive}
|
70
75
|
|
@@ -73,6 +78,9 @@ module Boxr
|
|
73
78
|
end
|
74
79
|
|
75
80
|
def copy_folder(folder_id, dest_folder_id, name: nil)
|
81
|
+
folder_id = ensure_id(folder_id)
|
82
|
+
dest_folder_id = ensure_id(dest_folder_id)
|
83
|
+
|
76
84
|
uri = "#{FOLDERS_URI}/#{folder_id}/copy"
|
77
85
|
attributes = {:parent => {:id => dest_folder_id}}
|
78
86
|
attributes[:name] = name unless name.nil?
|
@@ -82,11 +90,13 @@ module Boxr
|
|
82
90
|
end
|
83
91
|
|
84
92
|
def create_shared_link_for_folder(folder_id, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
|
93
|
+
folder_id = ensure_id(folder_id)
|
85
94
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
86
95
|
create_shared_link(uri, folder_id, access, unshared_at, can_download, can_preview)
|
87
96
|
end
|
88
97
|
|
89
98
|
def disable_shared_link_for_folder(folder_id)
|
99
|
+
folder_id = ensure_id(folder_id)
|
90
100
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
91
101
|
disable_shared_link(uri, folder_id)
|
92
102
|
end
|
@@ -99,6 +109,7 @@ module Boxr
|
|
99
109
|
end
|
100
110
|
|
101
111
|
def trashed_folder(folder_id, fields: [])
|
112
|
+
folder_id = ensure_id(folder_id)
|
102
113
|
uri = "#{FOLDERS_URI}/#{folder_id}/trash"
|
103
114
|
query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
|
104
115
|
|
@@ -107,12 +118,14 @@ module Boxr
|
|
107
118
|
end
|
108
119
|
|
109
120
|
def delete_trashed_folder(folder_id)
|
121
|
+
folder_id = ensure_id(folder_id)
|
110
122
|
uri = "#{FOLDERS_URI}/#{folder_id}/trash"
|
111
123
|
result, response = delete uri
|
112
124
|
result
|
113
125
|
end
|
114
126
|
|
115
127
|
def restore_trashed_folder(folder_id, name: nil, parent_id: nil)
|
128
|
+
folder_id = ensure_id(folder_id)
|
116
129
|
uri = "#{FOLDERS_URI}/#{folder_id}"
|
117
130
|
restore_trashed_item(uri, name, parent_id)
|
118
131
|
end
|
data/lib/boxr/groups.rb
CHANGED
@@ -13,6 +13,7 @@ module Boxr
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def update_group(group_id, name)
|
16
|
+
group_id = ensure_id(group_id)
|
16
17
|
uri = "#{GROUPS_URI}/#{group_id}"
|
17
18
|
attributes = {name: name}
|
18
19
|
|
@@ -23,17 +24,20 @@ module Boxr
|
|
23
24
|
alias :rename_group :update_group
|
24
25
|
|
25
26
|
def delete_group(group_id)
|
27
|
+
group_id = ensure_id(group_id)
|
26
28
|
uri = "#{GROUPS_URI}/#{group_id}"
|
27
29
|
result, response = delete(uri)
|
28
30
|
result
|
29
31
|
end
|
30
32
|
|
31
33
|
def group_memberships(group_id)
|
34
|
+
group_id = ensure_id(group_id)
|
32
35
|
uri = "#{GROUPS_URI}/#{group_id}/memberships"
|
33
36
|
memberships = get_with_pagination(uri)
|
34
37
|
end
|
35
38
|
|
36
39
|
def group_memberships_for_user(user_id)
|
40
|
+
user_id = ensure_id(user_id)
|
37
41
|
uri = "#{USERS_URI}/#{user_id}/memberships"
|
38
42
|
memberships = get_with_pagination(uri)
|
39
43
|
end
|
@@ -44,12 +48,16 @@ module Boxr
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def group_membership(membership_id)
|
51
|
+
membership_id = ensure_id(membership_id)
|
47
52
|
uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
|
48
53
|
membership, response = get(uri)
|
49
54
|
membership
|
50
55
|
end
|
51
56
|
|
52
57
|
def add_user_to_group(user_id, group_id, role: nil)
|
58
|
+
user_id = ensure_id(user_id)
|
59
|
+
group_id = ensure_id(group_id)
|
60
|
+
|
53
61
|
attributes = {user: {id: user_id}, group: {id: group_id}}
|
54
62
|
attributes[:role] = role unless role.nil?
|
55
63
|
membership, response = post(GROUP_MEMBERSHIPS_URI, attributes)
|
@@ -57,6 +65,7 @@ module Boxr
|
|
57
65
|
end
|
58
66
|
|
59
67
|
def update_group_membership(membership_id, role)
|
68
|
+
membership_id = ensure_id(membership_id)
|
60
69
|
uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
|
61
70
|
attributes = {role: role}
|
62
71
|
updated_membership, response = put(uri, attributes)
|
@@ -64,12 +73,14 @@ module Boxr
|
|
64
73
|
end
|
65
74
|
|
66
75
|
def delete_group_membership(membership_id)
|
76
|
+
membership_id = ensure_id(membership_id)
|
67
77
|
uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
|
68
78
|
result, response = delete(uri)
|
69
79
|
result
|
70
80
|
end
|
71
81
|
|
72
82
|
def group_collaborations(group_id)
|
83
|
+
group_id = ensure_id(group_id)
|
73
84
|
uri = "#{GROUPS_URI}/#{group_id}/collaborations"
|
74
85
|
collaborations = get_with_pagination(uri)
|
75
86
|
end
|
data/lib/boxr/metadata.rb
CHANGED
@@ -2,24 +2,28 @@ module Boxr
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
def create_metadata(file_id, metadata, type: :properties)
|
5
|
+
file_id = ensure_id(file_id)
|
5
6
|
uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
|
6
7
|
metadata, response = post uri, metadata, content_type: "application/json"
|
7
8
|
metadata
|
8
9
|
end
|
9
10
|
|
10
11
|
def metadata(file_id, type: :properties)
|
12
|
+
file_id = ensure_id(file_id)
|
11
13
|
uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
|
12
14
|
metadata, response = get uri
|
13
15
|
metadata
|
14
16
|
end
|
15
17
|
|
16
18
|
def update_metadata(file_id, updates, type: :properties)
|
19
|
+
file_id = ensure_id(file_id)
|
17
20
|
uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
|
18
21
|
metadata, response = put uri, updates, content_type: "application/json-patch+json"
|
19
22
|
metadata
|
20
23
|
end
|
21
24
|
|
22
25
|
def delete_metadata(file_id, type: :properties)
|
26
|
+
file_id = ensure_id(file_id)
|
23
27
|
uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
|
24
28
|
result, response = delete uri
|
25
29
|
result
|
data/lib/boxr/tasks.rb
CHANGED
@@ -2,6 +2,7 @@ module Boxr
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
def file_tasks(file_id, fields: [])
|
5
|
+
file_id = ensure_id(file_id)
|
5
6
|
uri = "#{FILES_URI}/#{file_id}/tasks"
|
6
7
|
query = build_fields_query(fields, TASK_FIELDS_QUERY)
|
7
8
|
|
@@ -10,6 +11,7 @@ module Boxr
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def create_task(file_id, action: :review, message: nil, due_at: nil)
|
14
|
+
file_id = ensure_id(file_id)
|
13
15
|
attributes = {item: {type: :file, id: file_id}}
|
14
16
|
attributes[:action] = action unless action.nil?
|
15
17
|
attributes[:message] = message unless message.nil?
|
@@ -20,12 +22,14 @@ module Boxr
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def task(task_id)
|
25
|
+
task_id = ensure_id(task_id)
|
23
26
|
uri = "#{TASKS_URI}/#{task_id}"
|
24
27
|
task, response = get uri
|
25
28
|
task
|
26
29
|
end
|
27
30
|
|
28
31
|
def update_task(task_id, action: :review, message: nil, due_at: nil)
|
32
|
+
task_id = ensure_id(task_id)
|
29
33
|
uri = "#{TASKS_URI}/#{task_id}"
|
30
34
|
attributes = {}
|
31
35
|
attributes[:action] = action unless action.nil?
|
@@ -37,18 +41,21 @@ module Boxr
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def delete_task(task_id)
|
44
|
+
task_id = ensure_id(task_id)
|
40
45
|
uri = "#{TASKS_URI}/#{task_id}"
|
41
46
|
result, response = delete uri
|
42
47
|
result
|
43
48
|
end
|
44
49
|
|
45
50
|
def task_assignments(task_id)
|
51
|
+
task_id = ensure_id(task_id)
|
46
52
|
uri = "#{TASKS_URI}/#{task_id}/assignments"
|
47
53
|
assignments, response = get uri
|
48
54
|
assignments['entries']
|
49
55
|
end
|
50
56
|
|
51
57
|
def create_task_assignment(task_id, assign_to_id: nil, assign_to_login: nil)
|
58
|
+
task_id = ensure_id(task_id)
|
52
59
|
attributes = {task: {type: :task, id: "#{task_id}"}}
|
53
60
|
|
54
61
|
attributes[:assign_to] = {}
|
@@ -60,18 +67,21 @@ module Boxr
|
|
60
67
|
end
|
61
68
|
|
62
69
|
def task_assignment(task_id)
|
70
|
+
task_id = ensure_id(task_id)
|
63
71
|
uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
|
64
72
|
task_assignment, response = get uri
|
65
73
|
task_assignment
|
66
74
|
end
|
67
75
|
|
68
76
|
def delete_task_assignment(task_id)
|
77
|
+
task_id = ensure_id(task_id)
|
69
78
|
uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
|
70
79
|
result, response = delete uri
|
71
80
|
result
|
72
81
|
end
|
73
82
|
|
74
83
|
def update_task_assignment(task_id, message: nil, resolution_state: nil)
|
84
|
+
task_id = ensure_id(task_id)
|
75
85
|
uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
|
76
86
|
attributes = {}
|
77
87
|
attributes[:message] = message unless message.nil?
|
data/lib/boxr/users.rb
CHANGED
@@ -11,6 +11,7 @@ module Boxr
|
|
11
11
|
alias :me :current_user
|
12
12
|
|
13
13
|
def user(user_id, fields: [])
|
14
|
+
user_id = ensure_id(user_id)
|
14
15
|
uri = "#{USERS_URI}/#{user_id}"
|
15
16
|
query = build_fields_query(fields, USER_FIELDS_QUERY)
|
16
17
|
user, response = get(uri, query: query)
|
@@ -55,6 +56,7 @@ module Boxr
|
|
55
56
|
can_see_managed_users: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil,
|
56
57
|
is_exempt_from_login_verification: nil, is_exempt_from_reset_required: nil, is_external_collab_restricted: nil)
|
57
58
|
|
59
|
+
user_id = ensure_id(user_id)
|
58
60
|
uri = "#{USERS_URI}/#{user_id}"
|
59
61
|
query = {notify: notify} unless notify.nil?
|
60
62
|
|
@@ -82,6 +84,7 @@ module Boxr
|
|
82
84
|
end
|
83
85
|
|
84
86
|
def delete_user(user_id, notify: nil, force: nil)
|
87
|
+
user_id = ensure_id(user_id)
|
85
88
|
uri = "#{USERS_URI}/#{user_id}"
|
86
89
|
query = {}
|
87
90
|
query[:notify] = notify unless notify.nil?
|
data/lib/boxr/version.rb
CHANGED
data/spec/boxr_spec.rb
CHANGED
@@ -40,65 +40,65 @@ describe Boxr::Client do
|
|
40
40
|
root_folders = BOX_CLIENT.root_folder_items.folders
|
41
41
|
test_folder = root_folders.find{|f| f.name == TEST_FOLDER_NAME}
|
42
42
|
if(test_folder)
|
43
|
-
BOX_CLIENT.delete_folder(test_folder
|
43
|
+
BOX_CLIENT.delete_folder(test_folder, recursive: true)
|
44
44
|
end
|
45
45
|
new_folder = BOX_CLIENT.create_folder(TEST_FOLDER_NAME, Boxr::ROOT)
|
46
|
-
@
|
46
|
+
@test_folder = new_folder
|
47
47
|
|
48
48
|
all_users = BOX_CLIENT.all_users
|
49
49
|
test_user = all_users.find{|u| u.name == TEST_USER_NAME}
|
50
50
|
if(test_user)
|
51
|
-
BOX_CLIENT.delete_user(test_user
|
51
|
+
BOX_CLIENT.delete_user(test_user, force: true)
|
52
52
|
end
|
53
53
|
sleep BOX_SERVER_SLEEP
|
54
54
|
test_user = BOX_CLIENT.create_user(TEST_USER_LOGIN, TEST_USER_NAME)
|
55
|
-
@
|
55
|
+
@test_user = test_user
|
56
56
|
|
57
57
|
all_groups = BOX_CLIENT.groups
|
58
58
|
test_group = all_groups.find{|g| g.name == TEST_GROUP_NAME}
|
59
59
|
if(test_group)
|
60
|
-
BOX_CLIENT.delete_group(test_group
|
60
|
+
BOX_CLIENT.delete_group(test_group)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'invokes folder operations' do
|
65
65
|
puts "get folder using path"
|
66
66
|
folder = BOX_CLIENT.folder_from_path(TEST_FOLDER_NAME)
|
67
|
-
expect(folder.id).to eq(@
|
67
|
+
expect(folder.id).to eq(@test_folder.id)
|
68
68
|
|
69
69
|
puts "get folder info"
|
70
|
-
folder = BOX_CLIENT.folder(@
|
71
|
-
expect(folder.id).to eq(@
|
70
|
+
folder = BOX_CLIENT.folder(@test_folder)
|
71
|
+
expect(folder.id).to eq(@test_folder.id)
|
72
72
|
|
73
73
|
puts "create new folder"
|
74
|
-
new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @
|
74
|
+
new_folder = BOX_CLIENT.create_folder(SUB_FOLDER_NAME, @test_folder)
|
75
75
|
expect(new_folder).to be_a Hashie::Mash
|
76
|
-
|
76
|
+
SUB_FOLDER = new_folder
|
77
77
|
|
78
78
|
puts "update folder"
|
79
|
-
updated_folder = BOX_CLIENT.update_folder(
|
79
|
+
updated_folder = BOX_CLIENT.update_folder(SUB_FOLDER, description: SUB_FOLDER_DESCRIPTION)
|
80
80
|
expect(updated_folder.description).to eq(SUB_FOLDER_DESCRIPTION)
|
81
81
|
|
82
82
|
puts "copy folder"
|
83
|
-
new_folder = BOX_CLIENT.copy_folder(
|
83
|
+
new_folder = BOX_CLIENT.copy_folder(SUB_FOLDER,@test_folder, name: 'copy of sub_folder_1')
|
84
84
|
expect(new_folder).to be_a Hashie::Mash
|
85
|
-
|
85
|
+
SUB_FOLDER_COPY = new_folder
|
86
86
|
|
87
87
|
puts "create shared link for folder"
|
88
|
-
updated_folder = BOX_CLIENT.create_shared_link_for_folder(@
|
88
|
+
updated_folder = BOX_CLIENT.create_shared_link_for_folder(@test_folder, access: :open)
|
89
89
|
expect(updated_folder.shared_link.access).to eq("open")
|
90
90
|
shared_link = updated_folder.shared_link.url
|
91
91
|
|
92
92
|
puts "inspect shared link"
|
93
93
|
shared_item = BOX_CLIENT.shared_item(shared_link)
|
94
|
-
expect(shared_item.id).to eq(@
|
94
|
+
expect(shared_item.id).to eq(@test_folder.id)
|
95
95
|
|
96
96
|
puts "disable shared link for folder"
|
97
|
-
updated_folder = BOX_CLIENT.disable_shared_link_for_folder(@
|
97
|
+
updated_folder = BOX_CLIENT.disable_shared_link_for_folder(@test_folder)
|
98
98
|
expect(updated_folder.shared_link).to be_nil
|
99
99
|
|
100
100
|
puts "delete folder"
|
101
|
-
result = BOX_CLIENT.delete_folder(
|
101
|
+
result = BOX_CLIENT.delete_folder(SUB_FOLDER_COPY, recursive: true)
|
102
102
|
expect(result).to eq ({})
|
103
103
|
|
104
104
|
puts "inspect the trash"
|
@@ -106,44 +106,44 @@ describe Boxr::Client do
|
|
106
106
|
expect(trash).to be_a Array
|
107
107
|
|
108
108
|
puts "inspect trashed folder"
|
109
|
-
trashed_folder = BOX_CLIENT.trashed_folder(
|
109
|
+
trashed_folder = BOX_CLIENT.trashed_folder(SUB_FOLDER_COPY)
|
110
110
|
expect(trashed_folder.item_status).to eq("trashed")
|
111
111
|
|
112
112
|
puts "restore trashed folder"
|
113
|
-
restored_folder = BOX_CLIENT.restore_trashed_folder(
|
113
|
+
restored_folder = BOX_CLIENT.restore_trashed_folder(SUB_FOLDER_COPY)
|
114
114
|
expect(restored_folder.item_status).to eq("active")
|
115
115
|
|
116
116
|
puts "trash and permanently delete folder"
|
117
|
-
BOX_CLIENT.delete_folder(
|
118
|
-
result = BOX_CLIENT.delete_trashed_folder(
|
117
|
+
BOX_CLIENT.delete_folder(SUB_FOLDER_COPY, recursive: true)
|
118
|
+
result = BOX_CLIENT.delete_trashed_folder(SUB_FOLDER_COPY)
|
119
119
|
expect(result).to eq({})
|
120
120
|
end
|
121
121
|
|
122
122
|
it "invokes file operations" do
|
123
123
|
puts "upload a file"
|
124
|
-
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @
|
124
|
+
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
125
125
|
expect(new_file.name).to eq(TEST_FILE_NAME)
|
126
|
-
|
126
|
+
test_file = new_file
|
127
127
|
|
128
128
|
puts "get file using path"
|
129
129
|
file = BOX_CLIENT.file_from_path("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
|
130
|
-
expect(file.id).to eq(
|
130
|
+
expect(file.id).to eq(test_file.id)
|
131
131
|
|
132
132
|
puts "get file download url"
|
133
|
-
download_url = BOX_CLIENT.download_url(
|
133
|
+
download_url = BOX_CLIENT.download_url(test_file)
|
134
134
|
expect(download_url).to start_with("https://")
|
135
135
|
|
136
136
|
puts "get file info"
|
137
|
-
file_info = BOX_CLIENT.file(
|
138
|
-
expect(file_info.id).to eq(
|
137
|
+
file_info = BOX_CLIENT.file(test_file)
|
138
|
+
expect(file_info.id).to eq(test_file.id)
|
139
139
|
|
140
140
|
puts "update file"
|
141
141
|
new_description = 'this file is used to test Boxr'
|
142
|
-
updated_file_info = BOX_CLIENT.update_file(
|
142
|
+
updated_file_info = BOX_CLIENT.update_file(test_file, description: new_description)
|
143
143
|
expect(updated_file_info.description).to eq(new_description)
|
144
144
|
|
145
145
|
puts "download file"
|
146
|
-
file = BOX_CLIENT.download_file(
|
146
|
+
file = BOX_CLIENT.download_file(test_file)
|
147
147
|
f = open("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}", 'w+')
|
148
148
|
f.write(file)
|
149
149
|
f.close
|
@@ -151,57 +151,57 @@ describe Boxr::Client do
|
|
151
151
|
File.delete("./spec/test_files/#{DOWNLOADED_TEST_FILE_NAME}")
|
152
152
|
|
153
153
|
puts "upload new version of file"
|
154
|
-
new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}",
|
155
|
-
expect(new_version.id).to eq(
|
154
|
+
new_version = BOX_CLIENT.upload_new_version_of_file("./spec/test_files/#{TEST_FILE_NAME}", test_file)
|
155
|
+
expect(new_version.id).to eq(test_file.id)
|
156
156
|
|
157
157
|
puts "inspect versions of file"
|
158
|
-
versions = BOX_CLIENT.versions_of_file(
|
158
|
+
versions = BOX_CLIENT.versions_of_file(test_file)
|
159
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
|
-
|
160
|
+
v1 = versions.first
|
161
161
|
|
162
162
|
puts "promote old version of file"
|
163
|
-
newer_version = BOX_CLIENT.promote_old_version_of_file(
|
164
|
-
versions = BOX_CLIENT.versions_of_file(
|
163
|
+
newer_version = BOX_CLIENT.promote_old_version_of_file(test_file, v1)
|
164
|
+
versions = BOX_CLIENT.versions_of_file(test_file)
|
165
165
|
expect(versions.count).to eq(2)
|
166
166
|
|
167
167
|
puts "delete old version of file"
|
168
|
-
result = BOX_CLIENT.delete_old_version_of_file(
|
169
|
-
versions = BOX_CLIENT.versions_of_file(
|
168
|
+
result = BOX_CLIENT.delete_old_version_of_file(test_file,v1)
|
169
|
+
versions = BOX_CLIENT.versions_of_file(test_file)
|
170
170
|
expect(versions.count).to eq(2) #this is still 2 because with Box you can restore a trashed old version
|
171
171
|
|
172
172
|
puts "get file thumbnail"
|
173
|
-
thumb = BOX_CLIENT.thumbnail(
|
173
|
+
thumb = BOX_CLIENT.thumbnail(test_file)
|
174
174
|
expect(thumb).not_to be_nil
|
175
175
|
|
176
176
|
puts "create shared link for file"
|
177
|
-
updated_file = BOX_CLIENT.create_shared_link_for_file(
|
177
|
+
updated_file = BOX_CLIENT.create_shared_link_for_file(test_file, access: :open)
|
178
178
|
expect(updated_file.shared_link.access).to eq("open")
|
179
179
|
|
180
180
|
puts "disable shared link for file"
|
181
|
-
updated_file = BOX_CLIENT.disable_shared_link_for_file(
|
181
|
+
updated_file = BOX_CLIENT.disable_shared_link_for_file(test_file)
|
182
182
|
expect(updated_file.shared_link).to be_nil
|
183
183
|
|
184
184
|
puts "copy file"
|
185
185
|
new_file_name = "copy of #{TEST_FILE_NAME}"
|
186
|
-
new_file = BOX_CLIENT.copy_file(
|
186
|
+
new_file = BOX_CLIENT.copy_file(test_file, @test_folder, name: new_file_name)
|
187
187
|
expect(new_file.name).to eq(new_file_name)
|
188
|
-
|
188
|
+
NEW_FILE = new_file
|
189
189
|
|
190
190
|
puts "delete file"
|
191
|
-
result = BOX_CLIENT.delete_file(
|
191
|
+
result = BOX_CLIENT.delete_file(NEW_FILE)
|
192
192
|
expect(result).to eq({})
|
193
193
|
|
194
194
|
puts "get trashed file info"
|
195
|
-
trashed_file = BOX_CLIENT.trashed_file(
|
195
|
+
trashed_file = BOX_CLIENT.trashed_file(NEW_FILE)
|
196
196
|
expect(trashed_file.item_status).to eq("trashed")
|
197
197
|
|
198
198
|
puts "restore trashed file"
|
199
|
-
restored_file = BOX_CLIENT.restore_trashed_file(
|
199
|
+
restored_file = BOX_CLIENT.restore_trashed_file(NEW_FILE)
|
200
200
|
expect(restored_file.item_status).to eq("active")
|
201
201
|
|
202
202
|
puts "trash and permanently delete file"
|
203
|
-
BOX_CLIENT.delete_file(
|
204
|
-
result = BOX_CLIENT.delete_trashed_file(
|
203
|
+
BOX_CLIENT.delete_file(NEW_FILE)
|
204
|
+
result = BOX_CLIENT.delete_trashed_file(NEW_FILE)
|
205
205
|
expect(result).to eq({})
|
206
206
|
end
|
207
207
|
|
@@ -213,23 +213,23 @@ describe Boxr::Client do
|
|
213
213
|
expect(user.role).to_not be_nil
|
214
214
|
|
215
215
|
puts "inspect a user"
|
216
|
-
user = BOX_CLIENT.user(@
|
217
|
-
expect(user.id).to eq(@
|
216
|
+
user = BOX_CLIENT.user(@test_user)
|
217
|
+
expect(user.id).to eq(@test_user.id)
|
218
218
|
|
219
219
|
puts "inspect all users"
|
220
220
|
all_users = BOX_CLIENT.all_users()
|
221
|
-
test_user = all_users.find{|u| u.id == @
|
221
|
+
test_user = all_users.find{|u| u.id == @test_user.id}
|
222
222
|
expect(test_user).to_not be_nil
|
223
223
|
|
224
224
|
puts "update user"
|
225
225
|
new_name = "Chuck Nevitt"
|
226
|
-
user = BOX_CLIENT.update_user(@
|
226
|
+
user = BOX_CLIENT.update_user(@test_user, name: new_name)
|
227
227
|
expect(user.name).to eq(new_name)
|
228
228
|
|
229
229
|
#create user is tested in the before method
|
230
230
|
|
231
231
|
puts "delete user"
|
232
|
-
result = BOX_CLIENT.delete_user(@
|
232
|
+
result = BOX_CLIENT.delete_user(@test_user, force: true)
|
233
233
|
expect(result).to eq({})
|
234
234
|
end
|
235
235
|
|
@@ -237,7 +237,6 @@ describe Boxr::Client do
|
|
237
237
|
puts "create group"
|
238
238
|
group = BOX_CLIENT.create_group(TEST_GROUP_NAME)
|
239
239
|
expect(group.name).to eq(TEST_GROUP_NAME)
|
240
|
-
test_group_id = group.id
|
241
240
|
|
242
241
|
puts "inspect groups"
|
243
242
|
groups = BOX_CLIENT.groups
|
@@ -246,30 +245,30 @@ describe Boxr::Client do
|
|
246
245
|
|
247
246
|
puts "update group"
|
248
247
|
new_name = "Test Boxr Group Renamed"
|
249
|
-
group = BOX_CLIENT.update_group(
|
248
|
+
group = BOX_CLIENT.update_group(test_group, new_name)
|
250
249
|
expect(group.name).to eq(new_name)
|
251
|
-
group = BOX_CLIENT.rename_group(
|
250
|
+
group = BOX_CLIENT.rename_group(test_group,TEST_GROUP_NAME)
|
252
251
|
expect(group.name).to eq(TEST_GROUP_NAME)
|
253
252
|
|
254
253
|
puts "add user to group"
|
255
|
-
group_membership = BOX_CLIENT.add_user_to_group(@
|
256
|
-
expect(group_membership.user.id).to eq(@
|
257
|
-
expect(group_membership.group.id).to eq(
|
258
|
-
|
254
|
+
group_membership = BOX_CLIENT.add_user_to_group(@test_user, test_group)
|
255
|
+
expect(group_membership.user.id).to eq(@test_user.id)
|
256
|
+
expect(group_membership.group.id).to eq(test_group.id)
|
257
|
+
membership = group_membership
|
259
258
|
|
260
259
|
puts "inspect group membership"
|
261
|
-
group_membership = BOX_CLIENT.group_membership(
|
262
|
-
expect(group_membership.id).to eq(
|
260
|
+
group_membership = BOX_CLIENT.group_membership(membership)
|
261
|
+
expect(group_membership.id).to eq(membership.id)
|
263
262
|
|
264
263
|
puts "inspect group memberships"
|
265
|
-
group_memberships = BOX_CLIENT.group_memberships(
|
264
|
+
group_memberships = BOX_CLIENT.group_memberships(test_group)
|
266
265
|
expect(group_memberships.count).to eq(1)
|
267
|
-
expect(group_memberships.first.id).to eq(
|
266
|
+
expect(group_memberships.first.id).to eq(membership.id)
|
268
267
|
|
269
268
|
puts "inspect group memberships for a user"
|
270
|
-
group_memberships = BOX_CLIENT.group_memberships_for_user(@
|
269
|
+
group_memberships = BOX_CLIENT.group_memberships_for_user(@test_user)
|
271
270
|
expect(group_memberships.count).to eq(1)
|
272
|
-
expect(group_memberships.first.id).to eq(
|
271
|
+
expect(group_memberships.first.id).to eq(membership.id)
|
273
272
|
|
274
273
|
puts "inspect group memberships for me"
|
275
274
|
#this is whatever user your developer token is tied to
|
@@ -277,77 +276,77 @@ describe Boxr::Client do
|
|
277
276
|
expect(group_memberships).to be_a(Array)
|
278
277
|
|
279
278
|
puts "update group membership"
|
280
|
-
group_membership = BOX_CLIENT.update_group_membership(
|
279
|
+
group_membership = BOX_CLIENT.update_group_membership(membership, :admin)
|
281
280
|
expect(group_membership.role).to eq("admin")
|
282
281
|
|
283
282
|
puts "delete group membership"
|
284
|
-
result = BOX_CLIENT.delete_group_membership(
|
283
|
+
result = BOX_CLIENT.delete_group_membership(membership)
|
285
284
|
expect(result).to eq({})
|
286
|
-
group_memberships = BOX_CLIENT.group_memberships_for_user(@
|
285
|
+
group_memberships = BOX_CLIENT.group_memberships_for_user(@test_user)
|
287
286
|
expect(group_memberships.count).to eq(0)
|
288
287
|
|
289
288
|
puts "inspect group collaborations"
|
290
|
-
group_collaboration = BOX_CLIENT.add_collaboration(@
|
291
|
-
expect(group_collaboration.accessible_by.id).to eq(
|
289
|
+
group_collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: test_group.id, type: :group}, :editor)
|
290
|
+
expect(group_collaboration.accessible_by.id).to eq(test_group.id)
|
292
291
|
|
293
292
|
puts "delete group"
|
294
|
-
response = BOX_CLIENT.delete_group(
|
293
|
+
response = BOX_CLIENT.delete_group(test_group)
|
295
294
|
expect(response).to eq({})
|
296
295
|
end
|
297
296
|
|
298
297
|
it "invokes comment operations" do
|
299
|
-
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @
|
300
|
-
|
298
|
+
new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
299
|
+
test_file = new_file
|
301
300
|
|
302
301
|
puts "add comment to file"
|
303
|
-
comment = BOX_CLIENT.add_comment_to_file(
|
302
|
+
comment = BOX_CLIENT.add_comment_to_file(test_file, message: COMMENT_MESSAGE)
|
304
303
|
expect(comment.message).to eq(COMMENT_MESSAGE)
|
305
|
-
|
304
|
+
COMMENT = comment
|
306
305
|
|
307
306
|
puts "reply to comment"
|
308
|
-
reply = BOX_CLIENT.reply_to_comment(
|
307
|
+
reply = BOX_CLIENT.reply_to_comment(COMMENT, message: REPLY_MESSAGE)
|
309
308
|
expect(reply.message).to eq(REPLY_MESSAGE)
|
310
309
|
|
311
310
|
puts "get file comments"
|
312
|
-
comments = BOX_CLIENT.file_comments(
|
311
|
+
comments = BOX_CLIENT.file_comments(test_file)
|
313
312
|
expect(comments.count).to eq(2)
|
314
313
|
|
315
314
|
puts "update a comment"
|
316
|
-
comment = BOX_CLIENT.change_comment(
|
315
|
+
comment = BOX_CLIENT.change_comment(COMMENT, CHANGED_COMMENT_MESSAGE)
|
317
316
|
expect(comment.message).to eq(CHANGED_COMMENT_MESSAGE)
|
318
317
|
|
319
318
|
puts "get comment info"
|
320
|
-
comment = BOX_CLIENT.comment(
|
321
|
-
expect(comment.id).to eq(
|
319
|
+
comment = BOX_CLIENT.comment(COMMENT)
|
320
|
+
expect(comment.id).to eq(COMMENT.id)
|
322
321
|
|
323
322
|
puts "delete comment"
|
324
|
-
result = BOX_CLIENT.delete_comment(
|
323
|
+
result = BOX_CLIENT.delete_comment(COMMENT)
|
325
324
|
expect(result).to eq({})
|
326
325
|
end
|
327
326
|
|
328
327
|
it "invokes collaborations operations" do
|
329
328
|
puts "add collaboration"
|
330
|
-
collaboration = BOX_CLIENT.add_collaboration(@
|
331
|
-
expect(collaboration.accessible_by.id).to eq(@
|
332
|
-
|
329
|
+
collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :editor)
|
330
|
+
expect(collaboration.accessible_by.id).to eq(@test_user.id)
|
331
|
+
COLLABORATION = collaboration
|
333
332
|
|
334
333
|
puts "inspect collaboration"
|
335
|
-
collaboration = BOX_CLIENT.collaboration(
|
336
|
-
expect(collaboration.id).to eq(
|
334
|
+
collaboration = BOX_CLIENT.collaboration(COLLABORATION)
|
335
|
+
expect(collaboration.id).to eq(COLLABORATION.id)
|
337
336
|
|
338
337
|
puts "edit collaboration"
|
339
|
-
collaboration = BOX_CLIENT.edit_collaboration(
|
338
|
+
collaboration = BOX_CLIENT.edit_collaboration(COLLABORATION, role: "viewer uploader")
|
340
339
|
expect(collaboration.role).to eq("viewer uploader")
|
341
340
|
|
342
341
|
puts "inspect folder collaborations"
|
343
|
-
collaborations = BOX_CLIENT.folder_collaborations(@
|
342
|
+
collaborations = BOX_CLIENT.folder_collaborations(@test_folder)
|
344
343
|
expect(collaborations.count).to eq(1)
|
345
|
-
expect(collaborations[0].id).to eq(
|
344
|
+
expect(collaborations[0].id).to eq(COLLABORATION.id)
|
346
345
|
|
347
346
|
puts "remove collaboration"
|
348
|
-
result = BOX_CLIENT.remove_collaboration(
|
347
|
+
result = BOX_CLIENT.remove_collaboration(COLLABORATION)
|
349
348
|
expect(result).to eq({})
|
350
|
-
collaborations = BOX_CLIENT.folder_collaborations(@
|
349
|
+
collaborations = BOX_CLIENT.folder_collaborations(@test_folder)
|
351
350
|
expect(collaborations.count).to eq(0)
|
352
351
|
|
353
352
|
puts "inspect pending collaborations"
|
@@ -356,79 +355,78 @@ describe Boxr::Client do
|
|
356
355
|
end
|
357
356
|
|
358
357
|
it "invokes task operations" do
|
359
|
-
|
360
|
-
|
361
|
-
collaboration = BOX_CLIENT.add_collaboration(@test_folder_id, {id: @test_user_id, type: :user}, :editor)
|
358
|
+
test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
359
|
+
collaboration = BOX_CLIENT.add_collaboration(@test_folder, {id: @test_user.id, type: :user}, :editor)
|
362
360
|
|
363
361
|
puts "create task"
|
364
|
-
new_task = BOX_CLIENT.create_task(
|
362
|
+
new_task = BOX_CLIENT.create_task(test_file, message: TEST_TASK_MESSAGE)
|
365
363
|
expect(new_task.message).to eq(TEST_TASK_MESSAGE)
|
366
|
-
|
364
|
+
TEST_TASK = new_task
|
367
365
|
|
368
366
|
puts "inspect file tasks"
|
369
|
-
tasks = BOX_CLIENT.file_tasks(
|
370
|
-
expect(tasks.first.id).to eq(
|
367
|
+
tasks = BOX_CLIENT.file_tasks(test_file)
|
368
|
+
expect(tasks.first.id).to eq(TEST_TASK.id)
|
371
369
|
|
372
370
|
puts "inspect task"
|
373
|
-
task = BOX_CLIENT.task(
|
374
|
-
expect(task.id).to eq(
|
371
|
+
task = BOX_CLIENT.task(TEST_TASK)
|
372
|
+
expect(task.id).to eq(TEST_TASK.id)
|
375
373
|
|
376
374
|
puts "update task"
|
377
375
|
NEW_TASK_MESSAGE = "new task message"
|
378
|
-
updated_task = BOX_CLIENT.update_task(
|
376
|
+
updated_task = BOX_CLIENT.update_task(TEST_TASK, message: NEW_TASK_MESSAGE)
|
379
377
|
expect(updated_task.message).to eq(NEW_TASK_MESSAGE)
|
380
378
|
|
381
379
|
puts "create task assignment"
|
382
|
-
task_assignment = BOX_CLIENT.create_task_assignment(
|
383
|
-
expect(task_assignment.assigned_to.id).to eq(@
|
384
|
-
|
380
|
+
task_assignment = BOX_CLIENT.create_task_assignment(TEST_TASK, assign_to_id: @test_user.id)
|
381
|
+
expect(task_assignment.assigned_to.id).to eq(@test_user.id)
|
382
|
+
TASK_ASSIGNMENT = task_assignment
|
385
383
|
|
386
384
|
puts "inspect task assignment"
|
387
|
-
task_assignment = BOX_CLIENT.task_assignment(
|
388
|
-
expect(task_assignment.id).to eq(
|
385
|
+
task_assignment = BOX_CLIENT.task_assignment(TASK_ASSIGNMENT)
|
386
|
+
expect(task_assignment.id).to eq(TASK_ASSIGNMENT.id)
|
389
387
|
|
390
388
|
puts "inspect task assignments"
|
391
|
-
task_assignments = BOX_CLIENT.task_assignments(
|
389
|
+
task_assignments = BOX_CLIENT.task_assignments(TEST_TASK)
|
392
390
|
expect(task_assignments.count).to eq(1)
|
393
|
-
expect(task_assignments[0].id).to eq(
|
391
|
+
expect(task_assignments[0].id).to eq(TASK_ASSIGNMENT.id)
|
394
392
|
|
395
393
|
#TODO: can't do this test yet because the test user needs to confirm their email address before you can do this
|
396
394
|
puts "update task assignment"
|
397
395
|
expect {
|
398
|
-
box_client_as_test_user = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'], as_user_id: @
|
396
|
+
box_client_as_test_user = Boxr::Client.new(ENV['BOX_DEVELOPER_TOKEN'], as_user_id: @test_user.id)
|
399
397
|
new_message = "Updated task message"
|
400
|
-
task_assignment = box_client_as_test_user.update_task_assignment(
|
398
|
+
task_assignment = box_client_as_test_user.update_task_assignment(TEST_TASK, resolution_state: :completed)
|
401
399
|
expect(task_assignment.resolution_state).to eq('completed')
|
402
400
|
}.to raise_error
|
403
401
|
|
404
402
|
puts "delete task assignment"
|
405
|
-
result = BOX_CLIENT.delete_task_assignment(
|
403
|
+
result = BOX_CLIENT.delete_task_assignment(TASK_ASSIGNMENT)
|
406
404
|
expect(result).to eq({})
|
407
405
|
|
408
406
|
puts "delete task"
|
409
|
-
result = BOX_CLIENT.delete_task(
|
407
|
+
result = BOX_CLIENT.delete_task(TEST_TASK)
|
410
408
|
expect(result).to eq({})
|
411
409
|
end
|
412
410
|
|
413
411
|
it "invokes metadata operations" do
|
414
|
-
|
415
|
-
test_file_id = new_file.id
|
412
|
+
test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
|
413
|
+
#test_file_id = new_file.id
|
416
414
|
|
417
415
|
puts "create metadata"
|
418
416
|
meta = {"a" => "hello", "b" => "world"}
|
419
|
-
metadata = BOX_CLIENT.create_metadata(
|
417
|
+
metadata = BOX_CLIENT.create_metadata(test_file, meta)
|
420
418
|
expect(metadata.a).to eq("hello")
|
421
419
|
|
422
420
|
puts "update metadata"
|
423
|
-
metadata = BOX_CLIENT.update_metadata(
|
421
|
+
metadata = BOX_CLIENT.update_metadata(test_file, [{op: :replace, path: "/b", value: "there"}])
|
424
422
|
expect(metadata.b).to eq("there")
|
425
423
|
|
426
424
|
puts "get metadata"
|
427
|
-
metadata = BOX_CLIENT.metadata(
|
425
|
+
metadata = BOX_CLIENT.metadata(test_file)
|
428
426
|
expect(metadata.a).to eq("hello")
|
429
427
|
|
430
428
|
puts "delete metadata"
|
431
|
-
result = BOX_CLIENT.delete_metadata(
|
429
|
+
result = BOX_CLIENT.delete_metadata(test_file)
|
432
430
|
expect(result).to eq({})
|
433
431
|
end
|
434
432
|
|