ThreeStore 0.0.1.a

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.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ tmp/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --profile
3
+ -fs
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ThreeStore.gemspec
4
+ gemspec
@@ -0,0 +1,14 @@
1
+ = ThreeStore
2
+
3
+ http://stillmaintained.com/cowmanifestation/ThreeStore.png
4
+ http://travis-ci.org/cowmanifestation/ThreeStore.png ({More info}[http://travis-ci.org/cowmanifestation/ThreeStore])
5
+
6
+ == Tutorial
7
+
8
+ TODO
9
+
10
+ == FAQ
11
+
12
+ === "ThreeStore"? That's stupid. Why isn't it called "3store"? That's much cooler.
13
+
14
+ Because modules can't start with a number. Jeez, lay off! And get off my lawn!
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ThreeStore/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ThreeStore"
7
+ s.version = Threestore::VERSION
8
+ s.authors = ["Chenoa Siegenthaler"]
9
+ s.email = ["cowmanifestation@gmail.com"]
10
+ s.homepage = "http://github.com/cowmanifestation/threestore"
11
+ s.summary = 'Get files from a url and store them on s3'
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = "ThreeStore"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency('aws-s3')
22
+ s.add_development_dependency('rake', '~> 0.9.2.2')
23
+ s.add_development_dependency('rspec', '~> 2.5.0')
24
+ end
@@ -0,0 +1,38 @@
1
+ require 'open-uri'
2
+ require 'aws/s3'
3
+ require 'digest/md5'
4
+ autoload :VERSION, "ThreeStore/version"
5
+
6
+ class ThreeStore
7
+ def initialize(key, secret, bucket)
8
+ AWS::S3::Base.establish_connection!(:access_key_id => key, :secret_access_key => secret)
9
+ @bucket = bucket
10
+ end
11
+
12
+ # Options: url (required),
13
+ # content_type,
14
+ # access_level
15
+ def store_on_s3(options)
16
+ # Deleting :url from options because we don't want it in the options that we pass to s3
17
+ # and removing some characters that aren't allowed in urls
18
+ url = options.delete(:url).gsub(/ /, '%20').gsub(/\^/, '%5E')
19
+ file = open(url)
20
+
21
+ key = create_key(url, file)
22
+
23
+ AWS::S3::S3Object.store(key, file, @bucket, :access => options[:access], :content_type => options[:content_type])
24
+
25
+ # Return location on s3
26
+ "http://s3.amazonaws.com/" + @bucket + "/" + key
27
+ 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
+ end
@@ -0,0 +1,3 @@
1
+ module Threestore
2
+ VERSION = "0.0.1.a"
3
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe ThreeStore do
4
+
5
+ before(:all) do
6
+ @test_bucket = 'hedgeye-ent-bucket'
7
+ @store = ThreeStore.new(ENV['S3_KEY'], ENV['S3_SECRET'], @test_bucket)
8
+ @url = "http://www2.hedgeye.com/assets/hedgeye-ui/button-sprite.png"
9
+ @s3_object_path = @store.store_on_s3(:url => @url, :content_type => 'image/png', :access => 'public-read')
10
+ end
11
+
12
+ # after(:all) do
13
+ # AWS::S3::Bucket.find(@test_bucket).clear
14
+ # end
15
+
16
+ it "should establish a connection with s3" do
17
+ AWS::S3::Base.connected?.should be_true
18
+ end
19
+
20
+ it "should put a given file on s3" do
21
+ # TODO: test with this url (a quotemedia chart) - it has some issues
22
+ # url = "http://app.quotemedia.com/quotetools/getChart.go?webmasterId=98924&symbol=COMP&chsym=Nasdaq%20Comp&chscale=5d&chtype=AreaChart&chfrmon=on&chfrm=ffffff&chbdron=on&chbdr=cccccc&chbg=ffffff&chbgch=ffffff&chln=465665&chfill=1B57AA&chfill2=c0c9d2&chgrdon=on&chgrd=cccccc&chton=on&chtcol=000000&chxyc=111111&chpcon=on&chpccol=ee0000&chmrg=2&chhig=250&chwid=380"
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)
30
+
31
+ @s3_object_path.should match(digest)
32
+ end
33
+
34
+ # Regression test because quotemedia urls have spaces and carets for some reason.
35
+ it "should remove spaces and carets from the given url" do
36
+ url = "http://app.quotemedia.com/quotetools/getChart.go?webmasterId=500&symbol=^DOW&chsym=^DOW Comp&chscale=5d&chtype=AreaChart&chfrmon=on&chfrm=ffffff&chbdron=on&chbdr=cccccc&chbg=ffffff&chbgch=ffffff&chln=465665&chfill=1B57AA&chfill2=c0c9d2&chgrdon=on&chgrd=cccccc&chton=on&chtcol=000000&chxyc=111111&chpcon=on&chpccol=ee0000&chmrg=2&chhig=250&chwid=380"
37
+
38
+ s3_object_path = @store.store_on_s3(:url => url, :content_type => 'image/png', :access => 'public-read')
39
+
40
+ s3_object_path.should_not match(/ /)
41
+ s3_object_path.should_not match(/\^/)
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ require 'ThreeStore'
5
+
6
+ Rspec.configure do |c|
7
+ c.mock_with :rspec
8
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ThreeStore
3
+ version: !ruby/object:Gem::Version
4
+ hash: 46
5
+ prerelease: 6
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ - a
11
+ version: 0.0.1.a
12
+ platform: ruby
13
+ authors:
14
+ - Chenoa Siegenthaler
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-12-02 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: aws-s3
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 11
44
+ segments:
45
+ - 0
46
+ - 9
47
+ - 2
48
+ - 2
49
+ version: 0.9.2.2
50
+ type: :development
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 27
61
+ segments:
62
+ - 2
63
+ - 5
64
+ - 0
65
+ version: 2.5.0
66
+ type: :development
67
+ version_requirements: *id003
68
+ description: Get files from a url and store them on s3
69
+ email:
70
+ - cowmanifestation@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files: []
76
+
77
+ files:
78
+ - .gitignore
79
+ - .rspec
80
+ - .travis.yml
81
+ - Gemfile
82
+ - README.rdoc
83
+ - Rakefile
84
+ - ThreeStore.gemspec
85
+ - lib/ThreeStore.rb
86
+ - lib/ThreeStore/version.rb
87
+ - spec/lib/ThreeStore_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: http://github.com/cowmanifestation/threestore
90
+ licenses: []
91
+
92
+ post_install_message:
93
+ rdoc_options: []
94
+
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">"
110
+ - !ruby/object:Gem::Version
111
+ hash: 25
112
+ segments:
113
+ - 1
114
+ - 3
115
+ - 1
116
+ version: 1.3.1
117
+ requirements: []
118
+
119
+ rubyforge_project: ThreeStore
120
+ rubygems_version: 1.8.5
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: Get files from a url and store them on s3
124
+ test_files:
125
+ - spec/lib/ThreeStore_spec.rb
126
+ - spec/spec_helper.rb