boxr 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ecd063a6d71a477dc1aa7d50d53b2f649354599
4
- data.tar.gz: 16fbb18c677d990d8dba2071226d1ce8f59ee145
3
+ metadata.gz: 9cdb5f7265259244d249458468620150e7a64f19
4
+ data.tar.gz: 0adf2236b65d01221f5b5b00d249387ac613e6a8
5
5
  SHA512:
6
- metadata.gz: 657845370199ea7d468ea248c06038febfa0e58ba126b2bfb35cc6b7140262b0f078485ad4de83cf9b8bf8a8a7944831a498d6315cfc95e71dc706e10259cde7
7
- data.tar.gz: 4dd7d41e230f9729cbb9ff2a90ecbca5e31cf7116800e034e9f9e4a3dc1195f15dd4e45aca0d0840c9dbf5e5d66ca13d512bca46a51fbf7533ea9ac52b764dd0
6
+ metadata.gz: 1113cc5af8e5de187b8c6ebd15625ae2164120ccde300b1e70dd484079ff6139d5eb4871605c1a6473c25e54e9a0896a07aef5ec63a62ff25d9429e3b3dd4963
7
+ data.tar.gz: 5a9985a2d4799935c622c0120cd477e7f3c8fd5a2061494dc0ac2cd3046729bb522daf747bd03c09ef7acded42a1863fd895ee069f6977254e3b2cb7386030a1
data/README.md CHANGED
@@ -3,7 +3,7 @@ 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). 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 test found [here](https://github.com/cburnette/boxr/blob/master/spec/boxr_spec.rb).
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 test found [here](https://github.com/cburnette/boxr/blob/master/spec/boxr_spec.rb).
7
7
 
8
8
  ## Installation
9
9
  Add this line to your application's Gemfile:
data/lib/boxr/client.rb CHANGED
@@ -82,7 +82,7 @@ module Boxr
82
82
 
83
83
  def get(uri, query: nil, success_codes: [200], process_response: true, if_match: nil, box_api_header: nil)
84
84
  res = with_auto_token_refresh do
85
- headers = standard_headers()
85
+ headers = standard_headers
86
86
  headers['If-Match'] = if_match unless if_match.nil?
87
87
  headers['BoxApi'] = box_api_header unless box_api_header.nil?
88
88
 
@@ -92,21 +92,20 @@ module Boxr
92
92
  check_response_status(res, success_codes)
93
93
 
94
94
  if process_response
95
- return processed_response res
95
+ return processed_response(res)
96
96
  else
97
97
  return res.body, res
98
98
  end
99
99
  end
100
100
 
101
- def get_with_pagination(uri, query: {}, limit: DEFAULT_LIMIT)
101
+ def get_with_pagination(uri, query: {}, offset: 0, limit: DEFAULT_LIMIT)
102
102
  entries = []
103
- offset = 0
104
103
 
105
104
  begin
106
105
  query[:limit] = limit
107
106
  query[:offset] = offset
108
107
  res = with_auto_token_refresh do
109
- headers = standard_headers()
108
+ headers = standard_headers
110
109
  BOX_CLIENT.get(uri, query: query, header: headers)
111
110
  end
112
111
 
@@ -128,7 +127,7 @@ module Boxr
128
127
  body = Oj.dump(body) if process_body
129
128
 
130
129
  res = with_auto_token_refresh do
131
- headers = standard_headers()
130
+ headers = standard_headers
132
131
  headers['If-Match'] = if_match unless if_match.nil?
133
132
  headers["Content-MD5"] = content_md5 unless content_md5.nil?
134
133
  headers["Content-Type"] = content_type unless content_type.nil?
@@ -138,12 +137,12 @@ module Boxr
138
137
 
139
138
  check_response_status(res, success_codes)
140
139
 
141
- processed_response res
140
+ processed_response(res)
142
141
  end
143
142
 
144
143
  def put(uri, body, query: nil, success_codes: [200], content_type: nil, if_match: nil)
145
144
  res = with_auto_token_refresh do
146
- headers = standard_headers()
145
+ headers = standard_headers
147
146
  headers['If-Match'] = if_match unless if_match.nil?
148
147
  headers["Content-Type"] = content_type unless content_type.nil?
149
148
 
@@ -152,12 +151,12 @@ module Boxr
152
151
 
153
152
  check_response_status(res, success_codes)
154
153
 
155
- processed_response res
154
+ processed_response(res)
156
155
  end
157
156
 
158
157
  def delete(uri, query: nil, success_codes: [204], if_match: nil)
159
158
  res = with_auto_token_refresh do
160
- headers = standard_headers()
159
+ headers = standard_headers
161
160
  headers['If-Match'] = if_match unless if_match.nil?
162
161
 
163
162
  BOX_CLIENT.delete(uri, query: query, header: headers)
@@ -165,18 +164,18 @@ module Boxr
165
164
 
166
165
  check_response_status(res, success_codes)
167
166
 
168
- processed_response res
167
+ processed_response(res)
169
168
  end
170
169
 
171
170
  def options(uri, body, success_codes: [200])
172
171
  res = with_auto_token_refresh do
173
- headers = standard_headers()
172
+ headers = standard_headers
174
173
  BOX_CLIENT.options(uri, body: Oj.dump(body), header: headers)
175
174
  end
176
175
 
177
176
  check_response_status(res, success_codes)
178
177
 
179
- processed_response res
178
+ processed_response(res)
180
179
  end
181
180
 
182
181
  def standard_headers()
@@ -233,7 +232,7 @@ module Boxr
233
232
  attributes[:name] = name unless name.nil?
234
233
  attributes[:parent] = {id: parent_id} unless parent_id.nil?
235
234
 
236
- restored_item, response = post uri, attributes
235
+ restored_item, response = post(uri, attributes)
237
236
  restored_item
238
237
  end
239
238
 
@@ -248,14 +247,14 @@ module Boxr
248
247
  attributes[:shared_link][:permissions][:can_preview] = can_preview unless can_preview.nil?
249
248
  end
250
249
 
251
- updated_item, response = put uri, attributes
250
+ updated_item, response = put(uri, attributes)
252
251
  updated_item
253
252
  end
254
253
 
255
254
  def disable_shared_link(uri, item_id)
256
255
  attributes = {shared_link: nil}
257
256
 
258
- updated_item, response = put uri, attributes
257
+ updated_item, response = put(uri, attributes)
259
258
  updated_item
260
259
  end
261
260
 
@@ -1,16 +1,16 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def folder_collaborations(folder_id)
5
- folder_id = ensure_id(folder_id)
4
+ def folder_collaborations(folder)
5
+ folder_id = ensure_id(folder)
6
6
  uri = "#{FOLDERS_URI}/#{folder_id}/collaborations"
7
7
  collaborations, response = get(uri)
8
8
  collaborations['entries']
9
9
  end
10
10
 
11
11
  #make sure 'role' value is a string as Box has role values with spaces and dashes; e.g. 'previewer uploader'
12
- def add_collaboration(folder_id, accessible_by, role, fields: [], notify: nil)
13
- folder_id = ensure_id(folder_id)
12
+ def add_collaboration(folder, accessible_by, role, fields: [], notify: nil)
13
+ folder_id = ensure_id(folder)
14
14
  query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
15
15
  query[:notify] = :notify unless notify.nil?
16
16
 
@@ -22,8 +22,8 @@ module Boxr
22
22
  collaboration
23
23
  end
24
24
 
25
- def edit_collaboration(collaboration_id, role: nil, status: nil)
26
- collaboration_id = ensure_id(collaboration_id)
25
+ def edit_collaboration(collaboration, role: nil, status: nil)
26
+ collaboration_id = ensure_id(collaboration)
27
27
  uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
28
28
  attributes = {}
29
29
  attributes[:role] = role unless role.nil?
@@ -33,15 +33,15 @@ module Boxr
33
33
  updated_collaboration
34
34
  end
35
35
 
36
- def remove_collaboration(collaboration_id)
37
- collaboration_id = ensure_id(collaboration_id)
36
+ def remove_collaboration(collaboration)
37
+ collaboration_id = ensure_id(collaboration)
38
38
  uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
39
39
  result, response = delete(uri)
40
40
  result
41
41
  end
42
42
 
43
- def collaboration(collaboration_id, fields: [], status: nil)
44
- collaboration_id = ensure_id(collaboration_id)
43
+ def collaboration(collaboration, fields: [], status: nil)
44
+ collaboration_id = ensure_id(collaboration)
45
45
  uri = "#{COLLABORATIONS_URI}/#{collaboration_id}"
46
46
 
47
47
  query = build_fields_query(fields, COLLABORATION_FIELDS_QUERY)
data/lib/boxr/comments.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def file_comments(file_id, fields: [])
5
- file_id = ensure_id(file_id)
4
+ def file_comments(file, fields: [], offset: 0, limit: DEFAULT_LIMIT)
5
+ file_id = ensure_id(file)
6
6
  uri = "#{FILES_URI}/#{file_id}/comments"
7
7
  query = build_fields_query(fields, COMMENT_FIELDS_QUERY)
8
8
 
9
- comments = get_with_pagination uri, query: query
9
+ comments = get_with_pagination(uri, query: query, offset: offset, limit: limit)
10
10
  end
11
11
 
12
- def add_comment_to_file(file_id, message: nil, tagged_message: nil)
13
- file_id = ensure_id(file_id)
12
+ def add_comment_to_file(file, message: nil, tagged_message: nil)
13
+ file_id = ensure_id(file)
14
14
  add_comment(:file, file_id, message, tagged_message)
15
15
  end
16
16
 
@@ -19,25 +19,25 @@ module Boxr
19
19
  add_comment(:comment, comment_id, message, tagged_message)
20
20
  end
21
21
 
22
- def change_comment(comment_id, message)
23
- comment_id = ensure_id(comment_id)
22
+ def change_comment(comment, message)
23
+ comment_id = ensure_id(comment)
24
24
  uri = "#{COMMENTS_URI}/#{comment_id}"
25
25
  attributes = {message: message}
26
- updated_comment, response = put uri, attributes
26
+ updated_comment, response = put(uri, attributes)
27
27
  updated_comment
28
28
  end
29
29
 
30
- def comment(comment_id, fields: [])
31
- comment_id = ensure_id(comment_id)
30
+ def comment(comment, fields: [])
31
+ comment_id = ensure_id(comment)
32
32
  uri ="#{COMMENTS_URI}/#{comment_id}"
33
- comment, response = get uri
33
+ comment, response = get(uri)
34
34
  comment
35
35
  end
36
36
 
37
- def delete_comment(comment_id)
38
- comment_id = ensure_id(comment_id)
37
+ def delete_comment(comment)
38
+ comment_id = ensure_id(comment)
39
39
  uri = "#{COMMENTS_URI}/#{comment_id}"
40
- result, response = delete uri
40
+ result, response = delete(uri)
41
41
  result
42
42
  end
43
43
 
@@ -50,7 +50,7 @@ module Boxr
50
50
  attributes[:message] = message unless message.nil?
51
51
  attributes[:tagged_message] = tagged_message unless tagged_message.nil?
52
52
 
53
- new_comment, response = post uri, attributes
53
+ new_comment, response = post(uri, attributes)
54
54
  new_comment
55
55
  end
56
56
 
data/lib/boxr/files.rb CHANGED
@@ -11,22 +11,22 @@ module Boxr
11
11
 
12
12
  folder = folder_from_path(path_items.join('/'))
13
13
 
14
- files = folder_items(folder.id, fields: [:id, :name]).files
14
+ files = folder_items(folder, fields: [:id, :name]).files
15
15
  file = files.select{|f| f.name == file_name}.first
16
16
  raise BoxrException.new(boxr_message: "File not found: '#{file_name}'") if file.nil?
17
17
  file
18
18
  end
19
19
 
20
- def file(file_id, fields: [])
21
- file_id = ensure_id(file_id)
20
+ def file(file, fields: [])
21
+ file_id = ensure_id(file)
22
22
  uri = "#{FILES_URI}/#{file_id}"
23
23
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
24
- file, response = get uri, query: query
24
+ file, response = get(uri, query: query)
25
25
  file
26
26
  end
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
+ def update_file(file, name: nil, description: nil, parent_id: nil, shared_link: nil, tags: nil, if_match: nil)
29
+ file_id = ensure_id(file)
30
30
  uri = "#{FILES_URI}/#{file_id}"
31
31
 
32
32
  attributes = {}
@@ -36,23 +36,23 @@ module Boxr
36
36
  attributes[:shared_link] = shared_link unless shared_link.nil?
37
37
  attributes[:tags] = tags unless tags.nil?
38
38
 
39
- updated_file, response = put uri, attributes, if_match: if_match
39
+ updated_file, response = put(uri, attributes, if_match: if_match)
40
40
  updated_file
41
41
  end
42
42
 
43
- def download_file(file_id, version: nil, follow_redirect: true)
44
- file_id = ensure_id(file_id)
43
+ def download_file(file, version: nil, follow_redirect: true)
44
+ file_id = ensure_id(file)
45
45
  begin
46
46
  uri = "#{FILES_URI}/#{file_id}/content"
47
47
  query = {}
48
48
  query[:version] = version unless version.nil?
49
- body_json, response = get uri, query: query, success_codes: [302,202]
49
+ body_json, response = get(uri, query: query, success_codes: [302,202])
50
50
 
51
51
  if(response.status==302)
52
52
  location = response.header['Location'][0]
53
53
 
54
54
  if(follow_redirect)
55
- file, response = get location, process_response: false
55
+ file, response = get(location, process_response: false)
56
56
  else
57
57
  return location #simply return the url
58
58
  end
@@ -65,14 +65,14 @@ module Boxr
65
65
  file
66
66
  end
67
67
 
68
- def download_url(file_id, version: nil)
69
- download_file(file_id, version: version, follow_redirect: false)
68
+ def download_url(file, version: nil)
69
+ download_file(file, version: version, follow_redirect: false)
70
70
  end
71
71
 
72
- def upload_file(path_to_file, parent_id, content_created_at: nil, content_modified_at: nil,
72
+ def upload_file(path_to_file, parent, content_created_at: nil, content_modified_at: nil,
73
73
  preflight_check: true, send_content_md5: true)
74
74
 
75
- parent_id = ensure_id(parent_id)
75
+ parent_id = ensure_id(parent)
76
76
  preflight_check(path_to_file, parent_id) if preflight_check
77
77
 
78
78
  file_info = nil
@@ -83,22 +83,22 @@ module Boxr
83
83
  attributes = {filename: file, parent_id: parent_id}
84
84
  attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
85
85
  attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
86
- file_info, response = post FILES_UPLOAD_URI, attributes, process_body: false, content_md5: content_md5
86
+ file_info, response = post(FILES_UPLOAD_URI, attributes, process_body: false, content_md5: content_md5)
87
87
  end
88
88
 
89
89
  file_info["entries"][0]
90
90
  end
91
91
 
92
- def delete_file(file_id, if_match: nil)
93
- file_id = ensure_id(file_id)
92
+ def delete_file(file, if_match: nil)
93
+ file_id = ensure_id(file)
94
94
  uri = "#{FILES_URI}/#{file_id}"
95
- result, response = delete uri, if_match: if_match
95
+ result, response = delete(uri, if_match: if_match)
96
96
  result
97
97
  end
98
98
 
99
- def upload_new_version_of_file(path_to_file, file_id, content_modified_at: nil, send_content_md5: true,
99
+ def upload_new_version_of_file(path_to_file, file, content_modified_at: nil, send_content_md5: true,
100
100
  preflight_check: true, if_match: nil)
101
- file_id = ensure_id(file_id)
101
+ file_id = ensure_id(file)
102
102
  preflight_check_new_version_of_file(path_to_file, file_id) if preflight_check
103
103
 
104
104
  uri = "#{UPLOAD_URI}/files/#{file_id}/content"
@@ -109,62 +109,62 @@ module Boxr
109
109
  content_md5 = send_content_md5 ? Digest::SHA1.file(file).hexdigest : nil
110
110
  attributes = {filename: file}
111
111
  attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
112
- file_info, response = post uri, attributes, process_body: false, content_md5: content_md5, if_match: if_match
112
+ file_info, response = post(uri, attributes, process_body: false, content_md5: content_md5, if_match: if_match)
113
113
  end
114
114
 
115
115
  file_info["entries"][0]
116
116
  end
117
117
 
118
- def versions_of_file(file_id)
119
- file_id = ensure_id(file_id)
118
+ def versions_of_file(file)
119
+ file_id = ensure_id(file)
120
120
  uri = "#{FILES_URI}/#{file_id}/versions"
121
- versions, response = get uri
121
+ versions, response = get(uri)
122
122
  versions["entries"]
123
123
  end
124
124
 
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)
125
+ def promote_old_version_of_file(file, file_version)
126
+ file_id = ensure_id(file)
127
+ file_version_id = ensure_id(file_version)
128
128
 
129
129
  uri = "#{FILES_URI}/#{file_id}/versions/current"
130
130
  attributes = {:type => 'file_version', :id => file_version_id}
131
- new_version, res = post uri, attributes
131
+ new_version, res = post(uri, attributes)
132
132
  new_version
133
133
  end
134
134
 
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)
135
+ def delete_old_version_of_file(file, file_version, if_match: nil)
136
+ file_id = ensure_id(file)
137
+ file_version_id = ensure_id(file_version)
138
138
 
139
139
  uri = "#{FILES_URI}/#{file_id}/versions/#{file_version_id}"
140
- result, response = delete uri, if_match: if_match
140
+ result, response = delete(uri, if_match: if_match)
141
141
  result
142
142
  end
143
143
 
144
- def copy_file(file_id, parent_id, name: nil)
145
- file_id = ensure_id(file_id)
146
- parent_id = ensure_id(parent_id)
144
+ def copy_file(file, parent, name: nil)
145
+ file_id = ensure_id(file)
146
+ parent_id = ensure_id(parent)
147
147
 
148
148
  uri = "#{FILES_URI}/#{file_id}/copy"
149
149
  attributes = {:parent => {:id => parent_id}}
150
150
  attributes[:name] = name unless name.nil?
151
- new_file, res = post uri, attributes
151
+ new_file, res = post(uri, attributes)
152
152
  new_file
153
153
  end
154
154
 
155
- def thumbnail(file_id, min_height: nil, min_width: nil, max_height: nil, max_width: nil)
156
- file_id = ensure_id(file_id)
155
+ def thumbnail(file, min_height: nil, min_width: nil, max_height: nil, max_width: nil)
156
+ file_id = ensure_id(file)
157
157
  uri = "#{FILES_URI}/#{file_id}/thumbnail.png"
158
158
  query = {}
159
159
  query[:min_height] = min_height unless min_height.nil?
160
160
  query[:min_width] = min_width unless min_width.nil?
161
161
  query[:max_height] = max_height unless max_height.nil?
162
162
  query[:max_width] = max_width unless max_width.nil?
163
- body, response = get uri, query: query, success_codes: [302,202,200], process_response: false
163
+ body, response = get(uri, query: query, success_codes: [302,202,200], process_response: false)
164
164
 
165
165
  if(response.status==202 || response.status==302)
166
166
  location = response.header['Location'][0]
167
- thumbnail, response = get location, process_response: false
167
+ thumbnail, response = get(location, process_response: false)
168
168
  else #200
169
169
  thumbnail = body
170
170
  end
@@ -172,37 +172,37 @@ module Boxr
172
172
  thumbnail
173
173
  end
174
174
 
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)
175
+ def create_shared_link_for_file(file, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
176
+ file_id = ensure_id(file)
177
177
  uri = "#{FILES_URI}/#{file_id}"
178
178
  create_shared_link(uri, file_id, access, unshared_at, can_download, can_preview)
179
179
  end
180
180
 
181
- def disable_shared_link_for_file(file_id)
182
- file_id = ensure_id(file_id)
181
+ def disable_shared_link_for_file(file)
182
+ file_id = ensure_id(file)
183
183
  uri = "#{FILES_URI}/#{file_id}"
184
184
  disable_shared_link(uri, file_id)
185
185
  end
186
186
 
187
- def trashed_file(file_id, fields: [])
188
- file_id = ensure_id(file_id)
187
+ def trashed_file(file, fields: [])
188
+ file_id = ensure_id(file)
189
189
  uri = "#{FILES_URI}/#{file_id}/trash"
190
190
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
191
191
 
192
- trashed_file, response = get uri, query: query
192
+ trashed_file, response = get(uri, query: query)
193
193
  trashed_file
194
194
  end
195
195
 
196
- def delete_trashed_file(file_id)
197
- file_id = ensure_id(file_id)
196
+ def delete_trashed_file(file)
197
+ file_id = ensure_id(file)
198
198
  uri = "#{FILES_URI}/#{file_id}/trash"
199
199
 
200
- result, response = delete uri
200
+ result, response = delete(uri)
201
201
  result
202
202
  end
203
203
 
204
- def restore_trashed_file(file_id, name: nil, parent_id: nil)
205
- file_id = ensure_id(file_id)
204
+ def restore_trashed_file(file, name: nil, parent_id: nil)
205
+ file_id = ensure_id(file)
206
206
  uri = "#{FILES_URI}/#{file_id}"
207
207
  restore_trashed_item(uri, name, parent_id)
208
208
  end
@@ -216,13 +216,13 @@ module Boxr
216
216
  #TODO: need to make sure that figuring out the filename from the path_to_file works for people using Winblows
217
217
  filename = File.basename(path_to_file)
218
218
  attributes = {"name" => filename, "parent" => {"id" => "#{parent_id}"}, "size" => size}
219
- body_json, res = options "#{FILES_URI}/content", attributes
219
+ body_json, res = options("#{FILES_URI}/content", attributes)
220
220
  end
221
221
 
222
222
  def preflight_check_new_version_of_file(path_to_file, file_id)
223
223
  size = File.size(path_to_file)
224
224
  attributes = {"size" => size}
225
- body_json, res = options "#{FILES_URI}/#{file_id}/content", attributes
225
+ body_json, res = options("#{FILES_URI}/#{file_id}/content", attributes)
226
226
  end
227
227
 
228
228
  end
data/lib/boxr/folders.rb CHANGED
@@ -8,49 +8,48 @@ module Boxr
8
8
 
9
9
  path_folders = path.split('/')
10
10
 
11
- root_folder = Hashie::Mash.new({id: Boxr::ROOT})
12
- folder = path_folders.inject(root_folder) do |parent_folder, folder_name|
13
- folders = folder_items(parent_folder.id, fields: [:id, :name]).folders
11
+ folder = path_folders.inject(Boxr::ROOT) do |parent_folder, folder_name|
12
+ folders = folder_items(parent_folder, fields: [:id, :name]).folders
14
13
  folder = folders.select{|f| f.name == folder_name}.first
15
14
  raise BoxrException.new(boxr_message: "Folder not found: '#{folder_name}'") if folder.nil?
16
15
  folder
17
16
  end
18
17
  end
19
18
 
20
- def folder_items(folder_id, fields: [])
21
- folder_id = ensure_id(folder_id)
19
+ def folder_items(folder, fields: [], offset: 0, limit: FOLDER_ITEMS_LIMIT)
20
+ folder_id = ensure_id(folder)
22
21
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
23
22
  uri = "#{FOLDERS_URI}/#{folder_id}/items"
24
23
 
25
- items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
24
+ items = get_with_pagination(uri, query: query, offset: offset, limit: limit)
26
25
  end
27
26
 
28
27
  def root_folder_items(fields: [])
29
28
  folder_items(Boxr::ROOT, fields: fields)
30
29
  end
31
30
 
32
- def create_folder(name, parent_id)
33
- parent_id = ensure_id(parent_id)
31
+ def create_folder(name, parent)
32
+ parent_id = ensure_id(parent)
34
33
  uri = "#{FOLDERS_URI}"
35
34
  attributes = {:name => name, :parent => {:id => parent_id}}
36
35
 
37
- created_folder, response = post uri, attributes
36
+ created_folder, response = post(uri, attributes)
38
37
  created_folder
39
38
  end
40
39
 
41
- def folder(folder_id, fields: [])
42
- folder_id = ensure_id(folder_id)
40
+ def folder(folder, fields: [])
41
+ folder_id = ensure_id(folder)
43
42
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
44
43
  uri = "#{FOLDERS_URI}/#{folder_id}"
45
44
 
46
- folder, response = get uri, query: query
45
+ folder, response = get(uri, query: query)
47
46
  folder
48
47
  end
49
48
 
50
- def update_folder(folder_id, name: nil, description: nil, parent_id: nil, shared_link: nil,
49
+ def update_folder(folder, name: nil, description: nil, parent_id: nil, shared_link: nil,
51
50
  folder_upload_email_access: nil, owned_by_id: nil, sync_state: nil, tags: nil,
52
51
  can_non_owners_invite: nil, if_match: nil)
53
- folder_id = ensure_id(folder_id)
52
+ folder_id = ensure_id(folder)
54
53
  uri = "#{FOLDERS_URI}/#{folder_id}"
55
54
 
56
55
  attributes = {}
@@ -64,68 +63,68 @@ module Boxr
64
63
  attributes[:tags] = tags unless tags.nil?
65
64
  attributes[:can_non_owners_invite] = can_non_owners_invite unless can_non_owners_invite.nil?
66
65
 
67
- updated_folder, response = put uri, attributes, if_match: if_match
66
+ updated_folder, response = put(uri, attributes, if_match: if_match)
68
67
  updated_folder
69
68
  end
70
69
 
71
- def delete_folder(folder_id, recursive: false, if_match: nil)
72
- folder_id = ensure_id(folder_id)
70
+ def delete_folder(folder, recursive: false, if_match: nil)
71
+ folder_id = ensure_id(folder)
73
72
  uri = "#{FOLDERS_URI}/#{folder_id}"
74
73
  query = {:recursive => recursive}
75
74
 
76
- result, response = delete uri, query: query, if_match: if_match
75
+ result, response = delete(uri, query: query, if_match: if_match)
77
76
  result
78
77
  end
79
78
 
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)
79
+ def copy_folder(folder, dest_folder, name: nil)
80
+ folder_id = ensure_id(folder)
81
+ dest_folder_id = ensure_id(dest_folder)
83
82
 
84
83
  uri = "#{FOLDERS_URI}/#{folder_id}/copy"
85
84
  attributes = {:parent => {:id => dest_folder_id}}
86
85
  attributes[:name] = name unless name.nil?
87
86
 
88
- new_folder, response = post uri, attributes
87
+ new_folder, response = post(uri, attributes)
89
88
  new_folder
90
89
  end
91
90
 
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)
91
+ def create_shared_link_for_folder(folder, access: nil, unshared_at: nil, can_download: nil, can_preview: nil)
92
+ folder_id = ensure_id(folder)
94
93
  uri = "#{FOLDERS_URI}/#{folder_id}"
95
94
  create_shared_link(uri, folder_id, access, unshared_at, can_download, can_preview)
96
95
  end
97
96
 
98
- def disable_shared_link_for_folder(folder_id)
99
- folder_id = ensure_id(folder_id)
97
+ def disable_shared_link_for_folder(folder)
98
+ folder_id = ensure_id(folder)
100
99
  uri = "#{FOLDERS_URI}/#{folder_id}"
101
100
  disable_shared_link(uri, folder_id)
102
101
  end
103
102
 
104
- def trash(fields: [])
103
+ def trash(fields: [], offset: 0, limit: FOLDER_ITEMS_LIMIT)
105
104
  uri = "#{FOLDERS_URI}/trash/items"
106
105
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
107
106
 
108
- items = get_with_pagination uri, query: query, limit: FOLDER_ITEMS_LIMIT
107
+ items = get_with_pagination(uri, query: query, offset: offset, limit: limit)
109
108
  end
110
109
 
111
- def trashed_folder(folder_id, fields: [])
112
- folder_id = ensure_id(folder_id)
110
+ def trashed_folder(folder, fields: [])
111
+ folder_id = ensure_id(folder)
113
112
  uri = "#{FOLDERS_URI}/#{folder_id}/trash"
114
113
  query = build_fields_query(fields, FOLDER_AND_FILE_FIELDS_QUERY)
115
114
 
116
- folder, response = get uri, query: query
115
+ folder, response = get(uri, query: query)
117
116
  folder
118
117
  end
119
118
 
120
- def delete_trashed_folder(folder_id)
121
- folder_id = ensure_id(folder_id)
119
+ def delete_trashed_folder(folder)
120
+ folder_id = ensure_id(folder)
122
121
  uri = "#{FOLDERS_URI}/#{folder_id}/trash"
123
- result, response = delete uri
122
+ result, response = delete(uri)
124
123
  result
125
124
  end
126
125
 
127
- def restore_trashed_folder(folder_id, name: nil, parent_id: nil)
128
- folder_id = ensure_id(folder_id)
126
+ def restore_trashed_folder(folder, name: nil, parent_id: nil)
127
+ folder_id = ensure_id(folder)
129
128
  uri = "#{FOLDERS_URI}/#{folder_id}"
130
129
  restore_trashed_item(uri, name, parent_id)
131
130
  end
data/lib/boxr/groups.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def groups(fields: [])
4
+ def groups(fields: [], offset: 0, limit: DEFAULT_LIMIT)
5
5
  query = build_fields_query(fields, GROUP_FIELDS_QUERY)
6
- groups = get_with_pagination(GROUPS_URI, query: query)
6
+ groups = get_with_pagination(GROUPS_URI, query: query, offset: offset, limit: limit)
7
7
  end
8
8
 
9
9
  def create_group(name)
@@ -12,8 +12,8 @@ module Boxr
12
12
  new_group
13
13
  end
14
14
 
15
- def update_group(group_id, name)
16
- group_id = ensure_id(group_id)
15
+ def update_group(group, name)
16
+ group_id = ensure_id(group)
17
17
  uri = "#{GROUPS_URI}/#{group_id}"
18
18
  attributes = {name: name}
19
19
 
@@ -23,40 +23,40 @@ module Boxr
23
23
 
24
24
  alias :rename_group :update_group
25
25
 
26
- def delete_group(group_id)
27
- group_id = ensure_id(group_id)
26
+ def delete_group(group)
27
+ group_id = ensure_id(group)
28
28
  uri = "#{GROUPS_URI}/#{group_id}"
29
29
  result, response = delete(uri)
30
30
  result
31
31
  end
32
32
 
33
- def group_memberships(group_id)
34
- group_id = ensure_id(group_id)
33
+ def group_memberships(group, offset: 0, limit: DEFAULT_LIMIT)
34
+ group_id = ensure_id(group)
35
35
  uri = "#{GROUPS_URI}/#{group_id}/memberships"
36
- memberships = get_with_pagination(uri)
36
+ memberships = get_with_pagination(uri, offset: offset, limit: limit)
37
37
  end
38
38
 
39
- def group_memberships_for_user(user_id)
40
- user_id = ensure_id(user_id)
39
+ def group_memberships_for_user(user, offset: 0, limit: DEFAULT_LIMIT)
40
+ user_id = ensure_id(user)
41
41
  uri = "#{USERS_URI}/#{user_id}/memberships"
42
- memberships = get_with_pagination(uri)
42
+ memberships = get_with_pagination(uri, offset: offset, limit: limit)
43
43
  end
44
44
 
45
- def group_memberships_for_me
45
+ def group_memberships_for_me(offset: 0, limit: DEFAULT_LIMIT)
46
46
  uri = "#{USERS_URI}/me/memberships"
47
- memberships = get_with_pagination(uri)
47
+ memberships = get_with_pagination(uri, offset: offset, limit: limit)
48
48
  end
49
49
 
50
- def group_membership(membership_id)
51
- membership_id = ensure_id(membership_id)
50
+ def group_membership(membership)
51
+ membership_id = ensure_id(membership)
52
52
  uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
53
53
  membership, response = get(uri)
54
54
  membership
55
55
  end
56
56
 
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)
57
+ def add_user_to_group(user, group, role: nil)
58
+ user_id = ensure_id(user)
59
+ group_id = ensure_id(group)
60
60
 
