ahora 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/AUTHORS +3 -1
- data/lib/ahora.rb +1 -1
- data/lib/ahora/error.rb +6 -0
- data/lib/ahora/resource.rb +31 -7
- data/lib/ahora/version.rb +1 -1
- data/test/ahora/resource_test.rb +26 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0985b57a670034c7945f5e36a9cc90101bf8f83
|
4
|
+
data.tar.gz: d0092b586366a543d87a11cec7b739c325fb7f50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51b4dfac648230d1fd5e0e1623045e38ead1401db50509e6b982b1cd4a6b59b93e240c0dd9ce95329a139104745267db76307b0569258bfb64313cc21033b3e6
|
7
|
+
data.tar.gz: 1e388b5863a1f2a9808c3b1a59040464a1b35386296ad0d81afb53f578320da1b9b4745cf21b604430c695bf7b194551737e965d608d189f2a552ac98010af80
|
data/AUTHORS
CHANGED
data/lib/ahora.rb
CHANGED
data/lib/ahora/error.rb
ADDED
data/lib/ahora/resource.rb
CHANGED
@@ -5,23 +5,35 @@ module Ahora
|
|
5
5
|
attr_writer :document_parser
|
6
6
|
|
7
7
|
def get(url, params = nil)
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
begin
|
9
|
+
connection.run_request(:get, url, nil, nil) do |req|
|
10
|
+
req.params.update(params) if params
|
11
|
+
yield req if block_given?
|
12
|
+
end
|
13
|
+
rescue => e
|
14
|
+
handle_exception(e)
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
18
|
# FIXME test
|
15
19
|
def post(url, body = nil)
|
16
|
-
|
17
|
-
|
20
|
+
begin
|
21
|
+
connection.run_request(:post, url, body, nil) do |req|
|
22
|
+
yield req if block_given?
|
23
|
+
end
|
24
|
+
rescue => e
|
25
|
+
handle_exception(e)
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
21
29
|
# FIXME test
|
22
30
|
def put(url, body = nil)
|
23
|
-
|
24
|
-
|
31
|
+
begin
|
32
|
+
connection.run_request(:put, url, body, nil) do |req|
|
33
|
+
yield req if block_given?
|
34
|
+
end
|
35
|
+
rescue => e
|
36
|
+
handle_exception(e)
|
25
37
|
end
|
26
38
|
end
|
27
39
|
|
@@ -64,6 +76,7 @@ module Ahora
|
|
64
76
|
end
|
65
77
|
|
66
78
|
private
|
79
|
+
|
67
80
|
def document_parser
|
68
81
|
@document_parser ||= XmlParser.method(:parse)
|
69
82
|
end
|
@@ -72,5 +85,16 @@ module Ahora
|
|
72
85
|
(defined?(super) ? super.dup : {}).update \
|
73
86
|
:headers => headers
|
74
87
|
end
|
88
|
+
|
89
|
+
def handle_exception(e)
|
90
|
+
case e
|
91
|
+
when Faraday::Error::TimeoutError
|
92
|
+
e.extend Ahora::Error::TimeoutError
|
93
|
+
else
|
94
|
+
e.extend Ahora::Error::ClientError
|
95
|
+
end
|
96
|
+
raise
|
97
|
+
end
|
98
|
+
|
75
99
|
end
|
76
100
|
end
|
data/lib/ahora/version.rb
CHANGED
data/test/ahora/resource_test.rb
CHANGED
@@ -77,3 +77,29 @@ describe '#put' do
|
|
77
77
|
}.body.must_equal 'param'
|
78
78
|
end
|
79
79
|
end
|
80
|
+
|
81
|
+
describe 'exception handling' do
|
82
|
+
before do
|
83
|
+
@post = DefaultPost.new
|
84
|
+
end
|
85
|
+
|
86
|
+
%w(get post put).each do |http_method|
|
87
|
+
|
88
|
+
describe "##{http_method}" do
|
89
|
+
it 'should raise a TimeoutError in case of a Faraday timeout' do
|
90
|
+
FakeWeb.register_uri http_method.to_sym, 'http://test.net/posts', :exception => Faraday::Error::TimeoutError
|
91
|
+
lambda {
|
92
|
+
@post.send(http_method, 'posts')
|
93
|
+
}.must_raise Ahora::Error::TimeoutError
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should raise an ClientError in case of a Faraday error' do
|
97
|
+
FakeWeb.register_uri http_method.to_sym, 'http://test.net/posts', :body => 'Forbidden', :status => [403, 'Forbidden']
|
98
|
+
lambda {
|
99
|
+
@post.send(http_method, 'posts')
|
100
|
+
}.must_raise Ahora::Error::ClientError
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthijs Langenberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nibbler
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- ahora.gemspec
|
111
111
|
- lib/ahora.rb
|
112
|
+
- lib/ahora/error.rb
|
112
113
|
- lib/ahora/middleware.rb
|
113
114
|
- lib/ahora/middleware/last_modified_caching.rb
|
114
115
|
- lib/ahora/middleware/request_logger.rb
|