simples3 0.0.1
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 +4 -0
- data/Gemfile +4 -0
- data/README.markdown +32 -0
- data/Rakefile +10 -0
- data/lib/simples3.rb +62 -0
- data/lib/simples3/version.rb +3 -0
- data/simples3.gemspec +24 -0
- data/spec/simples3/simples3_spec.rb +15 -0
- data/spec/spec_helper.rb +12 -0
- metadata +102 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# simples3
|
2
|
+
## Install
|
3
|
+
### coming soon
|
4
|
+
$ gem install simples3
|
5
|
+
|
6
|
+
### from source
|
7
|
+
$ git clone http://github.com/forrestgrant/simples3
|
8
|
+
$ cd simples3
|
9
|
+
$ rake build
|
10
|
+
$ rake install
|
11
|
+
|
12
|
+
## Configuration
|
13
|
+
Add `config/simples3.yml` with the following:
|
14
|
+
|
15
|
+
development:
|
16
|
+
bucket_name: appname_development
|
17
|
+
access_key_id:
|
18
|
+
secret_access_key:
|
19
|
+
|
20
|
+
test:
|
21
|
+
bucket_name: appname_test
|
22
|
+
access_key_id:
|
23
|
+
secret_access_key:
|
24
|
+
|
25
|
+
production:
|
26
|
+
bucket_name: appname
|
27
|
+
access_key_id:
|
28
|
+
secret_access_key:
|
29
|
+
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
See `lib/simples3.rb` for methods
|
data/Rakefile
ADDED
data/lib/simples3.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'aws/s3'
|
2
|
+
|
3
|
+
module Simples3
|
4
|
+
|
5
|
+
class Config < RuntimeError; end
|
6
|
+
|
7
|
+
def self.ensure_connection
|
8
|
+
raise Config.new "#{Rails.root}/config/simples3.yml not found." unless File.exists?("#{Rails.root}/config/simples3.yml")
|
9
|
+
@@config = YAML.load(ERB.new(File.read("#{Rails.root}/config/simples3.yml")).result)[RAILS_ENV].symbolize_keys
|
10
|
+
@@connection = AWS::S3::Base.establish_connection!(
|
11
|
+
:access_key_id => @@config[:access_key_id],
|
12
|
+
:secret_access_key => @@config[:secret_access_key]
|
13
|
+
) if AWS::S3::Base.connections.empty?
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.file_exists?(path, bucket = nil)
|
17
|
+
ensure_connection
|
18
|
+
AWS::S3::S3Object.exists?( path, bucket || @@config[:bucket_name] )
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.about( path, bucket = nil )
|
22
|
+
ensure_connection
|
23
|
+
AWS::S3::S3Object.about( path, bucket || @@config[:bucket_name] )
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.delete(path, bucket = nil)
|
27
|
+
ensure_connection
|
28
|
+
Rails.logger.info "Deleting #{path} from S3..."
|
29
|
+
AWS::S3::S3Object.delete( path, bucket || @@config[:bucket_name] )
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.save(path, data, bucket = nil)
|
33
|
+
ensure_connection
|
34
|
+
Rails.logger.info "Saving #{path} to S3..."
|
35
|
+
AWS::S3::S3Object.store( path, data, bucket || @@config[:bucket_name], :access => :public_read, 'cache-control' => 'public', "expires" => (Time.now+20.years).httpdate )
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.move(from, to, bucket = nil)
|
39
|
+
ensure_connection
|
40
|
+
AWS::S3::S3Object.rename(from, to, bucket || @@config[:bucket_name])
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.list( path = '', bucket = nil)
|
44
|
+
ensure_connection
|
45
|
+
AWS::S3::Bucket.objects( bucket || @@config[:bucket_name] ).collect{|o| o.path.gsub("/#{self.bucket_name}",'')}.select{|o| o.match(/^\/#{path}\//)}
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.make_public( path = '', bucket = nil)
|
49
|
+
ensure_connection
|
50
|
+
object = AWS::S3::S3Object.find(path, bucket || @@config[:bucket_name])
|
51
|
+
object.acl.grants << AWS::S3::ACL::Grant.grant(:public_read)
|
52
|
+
object.acl( object.acl )
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.change_content_type( path = '', new_content_type = '', bucket = nil)
|
56
|
+
ensure_connection
|
57
|
+
object = AWS::S3::S3Object.find(path, bucket || @@config[:bucket_name])
|
58
|
+
object.content_type = new_content_type
|
59
|
+
object.store
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/simples3.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "simples3/version"
|
4
|
+
require "simples3/exceptions"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "simples3"
|
8
|
+
s.version = Simples3::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Forrest Grant"]
|
11
|
+
s.email = ["forrest@forrestgrant.com"]
|
12
|
+
s.homepage = "https://github.com/forrestgrant/simples3"
|
13
|
+
s.summary = %q{Makes AWS::S3 Calls simpler}
|
14
|
+
s.description = %q{Simple Wrapper for AWS::S3}
|
15
|
+
|
16
|
+
s.rubyforge_project = "simples3"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.add_dependency 'aws-s3'
|
23
|
+
s.add_development_dependency 'rspec-rails'
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Simples3 do
|
4
|
+
|
5
|
+
it "should load Simples3" do
|
6
|
+
Simples3.should_not be_nil
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should fail without config file" do
|
10
|
+
lambda {
|
11
|
+
Simples3.ensure_connection
|
12
|
+
}.should raise_error Simples3::Config
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simples3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Forrest Grant
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-03 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: aws-s3
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec-rails
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
description: Simple Wrapper for AWS::S3
|
49
|
+
email:
|
50
|
+
- forrest@forrestgrant.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- README.markdown
|
61
|
+
- Rakefile
|
62
|
+
- lib/simples3.rb
|
63
|
+
- lib/simples3/version.rb
|
64
|
+
- simples3.gemspec
|
65
|
+
- spec/simples3/simples3_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
67
|
+
homepage: https://github.com/forrestgrant/simples3
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 3
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
hash: 3
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: simples3
|
96
|
+
rubygems_version: 1.8.4
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Makes AWS::S3 Calls simpler
|
100
|
+
test_files:
|
101
|
+
- spec/simples3/simples3_spec.rb
|
102
|
+
- spec/spec_helper.rb
|