s3batch 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/s3batch.rb CHANGED
@@ -6,6 +6,7 @@ require File.expand_path(File.dirname(__FILE__) + '/s3batch/happening_patch')
6
6
  require File.expand_path(File.dirname(__FILE__) + '/s3batch/multi_delete')
7
7
  require File.expand_path(File.dirname(__FILE__) + '/s3batch/batch_upload')
8
8
  require File.expand_path(File.dirname(__FILE__) + '/s3batch/website_enabler')
9
+ require File.expand_path(File.dirname(__FILE__) + '/s3batch/bucket_creator')
9
10
 
10
11
  #ruby s3batch.rb S3ID S3KEY BUCKET DIR
11
12
  if $0 == __FILE__
@@ -15,7 +16,8 @@ if $0 == __FILE__
15
16
  dir = ARGV[3]
16
17
  pattern = ARGV[4] || "**/*"
17
18
 
18
- S3Batch::WebsiteEnabler.run s3id, s3key, bucket
19
+ S3Batch::BucketCreator.run s3id, s3key, bucket
20
+ #S3Batch::WebsiteEnabler.run s3id, s3key, bucket
19
21
  #S3Batch::Upload.run s3id, s3key, bucket, dir, pattern
20
22
  #S3Batch::Delete.run s3id, s3key, bucket, [dir]
21
23
  end
@@ -0,0 +1,31 @@
1
+ module S3Batch
2
+ class BucketCreator < Happening::S3::Item
3
+ def path(with_bucket=true)
4
+ with_bucket ? "/#{bucket}/" : "/"
5
+ end
6
+
7
+ def create region, request_options = {}, &blk
8
+ data =<<EOF
9
+ <CreateBucketConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
10
+ <LocationConstraint>#{region}</LocationConstraint>
11
+ </CreateBucketConfiguration>
12
+ EOF
13
+ data = '' unless region
14
+
15
+ md5 = Base64.encode64(Digest::MD5.digest(data)).strip
16
+ headers = aws.sign("PUT", path, {"Content-MD5" => md5})
17
+ request_options[:on_success] = blk if blk
18
+ request_options.update(:headers => headers, :data => data)
19
+ Happening::S3::Request.new(:put, url, {:ssl => options[:ssl]}.update(request_options)).execute
20
+ end
21
+
22
+ def self.run s3id, s3key, bucket, region = nil
23
+ EM.run {
24
+ on_error = Proc.new {|response| puts "An error occured: #{response.response}"; EM.stop; }
25
+ on_success = Proc.new {|response| puts "Created #{response.response}"; EM.stop; }
26
+ item = S3Batch::BucketCreator.new(bucket, "NO_USE", :aws_access_key_id => s3id, :aws_secret_access_key => s3key, :protocol => 'http')
27
+ item.create(region, :on_error => on_error, :on_success => on_success)
28
+ }
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: happening
16
- requirement: &75533120 !ruby/object:Gem::Requirement
16
+ requirement: &82850300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75533120
24
+ version_requirements: *82850300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &76159880 !ruby/object:Gem::Requirement
27
+ requirement: &82849940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *76159880
35
+ version_requirements: *82849940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mime-types
38
- requirement: &76159410 !ruby/object:Gem::Requirement
38
+ requirement: &82849600 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *76159410
46
+ version_requirements: *82849600
47
47
  description:
48
48
  email:
49
49
  - yong@intridea.com
@@ -55,6 +55,7 @@ files:
55
55
  - lib/s3batch/batch_upload.rb
56
56
  - lib/s3batch/website_enabler.rb
57
57
  - lib/s3batch/happening_patch.rb
58
+ - lib/s3batch/bucket_creator.rb
58
59
  - lib/s3batch.rb
59
60
  homepage: http://github.com/yong/s3batch
60
61
  licenses: []