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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62ad288812b561ef44fb7da891c744a3f703bff7
4
- data.tar.gz: 2022328ba2e73d65a131cafa976389e3b443cd5b
3
+ metadata.gz: f0985b57a670034c7945f5e36a9cc90101bf8f83
4
+ data.tar.gz: d0092b586366a543d87a11cec7b739c325fb7f50
5
5
  SHA512:
6
- metadata.gz: f9ab7f72fe0aceb9dad7b35e9b9da672dd11a1dd1b60e12fdc8a8e77ebae33a9bc08e509de75d10b0acde640ca6d4811eece4faf51ef079f76a48955cb15eaf4
7
- data.tar.gz: 93f01442df08707277bf9860e91212fda599c2809b1cec67f95a287184b943a27f507e97e2cd941fab75c74a815d99325a27bf0932d82816c39a8338d444fb2a
6
+ metadata.gz: 51b4dfac648230d1fd5e0e1623045e38ead1401db50509e6b982b1cd4a6b59b93e240c0dd9ce95329a139104745267db76307b0569258bfb64313cc21033b3e6
7
+ data.tar.gz: 1e388b5863a1f2a9808c3b1a59040464a1b35386296ad0d81afb53f578320da1b9b4745cf21b604430c695bf7b194551737e965d608d189f2a552ac98010af80
data/AUTHORS CHANGED
@@ -1,2 +1,4 @@
1
- Norbert Crombach
1
+ Mark Oude Veldhuis
2
2
  Matthijs Langenberg
3
+ Mislav Marohnić
4
+ Norbert Crombach
@@ -1,3 +1,3 @@
1
- %w( resource representation middleware ).each do |component|
1
+ %w( error resource representation middleware ).each do |component|
2
2
  require File.join(File.expand_path(File.dirname(__FILE__)), 'ahora', component)
3
3
  end
@@ -0,0 +1,6 @@
1
+ module Ahora
2
+ module Error
3
+ ClientError = Module.new
4
+ TimeoutError = Module.new
5
+ end
6
+ end
@@ -5,23 +5,35 @@ module Ahora
5
5
  attr_writer :document_parser
6
6
 
7
7
  def get(url, params = nil)
8
- connection.run_request(:get, url, nil, nil) do |req|
9
- req.params.update(params) if params
10
- yield req if block_given?
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
- connection.run_request(:post, url, body, nil) do |req|
17
- yield req if block_given?
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
- connection.run_request(:put, url, body, nil) do |req|
24
- yield req if block_given?
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
@@ -1,3 +1,3 @@
1
1
  module Ahora
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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.3
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-02 00:00:00.000000000 Z
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