61
61
  attributes = {user: {id: user_id}, group: {id: group_id}}
62
62
  attributes[:role] = role unless role.nil?
@@ -64,25 +64,25 @@ module Boxr
64
64
  membership
65
65
  end
66
66
 
67
- def update_group_membership(membership_id, role)
68
- membership_id = ensure_id(membership_id)
67
+ def update_group_membership(membership, role)
68
+ membership_id = ensure_id(membership)
69
69
  uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
70
70
  attributes = {role: role}
71
71
  updated_membership, response = put(uri, attributes)
72
72
  updated_membership
73
73
  end
74
74
 
75
- def delete_group_membership(membership_id)
76
- membership_id = ensure_id(membership_id)
75
+ def delete_group_membership(membership)
76
+ membership_id = ensure_id(membership)
77
77
  uri = "#{GROUP_MEMBERSHIPS_URI}/#{membership_id}"
78
78
  result, response = delete(uri)
79
79
  result
80
80
  end
81
81
 
82
- def group_collaborations(group_id)
83
- group_id = ensure_id(group_id)
82
+ def group_collaborations(group, offset: 0, limit: DEFAULT_LIMIT)
83
+ group_id = ensure_id(group)
84
84
  uri = "#{GROUPS_URI}/#{group_id}/collaborations"
