spec/capgun/client_spec.rb in capgun-0.1.0 vs spec/capgun/client_spec.rb in capgun-0.1.1
- old
+ new
@@ -9,44 +9,44 @@
context "invalid client" do
specify "not allowed to get estimates without authorization" do
stub_request(:post, "https://api.capgun.io/v1/orders/estimate.json").
with(:body => "{\"url\":\"http://example.com/test\"}",
- :headers => {'Accept'=>'application/json', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 401, :body => fixture("unauthorized.json"), :headers => {})
lambda { Capgun.estimate("http://example.com/test") }.should raise_error(Capgun::Error::Unauthorized, "Unauthorized")
end
specify "no urls are submitted for capture" do
stub_request(:post, "https://api.capgun.io/v1/orders.json").
with(:body => "{\"url\":\"http://example.com/test\"}",
- :headers => {'Accept'=>'application/json', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 401, :body => fixture("unauthorized.json"), :headers => {})
lambda { Capgun.capture("http://example.com/test") }.should raise_error(Capgun::Error::Unauthorized, "Unauthorized")
end
specify "not allowed to view on order without authorization" do
stub_request(:get, "https://api.capgun.io/v1/orders/4fd20a1288f560177600000a.json").
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 401, :body => fixture("unauthorized.json"), :headers => {})
lambda { Capgun.order("4fd20a1288f560177600000a") }.should raise_error(Capgun::Error::Unauthorized, "Unauthorized")
end
specify "not allowed to view job status without authorization" do
stub_request(:get, "https://api.capgun.io/v1/jobs/4fd20a1288f5601776000012.json").
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 401, :body => fixture('unauthorized.json'), :headers => {})
lambda { Capgun.status("4fd20a1288f5601776000012") }.should raise_error(Capgun::Error::Unauthorized, "Unauthorized")
end
specify "not allowed to view account" do
stub_request(:get, "https://api.capgun.io/v1/account.json").
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 401, :body => fixture('unauthorized.json'), :headers => {})
lambda { Capgun.account }.should raise_error(Capgun::Error::Unauthorized, "Unauthorized")
end
@@ -65,21 +65,21 @@
end
specify "get an estimate to capture a url" do
stub_request(:post, "https://api.capgun.io/v1/orders/estimate.json").
with(:body => "{\"url\":\"http://example.com/test\"}",
- :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture("estimate.json"), :headers => {})
estimate = Capgun.estimate("http://example.com/test")
estimate.cost.should == 1
end
specify "estimate with options in a block" do
stub_request(:post, "https://api.capgun.io/v1/orders/estimate.json").
with(:body => '{"viewport":"1024x2048","packages":["images","viewport"],"url":"http://example.com/test"}',
- :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture("estimate-with-options.json"), :headers => {})
estimate = Capgun.estimate("http://example.com/test", :viewport => "200x100") do |options|
options.packages = ['images', 'viewport']
options.viewport = '1024x2048'
@@ -88,22 +88,22 @@
end
specify "urls are submitted for capture" do
stub_request(:post, "https://api.capgun.io/v1/orders.json").
with(:body => "{\"url\":\"http://example.com/test\"}",
- :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture("order.json"), :headers => {})
order = Capgun.capture("http://example.com/test")
order.id.should == '4fd20a1288f560177600000a'
order.cost.should == 1
end
specify "capture with options can be in a block" do
stub_request(:post, "https://api.capgun.io/v1/orders.json").
with(:body => '{"packages":["images","viewport"],"viewport":"1024x2048","url":"http://example.com/test"}',
- :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture("order-with-options.json"), :headers => {})
order = Capgun.capture("http://example.com/test", :packages => [ :images, :viewport ], :viewport => "1024x2048")
order.id.should == '4fd20a1288f560177600000a'
order.cost.should == 1
@@ -112,11 +112,11 @@
end
specify "capture with options can be in a block" do
stub_request(:post, "https://api.capgun.io/v1/orders.json").
with(:body => '{"viewport":"1024x2048","packages":["images","viewport"],"url":"http://example.com/test"}',
- :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture("order-with-options.json"), :headers => {})
order = Capgun.capture("http://example.com/test", :viewport => "200x100") do |options|
options.packages = ['images', 'viewport']
options.viewport = '1024x2048'
@@ -127,31 +127,31 @@
order.packages.should == ['base', 'images', 'viewport']
end
specify "showing a capture order" do
stub_request(:get, "https://api.capgun.io/v1/orders/4fd20a1288f560177600000a.json").
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture("order.json"), :headers => {})
order = Capgun.order("4fd20a1288f560177600000a")
order.id.should == '4fd20a1288f560177600000a'
order.cost.should == 1
end
specify "capture jobs have a status" do
stub_request(:get, "https://api.capgun.io/v1/jobs/4fd20a1288f5601776000012.json").
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture('job.json'), :headers => {})
job = Capgun.status("4fd20a1288f5601776000012")
job.id.should == '4fd20a1288f5601776000012'
job.state.should == 'initialized'
end
specify "account can be retrieved" do
stub_request(:get, "https://api.capgun.io/v1/account.json").
- with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.0.3'}).
+ with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'test', 'User-Agent'=>'Capgun.io Ruby Gem 0.1.1'}).
to_return(:status => 200, :body => fixture('account.json'), :headers => {})
account = Capgun.account
account.id.should == '4fd193db88f5600472000001'
account.name.should == 'Acme Co.'