restfulie 1.0.0.beta5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -27,8 +27,8 @@ spec = Gem::Specification.new do |s|
27
27
  s.add_dependency("json_pure", [">= 1.2.4"])
28
28
  s.add_dependency("rack-conneg")
29
29
  s.add_dependency("sqlite3-ruby")
30
- s.add_dependency('tokamak', ">= 1.0.0.beta4")
31
- s.add_dependency('medie', ">= 1.0.0.beta4")
30
+ s.add_dependency('tokamak', "~> 1.1.2")
31
+ s.add_dependency('medie', "~> 1.0.0")
32
32
  s.add_dependency('respondie', "~> 0.9.0")
33
33
 
34
34
 
@@ -6,6 +6,7 @@ module Restfulie::Client
6
6
  trait :base
7
7
  trait :verb
8
8
  request :base_request
9
+ request :rescue_exception
9
10
  request :setup_header
10
11
  request :serialize_body
11
12
  request :enhance_response
@@ -11,25 +11,29 @@ class Restfulie::Client::Feature::BaseRequest
11
11
  def request!(method, host, path, request, flow, env)
12
12
 
13
13
  ::Restfulie::Common::Logger.logger.info(request.http_to_s(method, path, [request.headers])) if ::Restfulie::Common::Logger.logger
14
- begin
15
- http_request = get_connection_provider(host)
14
+ http_request = get_connection_provider(host)
16
15
 
17
- if env[:body]
18
- response = http_request.send(method, path, env[:body], request.headers)
19
- else
20
- response = http_request.send(method, path, request.headers)
21
- end
22
-
23
- rescue Exception => e
24
- response = e
16
+ if env[:body]
17
+ enhance http_request.send(method, path, env[:body], request.headers)
18
+ else
19
+ enhance http_request.send(method, path, request.headers)
25
20
  end
26
21
 
27
- response
28
-
29
22
  end
30
23
 
24
+ protected
25
+
31
26
  def get_connection_provider(host)
32
27
  @connection ||= ::Net::HTTP.new(host.host, host.port)
33
28
  end
29
+
30
+ private
31
+
32
+ def enhance(response)
33
+ def response.code
34
+ super.to_i
35
+ end
36
+ response
37
+ end
34
38
 
35
39
  end
@@ -11,7 +11,7 @@ module Restfulie::Client::Feature
11
11
 
12
12
  def execute(chain, request, env)
13
13
  resp = chain.continue(request, env)
14
- return resp if resp.code.to_i!=406
14
+ return resp if resp.code!=406
15
15
 
16
16
  accept = Medie.registry.for(resp.headers["Accept"])
17
17
  return resp if accept.nil?
@@ -0,0 +1,13 @@
1
+ # Simple feature that returns the exception in case it occurs.
2
+ # This feature is automatically loaded in the stack.
3
+ class Restfulie::Client::Feature::RescueException
4
+
5
+ def execute(flow, request, env)
6
+ begin
7
+ flow.continue(request, env)
8
+ rescue Exception => e
9
+ e
10
+ end
11
+ end
12
+
13
+ end
@@ -17,7 +17,7 @@ module Restfulie::Client::Feature
17
17
  # extension point that allows you to redefine
18
18
  # when a request should be retried
19
19
  def should_retry?(response, env)
20
- response.code.to_i == 503
20
+ response.code == 503
21
21
  end
22
22
 
23
23
  end
@@ -9,7 +9,7 @@ class Restfulie::Client::Feature::ThrowError
9
9
  Restfulie::Common::Logger.logger.error(result)
10
10
  raise Restfulie::Client::HTTP::Error::ServerNotAvailableError.new(request, Restfulie::Client::HTTP::Response.new(request.verb, request.path, 503, nil, {}), result )
11
11
  end
12
- case result.response.code.to_i
12
+ case result.response.code
13
13
  when 100..299
14
14
  result
15
15
  when 300..399
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restfulie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 62196361
5
- prerelease: 6
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - beta
11
- - 5
12
- version: 1.0.0.beta5
10
+ version: 1.0.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Guilherme Silveira, Caue Guerra, Luis Cipriani, Everton Ribeiro, George Guimaraes, Paulo Ahagon, and many more!
@@ -40,16 +38,14 @@ dependencies:
40
38
  requirement: &id002 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
- - - ">="
41
+ - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 62196363
43
+ hash: 23
46
44
  segments:
47
45
  - 1
48
- - 0
49
- - 0
50
- - beta
51
- - 4
52
- version: 1.0.0.beta4
46
+ - 1
47
+ - 2
48
+ version: 1.1.2
53
49
  type: :runtime
54
50
  version_requirements: *id002
55
51
  - !ruby/object:Gem::Dependency
@@ -58,16 +54,14 @@ dependencies:
58
54
  requirement: &id003 !ruby/object:Gem::Requirement
59
55
  none: false
60
56
  requirements:
61
- - - ">="
57
+ - - ~>
62
58
  - !ruby/object:Gem::Version
63
- hash: 62196363
59
+ hash: 23
64
60
  segments:
65
61
  - 1
66
62
  - 0
67
63
  - 0
68
- - beta
69
- - 4
70
- version: 1.0.0.beta4
64
+ version: 1.0.0
71
65
  type: :runtime
72
66
  version_requirements: *id003
73
67
  - !ruby/object:Gem::Dependency
@@ -155,6 +149,7 @@ files:
155
149
  - lib/restfulie/client/ext/open_search_ext.rb
156
150
  - lib/restfulie/client/ext.rb
157
151
  - lib/restfulie/client/feature/base.rb
152
+ - lib/restfulie/client/feature/rescue_exception.rb
158
153
  - lib/restfulie/client/feature/base_request.rb
159
154
  - lib/restfulie/client/feature/cache.rb
160
155
  - lib/restfulie/client/feature/conneg_when_unaccepted.rb