s3 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +2 -3
- data/README.md +78 -0
- data/extra/s3_paperclip.rb +4 -1
- data/lib/s3/bucket.rb +7 -0
- data/lib/s3/object.rb +1 -1
- data/lib/s3/service.rb +7 -0
- data/lib/s3/signature.rb +17 -1
- data/lib/s3/version.rb +1 -1
- data/s3.gemspec +5 -2
- data/test/object_test.rb +14 -5
- metadata +8 -27
- data/README.rdoc +0 -22
data/Gemfile.lock
CHANGED
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# S3
|
2
|
+
|
3
|
+
S3 library provides access to [Amazon's Simple Storage Service](http://aws.amazon.com/s3/).
|
4
|
+
|
5
|
+
It supports both: European and US buckets through the [REST API](http://docs.amazonwebservices.com/AmazonS3/latest/API/APIRest.html).
|
6
|
+
|
7
|
+
<a href="http://pledgie.com/campaigns/14173"><img alt="Click here to lend your support to: S3 and make a donation at www.pledgie.com!" src="http://pledgie.com/campaigns/14173.png?skin_name=chrome" border="0" /></a>
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
gem install s3
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Initialize the service
|
16
|
+
|
17
|
+
require "s3"
|
18
|
+
service = S3::Service.new(:access_key_id => "...",
|
19
|
+
:secret_access_key => "...")
|
20
|
+
#=> #<S3::Service:...>
|
21
|
+
|
22
|
+
### List buckets
|
23
|
+
|
24
|
+
service.buckets
|
25
|
+
#=> [#<S3::Bucket:first-bucket>,
|
26
|
+
# #<S3::Bucket:second-bucket>]
|
27
|
+
|
28
|
+
### Find bucket
|
29
|
+
|
30
|
+
first_bucket = service.buckets.find("first-bucket")
|
31
|
+
#=> #<S3::Bucket:first-bucket>
|
32
|
+
|
33
|
+
### List objects in a bucket
|
34
|
+
|
35
|
+
first_bucket.objects
|
36
|
+
#=> [#<S3::Object:/first-bucket/lenna.png>,
|
37
|
+
# #<S3::Object:/first-bucket/lenna_mini.png>]
|
38
|
+
|
39
|
+
### Find object in a bucket
|
40
|
+
|
41
|
+
object = first_bucket.objects.find("lenna.png")
|
42
|
+
#=> #<S3::Object:/first-bucket/lenna.png>
|
43
|
+
|
44
|
+
### Access object metadata (cached from find)
|
45
|
+
|
46
|
+
object.content_type
|
47
|
+
#=> "image/png"
|
48
|
+
|
49
|
+
### Access object content (downloads the object)
|
50
|
+
|
51
|
+
object.content
|
52
|
+
#=> "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00..."
|
53
|
+
|
54
|
+
### Delete an object
|
55
|
+
|
56
|
+
object.destroy
|
57
|
+
#=> true
|
58
|
+
|
59
|
+
### Create an object
|
60
|
+
|
61
|
+
new_object = bucket.objects.build("bender.png")
|
62
|
+
#=> #<S3::Object:/synergy-staging/bender.png>
|
63
|
+
|
64
|
+
new_object.content = open("bender.png")
|
65
|
+
|
66
|
+
new_object.save
|
67
|
+
#=> true
|
68
|
+
|
69
|
+
## See also
|
70
|
+
|
71
|
+
* [gemcutter](http://gemcutter.org/gems/s3)
|
72
|
+
* [repository](http://github.com/qoobaa/s3)
|
73
|
+
* [issue tracker](http://github.com/qoobaa/s3/issues)
|
74
|
+
* [documentation](http://qoobaa.github.com/s3)
|
75
|
+
|
76
|
+
## Copyright
|
77
|
+
|
78
|
+
Copyright (c) 2009 Jakub Kuźma, Mirosław Boruta. See [LICENSE](http://github.com/qoobaa/s3/raw/master/LICENSE) for details.
|
data/extra/s3_paperclip.rb
CHANGED
@@ -95,7 +95,10 @@ module Paperclip
|
|
95
95
|
def to_file style = default_style
|
96
96
|
return @queued_for_write[style] if @queued_for_write[style]
|
97
97
|
begin
|
98
|
-
|
98
|
+
filename = path(style)
|
99
|
+
extname = File.extname(filename)
|
100
|
+
basename = File.basename(filename, extname)
|
101
|
+
file = Tempfile.new([basename, extname])
|
99
102
|
file.binmode if file.respond_to?(:binmode)
|
100
103
|
file.write(bucket.objects.find(path(style)).content)
|
101
104
|
file.rewind
|
data/lib/s3/bucket.rb
CHANGED
@@ -94,6 +94,13 @@ module S3
|
|
94
94
|
Proxy.new(lambda { list_bucket }, :owner => self, :extend => ObjectsExtension)
|
95
95
|
end
|
96
96
|
|
97
|
+
# Returns the object with the given key. Does not check whether the
|
98
|
+
# object exists. But also does not issue any HTTP requests, so it's
|
99
|
+
# much faster than objects.find
|
100
|
+
def object(key)
|
101
|
+
Object.send(:new, self, :key => key)
|
102
|
+
end
|
103
|
+
|
97
104
|
def inspect #:nodoc:
|
98
105
|
"#<#{self.class}:#{name}>"
|
99
106
|
end
|
data/lib/s3/object.rb
CHANGED
@@ -150,7 +150,7 @@ module S3
|
|
150
150
|
headers[:content_disposition] = options[:content_disposition] if options[:content_disposition]
|
151
151
|
headers[:cache_control] = options[:cache_control] if options[:cache_control]
|
152
152
|
headers[:x_amz_copy_source] = full_key
|
153
|
-
headers[:x_amz_metadata_directive] = "REPLACE"
|
153
|
+
headers[:x_amz_metadata_directive] = options[:replace] == false ? "COPY" : "REPLACE"
|
154
154
|
headers[:x_amz_copy_source_if_match] = options[:if_match] if options[:if_match]
|
155
155
|
headers[:x_amz_copy_source_if_none_match] = options[:if_none_match] if options[:if_none_match]
|
156
156
|
headers[:x_amz_copy_source_if_unmodified_since] = options[:if_modified_since] if options[:if_modified_since]
|
data/lib/s3/service.rb
CHANGED
@@ -39,6 +39,13 @@ module S3
|
|
39
39
|
Proxy.new(lambda { list_all_my_buckets }, :owner => self, :extend => BucketsExtension)
|
40
40
|
end
|
41
41
|
|
42
|
+
# Returns the bucket with the given name. Does not check whether the
|
43
|
+
# bucket exists. But also does not issue any HTTP requests, so it's
|
44
|
+
# much faster than buckets.find
|
45
|
+
def bucket(name)
|
46
|
+
Bucket.send(:new, self, name)
|
47
|
+
end
|
48
|
+
|
42
49
|
# Returns "http://" or "https://", depends on <tt>:use_ssl</tt>
|
43
50
|
# value from initializer
|
44
51
|
def protocol
|
data/lib/s3/signature.rb
CHANGED
@@ -220,7 +220,23 @@ module S3
|
|
220
220
|
# 4. If the request addresses a sub-resource, like ?location,
|
221
221
|
# ?acl, or ?torrent, append the sub-resource including question
|
222
222
|
# mark.
|
223
|
-
|
223
|
+
sub_resources = [
|
224
|
+
'acl',
|
225
|
+
'location',
|
226
|
+
'logging',
|
227
|
+
'notification',
|
228
|
+
'partNumber',
|
229
|
+
'policy',
|
230
|
+
'requestPayment',
|
231
|
+
'torrent',
|
232
|
+
'uploadId',
|
233
|
+
'uploads',
|
234
|
+
'versionId',
|
235
|
+
'versioning',
|
236
|
+
'versions',
|
237
|
+
'website'
|
238
|
+
]
|
239
|
+
string << "?#{$1}" if uri.query =~ /&?(#{sub_resources.join('|')})(?:&|=|\Z)/
|
224
240
|
string
|
225
241
|
end
|
226
242
|
end
|
data/lib/s3/version.rb
CHANGED
data/s3.gemspec
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
-
|
3
|
+
# Load version requiring the canonical "s3/version", otherwise Ruby will think
|
4
|
+
# is a different file and complaint about a double declaration of S3::VERSION.
|
5
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
6
|
+
require "s3/version"
|
4
7
|
|
5
8
|
Gem::Specification.new do |s|
|
6
9
|
s.name = "s3"
|
@@ -15,7 +18,7 @@ Gem::Specification.new do |s|
|
|
15
18
|
s.required_rubygems_version = ">= 1.3.6"
|
16
19
|
s.rubyforge_project = "s3"
|
17
20
|
|
18
|
-
s.add_dependency "proxies"
|
21
|
+
s.add_dependency "proxies", "~> 0.2.0"
|
19
22
|
s.add_development_dependency "test-unit", ">= 2.0"
|
20
23
|
s.add_development_dependency "mocha"
|
21
24
|
s.add_development_dependency "bundler", ">= 1.0.0"
|
data/test/object_test.rb
CHANGED
@@ -157,18 +157,18 @@ class ObjectTest < Test::Unit::TestCase
|
|
157
157
|
actual = @object_lena.acl
|
158
158
|
assert_equal expected, actual
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
test "storage-class writer" do
|
162
162
|
expected = nil
|
163
163
|
actual = @object_lena.storage_class
|
164
164
|
assert_equal expected, actual
|
165
|
-
|
165
|
+
|
166
166
|
assert @object_lena.storage_class = :standard
|
167
|
-
|
167
|
+
|
168
168
|
expected = "STANDARD"
|
169
169
|
actual = @object_lena.storage_class
|
170
170
|
assert_equal expected, actual
|
171
|
-
|
171
|
+
|
172
172
|
assert @object_lena.storage_class = :reduced_redundancy
|
173
173
|
|
174
174
|
expected = "REDUCED_REDUNDANCY"
|
@@ -176,7 +176,7 @@ class ObjectTest < Test::Unit::TestCase
|
|
176
176
|
assert_equal expected, actual
|
177
177
|
end
|
178
178
|
|
179
|
-
test "
|
179
|
+
test "replace" do
|
180
180
|
@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)
|
181
181
|
|
182
182
|
new_object = @object_lena.copy(:key => "Lena-copy.png")
|
@@ -184,4 +184,13 @@ class ObjectTest < Test::Unit::TestCase
|
|
184
184
|
assert_equal "Lena-copy.png", new_object.key
|
185
185
|
assert_equal "Lena.png", @object_lena.key
|
186
186
|
end
|
187
|
+
|
188
|
+
test "copy" do
|
189
|
+
@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 => "COPY" }).returns(@response_xml)
|
190
|
+
|
191
|
+
new_object = @object_lena.copy(:key => "Lena-copy.png", :replace => false)
|
192
|
+
|
193
|
+
assert_equal "Lena-copy.png", new_object.key
|
194
|
+
assert_equal "Lena.png", @object_lena.key
|
195
|
+
end
|
187
196
|
end
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 3
|
8
|
-
- 7
|
9
|
-
version: 0.3.7
|
4
|
+
prerelease:
|
5
|
+
version: 0.3.8
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- "Jakub Ku\xC5\xBAma"
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date:
|
13
|
+
date: 2011-03-17 00:00:00 +01:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -22,11 +18,9 @@ dependencies:
|
|
22
18
|
requirement: &id001 !ruby/object:Gem::Requirement
|
23
19
|
none: false
|
24
20
|
requirements:
|
25
|
-
- -
|
21
|
+
- - ~>
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 0
|
29
|
-
version: "0"
|
23
|
+
version: 0.2.0
|
30
24
|
type: :runtime
|
31
25
|
prerelease: false
|
32
26
|
version_requirements: *id001
|
@@ -37,9 +31,6 @@ dependencies:
|
|
37
31
|
requirements:
|
38
32
|
- - ">="
|
39
33
|
- !ruby/object:Gem::Version
|
40
|
-
segments:
|
41
|
-
- 2
|
42
|
-
- 0
|
43
34
|
version: "2.0"
|
44
35
|
type: :development
|
45
36
|
prerelease: false
|
@@ -51,8 +42,6 @@ dependencies:
|
|
51
42
|
requirements:
|
52
43
|
- - ">="
|
53
44
|
- !ruby/object:Gem::Version
|
54
|
-
segments:
|
55
|
-
- 0
|
56
45
|
version: "0"
|
57
46
|
type: :development
|
58
47
|
prerelease: false
|
@@ -64,10 +53,6 @@ dependencies:
|
|
64
53
|
requirements:
|
65
54
|
- - ">="
|
66
55
|
- !ruby/object:Gem::Version
|
67
|
-
segments:
|
68
|
-
- 1
|
69
|
-
- 0
|
70
|
-
- 0
|
71
56
|
version: 1.0.0
|
72
57
|
type: :development
|
73
58
|
prerelease: false
|
@@ -86,7 +71,7 @@ files:
|
|
86
71
|
- Gemfile
|
87
72
|
- Gemfile.lock
|
88
73
|
- LICENSE
|
89
|
-
- README.
|
74
|
+
- README.md
|
90
75
|
- Rakefile
|
91
76
|
- extra/s3_attachment_fu.rb
|
92
77
|
- extra/s3_paperclip.rb
|
@@ -123,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
108
|
requirements:
|
124
109
|
- - ">="
|
125
110
|
- !ruby/object:Gem::Version
|
126
|
-
hash:
|
111
|
+
hash: 1379753891873581983
|
127
112
|
segments:
|
128
113
|
- 0
|
129
114
|
version: "0"
|
@@ -132,15 +117,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
117
|
requirements:
|
133
118
|
- - ">="
|
134
119
|
- !ruby/object:Gem::Version
|
135
|
-
segments:
|
136
|
-
- 1
|
137
|
-
- 3
|
138
|
-
- 6
|
139
120
|
version: 1.3.6
|
140
121
|
requirements: []
|
141
122
|
|
142
123
|
rubyforge_project: s3
|
143
|
-
rubygems_version: 1.
|
124
|
+
rubygems_version: 1.6.2
|
144
125
|
signing_key:
|
145
126
|
specification_version: 3
|
146
127
|
summary: Library for accessing S3 objects and buckets
|
data/README.rdoc
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
= S3
|
2
|
-
|
3
|
-
S3 library provides access to {Amazon's Simple Storage Service}[http://aws.amazon.com/s3/].
|
4
|
-
It supports both: European and US buckets through {REST API}[http://docs.amazonwebservices.com/AmazonS3/latest/RESTAPI.html].
|
5
|
-
|
6
|
-
* homepage[http://jah.pl/projects/s3.html]
|
7
|
-
* gemcutter[http://gemcutter.org/gems/s3]
|
8
|
-
* repository[http://github.com/qoobaa/s3]
|
9
|
-
* {issue tracker}[http://github.com/qoobaa/s3/issues]
|
10
|
-
* rdoc[http://qoobaa.github.com/s3]
|
11
|
-
|
12
|
-
== Installation
|
13
|
-
|
14
|
-
gem install s3
|
15
|
-
|
16
|
-
== Usage
|
17
|
-
|
18
|
-
See homepage[http://jah.pl/projects/s3.html] for details.
|
19
|
-
|
20
|
-
== Copyright
|
21
|
-
|
22
|
-
Copyright (c) 2009 Jakub Kuźma, Mirosław Boruta. See LICENSE[http://github.com/qoobaa/s3/raw/master/LICENSE] for details.
|