85
- collaborations = get_with_pagination(uri)
85
+ collaborations = get_with_pagination(uri, offset: offset, limit: limit)
86
86
  end
87
87
 
88
88
  end
data/lib/boxr/metadata.rb CHANGED
@@ -1,31 +1,31 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def create_metadata(file_id, metadata, type: :properties)
5
- file_id = ensure_id(file_id)
4
+ def create_metadata(file, metadata, type: :properties)
5
+ file_id = ensure_id(file)
6
6
  uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
7
- metadata, response = post uri, metadata, content_type: "application/json"
7
+ metadata, response = post(uri, metadata, content_type: "application/json")
8
8
  metadata
9
9
  end
10
10
 
11
- def metadata(file_id, type: :properties)
12
- file_id = ensure_id(file_id)
11
+ def metadata(file, type: :properties)
12
+ file_id = ensure_id(file)
13
13
  uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
14
- metadata, response = get uri
14
+ metadata, response = get(uri)
15
15
  metadata
16
16
  end
17
17
 
18
- def update_metadata(file_id, updates, type: :properties)
19
- file_id = ensure_id(file_id)
18
+ def update_metadata(file, updates, type: :properties)
19
+ file_id = ensure_id(file)
20
20
  uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
21
- metadata, response = put uri, updates, content_type: "application/json-patch+json"
21
+ metadata, response = put(uri, updates, content_type: "application/json-patch+json")
22
22
  metadata
