ThreeStore 0.0.1.a → 0.0.1.b
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/.gitignore +1 -0
- data/README.rdoc +28 -1
- data/lib/ThreeStore.rb +6 -14
- data/lib/ThreeStore/version.rb +1 -1
- data/spec/lib/ThreeStore_spec.rb +17 -23
- metadata +4 -4
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -5,7 +5,34 @@ http://travis-ci.org/cowmanifestation/ThreeStore.png ({More info}[http://travis-
|
|
5
5
|
|
6
6
|
== Tutorial
|
7
7
|
|
8
|
-
|
8
|
+
To store something on s3:
|
9
|
+
|
10
|
+
Perhaps you are storing your s3 secret access key id and secret access key as environment variables - you can access them like this:
|
11
|
+
|
12
|
+
@store = ThreeStore.new(ENV['S3_KEY'], ENV['S3_SECRET'], 'my-bucket')
|
13
|
+
|
14
|
+
If you are storing aforementioned credentials in a yaml file:
|
15
|
+
|
16
|
+
@yaml = 'path_to_my_yaml_file.yml'
|
17
|
+
@store = ThreeStore.new(@yaml[:access_key_id], @yaml[:secret_access_key], 'my-bucket')
|
18
|
+
|
19
|
+
To upload a file, use ThreeStore#store_on_s3:
|
20
|
+
|
21
|
+
@store.store_on_s3(:url => 'http://example.com/assets/picture.png', :key => 'picture.png', :content_type => 'image/png', :access => 'public-read')
|
22
|
+
|
23
|
+
Options to pass to +store_on_s3+:
|
24
|
+
* :url, the url or path from which to fetch the file
|
25
|
+
* :key, the that you wish your object to have on s3
|
26
|
+
* :content_type (optional) - the content type will be inferred from the file extension, but it can be passed in if needed
|
27
|
+
* :access (optional) - Default access is private, but can be set to 'public-read' and maybe even 'public-write'
|
28
|
+
|
29
|
+
(For more information on access level options, look in the Amazon S3 docs: http://aws.amazon.com/documentation)
|
30
|
+
|
31
|
+
This will return your file's new location on s3:
|
32
|
+
|
33
|
+
=> 'http://s3.amazonaws.com/my-bucket/picture.png'
|
34
|
+
|
35
|
+
The destination path is constructed thus: http://s3.amazonaws.com/ + bucket name + key
|
9
36
|
|
10
37
|
== FAQ
|
11
38
|
|
data/lib/ThreeStore.rb
CHANGED
@@ -11,28 +11,20 @@ class ThreeStore
|
|
11
11
|
|
12
12
|
# Options: url (required),
|
13
13
|
# content_type,
|
14
|
-
# access_level
|
14
|
+
# access_level,
|
15
|
+
# key (destination on s3)
|
16
|
+
|
15
17
|
def store_on_s3(options)
|
16
18
|
# Deleting :url from options because we don't want it in the options that we pass to s3
|
17
19
|
# and removing some characters that aren't allowed in urls
|
18
20
|
url = options.delete(:url).gsub(/ /, '%20').gsub(/\^/, '%5E')
|
19
21
|
file = open(url)
|
22
|
+
|
23
|
+
key = options.delete(:key)
|
20
24
|
|
21
|
-
key
|
22
|
-
|
23
|
-
AWS::S3::S3Object.store(key, file, @bucket, :access => options[:access], :content_type => options[:content_type])
|
25
|
+
AWS::S3::S3Object.store(key, file, @bucket, options)
|
24
26
|
|
25
27
|
# Return location on s3
|
26
28
|
"http://s3.amazonaws.com/" + @bucket + "/" + key
|
27
29
|
end
|
28
|
-
|
29
|
-
def create_key(url, file)
|
30
|
-
key = CGI.escape(url.gsub(/http:\/\//, ''))
|
31
|
-
file_content = file.read
|
32
|
-
|
33
|
-
digest = Digest::MD5.hexdigest(file_content)
|
34
|
-
extname = File.extname(url)
|
35
|
-
|
36
|
-
key.gsub(extname, "-#{digest}#{extname}")
|
37
|
-
end
|
38
30
|
end
|
data/lib/ThreeStore/version.rb
CHANGED
data/spec/lib/ThreeStore_spec.rb
CHANGED
@@ -1,43 +1,37 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'yaml'
|
2
3
|
|
3
4
|
describe ThreeStore do
|
4
|
-
|
5
5
|
before(:all) do
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@s3_object_path = @store.store_on_s3(:url => @url, :content_type => 'image/png', :access => 'public-read')
|
6
|
+
@yaml = YAML.load_file('ThreeStore.yml')
|
7
|
+
@test_bucket = @yaml[:test_bucket]
|
8
|
+
@store = ThreeStore.new(@yaml[:access_key_id], @yaml[:secret_access_key], @test_bucket)
|
10
9
|
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
after(:all) do
|
12
|
+
AWS::S3::Bucket.find(@test_bucket).clear
|
13
|
+
end
|
15
14
|
|
16
15
|
it "should establish a connection with s3" do
|
17
16
|
AWS::S3::Base.connected?.should be_true
|
18
17
|
end
|
19
18
|
|
20
19
|
it "should put a given file on s3" do
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
open(@s3_object_path).read.should == open(@url).read
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should add an md5 hexdigest to the key" do
|
28
|
-
file_content = open(@url).read
|
29
|
-
digest = Digest::MD5.hexdigest(file_content)
|
20
|
+
url = @yaml[:test_image]
|
21
|
+
s3_object_path = @store.store_on_s3(:url => url, :key => "hedgeye-button-sprite.png", :access => 'public-read')
|
30
22
|
|
31
|
-
|
23
|
+
open(s3_object_path).read.should == open(url).read
|
32
24
|
end
|
33
25
|
|
34
26
|
# Regression test because quotemedia urls have spaces and carets for some reason.
|
35
|
-
it "should
|
36
|
-
url = "http://app.quotemedia.com/quotetools/getChart.go?webmasterId=500&symbol=^DOW&chsym=^DOW Comp
|
27
|
+
it "should be able to prcess urls with spaces and carets" do
|
28
|
+
url = "http://app.quotemedia.com/quotetools/getChart.go?webmasterId=500&symbol=^DOW&chsym=^DOW Comp" +
|
29
|
+
"&chscale=5d&chtype=AreaChart&chfrmon=on&chfrm=ffffff&chbdron=on&chbdr=cccccc&chbg=ffffff" +
|
30
|
+
"&chbgch=ffffff&chln=465665&chfill=1B57AA&chfill2=c0c9d2&chgrdon=on&chgrd=cccccc&chton=on" +
|
31
|
+
"&chtcol=000000&chxyc=111111&chpcon=on&chpccol=ee0000&chmrg=2&chhig=250&chwid=380"
|
37
32
|
|
38
|
-
s3_object_path = @store.store_on_s3(:url => url, :content_type => 'image/png', :access => 'public-read')
|
33
|
+
s3_object_path = @store.store_on_s3(:url => url, :key => "quotemedia_chart.png", :content_type => 'image/png', :access => 'public-read')
|
39
34
|
|
40
|
-
s3_object_path.
|
41
|
-
s3_object_path.should_not match(/\^/)
|
35
|
+
open(s3_object_path).should be_true
|
42
36
|
end
|
43
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ThreeStore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 47
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- 1
|
10
|
-
-
|
11
|
-
version: 0.0.1.
|
10
|
+
- b
|
11
|
+
version: 0.0.1.b
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Chenoa Siegenthaler
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-12-
|
19
|
+
date: 2011-12-06 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: aws-s3
|