boxr 1.2.0 → 1.3.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: 6b219a0546f48304aa3786f78c7fee4633b2a93e
4
- data.tar.gz: 24e175d1d4d4164c7d9fe493ffe58e9961e6ee68
3
+ metadata.gz: c454c797a01d524a1d291f614b6cbc325cd3b752
4
+ data.tar.gz: 706e102052b88ddbb8f2728bfc259a2352d6da08
5
5
  SHA512:
6
- metadata.gz: a1ae72b408546796a1f22e3870afd2b2adecc2cd8016269d64df8849662dbf8eeb45e076987cbe9f8ad88a199403be98896e01fd491905f84798a3fc9a2028b4
7
- data.tar.gz: 5532462b58dca43097386ba4ccdf52d0f04b3f318dbe160548903075bc333a3433023c4223ee8a2a929fd0462a8a0b99f296be9311e05b06bbfcbb1b9268a7cb
6
+ metadata.gz: ea87475ea281d5fa10a3d48bc8fec22dceec7bd2fe13f8e3e4166a230393c6925bd0b9b342ab99e15b5a7cceb2d7778a3601bf06aae7bb959dd52bd87393dc6d
7
+ data.tar.gz: f31f1792ab1e85af9f091d5fedbbbc1ba03ce31092abdc98300275e82e9d680f3f6c18fc7593f089a6994b2313e46d812d7005a297e9905697fca78fe5e445f4
data/README.md CHANGED
@@ -111,6 +111,16 @@ updated_file = client.create_shared_link_for_file(file, access: :open)
111
111
  puts "Shared Link: #{updated_file.shared_link.url}"
112
112
  ```
113
113
 
114
+ ### NOTE: Using HTTP mocking libraries for testing
115
+ When using HTTP mocking libraries for testing, you may need to set Boxr::BOX_CLIENT to a fresh instance of HTTPClient in your test setup after loading the HTTP mocking library. For example, when using WebMock with RSpec you might could add the following to your RSpec configuration:
116
+ ``` ruby
117
+ RSpec.configure do |config|
118
+ config.before(:suite) do
119
+ Boxr::BOX_CLIENT = HTTPClient.new
120
+ end
121
+ end
122
+ ```
123
+
114
124
  ### Methods
115
125
  #### [OAuth & JWT](https://box-content.readme.io/reference#oauth-2)
116
126
  ```ruby
@@ -172,7 +182,7 @@ file_from_path(path)
172
182
  file_from_id(file_id, fields: [])
173
183
  alias :file :file_from_id
174
184
 
175
- embed_url(file)
185
+ def embed_url(file, show_download: false, show_annotations: false)
176
186
  alias :embed_link :embed_url
177
187
  alias :preview_url :embed_url
178
188
  alias :preview_link :embed_url
@@ -217,6 +227,16 @@ delete_trashed_file(file)
217
227
 
218
228
  restore_trashed_file(file, name: nil, parent: nil)
219
229
  ```
230
+ #### [Web Links](https://box-content.readme.io/reference#web-link-object)
231
+ ```ruby
232
+ create_web_link(url, parent, name: nil, description: nil)
233
+
234
+ get_web_link(web_link)
235
+
236
+ update_web_link(web_link, url: nil, parent: nil, name: nil, description: nil)
237
+
238
+ delete_web_link(web_link)
239
+ ```
220
240
  #### [Comments](https://box-content.readme.io/reference#comment-object)
221
241
  ```ruby
222
242
  file_comments(file, fields: [], offset: 0, limit: DEFAULT_LIMIT)
@@ -368,15 +388,20 @@ enterprise_metadata
368
388
 
369
389
  metadata_schema(scope, template_key)
370
390
  ```
371
- #### [Web Links](https://box-content.readme.io/reference#web-link-object)
391
+
392
+ #### [Watermarking](https://box-content.readme.io/reference#watermarking)
372
393
  ```ruby
373
- create_web_link(url, parent, name: nil, description: nil)
394
+ get_watermark_on_file(file)
374
395
 
375
- get_web_link(web_link)
396
+ apply_watermark_on_file(file)
376
397
 
377
- update_web_link(web_link_id, url: nil, parent: nil, name: nil, description: nil)
398
+ remove_watermark_on_file(file)
378
399
 
