breadbox 1.2.1 → 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: af6366ca6d82477de1f12bd73a9f73a5c365eedb
4
- data.tar.gz: bfaa27461d1e9a566add2fba9620a1e5508d57e5
3
+ metadata.gz: 864b92924c79c0de55813778e21139799b6a535c
4
+ data.tar.gz: 737a51e54067aa9f171f4db91a936696cf830782
5
5
  SHA512:
6
- metadata.gz: 423bd1ae34de4bd77727b7b730d9c6c1e7eaca6ce7fdeec42669d617abf7c6f7a086e91e6c9207fdf8870816357b90b5b0839a6fccdb71d0f084c751d73c1ce9
7
- data.tar.gz: ed241327293a87d34209cdf6c1a1eb4102e8ae136f73c88f939df4d87649ba181380c2189b8b6464c9254ef6c82df03a448aae55284fff49588963e96bc814fa
6
+ metadata.gz: ef2deb7707fc28b3b6deca9467acf318ab55a49f50a1b465a5f7fa066adf69671064e6fa58cdfc01455675626f85a34c1fc3377fab640122a3d1233cf39cd597
7
+ data.tar.gz: b88fc9242b7ee9a250ce5283dbaa17519b556939933db998965693773c3ffa8914d1e1b094f4f0caa20a67fd7d469d5e2e30aa9b981217f98f21eb7485311355
data/README.md CHANGED
@@ -50,6 +50,7 @@ end
50
50
  # config/initializers/breadbox.rb
51
51
 
52
52
  Breadbox.configure do |config|
53
+ config.s3_region = xxxxxxxx # OPTIONAL - defaults to "us-east-1"
53
54
  config.s3_bucket = "name of the bucket" # THIS IS REQUIRED
54
55
  config.s3_secret_access_key = xxxxxx # THIS IS REQUIRED
55
56
  config.s3_access_key_id = xxxxxxx # THIS IS REQUIRED
data/breadbox.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "dropbox-sdk", "~> 1.6"
22
- spec.add_dependency "aws-sdk", "~> 1.54"
22
+ spec.add_dependency "aws-sdk", "~> 2.1.7"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
25
25
  spec.add_development_dependency "rake"
@@ -7,6 +7,8 @@ module Breadbox
7
7
  :provider,
8
8
  :root_path
9
9
 
10
+ attr_writer :s3_region
11
+
10
12
  def initialize
11
13
  @root_path = default_root_path
12
14
  end
@@ -19,8 +21,16 @@ module Breadbox
19
21
  end
20
22
  end
21
23
 
24
+ def s3_region
25
+ @s3_region || default_s3_region
26
+ end
27
+
22
28
  protected
23
29
 
30
+ def default_s3_region
31
+ "us-east-1"
32
+ end
33
+
24
34
  def default_root_path
25
35
  "/"
26
36
  end
@@ -1,4 +1,4 @@
1
- require "aws"
1
+ require "aws-sdk"
2
2
  require "breadbox/client"
3
3
 
4
4
  module Breadbox
@@ -8,35 +8,39 @@ module Breadbox
8
8
  end
9
9
 
10
10
  def s3_bucket_object
11
- @bucket ||= AWS::S3.new.buckets[bucket]
11
+ @bucket ||= Aws::S3::Resource.new(client: s3_client_object).bucket(bucket)
12
12
  end
13
13
 
14
14
  def upload(options = {})
15
- path = options[:path]
16
- file = options[:file]
17
- acl = options[:public] ? :public_read : nil
18
- content_type = options[:content_type]
19
- filepath = filepath_from_paths_and_file(root_path, path, file)[1..-1]
20
- result = s3_bucket_object.objects[filepath].write(file, acl: acl, content_type: content_type)
15
+ path = options[:path]
16
+ file = options[:file]
17
+ acl = options[:public] ? :public_read : :private
18
+ content_type = options[:content_type]
19
+ filepath = filepath_from_paths_and_file(root_path, path, file)[1..-1]
20
+ s3_object = s3_bucket_object.object(filepath)
21
21
 
22
- if result
23
- result.public_url.to_s
22
+ result = s3_object.put(body: file, acl: acl, content_type: content_type)
23
+
24
+ if result && result.successful?
25
+ s3_object.public_url.to_s
24
26
  end
25
27
  end
26
28
 
29
+ def s3_client_object
30
+ @client ||= Aws::S3::Client.new(
31
+ region: configuration.s3_region,
32
+ credentials: Aws::Credentials.new(
33
+ configuration.s3_access_key_id,
34
+ configuration.s3_secret_access_key,
35
+ )
36
+ )
37
+ end
38
+
27
39
  protected
28
40
 
29
41
  def post_initialize
30
42
  validate_bucket
31
43
  validate_tokens
32
- setup_s3
33
- end
34
-
35
- def setup_s3
36
- AWS.config(
37
- access_key_id: configuration.s3_access_key_id,
38
- secret_access_key: configuration.s3_secret_access_key
39
- )
40
44
  end
41
45
 
42
46
  def validate_bucket
@@ -1,3 +1,3 @@
1
1
  module Breadbox
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -51,22 +51,32 @@ module Breadbox
51
51
  end
52
52
  end
53
53
 
54
- describe "with valid configuration settings" do
55
- it "assigns the AccessKeyId and SecretAccessKey to AWS::S3" do
56
- options = {
57
- access_key_id: configuration.s3_access_key_id,
58
- secret_access_key: configuration.s3_secret_access_key,
59
- }
60
- expect(AWS).to receive(:config).with(options)
61
- S3Client.new(configuration)
54
+ describe "#s3_bucket_object" do
55
+ it "returns a new bucket object from Aws::S3" do
56
+ client = S3Client.new(configuration)
57
+ bucket_object = client.s3_bucket_object
58
+ expect(bucket_object).to be_kind_of Aws::S3::Bucket
62
59
  end
63
60
  end
64
61
 
65
- describe "#s3_bucket_object" do
66
- it "returns a new bucket object from AWS::S3" do
62
+ describe "#s3_client_object" do
63
+ let(:credentials) { double(:credentials) }
64
+
65
+ before do
66
+ allow(Aws::Credentials).to receive(:new).with(
67
+ configuration.s3_access_key_id,
68
+ configuration.s3_secret_access_key,
69
+ ).and_return(credentials)
70
+ end
71
+
72
+ it "initializes with the correct data" do
73
+ expect(Aws::S3::Client).to receive(:new).with(
74
+ region: configuration.s3_region,
75
+ credentials: credentials
76
+ )
77
+
67
78
  client = S3Client.new(configuration)
68
- bucket_object = client.s3_bucket_object
69
- expect(bucket_object).to be_kind_of AWS::S3::Bucket
79
+ client.s3_client_object
70
80
  end
71
81
  end
72
82
 
@@ -78,19 +88,30 @@ module Breadbox
78
88
 
79
89
  it "writes a file to an S3 Bucket Object" do
80
90
  file = File.open("./tmp/new-file.jpg")
81
- options = { acl: :public_read, content_type: nil }
82
- expect_any_instance_of(AWS::S3::S3Object).to receive(:write)
83
- .with(file, options)
91
+ options = { body: file, acl: :public_read, content_type: nil }
92
+ expect_any_instance_of(Aws::S3::Object)
93
+ .to receive(:put).with(options)
94
+
84
95
  client.upload(path: "/", file: file, public: true)
85
96
  end
86
97
 
87
98
  it "passes content-type parameter" do
88
99
  file = File.open("./tmp/new-file.jpg")
89
- options = { content_type: "image/jpeg", acl: nil }
90
- expect_any_instance_of(AWS::S3::S3Object).to receive(:write)
91
- .with(file, options)
100
+ options = { body: file, acl: :private, content_type: "image/jpeg" }
101
+ expect_any_instance_of(Aws::S3::Object)
102
+ .to receive(:put).with(options)
103
+
92
104
  client.upload(path: "/", file: file, content_type: "image/jpeg")
93
105
  end
106
+
107
+ it "defaults to private :acl" do
108
+ file = File.open("./tmp/new-file.jpg")
109
+ options = { body: file, acl: :private, content_type: "image/jpeg" }
110
+ expect_any_instance_of(Aws::S3::Object)
111
+ .to receive(:put).with(options)
112
+
113
+ client.upload(path: "/", file: file, public: nil, content_type: "image/jpeg")
114
+ end
94
115
  end
95
116
  end
96
117
  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.2.1
4
+ version: 1.3.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-01-29 00:00:00.000000000 Z
11
+ date: 2015-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dropbox-sdk
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.54'
33
+ version: 2.1.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.54'
40
+ version: 2.1.7
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement