boxr 0.26.0 → 0.27.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: 80bb5e98b518eb34aaaddc369a739111cb2bbcd1
4
- data.tar.gz: 852abc3f680cf0e7e379c67e1fad79096c871d3a
3
+ metadata.gz: 93e44fc598ab6789018d63eaf7277ab1cd616138
4
+ data.tar.gz: a7bf8e2e7e8043ec2c48c818e3a2e4396de14816
5
5
  SHA512:
6
- metadata.gz: eb43cff1678d67aaa57366a99bed71eed95babcaa3d608404c3362385d26e30e3d69d5a528f11e1ec752b1a3f83ce168c3da4c984f8bdbc65f9e44064540de61
7
- data.tar.gz: 24926c43ccc5d4992168b231c97f68780732e5d502be9590f359107edf7c6cadf37171f76b4b9153397c42f8cfa1a6de026abd16067f6e90c1ae23ac8f5bcc15
6
+ metadata.gz: a23f74f3d18e47d704bc08f0ec9fa5d59d6d0ef245bac16bad986759915f51f28a834e7b2e2e06ca76986971e4c6225567a7b7c8ea05ff39eb2d9ace82e41585
7
+ data.tar.gz: 9356cbc841b364d9451652d9c609b6b2b428ab9c8da8f31aed3a6a3d3e17505129f1d8c15e96e999c131629a3077b80f6bf4f2d1263a8335c88d0333a0905748
@@ -93,22 +93,27 @@ module Boxr
93
93
  download_file(file, version: version, follow_redirect: false)
94
94
  end
95
95
 
96
- def upload_file(path_to_file, parent, content_created_at: nil, content_modified_at: nil,
96
+ def upload_file(path_to_file, parent, name: nil, content_created_at: nil, content_modified_at: nil,
97
97
  preflight_check: true, send_content_md5: true)
98
98
 
99
99
  parent_id = ensure_id(parent)
100
- preflight_check(path_to_file, parent_id) if preflight_check
100
+
101
+ filename = name ? name : File.basename(path_to_file)
102
+ preflight_check(path_to_file, filename, parent_id) if preflight_check
101
103
 
102
104
  file_info = nil
103
105
  response = nil
104
106
 
105
107
  File.open(path_to_file) do |file|
106
108
  content_md5 = send_content_md5 ? Digest::SHA1.file(file).hexdigest : nil
107
-
108
- attributes = {filename: file, parent_id: parent_id}
109
+
110
+ attributes = {name: filename, parent: {id: parent_id}}
109
111
  attributes[:content_created_at] = content_created_at.to_datetime.rfc3339 unless content_created_at.nil?
110
112
  attributes[:content_modified_at] = content_modified_at.to_datetime.rfc3339 unless content_modified_at.nil?
111
- file_info, response = post(FILES_UPLOAD_URI, attributes, process_body: false, content_md5: content_md5)
113
+
114
+ body = {attributes: Oj.dump(attributes), file: file}
115
+
116
+ file_info, response = post(FILES_UPLOAD_URI, body, process_body: false, content_md5: content_md5)
112
117
  end
113
118
 
114
119
  file_info["entries"][0]
@@ -237,18 +242,17 @@ module Boxr
237
242
 
238
243
  private
239
244
 
240
- def preflight_check(path_to_file, parent_id)
245
+ def preflight_check(path_to_file, filename, parent_id)
241
246
  size = File.size(path_to_file)
242
247
 
243
248
  #TODO: need to make sure that figuring out the filename from the path_to_file works for people using Windows
244
- filename = File.basename(path_to_file)
245
- attributes = {"name" => filename, "parent" => {"id" => "#{parent_id}"}, "size" => size}
249
+ attributes = {name: filename, parent: {id: "#{parent_id}"}, size: size}
246
250
  body_json, res = options("#{FILES_URI}/content", attributes)
247
251
  end
248
252
 
249
253
  def preflight_check_new_version_of_file(path_to_file, file_id)
250
254
  size = File.size(path_to_file)
251
- attributes = {"size" => size}
255
+ attributes = {size: size}
252
256
  body_json, res = options("#{FILES_URI}/#{file_id}/content", attributes)
253
257
  end
254
258
 
@@ -1,3 +1,3 @@
1
1
  module Boxr
2
- VERSION = "0.26.0"
2
+ VERSION = "0.27.0"
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Boxr::Client do
4
4
 
5
- #PLEASE NOTE
5
+ #PLEASE NOTE
6
6
  #This test is intentionally NOT a series of unit tests. The goal is to smoke test the entire code base
7
7
  #against an actual Box account, making real calls to the Box API. The Box API is subject to frequent
8
8
  #changes and it is not sufficient to mock responses as those responses will change over time. Successfully
@@ -16,7 +16,7 @@ describe Boxr::Client do
16
16
  #follow the directions in .env.example to set up your BOX_DEVELOPER_TOKEN
17
17
  #keep in mind it is only valid for 60 minutes
18
18
  BOX_CLIENT = Boxr::Client.new #using ENV['BOX_DEVELOPER_TOKEN']
19
-
19
+
20
20
  #uncomment this line to see the HTTP request and response debug info in the rspec output
21
21
  #Boxr::turn_on_debugging
22
22
 
@@ -25,6 +25,7 @@ describe Boxr::Client do
25
25
  SUB_FOLDER_NAME = 'sub_folder_1'
26
26
  SUB_FOLDER_DESCRIPTION = 'This was created by the Boxr test suite'
27
27
  TEST_FILE_NAME = 'test file.txt'
28
+ TEST_FILE_NAME_CUSTOM = 'test file custom.txt'
28
29
  DOWNLOADED_TEST_FILE_NAME = 'downloaded test file.txt'
29
30
  COMMENT_MESSAGE = 'this is a comment'
30
31
  REPLY_MESSAGE = 'this is a comment reply'
@@ -134,6 +135,10 @@ describe Boxr::Client do
134
135
  expect(new_file.name).to eq(TEST_FILE_NAME)
135
136
  test_file = new_file
136
137
 
138
+ puts "upload a file with custom name"
139
+ new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder, name: TEST_FILE_NAME_CUSTOM)
140
+ expect(new_file.name).to eq(TEST_FILE_NAME_CUSTOM)
141
+
137
142
  puts "get file using path"