379
- delete_web_link(web_link)
400
+ get_watermark_on_folder(folder)
401
+
402
+ apply_watermark_on_folder(folder)
403
+
404
+ remove_watermark_on_folder(folder)
380
405
  ```
381
406
  ## Contributing
382
407
 
data/boxr.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Boxr::VERSION
9
9
  spec.authors = ["Chad Burnette"]
10
10
  spec.email = ["chadburnette@me.com"]
11
- spec.summary = "A Ruby client library for the Box V2 Content API that covers 100% of the underlying REST API."
11
+ spec.summary = "A Ruby client library for the Box V2 Content API."
12
12
  spec.description = ""
13
13
  spec.homepage = "https://github.com/cburnette/boxr"
14
14
  spec.license = "MIT"
@@ -28,9 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "awesome_print"
29
29
  spec.add_development_dependency "lru_redux", "~> 0.8"
30
30
 
31
- spec.add_runtime_dependency "oj", "~> 2.11"
32
- spec.add_runtime_dependency "httpclient", "~> 2.5"
33
- spec.add_runtime_dependency "hashie", "~> 3.3"
31
+ spec.add_runtime_dependency "httpclient", "~> 2.8"
32
+ spec.add_runtime_dependency "hashie", "~> 3.5"
34
33
  spec.add_runtime_dependency "addressable", "~> 2.3"
35
34
  spec.add_runtime_dependency "jwt", "~> 1.4"
36
35
  end
data/lib/boxr.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'oj'
1
+ require 'json'
2
2
  require 'httpclient'
3
3
  require 'hashie'
4
4
  require 'addressable/template'
@@ -22,6 +22,7 @@ require 'boxr/metadata'
22
22
  require 'boxr/events'
23
23
  require 'boxr/auth'
24
24
  require 'boxr/web_links'
25
+ require 'boxr/watermarking'
25
26
 
26
27
  module Enumerable
27
28
  def files
@@ -38,6 +39,9 @@ module Enumerable
38
39
  end
39
40
 
40
41
  class BoxrMash < Hashie::Mash
42
+
43
+ self.disable_warnings
44
+
41
45
  def entries
42
46
  self["entries"]
43
47
  end
@@ -48,8 +52,6 @@ class BoxrMash < Hashie::Mash
48
52
  end
49
53
 
50
54
  module Boxr
51
- Oj.default_options = {:mode => :compat }
52
-
53
55
  #The root folder in Box is always identified by 0
54
56
  ROOT = 0
55
57
 
data/lib/boxr/auth.rb CHANGED
@@ -84,7 +84,7 @@ module Boxr
84
84
  res = BOX_CLIENT.post(uri, body: body)
85
85
 
86
86
  if(res.status==200)
87
- body_json = Oj.load(res.body)
87
+ body_json = JSON.load(res.body)
88
88
  return BoxrMash.new(body_json)
89
89
  else
90
90
  raise BoxrError.new(status: res.status, body: res.body, header: res.header)
data/lib/boxr/client.rb CHANGED
@@ -123,7 +123,7 @@ module Boxr
123
123
  end
124
124
 
125
125
  if (res.status==200)
126
- body_json = Oj.load(res.body)
126
+ body_json = JSON.load(res.body)
127
127
  total_count = body_json["total_count"]
128
128
  offset = offset + limit
129
129
 
@@ -138,7 +138,7 @@ module Boxr
138
138
 
139
139
  def post(uri, body, query: nil, success_codes: [201], process_body: true, content_md5: nil, content_type: nil, if_match: nil)
140
140
  uri = Addressable::URI.encode(uri)
141
- body = Oj.dump(body) if process_body
141
+ body = JSON.dump(body) if process_body
142
142
 
143
143
  res = with_auto_token_refresh do
144
144
  headers = standard_headers
@@ -154,7 +154,7 @@ module Boxr
154
154
  processed_response(res)
155
155
  end
156
156
 
157
- def put(uri, body, query: nil, success_codes: [200], content_type: nil, if_match: nil)
157
+ def put(uri, body, query: nil, success_codes: [200, 201], content_type: nil, if_match: nil)
158
158
  uri = Addressable::URI.encode(uri)
159
159
 
160
160
  res = with_auto_token_refresh do
@@ -162,7 +162,7 @@ module Boxr
162
162
  headers['If-Match'] = if_match unless if_match.nil?
163
163
  headers["Content-Type"] = content_type unless content_type.nil?
164
164
 
165
- BOX_CLIENT.put(uri, body: Oj.dump(body), query: query, header: headers)
165
+ BOX_CLIENT.put(uri, body: JSON.dump(body), query: query, header: headers)
166
166
  end
167
167
 
168
168
  check_response_status(res, success_codes)
@@ -190,7 +190,7 @@ module Boxr
190
190
 
191
191
  res = with_auto_token_refresh do
192
192
  headers = standard_headers
193
- BOX_CLIENT.options(uri, body: Oj.dump(body), header: headers)
193
+ BOX_CLIENT.options(uri, body: JSON.dump(body), header: headers)
194
194
  end
195
195
 
196
196
  check_response_status(res, success_codes)
@@ -207,7 +207,7 @@ module Boxr
207
207
  end
208
208
 
209
209
  def with_auto_token_refresh
210
- return yield unless @refresh_token or @jwt_secret_key
210
+ return yield unless @refresh_token or @jwt_private_key
211
211
 
212
212
  res = yield
213
213
  if res.status == 401
@@ -240,7 +240,7 @@ module Boxr
240
240
  end
241
241
 
242
242
  def processed_response(res)
243
- body_json = Oj.load(res.body)
243
+ body_json = JSON.load(res.body)
244
244
  return BoxrMash.new(body_json), res
245
245
  end
246
246
 
data/lib/boxr/errors.rb CHANGED
@@ -12,7 +12,7 @@ module Boxr
12
12
 
13
13
  if(body)
14
14
  begin
15
- body_json = Oj.load(body)
15
+ body_json = JSON.load(body)
16
16
 
17
17
  if body_json
18
18
  @type = body_json["type"]
data/lib/boxr/files.rb CHANGED
@@ -26,9 +26,9 @@ module Boxr
26
26
  end
27
27
  alias :file :file_from_id
28
28
 
29
- def embed_url(file)
29
+ def embed_url(file, show_download: false, show_annotations: false)
30
30
  file_info = file_from_id(file, fields:[:expiring_embed_link])
31
- url = file_info.expiring_embed_link.url
31
+ url = file_info.expiring_embed_link.url + "?showDownload=#{show_download}&showAnnotations=#{show_annotations}"
32
32
  url
33
33
  end
34
34
  alias :embed_link :embed_url
@@ -79,7 +79,7 @@ module Boxr
79
79
  uri = "#{FILES_URI}/#{file_id}/content"
80
80
  query = {}
81
81
  query[:version] = version unless version.nil?
82
- body_json, response = get(uri, query: query, success_codes: [302,202], follow_redirect: false) #we don't want httpclient to automatically follow the redirect; we need to grab it
82
+ body_json, response = get(uri, query: query, success_codes: [302,202], process_response: false, follow_redirect: false) #we don't want httpclient to automatically follow the redirect; we need to grab it
83
83
 
84
84
  if(response.status==302)
85
85
  location = response.header['Location'][0]
@@ -120,7 +120,7 @@ module Boxr
120
120
  attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
121
121
  attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
122
122
 
123
- body = {attributes: Oj.dump(attributes), file: file}
123
+ body = {attributes: JSON.dump(attributes), file: file}
124
124
 
125
125
  file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5)
126
126
  end
data/lib/boxr/search.rb CHANGED
@@ -14,7 +14,7 @@ module Boxr
14
14
  unless mdfilters.is_a? Array
15
15
  mdfilters = [mdfilters] #if just one mdfilter is specified ensure that it is packaged inside an array
16
16
  end
17
- mdfilters = Oj.dump(mdfilters)
17
+ mdfilters = JSON.dump(mdfilters)
18
18
  end
19
19
  end
20
20
 
data/lib/boxr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -0,0 +1,66 @@
1
+ module Boxr
2
+ class Client
3
+
4
+ def get_watermark_on_file(file)
5
+
6
+ file_id = ensure_id(file)
7
+ uri = "#{FILES_URI}/#{file_id}/watermark"
8
+
9
+ file, response = get(uri)
10
+ file
11
+ end
12
+
13
+ def apply_watermark_on_file(file)
14
+
15
+ file_id = ensure_id(file)
16
+ uri = "#{FILES_URI}/#{file_id}/watermark"
17
+
18
+ attributes = {}
19
+ attributes[:watermark] = {:imprint => "default"}
20
+
21
+ file, response = put(uri, attributes, content_type: "application/json")
22
+ file
23
+ end
24
+
25
+ def remove_watermark_on_file(file)
26
+
27
+ file_id = ensure_id(file)
28
+ uri = "#{FILES_URI}/#{file_id}/watermark"
29
+
30
+ result, response = delete(uri)
31
+ result
32
+ end
33
+
34
+ def get_watermark_on_folder(folder)
35
+
36
+ folder_id = ensure_id(folder)
37
+ uri = "#{FOLDERS_URI}/#{folder_id}/watermark"
38
+
39
+ folder, response = get(uri)
40
+ folder
41
+ end
42
+
43
+ def apply_watermark_on_folder(folder)
44
+
45
+ folder_id = ensure_id(folder)
46
+ uri = "#{FOLDERS_URI}/#{folder_id}/watermark"
47
+
48
+ attributes = {}
49
+ attributes[:watermark] = {:imprint => "default"}
50
+
51
+ folder, response = put(uri, attributes, content_type: "application/json")
52
+ folder
53
+ end
54
+
55
+ def remove_watermark_on_folder(folder)
56
+
57
+ folder_id = ensure_id(folder)
58
+ uri = "#{FOLDERS_URI}/#{folder_id}/watermark"
59
+
60
+ result, response = delete(uri)
61
+ result
62
+ end
63
+
64
+
65
+ end
66
+ end
data/spec/boxr_spec.rb CHANGED
@@ -265,6 +265,36 @@ describe Boxr::Client do
265
265
  expect(result).to eq({})
266
266
  end
267
267
 
268
+ #rake spec SPEC_OPTS="-e \"invokes watermarking operations"\"
269
+ it 'invokes watermarking operations' do
270
+ test_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
271
+ folder = BOX_CLIENT.folder(@test_folder)
272
+
273
+ puts "apply watermark on file"
274
+ watermark = BOX_CLIENT.apply_watermark_on_file(test_file)
275
+ expect(watermark.watermark).to_not be_nil
276
+
277
+ puts "get watermark on file"
278
+ watermark = BOX_CLIENT.get_watermark_on_file(test_file)
279
+ expect(watermark.watermark).to_not be_nil
280
+
281
+ puts "remove watermark on file"
282
+ result = BOX_CLIENT.remove_watermark_on_file(test_file)
283
+ expect(result).to eq({})
284
+
285
+ puts "apply watermark on folder"
286
+ watermark = BOX_CLIENT.apply_watermark_on_folder(folder)
287
+ expect(watermark.watermark).to_not be_nil
288
+
289
+ puts "get watermark on folder"
290
+ watermark = BOX_CLIENT.get_watermark_on_folder(folder)
291
+ expect(watermark.watermark).to_not be_nil
292
+
293
+ puts "remove watermark on folder"
294
+ result = BOX_CLIENT.remove_watermark_on_folder(folder)
295
+ expect(result).to eq({})
296
+ end
297
+
268
298
  #rake spec SPEC_OPTS="-e \"invokes user operations"\"
269
299
  it "invokes user operations" do
270
300
  puts "inspect current user"
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: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Burnette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,48 +108,34 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.8'
111
- - !ruby/object:Gem::Dependency
112
- name: oj
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '2.11'
118
- type: :runtime
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '2.11'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: httpclient
127
113
  requirement: !ruby/object:Gem::Requirement
128
114
  requirements:
129
115
  - - "~>"
130
116
  - !ruby/object:Gem::Version
131
- version: '2.5'
117
+ version: '2.8'
132
118
  type: :runtime
133
119
  prerelease: false
134
120
  version_requirements: !ruby/object:Gem::Requirement
135
121
  requirements:
136
122
  - - "~>"
137
123
  - !ruby/object:Gem::Version
138
- version: '2.5'
124
+ version: '2.8'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: hashie
141
127
  requirement: !ruby/object:Gem::Requirement
142
128
  requirements:
143
129
  - - "~>"
144
130
  - !ruby/object:Gem::Version
145
- version: '3.3'
131
+ version: '3.5'
146
132
  type: :runtime
147
133
  prerelease: false
148
134
  version_requirements: !ruby/object:Gem::Requirement
149
135
  requirements:
150
136
  - - "~>"
151
137
  - !ruby/object:Gem::Version
152
- version: '3.3'
138
+ version: '3.5'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: addressable
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -219,6 +205,7 @@ files:
219
205
  - lib/boxr/tasks.rb
220
206
  - lib/boxr/users.rb
221
207
  - lib/boxr/version.rb
208
+ - lib/boxr/watermarking.rb
222
209
  - lib/boxr/web_links.rb
223
210
  - spec/boxr_spec.rb
224
211
  - spec/spec_helper.rb
@@ -243,11 +230,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
230
  version: '0'
244
231
  requirements: []
245
232
  rubyforge_project:
246
- rubygems_version: 2.4.6
233
+ rubygems_version: 2.6.7
247
234
  signing_key:
248
235
  specification_version: 4
249
- summary: A Ruby client library for the Box V2 Content API that covers 100% of the
250
- underlying REST API.
236
+ summary: A Ruby client library for the Box V2 Content API.
251
237
  test_files:
252
238
  - spec/boxr_spec.rb
253
239
  - spec/spec_helper.rb