23
23
  end
24
24
 
25
- def delete_metadata(file_id, type: :properties)
26
- file_id = ensure_id(file_id)
25
+ def delete_metadata(file, type: :properties)
26
+ file_id = ensure_id(file)
27
27
  uri = "#{METADATA_URI}/#{file_id}/metadata/#{type}"
28
- result, response = delete uri
28
+ result, response = delete(uri)
29
29
  result
30
30
  end
31
31
 
data/lib/boxr/search.rb CHANGED
@@ -18,7 +18,7 @@ module Boxr
18
18
  query[:limit] = limit unless limit.nil?
19
19
  query[:offset] = offset unless offset.nil?
20
20
 
21
- results, response = get SEARCH_URI, query: query
21
+ results, response = get(SEARCH_URI, query: query)
22
22
  results["entries"]
23
23
  end
24
24
 
data/lib/boxr/tasks.rb CHANGED
@@ -1,93 +1,93 @@
1
1
  module Boxr
2
2
  class Client
3
3
 
4
- def file_tasks(file_id, fields: [])
5
- file_id = ensure_id(file_id)
4
+ def file_tasks(file, fields: [])
5
+ file_id = ensure_id(file)
6
6
  uri = "#{FILES_URI}/#{file_id}/tasks"
7
7
  query = build_fields_query(fields, TASK_FIELDS_QUERY)
