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 +22 -6
- data/panda.gemspec +1 -1
- data/spec/panda_spec.rb +15 -0
- metadata +1 -1
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
|
-
|
19
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
32
|
-
|
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
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
|