cloudhdr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,128 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Cloudhdr::Job" do
4
+
5
+ before(:each) do
6
+ @api_key = 'abc123'
7
+ end
8
+
9
+ describe ".create" do
10
+ before(:each) do
11
+ @url = "#{Cloudhdr.base_url}/api/v1/jobs"
12
+ @params = {:api_key => @api_key,:input => "s3://bucket-name/file-name.jpg" }
13
+ @params_as_json = Cloudhdr::Base.encode(@params, :json)
14
+ @params_as_xml = Cloudhdr::Base.encode(@params, :xml)
15
+ end
16
+
17
+ it "should POST to the correct url and return a response" do
18
+ Cloudhdr::HTTP.should_receive(:post).with(@url + ".json", @params_as_json, {}).and_return(Cloudhdr::Response.new)
19
+ r = Cloudhdr::Job.create(@params)
20
+ r.class.should == Cloudhdr::Response
21
+ end
22
+
23
+ it "should apply the global API key when JSON and no api_key is passed" do
24
+ pending "Need to fix"
25
+ Cloudhdr.api_key = 'asdfasdf'
26
+ Cloudhdr::HTTP.should_receive(:post).with(@url + ".json",@params_as_json,{}) do |url, params, options|
27
+ Cloudhdr::Base.decode(params)['api_key'].should == Cloudhdr.api_key
28
+ end.and_return(Cloudhdr::Response.new)
29
+ Cloudhdr::Job.create(:input => @params[:input])
30
+ Cloudhdr.api_key = nil
31
+ end
32
+
33
+ it "should apply the global API key when XML and no api_key is passed" do
34
+ pending "Need to fix"
35
+ Cloudhdr.api_key = 'asdfasdf'
36
+ Cloudhdr::HTTP.should_receive(:post).with(@url + ".xml",@params_as_xml,{}) do |url, params, options|
37
+ Cloudhdr::Base.decode(params, :xml)['api_request']['api_key'].should == Cloudhdr.api_key
38
+ end.and_return(Cloudhdr::Response.new)
39
+ Cloudhdr::Job.create({:api_request => {:input => @params[:input]}}, {:format => :xml})
40
+ Cloudhdr.api_key = nil
41
+ end
42
+
43
+ it "should apply the global API key when an XML string is passed and no api_key is passed" do
44
+ pending "Need to fix"
45
+ Cloudhdr.api_key = 'asdfasdf'
46
+ Cloudhdr::HTTP.should_receive(:post).with(@url + ".json",@params_as_xml,{}) do |url, params, options|
47
+ Cloudhdr::Base.decode(params, :xml)['api_request']['api_key'] == Cloudhdr.api_key
48
+ end.and_return(Cloudhdr::Response.new)
49
+ Cloudhdr::Job.create({:input => @params[:input]}.to_xml(:root => :api_request), {:format => :xml})
50
+ Cloudhdr.api_key = nil
51
+ end
52
+
53
+ end
54
+
55
+
56
+ describe ".list" do
57
+ before(:each) do
58
+ @url = "#{Cloudhdr.base_url}/api/v1/jobs"
59
+ end
60
+
61
+ it "should GET the correct url and return a response" do
62
+ Cloudhdr::HTTP.stub(:get).with(@url + ".json", {:params => {:api_key => @api_key,
63
+ :page => 1,
64
+ :per_page => 50,
65
+ :state => nil}}).and_return(Cloudhdr::Response.new)
66
+ Cloudhdr::Response.should == Cloudhdr::Job.list(:api_key => @api_key).class
67
+ end
68
+
69
+ it "should merge params well" do
70
+ Cloudhdr::HTTP.stub(:get).with(@url + ".json", {:params => {:api_key => @api_key,
71
+ :page => 1,
72
+ :per_page => 50,
73
+ :some => 'param',
74
+ :state => nil}}).and_return(Cloudhdr::Response.new)
75
+ Cloudhdr::Response.should == Cloudhdr::Job.list(:api_key => @api_key, :params => {:some => 'param'}).class
76
+ end
77
+ end
78
+
79
+ describe ".details" do
80
+ before(:each) do
81
+ @job_id = 1
82
+ @url = "#{Cloudhdr.base_url}/api/v1/jobs/#{@job_id}"
83
+ end
84
+
85
+ it "should GET the correct url and return a response" do
86
+ Cloudhdr::HTTP.stub(:get).with(@url + ".json", {:params => {:api_key => @api_key}}).and_return(Cloudhdr::Response.new)
87
+ Cloudhdr::Response.should == Cloudhdr::Job.details(1, :api_key => @api_key).class
88
+ end
89
+ end
90
+
91
+ describe ".resubmit" do
92
+ before(:each) do
93
+ @job_id = 1
94
+ @url = "#{Cloudhdr.base_url}/api/v1/jobs/#{@job_id}/resubmit"
95
+ end
96
+
97
+ it "should GET the correct url and return a response" do
98
+ Cloudhdr::HTTP.stub(:get).with(@url + ".json", {:params => {:api_key => @api_key}}).and_return(Cloudhdr::Response.new)
99
+ Cloudhdr::Response.should == Cloudhdr::Job.resubmit(1, :api_key => @api_key).class
100
+ end
101
+ end
102
+
103
+ describe ".cancel" do
104
+ before(:each) do
105
+ @job_id = 1
106
+ @url = "#{Cloudhdr.base_url}/api/v1/jobs/#{@job_id}/cancel"
107
+ end
108
+
109
+ it "should GET the correct url and return a response" do
110
+ Cloudhdr::HTTP.stub(:get).with(@url + ".json", {:params => {:api_key => @api_key}}).and_return(Cloudhdr::Response.new)
111
+ Cloudhdr::Response.should == Cloudhdr::Job.cancel(1, :api_key => @api_key).class
112
+ end
113
+ end
114
+
115
+ describe ".delete" do
116
+ before(:each) do
117
+ @job_id = 1
118
+ @url = "#{Cloudhdr.base_url}/api/v1/jobs/#{@job_id}"
119
+ end
120
+
121
+ it "should DELETE the correct url and return a response" do
122
+ Cloudhdr::HTTP.stub(:delete).with(@url + ".json", {:params => {:api_key => @api_key}}).and_return(Cloudhdr::Response.new)
123
+ Cloudhdr::Response.should == Cloudhdr::Job.delete(1, :api_key => @api_key).class
124
+ end
125
+ end
126
+
127
+
128
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Cloudhdr::Response" do
4
+
5
+
6
+ describe "#success?" do
7
+ it "should return true when code is between 200 and 299" do
8
+ Cloudhdr::Response.new(:code => 200).success?.should be_true
9
+ Cloudhdr::Response.new(:code => 299).success?.should be_true
10
+ Cloudhdr::Response.new(:code => 250).success?.should be_true
11
+ end
12
+
13
+ it "should return false when code it less than 200 or greater than 299" do
14
+ Cloudhdr::Response.new(:code => 300).success?.should_not be_true
15
+ Cloudhdr::Response.new(:code => 199).success?.should_not be_true
16
+ end
17
+ end
18
+
19
+ describe "#errors" do
20
+ it "should return an empty array when body is not a Hash" do
21
+ Cloudhdr::Response.new(:body => 1).errors.should == []
22
+ Cloudhdr::Response.new(:body => "something").errors.should == []
23
+ Cloudhdr::Response.new(:body => [1]).errors.should == []
24
+ end
25
+
26
+ it "should return the value of the key 'errors' as a compacted array when body is a Hash" do
27
+ Cloudhdr::Response.new(:body => {'errors' => ['must be awesome']}).errors.should == ['must be awesome']
28
+ Cloudhdr::Response.new(:body => {'errors' => 'must be awesome'}).errors.should == ['must be awesome']
29
+ Cloudhdr::Response.new(:body => {'errors' => ['must be awesome', nil]}).errors.should == ['must be awesome']
30
+ Cloudhdr::Response.new(:body => {}).errors.should == []
31
+ end
32
+ end
33
+
34
+ describe "#body_without_wrapper" do
35
+ it "should return the body when the body is a string" do
36
+ Cloudhdr::Response.new(:body => "some text").body_without_wrapper.should == "some text"
37
+ end
38
+
39
+ it "should return the body when the body is not wrapped in api_response and is a hash" do
40
+ Cloudhdr::Response.new(:body => {'some' => 'hash'}).body_without_wrapper.should == {'some' => 'hash'}
41
+ end
42
+
43
+ it "should return body['api_response'] when body is a hash and body['api_response'] exists" do
44
+ Cloudhdr::Response.new(:body => {'api_response' => {'some' => 'hash'}}).body_without_wrapper.should == {'some' => 'hash'}
45
+ end
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,22 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'webmock/rspec'
9
+ #require 'mocha/api'
10
+
11
+ require File.expand_path("../../lib/cloudhdr", __FILE__)
12
+ RSpec.configure do |config|
13
+ config.treat_symbols_as_metadata_keys_with_true_values = true
14
+ config.run_all_when_everything_filtered = true
15
+ config.filter_run :focus
16
+
17
+ # Run specs in random order to surface order dependencies. If you find an
18
+ # order dependency and want to debug it, you can fix the order by providing
19
+ # the seed, which is printed after each run.
20
+ # --seed 1234
21
+ config.order = 'random'
22
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudhdr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jeremy Green
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>'
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>'
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.13.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.11.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.11.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: builder
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 3.2.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 3.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Ruby wrapper for the CloudHdr Processing API
112
+ email:
113
+ - jeremy@octolabs.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - cloudhdr.gemspec
125
+ - lib/cloudhdr.rb
126
+ - lib/cloudhdr/base.rb
127
+ - lib/cloudhdr/cloudhdr.rb
128
+ - lib/cloudhdr/errors.rb
129
+ - lib/cloudhdr/extensions.rb
130
+ - lib/cloudhdr/http.rb
131
+ - lib/cloudhdr/http/net_http.rb
132
+ - lib/cloudhdr/http/typhoeus.rb
133
+ - lib/cloudhdr/job.rb
134
+ - lib/cloudhdr/response.rb
135
+ - lib/cloudhdr/version.rb
136
+ - spec/cloudhdr/cloudhdr_spec.rb
137
+ - spec/cloudhdr/http/net_http_spec.rb
138
+ - spec/cloudhdr/http/typhoeus_spec.rb
139
+ - spec/cloudhdr/http_spec.rb
140
+ - spec/cloudhdr/job_spec.rb
141
+ - spec/cloudhdr/response_spec.rb
142
+ - spec/spec_helper.rb
143
+ homepage: ''
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - '>='
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.0.3
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Ruby wrapper for the CloudHdr Processing API
167
+ test_files:
168
+ - spec/cloudhdr/cloudhdr_spec.rb
169
+ - spec/cloudhdr/http/net_http_spec.rb
170
+ - spec/cloudhdr/http/typhoeus_spec.rb
171
+ - spec/cloudhdr/http_spec.rb
172
+ - spec/cloudhdr/job_spec.rb
173
+ - spec/cloudhdr/response_spec.rb
174
+ - spec/spec_helper.rb