ungulate 0.0.0 → 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/Rakefile CHANGED
@@ -10,6 +10,7 @@ begin
10
10
  gem.email = "andrew@camelpunch.com"
11
11
  gem.homepage = "http://github.com/camelpunch/ungulate"
12
12
  gem.authors = ["Andrew Bruce"]
13
+ gem.add_dependency "activesupport", ">= 2.3.5"
13
14
  gem.add_dependency "right_aws", ">= 1.10.0"
14
15
  gem.add_dependency "rmagick", ">= 2.12.2"
15
16
  gem.add_development_dependency "rspec", ">= 1.2.9"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -0,0 +1,50 @@
1
+ require 'active_support'
2
+ require 'hmac/sha1'
3
+ class Ungulate::FileUpload
4
+ attr_accessor(
5
+ :access_key_id,
6
+ :bucket_url,
7
+ :key,
8
+ :policy,
9
+ :secret_access_key
10
+ )
11
+
12
+ def initialize(params)
13
+ self.access_key_id = params[:access_key_id]
14
+ self.bucket_url = params[:bucket_url]
15
+ self.key = params[:key]
16
+ self.policy = params[:policy]
17
+ self.secret_access_key = params[:secret_access_key]
18
+ end
19
+
20
+ def acl
21
+ condition 'acl'
22
+ end
23
+
24
+ def conditions
25
+ @conditions ||=
26
+ ActiveSupport::JSON.decode(@policy_json)['conditions'].
27
+ map {|condition| condition.to_a.flatten}
28
+ end
29
+
30
+ def policy=(json)
31
+ @policy_json = json
32
+ @policy = Base64.encode64(json).gsub("\n", '')
33
+ end
34
+
35
+ def success_action_redirect
36
+ condition 'success_action_redirect'
37
+ end
38
+
39
+ def signature
40
+ sha1 = HMAC::SHA1.new(secret_access_key)
41
+ sha1 << policy
42
+ Base64.encode64(sha1.digest).strip
43
+ end
44
+
45
+ protected
46
+
47
+ def condition(key)
48
+ conditions.find {|condition| condition.first == key}.second
49
+ end
50
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require 'ungulate/file_upload'
3
+
4
+ module Ungulate
5
+ describe FileUpload do
6
+ subject do
7
+ @bucket_url = "http://images.bob.com/"
8
+ @access_key_id = "asdf"
9
+ @key = "new-file"
10
+
11
+ @policy = '{ "expiration": "2007-12-01T12:00:00.000Z",
12
+ "conditions": [
13
+ {"bucket": "johnsmith" },
14
+ ["starts-with", "$key", "user/eric/"],
15
+ {"acl": "public-read" },
16
+ {"success_action_redirect": "http://johnsmith.s3.amazonaws.com/successful_upload.html" },
17
+ ["starts-with", "$Content-Type", "image/"],
18
+ {"x-amz-meta-uuid": "14365123651274"},
19
+ ["starts-with", "$x-amz-meta-tag", ""]
20
+ ]
21
+ }
22
+ '
23
+ @secret_access_key = 'uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o'
24
+
25
+ FileUpload.new(
26
+ :bucket_url => @bucket_url,
27
+ :access_key_id => @access_key_id,
28
+ :secret_access_key => @secret_access_key,
29
+ :policy => @policy,
30
+ :key => @key
31
+ )
32
+ end
33
+
34
+ its(:acl) { should == 'public-read' }
35
+ its(:bucket_url) { should == @bucket_url }
36
+ its(:conditions) { should == [
37
+ ['bucket', 'johnsmith'],
38
+ ['starts-with', '$key', 'user/eric/'],
39
+ ['acl', 'public-read'],
40
+ ['success_action_redirect', 'http://johnsmith.s3.amazonaws.com/successful_upload.html'],
41
+ ['starts-with', '$Content-Type', 'image/'],
42
+ ["x-amz-meta-uuid", "14365123651274"],
43
+ ["starts-with", "$x-amz-meta-tag", ""]
44
+ ] }
45
+ its(:access_key_id) { should == @access_key_id }
46
+ its(:key) { should == @key }
47
+ its(:success_action_redirect) { should == 'http://johnsmith.s3.amazonaws.com/successful_upload.html' }
48
+ its(:signature) { should == '4lCsX4TTdC/69HTJE7RWwEdJFgk=' }
49
+ its(:policy) { should == 'eyAiZXhwaXJhdGlvbiI6ICIyMDA3LTEyLTAxVDEyOjAwOjAwLjAwMFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJidWNrZXQiOiAiam9obnNtaXRoIiB9LAogICAgWyJzdGFydHMtd2l0aCIsICIka2V5IiwgInVzZXIvZXJpYy8iXSwKICAgIHsiYWNsIjogInB1YmxpYy1yZWFkIiB9LAogICAgeyJzdWNjZXNzX2FjdGlvbl9yZWRpcmVjdCI6ICJodHRwOi8vam9obnNtaXRoLnMzLmFtYXpvbmF3cy5jb20vc3VjY2Vzc2Z1bF91cGxvYWQuaHRtbCIgfSwKICAgIFsic3RhcnRzLXdpdGgiLCAiJENvbnRlbnQtVHlwZSIsICJpbWFnZS8iXSwKICAgIHsieC1hbXotbWV0YS11dWlkIjogIjE0MzY1MTIzNjUxMjc0In0sCiAgICBbInN0YXJ0cy13aXRoIiwgIiR4LWFtei1tZXRhLXRhZyIsICIiXQogIF0KfQo=' }
50
+
51
+ describe "conditions" do
52
+ it "should memoize" do
53
+ subject.instance_variable_set('@conditions', :cache)
54
+ subject.conditions.should == :cache
55
+ end
56
+ end
57
+ end
58
+ end
data/ungulate.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ungulate}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Bruce"]
12
- s.date = %q{2010-04-07}
12
+ s.date = %q{2010-04-08}
13
13
  s.default_executable = %q{ungulate_server.rb}
