panda 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/panda/panda.rb CHANGED
@@ -15,21 +15,29 @@ class Panda
15
15
  end
16
16
 
17
17
  def get(request_uri, params={})
18
- query = signed_query("GET", request_uri, params)
19
- body_of @connection[request_uri + '?' + query].get
18
+ rescue_resclient_error do
19
+ query = signed_query("GET", request_uri, params)
20
+ body_of @connection[request_uri + '?' + query].get
21
+ end
20
22
  end
21
23
 
22
24
  def post(request_uri, params)
23
- body_of @connection[request_uri].post(signed_params("POST", request_uri, params))
25
+ rescue_resclient_error do
26
+ body_of @connection[request_uri].post(signed_params("POST", request_uri, params))
27
+ end
24
28
  end
25
29
 
26
30
  def put(request_uri, params)
27
- body_of @connection[request_uri].put(signed_params("PUT", request_uri, params))
31
+ rescue_resclient_error do
32
+ body_of @connection[request_uri].put(signed_params("PUT", request_uri, params))
33
+ end
28
34
  end
29
35
 
30
36
  def delete(request_uri, params={})
31
- query = signed_query("DELETE", request_uri, params)
32
- body_of @connection[request_uri + '?' + query].delete
37
+ rescue_resclient_error do
38
+ query = signed_query("DELETE", request_uri, params)
39
+ body_of @connection[request_uri + '?' + query].delete
40
+ end
33
41
  end
34
42
 
35
43
  def authentication_params(verb, request_uri, params)
@@ -65,6 +73,14 @@ class Panda
65
73
 
66
74
  private
67
75
 
76
+ def rescue_resclient_error(&block)
77
+ begin
78
+ yield
79
+ rescue RestClient::Exception => e
80
+ e.http_body
81
+ end
82
+ end
83
+
68
84
  # API change on rest-client 1.4
69
85
  def body_of(response)
70
86
  response.respond_to?(:body) ? response.body : response
data/panda.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{panda}
8
- s.version = "0.4.2"
8
+ s.version = "0.4.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["New Bamboo"]
data/spec/panda_spec.rb CHANGED
@@ -58,4 +58,19 @@ describe Panda do
58
58
  'space' => ' '
59
59
  }
60
60
  end
61
+
62
+ it "should return a json file for every http code" do
63
+ FakeWeb.register_uri(:get, "http://myapihost:85/v2/videos?timestamp=2009-11-04T17%3A54%3A11%2B00%3A00&signature=CxSYPM65SeeWH4CE%2FLcq7Ny2NtwxlpS8QOXG2BKe4p8%3D&access_key=my_access_key&cloud_id=my_cloud_id", :body => "abc")
64
+
65
+ resource = RestClient::Resource.new("http://myapihost:85/v2")
66
+ RestClient::Resource.stub!(:new).and_return(resource)
67
+
68
+ e = RestClient::Exception.new({:body => "abc", :code => 400})
69
+ e.stub!(:http_body).and_return("abc")
70
+
71
+ resource.stub!(:get).and_raise(e)
72
+
73
+ panda = Panda.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
74
+ panda.get("/videos").should == "abc"
75
+ end
61
76
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - New Bamboo