8
8
 
9
- tasks, response = get uri, query: query
9
+ tasks, response = get(uri, query: query)
10
10
  tasks["entries"]
11
11
  end
12
12
 
13
- def create_task(file_id, action: :review, message: nil, due_at: nil)
14
- file_id = ensure_id(file_id)
13
+ def create_task(file, action: :review, message: nil, due_at: nil)
14
+ file_id = ensure_id(file)
15
15
  attributes = {item: {type: :file, id: file_id}}
16
16
  attributes[:action] = action unless action.nil?
17
17
  attributes[:message] = message unless message.nil?
18
18
  attributes[:due_at] = due_at.to_datetime.rfc3339 unless due_at.nil?
19
19
 
20
- new_task, response = post TASKS_URI, attributes
20
+ new_task, response = post(TASKS_URI, attributes)
21
21
  new_task
22
22
  end
23
23
 
24
- def task(task_id)
25
- task_id = ensure_id(task_id)
24
+ def task(task)
25
+ task_id = ensure_id(task)
26
26
  uri = "#{TASKS_URI}/#{task_id}"
27
- task, response = get uri
27
+ task, response = get(uri)
28
28
  task
29
29
  end
30
30
 
31
- def update_task(task_id, action: :review, message: nil, due_at: nil)
32
- task_id = ensure_id(task_id)
31
+ def update_task(task, action: :review, message: nil, due_at: nil)
32
+ task_id = ensure_id(task)
33
33
  uri = "#{TASKS_URI}/#{task_id}"
