breadbox 1.3.0 → 1.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: 864b92924c79c0de55813778e21139799b6a535c
4
- data.tar.gz: 737a51e54067aa9f171f4db91a936696cf830782
3
+ metadata.gz: b634f857a942ff27b4e9d5910efec955dca6bfe8
4
+ data.tar.gz: 133007d2560f3e7929587aecc519d9bbd5236b4c
5
5
  SHA512:
6
- metadata.gz: ef2deb7707fc28b3b6deca9467acf318ab55a49f50a1b465a5f7fa066adf69671064e6fa58cdfc01455675626f85a34c1fc3377fab640122a3d1233cf39cd597
7
- data.tar.gz: b88fc9242b7ee9a250ce5283dbaa17519b556939933db998965693773c3ffa8914d1e1b094f4f0caa20a67fd7d469d5e2e30aa9b981217f98f21eb7485311355
6
+ metadata.gz: 3eec8a130d1e0889d29fb5f35e038553124c35fc8b7f96eebb3c8d5e43c299271517e64276efee3a759a3b499647fd1e680cf97ccfcb32daf631ebfff13454fb
7
+ data.tar.gz: 241255df8c6631f51f028e549ff6b45bb9de2a5919412539d27f247dcad081bf587ad05435c0d1f8c5fcf150fe6a4321a35d0dab4b4f9d931d8164a70e16aeb3
data/README.md CHANGED
@@ -82,6 +82,7 @@ end
82
82
  - `path`: defaults to `nil`, but this is where you put a custom folder if you so wish (in relation
83
83
  to your `root_path`, which if you didn't configure in your initializer, will be your root Dropbox
84
84
  folder `/`.
85
+ - `filename`: defaults to the name of the file you are uploading, but you can specify a custom name here.
85
86
  - `file`: The file object that you are uploading, ex: `file = File.open('./path-to-local-file').
86
87
  - `cleanup`: defaults to `false`, but if you pass `true` - it will remove the local file after uploading.
87
88
  - `public`: defaults to `false`. Pass `true` if you'd like to set the file permission level to world readable.
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "dropbox-sdk", "~> 1.6"
21
+ spec.add_dependency "dropbox-sdk", "~> 1.6.4"
22
22
  spec.add_dependency "aws-sdk", "~> 2.1.7"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -23,8 +23,7 @@ module Breadbox
23
23
 
24
24
  protected
25
25
 
26
- def filepath_from_paths_and_file(root_path, path, file)
27
- filename = File.basename(file)
26
+ def filepath_from_paths_and_filename(root_path, path, filename)
28
27
  [root_path, path, filename].join("/").gsub(/\/{2,}/, "/")
29
28
  end
30
29
 
@@ -10,9 +10,11 @@ module Breadbox
10
10
  def upload(options = {})
11
11
  path = options[:path]
12
12
  file = options[:file]
13
+ filename = options[:filename] || File.basename(file)
13
14
  overwrite = options[:overwrite] || false
14
15
  share = options[:share]
15
- filepath = filepath_from_paths_and_file(root_path, path, file)
16
+
17
+ filepath = filepath_from_paths_and_filename(root_path, path, filename)
16
18
  result = client.put_file(filepath, file, overwrite)
17
19
 
18
20
  if share && result
@@ -14,9 +14,10 @@ module Breadbox
14
14
  def upload(options = {})
15
15
  path = options[:path]
16
16
  file = options[:file]
17
+ filename = options[:filename] || File.basename(file)
17
18
  acl = options[:public] ? :public_read : :private
18
19
  content_type = options[:content_type]
19
- filepath = filepath_from_paths_and_file(root_path, path, file)[1..-1]
20
+ filepath = filepath_from_paths_and_filename(root_path, path, filename)[1..-1]
20
21
  s3_object = s3_bucket_object.object(filepath)
21
22
 
22
23
  result = s3_object.put(body: file, acl: acl, content_type: content_type)
@@ -1,3 +1,3 @@
1
1
  module Breadbox
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -63,6 +63,17 @@ module Breadbox
63
63
 
64
64
  client.upload(path: "/", file: file)
65
65
  end
66
+
67
+ it "allows for a filename to be passed as an option" do
68
+ file = File.open("./tmp/new-file.jpg")
69
+ client = DropboxClient.new(configuration)
70
+ dropbox_client = instance_double(::DropboxClient)
71
+ allow(client).to receive(:client).and_return(dropbox_client)
72
+ expect(dropbox_client).to receive(:put_file)
73
+ .with("/my-cool-file.jpg", file, false)
74
+
75
+ client.upload(path: "/", file: file, filename: "my-cool-file.jpg")
76
+ end
66
77
  end
67
78
  end
68
79
  end
@@ -112,6 +112,33 @@ module Breadbox
112
112
 
113
113
  client.upload(path: "/", file: file, public: nil, content_type: "image/jpeg")
114
114
  end
115
+
116
+ it "passes path parameter" do
117
+ file = File.open("./tmp/new-file.jpg")
118
+ bucket_object = client.s3_bucket_object.object("new-file.jpg")
119
+
120
+ expect_any_instance_of(Aws::S3::Bucket).to receive(:object)
121
+ .with("my-path/new-file.jpg").and_return(bucket_object)
122
+ expect(bucket_object).to receive(:put)
123
+
124
+ client.upload(path: "my-path", file: file, content_type: "image/jpeg")
125
+ end
126
+
127
+ it "passes filename parameter" do
128
+ file = File.open("./tmp/new-file.jpg")
129
+ bucket_object = client.s3_bucket_object.object("my-cool-filename.jpg")
130
+
131
+ expect_any_instance_of(Aws::S3::Bucket).to receive(:object)
132
+ .with("my-cool-filename.jpg").and_return(bucket_object)
133
+ expect(bucket_object).to receive(:put)
134
+
135
+ client.upload(
136
+ path: "/",
137
+ file: file,
138
+ filename: "my-cool-filename.jpg",
139
+ content_type: "image/jpeg"
140
+ )
141
+ end
115
142
  end
116
143
  end
117
144
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathaniel Watts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-19 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dropbox-sdk
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: 1.6.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: 1.6.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aws-sdk
29
29
  requirement: !ruby/object:Gem::Requirement