14
14
  s.description = %q{WIP}
15
15
  s.email = %q{andrew@camelpunch.com}
@@ -34,8 +34,10 @@ Gem::Specification.new do |s|
34
34
  "features/step_definitions/version_steps.rb",
35
35
  "features/support.rb",
36
36
  "lib/ungulate.rb",
37
+ "lib/ungulate/file_upload.rb",
37
38
  "spec/spec.opts",
38
39
  "spec/spec_helper.rb",
40
+ "spec/ungulate/file_upload_spec.rb",
39
41
  "spec/ungulate_spec.rb",
40
42
  "ungulate.gemspec"
41
43
  ]
@@ -46,6 +48,7 @@ Gem::Specification.new do |s|
46
48
  s.summary = %q{Process images using Amazon SQS and S3}
47
49
  s.test_files = [
48
50
  "spec/spec_helper.rb",
51
+ "spec/ungulate/file_upload_spec.rb",
49
52
  "spec/ungulate_spec.rb"
50
53
  ]
51
54
 
@@ -54,17 +57,20 @@ Gem::Specification.new do |s|
54
57
  s.specification_version = 3
55
58
 
56
59
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
60
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
57
61
  s.add_runtime_dependency(%q<right_aws>, [">= 1.10.0"])
58
62
  s.add_runtime_dependency(%q<rmagick>, [">= 2.12.2"])
59
63
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
60
64
  s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
61
65
  else
66
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
62
67
  s.add_dependency(%q<right_aws>, [">= 1.10.0"])
63
68
  s.add_dependency(%q<rmagick>, [">= 2.12.2"])
64
69
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
65
70
  s.add_dependency(%q<cucumber>, [">= 0.6.2"])
66
71
  end
67
72
  else
73
+ s.add_dependency(%q<activesupport>, [">= 2.3.5"])
68
74
  s.add_dependency(%q<right_aws>, [">= 1.10.0"])
69
75
  s.add_dependency(%q<rmagick>, [">= 2.12.2"])
70
76
  s.add_dependency(%q<rspec>, [">= 1.2.9"])
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Bruce
@@ -14,13 +14,27 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-07 00:00:00 +01:00
17
+ date: 2010-04-08 00:00:00 +01:00
18
18
  default_executable: ungulate_server.rb
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: right_aws
21
+ name: activesupport
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 3
30
+ - 5
31
+ version: 2.3.5
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: right_aws
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
24
38
  requirements:
25
39
  - - ">="
26
40
  - !ruby/object:Gem::Version
@@ -30,11 +44,11 @@ dependencies:
30
44
  - 0
31
45
  version: 1.10.0
32
46
  type: :runtime
33
- version_requirements: *id001
47
+ version_requirements: *id002
34
48
  - !ruby/object:Gem::Dependency
35
49
  name: rmagick
36
50
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
51
+ requirement: &id003 !ruby/object:Gem::Requirement
38
52
  requirements:
39
53
  - - ">="
40
54
  - !ruby/object:Gem::Version
@@ -44,11 +58,11 @@ dependencies:
44
58
  - 2
45
59
  version: 2.12.2
46
60
  type: :runtime
47
- version_requirements: *id002
61
+ version_requirements: *id003
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: rspec
50
64
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
65
+ requirement: &id004 !ruby/object:Gem::Requirement
52
66
  requirements:
53
67
  - - ">="
54
68
  - !ruby/object:Gem::Version
@@ -58,11 +72,11 @@ dependencies:
58
72
  - 9
59
73
  version: 1.2.9
60
74
  type: :development
61
- version_requirements: *id003
75
+ version_requirements: *id004
62
76
  - !ruby/object:Gem::Dependency
63
77
  name: cucumber
64
78
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
79
+ requirement: &id005 !ruby/object:Gem::Requirement
66
80
  requirements:
67
81
  - - ">="
68
82
  - !ruby/object:Gem::Version
@@ -72,7 +86,7 @@ dependencies:
72
86
  - 2
73
87
  version: 0.6.2
74
88
  type: :development
75
- version_requirements: *id004
89
+ version_requirements: *id005
76
90
  description: WIP
77
91
  email: andrew@camelpunch.com
78
92
  executables:
@@ -98,8 +112,10 @@ files:
98
112
  - features/step_definitions/version_steps.rb
99
113
  - features/support.rb
100
114
  - lib/ungulate.rb
115
+ - lib/ungulate/file_upload.rb
101
116
  - spec/spec.opts
102
117
  - spec/spec_helper.rb
118
+ - spec/ungulate/file_upload_spec.rb
103
119
  - spec/ungulate_spec.rb
104
120
  - ungulate.gemspec
105
121
  has_rdoc: true
@@ -134,4 +150,5 @@ specification_version: 3
134
150
  summary: Process images using Amazon SQS and S3
135
151
  test_files:
136
152
  - spec/spec_helper.rb
153
+ - spec/ungulate/file_upload_spec.rb
137
154
  - spec/ungulate_spec.rb