34
34
  attributes = {}
35
35
  attributes[:action] = action unless action.nil?
36
36
  attributes[:message] = message unless message.nil?
37
37
  attributes[:due_at] = due_at.to_datetime.rfc3339 unless due_at.nil?
38
38
 
39
- task, response = put uri, attributes
39
+ task, response = put(uri, attributes)
40
40
  task
41
41
  end
42
42
 
43
- def delete_task(task_id)
44
- task_id = ensure_id(task_id)
43
+ def delete_task(task)
44
+ task_id = ensure_id(task)
45
45
  uri = "#{TASKS_URI}/#{task_id}"
46
- result, response = delete uri
46
+ result, response = delete(uri)
47
47
  result
48
48
  end
49
49
 
50
- def task_assignments(task_id)
51
- task_id = ensure_id(task_id)
50
+ def task_assignments(task)
51
+ task_id = ensure_id(task)
52
52
  uri = "#{TASKS_URI}/#{task_id}/assignments"
53
- assignments, response = get uri
53
+ assignments, response = get(uri)
54
54
  assignments['entries']
55
55
  end
56
56
 
57
- def create_task_assignment(task_id, assign_to_id: nil, assign_to_login: nil)
58
- task_id = ensure_id(task_id)
57
+ def create_task_assignment(task, assign_to_id: nil, assign_to_login: nil)
58
+ task_id = ensure_id(task)
59
59
  attributes = {task: {type: :task, id: "#{task_id}"}}