138
143
  file = BOX_CLIENT.file_from_path("/#{TEST_FOLDER_NAME}/#{TEST_FILE_NAME}")
139
144
  expect(file.id).to eq(test_file.id)
@@ -236,7 +241,7 @@ describe Boxr::Client do
236
241
  end
237
242
 
238
243
  #rake spec SPEC_OPTS="-e \"invokes user operations"\"
239
- it "invokes user operations" do
244
+ it "invokes user operations" do
240
245
  puts "inspect current user"
241
246
  user = BOX_CLIENT.current_user
242
247
  expect(user.status).to eq('active')
@@ -253,7 +258,7 @@ describe Boxr::Client do
253
258
  expect(test_user).to_not be_nil
254
259
 
255
260
  #create user is tested in the before method
256
-
261
+
257
262
  puts "update user"
258
263
  new_name = "Chuck Nevitt"
259
264
  user = BOX_CLIENT.update_user(@test_user, name: new_name)
@@ -340,7 +345,7 @@ describe Boxr::Client do
340
345
  end
341
346
 
342
347
  #rake spec SPEC_OPTS="-e \"invokes comment operations"\"
343
- it "invokes comment operations" do
348
+ it "invokes comment operations" do
344
349
  new_file = BOX_CLIENT.upload_file("./spec/test_files/#{TEST_FILE_NAME}", @test_folder)
345
350
  test_file = new_file
346
351
 
@@ -492,4 +497,4 @@ describe Boxr::Client do
492
497
  expect(results).to eq([])
493
498
  end
494
499
 
495
- end
500
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Burnette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler