s3 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/extra/s3_paperclip.rb +11 -9
- data/lib/s3/connection.rb +2 -2
- data/lib/s3/object.rb +12 -1
- data/lib/s3/version.rb +1 -1
- data/test/connection_test.rb +4 -0
- data/test/object_test.rb +19 -1
- data/test/test_helper.rb +2 -3
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/extra/s3_paperclip.rb
CHANGED
@@ -29,15 +29,16 @@ module Paperclip
|
|
29
29
|
end
|
30
30
|
|
31
31
|
base.instance_eval do
|
32
|
-
@s3_credentials
|
33
|
-
@bucket_name
|
34
|
-
@bucket_name
|
35
|
-
@s3_options
|
36
|
-
@s3_permissions
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
32
|
+
@s3_credentials = parse_credentials(@options[:s3_credentials])
|
33
|
+
@bucket_name = @options[:bucket] || @s3_credentials[:bucket]
|
34
|
+
@bucket_name = @bucket_name.call(self) if @bucket_name.is_a?(Proc)
|
35
|
+
@s3_options = @options[:s3_options] || {}
|
36
|
+
@s3_permissions = @options[:s3_permissions] || :public_read
|
37
|
+
@s3_storage_class = @options[:s3_storage_class] || :standard
|
38
|
+
@s3_protocol = @options[:s3_protocol] || (@s3_permissions == :public_read ? "http" : "https")
|
39
|
+
@s3_headers = @options[:s3_headers] || {}
|
40
|
+
@s3_host_alias = @options[:s3_host_alias]
|
41
|
+
@url = ":s3_path_url" unless @url.to_s.match(/^:s3.*url$/)
|
41
42
|
@service = ::S3::Service.new(@s3_options.merge(
|
42
43
|
:access_key_id => @s3_credentials[:access_key_id],
|
43
44
|
:secret_access_key => @s3_credentials[:secret_access_key],
|
@@ -112,6 +113,7 @@ module Paperclip
|
|
112
113
|
object = bucket.objects.build(path(style))
|
113
114
|
object.content = file.read
|
114
115
|
object.acl = @s3_permissions
|
116
|
+
object.storage_class = @s3_storage_class
|
115
117
|
object.content_type = instance_read(:content_type)
|
116
118
|
object.content_disposition = @s3_headers[:content_disposition]
|
117
119
|
object.content_encoding = @s3_headers[:content_encoding]
|
data/lib/s3/connection.rb
CHANGED
@@ -114,7 +114,7 @@ module S3
|
|
114
114
|
# Hash of headers translated from symbol to string, containing
|
115
115
|
# only interesting headers
|
116
116
|
def self.parse_headers(headers)
|
117
|
-
interesting_keys = [:content_type, :x_amz_acl, :range,
|
117
|
+
interesting_keys = [:content_type, :x_amz_acl, :x_amz_storage_class, :range,
|
118
118
|
:if_modified_since, :if_unmodified_since,
|
119
119
|
:if_match, :if_none_match,
|
120
120
|
:content_disposition, :content_encoding,
|
@@ -161,7 +161,7 @@ module S3
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def proxy_settings
|
164
|
-
@proxy.values_at(:host, :port, :user, :password) unless @proxy.
|
164
|
+
@proxy.values_at(:host, :port, :user, :password) unless @proxy.nil? || @proxy.empty?
|
165
165
|
end
|
166
166
|
|
167
167
|
def http(host)
|
data/lib/s3/object.rb
CHANGED
@@ -6,7 +6,7 @@ module S3
|
|
6
6
|
extend Forwardable
|
7
7
|
|
8
8
|
attr_accessor :content_type, :content_disposition, :content_encoding
|
9
|
-
attr_reader :last_modified, :etag, :size, :bucket, :key, :acl
|
9
|
+
attr_reader :last_modified, :etag, :size, :bucket, :key, :acl, :storage_class
|
10
10
|
attr_writer :content
|
11
11
|
|
12
12
|
def_instance_delegators :bucket, :name, :service, :bucket_request, :vhost?, :host, :path_prefix
|
@@ -40,6 +40,16 @@ module S3
|
|
40
40
|
def acl=(acl)
|
41
41
|
@acl = acl.to_s.gsub("_", "-") if acl
|
42
42
|
end
|
43
|
+
|
44
|
+
# Assigns a new storage class (RRS) to the object. Please note
|
45
|
+
# that the storage class is not retrieved from the server and set
|
46
|
+
# to "STANDARD" by default.
|
47
|
+
#
|
48
|
+
# ==== Example
|
49
|
+
# object.storage_class = :reduced_redundancy
|
50
|
+
def storage_class=(storage_class)
|
51
|
+
@storage_class = storage_class.to_s.upcase if storage_class
|
52
|
+
end
|
43
53
|
|
44
54
|
# Retrieves the object from the server. Method is used to download
|
45
55
|
# object information only (content type, size and so on). It does
|
@@ -215,6 +225,7 @@ module S3
|
|
215
225
|
def dump_headers
|
216
226
|
headers = {}
|
217
227
|
headers[:x_amz_acl] = @acl || "public-read"
|
228
|
+
headers[:x_amz_storage_class] = @storage_class || "STANDARD"
|
218
229
|
headers[:content_type] = @content_type || "application/octet-stream"
|
219
230
|
headers[:content_encoding] = @content_encoding if @content_encoding
|
220
231
|
headers[:content_disposition] = @content_disposition if @content_disposition
|
data/lib/s3/version.rb
CHANGED
data/test/connection_test.rb
CHANGED
@@ -115,6 +115,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
115
115
|
expected = {
|
116
116
|
"content-type" => nil,
|
117
117
|
"x-amz-acl" => nil,
|
118
|
+
"x-amz-storage-class" => nil,
|
118
119
|
"if-modified-since" => nil,
|
119
120
|
"if-unmodified-since" => nil,
|
120
121
|
"if-match" => nil,
|
@@ -125,6 +126,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
125
126
|
actual = S3::Connection.parse_headers(
|
126
127
|
:content_type => nil,
|
127
128
|
:x_amz_acl => nil,
|
129
|
+
:x_amz_storage_class => nil,
|
128
130
|
:if_modified_since => nil,
|
129
131
|
:if_unmodified_since => nil,
|
130
132
|
:if_match => nil,
|
@@ -139,6 +141,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
139
141
|
expected = {
|
140
142
|
"content-type" => "text/html",
|
141
143
|
"x-amz-acl" => "public-read",
|
144
|
+
"x-amz-storage-class" => "STANDARD",
|
142
145
|
"if-modified-since" => "today",
|
143
146
|
"if-unmodified-since" => "tomorrow",
|
144
147
|
"if-match" => "1234",
|
@@ -149,6 +152,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
149
152
|
actual = S3::Connection.parse_headers(
|
150
153
|
:content_type => "text/html",
|
151
154
|
:x_amz_acl => "public-read",
|
155
|
+
:x_amz_storage_class => "STANDARD",
|
152
156
|
:if_modified_since => "today",
|
153
157
|
:if_unmodified_since => "tomorrow",
|
154
158
|
:if_match => "1234",
|
data/test/object_test.rb
CHANGED
@@ -101,7 +101,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
101
101
|
end
|
102
102
|
|
103
103
|
test "save" do
|
104
|
-
@object_lena.expects(:object_request).with(:put, :body=>"test", :headers=>{ :x_amz_acl=>"public-read", :content_type=>"application/octet-stream" }).returns(@response_binary)
|
104
|
+
@object_lena.expects(:object_request).with(:put, :body=>"test", :headers=>{ :x_amz_acl=>"public-read", :x_amz_storage_class=>"STANDARD", :content_type=>"application/octet-stream" }).returns(@response_binary)
|
105
105
|
assert @object_lena.save
|
106
106
|
end
|
107
107
|
|
@@ -149,6 +149,24 @@ class ObjectTest < Test::Unit::TestCase
|
|
149
149
|
actual = @object_lena.acl
|
150
150
|
assert_equal expected, actual
|
151
151
|
end
|
152
|
+
|
153
|
+
test "storage-class writer" do
|
154
|
+
expected = nil
|
155
|
+
actual = @object_lena.storage_class
|
156
|
+
assert_equal expected, actual
|
157
|
+
|
158
|
+
assert @object_lena.storage_class = :standard
|
159
|
+
|
160
|
+
expected = "STANDARD"
|
161
|
+
actual = @object_lena.storage_class
|
162
|
+
assert_equal expected, actual
|
163
|
+
|
164
|
+
assert @object_lena.storage_class = :reduced_redundancy
|
165
|
+
|
166
|
+
expected = "REDUCED_REDUNDANCY"
|
167
|
+
actual = @object_lena.storage_class
|
168
|
+
assert_equal expected, actual
|
169
|
+
end
|
152
170
|
|
153
171
|
test "copy" do
|
154
172
|
@bucket_images.expects(:bucket_request).with(:put, :path => "Lena-copy.png", :headers => { :x_amz_acl => "public-read", :content_type => "application/octet-stream", :x_amz_copy_source => "images/Lena.png", :x_amz_metadata_directive => "REPLACE" }).returns(@response_xml)
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jakub Ku\xC5\xBAma"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-06 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|