60
60
 
61
61
  attributes[:assign_to] = {}
62
62
  attributes[:assign_to][:login] = assign_to_login unless assign_to_login.nil?
63
63
  attributes[:assign_to][:id] = assign_to_id unless assign_to_id.nil?
64
64
 
65
- new_task_assignment, response = post TASK_ASSIGNMENTS_URI, attributes
65
+ new_task_assignment, response = post(TASK_ASSIGNMENTS_URI, attributes)
66
66
  new_task_assignment
67
67
  end
68
68
 
69
- def task_assignment(task_id)
70
- task_id = ensure_id(task_id)
69
+ def task_assignment(task)
70
+ task_id = ensure_id(task)
71
71
  uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
72
- task_assignment, response = get uri
72
+ task_assignment, response = get(uri)
73
73
  task_assignment
74
74
  end
75
75
 
76
- def delete_task_assignment(task_id)
77
- task_id = ensure_id(task_id)
76
+ def delete_task_assignment(task)
77
+ task_id = ensure_id(task)
78
78
  uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
79
- result, response = delete uri
79
+ result, response = delete(uri)
80
80
  result
81
81
  end
82
82
 
83
- def update_task_assignment(task_id, message: nil, resolution_state: nil)
84
- task_id = ensure_id(task_id)
83
+ def update_task_assignment(task, message: nil, resolution_state: nil)
84
+ task_id = ensure_id(task)
85
85
  uri = "#{TASK_ASSIGNMENTS_URI}/#{task_id}"
86
86
  attributes = {}
87
87
  attributes[:message] = message unless message.nil?
88
88
  attributes[:resolution_state] = resolution_state unless resolution_state.nil?
89
89
 
90
- updated_task, response = put uri, attributes
90
+ updated_task, response = put(uri, attributes)
91
91
  updated_task
92
92
  end
93
93
 
data/lib/boxr/users.rb CHANGED
@@ -10,19 +10,19 @@ module Boxr
10
10
 
11
11
  alias :me :current_user
12
12
 
13
- def user(user_id, fields: [])
14
- user_id = ensure_id(user_id)
13
+ def user(user, fields: [])
14
+ user_id = ensure_id(user)
15
15
  uri = "#{USERS_URI}/#{user_id}"
16
16
  query = build_fields_query(fields, USER_FIELDS_QUERY)
17
17
  user, response = get(uri, query: query)
18
18
  user
19
19
  end
20
20
 
21
- def all_users(filter_term: nil, fields: [])
21
+ def all_users(filter_term: nil, fields: [], offset: 0, limit: DEFAULT_LIMIT)
22
22
  uri = USERS_URI
23
23
  query = build_fields_query(fields, USER_FIELDS_QUERY)
24
24
  query[:filter_term] = filter_term unless filter_term.nil?
25
- users = get_with_pagination(uri, query: query)
25
+ users = get_with_pagination(uri, query: query, offset: offset, limit: limit)
26
26
  end
27
27
 
28
28
  def create_user(login, name, role: nil, language: nil, is_sync_enabled: nil, job_title: nil,
@@ -51,12 +51,12 @@ module Boxr
51
51
  new_user
52
52
  end
53
53
 
54
- def update_user(user_id, notify: nil, enterprise: true, name: nil, role: nil, language: nil, is_sync_enabled: nil,
54
+ def update_user(user, notify: nil, enterprise: true, name: nil, role: nil, language: nil, is_sync_enabled: nil,
55
55
  job_title: nil, phone: nil, address: nil, space_amount: nil, tracking_codes: nil,
56
56
  can_see_managed_users: nil, status: nil, timezone: nil, is_exempt_from_device_limits: nil,
57
57
  is_exempt_from_login_verification: nil, is_exempt_from_reset_required: nil, is_external_collab_restricted: nil)
58
58
 
59
- user_id = ensure_id(user_id)
59
+ user_id = ensure_id(user)
60
60
  uri = "#{USERS_URI}/#{user_id}"
61
61
  query = {notify: notify} unless notify.nil?
62
62
 
@@ -83,8 +83,8 @@ module Boxr
83
83
  updated_user
84
84
  end
85
85
 
86
- def delete_user(user_id, notify: nil, force: nil)
87
- user_id = ensure_id(user_id)
86
+ def delete_user(user, notify: nil, force: nil)
87
+ user_id = ensure_id(user)
88
88
  uri = "#{USERS_URI}/#{user_id}"
89
89
  query = {}
90
90
  query[:notify] = notify unless notify.nil?
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Burnette