tropo_rest 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/faraday/response/raise_http_errors.rb +22 -29
- data/lib/faraday/response/resource.rb +8 -14
- data/lib/tropo_rest/connection.rb +8 -7
- data/lib/tropo_rest/version.rb +1 -1
- data/lib/tropo_rest.rb +1 -0
- data/spec/spec_helper.rb +1 -1
- data/tropo_rest.gemspec +4 -4
- metadata +7 -7
@@ -1,40 +1,33 @@
|
|
1
1
|
module Faraday
|
2
2
|
class Response::RaiseHttpErrors < Response::Middleware
|
3
|
-
def
|
4
|
-
env[:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
raise TropoRest::ServiceUnavailable, error_message(response)
|
22
|
-
end
|
3
|
+
def on_complete(env)
|
4
|
+
case env[:status].to_i
|
5
|
+
when 400
|
6
|
+
raise TropoRest::BadRequest, error_message(env)
|
7
|
+
when 401
|
8
|
+
raise TropoRest::NotAuthorized, error_message(env)
|
9
|
+
when 403
|
10
|
+
raise TropoRest::AccessDenied, error_message(env)
|
11
|
+
when 404
|
12
|
+
raise TropoRest::NotFound, error_message(env)
|
13
|
+
when 405
|
14
|
+
raise TropoRest::MethodNotAllowed, error_message(env)
|
15
|
+
when 415
|
16
|
+
raise TropoRest::UnsupportedMediaType, error_message(env)
|
17
|
+
when 500
|
18
|
+
raise TropoRest::InternalServerError, error_message(env)
|
19
|
+
when 503
|
20
|
+
raise TropoRest::ServiceUnavailable, error_message(env)
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
|
27
|
-
super
|
28
|
-
@parser = nil
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
24
|
+
private
|
32
25
|
|
33
|
-
def
|
34
|
-
"#{
|
26
|
+
def error_message(env)
|
27
|
+
"#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
|
35
28
|
end
|
36
29
|
|
37
|
-
def
|
30
|
+
def error_body(body)
|
38
31
|
if body.nil?
|
39
32
|
nil
|
40
33
|
elsif body['error']
|
@@ -1,25 +1,19 @@
|
|
1
1
|
module Faraday
|
2
2
|
class Response::Resource < Response::Middleware
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
response_body = response[:body]
|
11
|
-
if response_body.is_a?(Hash)
|
12
|
-
response[:body] = resource.new(response_body)
|
13
|
-
elsif response_body.is_a?(Array)
|
14
|
-
response[:body] = response_body.map{|item| item.is_a?(Hash) ? resource.new(item) : item}
|
15
|
-
end
|
3
|
+
def on_complete(env)
|
4
|
+
if @resource
|
5
|
+
response_body = env[:body]
|
6
|
+
if response_body.is_a?(Hash)
|
7
|
+
env[:body] = @resource.new(response_body)
|
8
|
+
elsif response_body.is_a?(Array)
|
9
|
+
env[:body] = response_body.map{|item| item.is_a?(Hash) ? @resource.new(item) : item}
|
16
10
|
end
|
17
11
|
end
|
18
12
|
end
|
19
13
|
|
20
14
|
def initialize(app, resource=nil)
|
21
15
|
super app
|
22
|
-
|
16
|
+
@resource = resource
|
23
17
|
@parser = nil
|
24
18
|
end
|
25
19
|
end
|
@@ -14,14 +14,15 @@ module TropoRest
|
|
14
14
|
:url => url
|
15
15
|
}
|
16
16
|
|
17
|
-
Faraday::Connection.new(options) do |
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
connection.use Faraday::Response::RaiseHttpErrors
|
17
|
+
connection = Faraday::Connection.new(options) do |builder|
|
18
|
+
builder.use Faraday::Request::SerializeJson
|
19
|
+
builder.use Faraday::Response::Resource, resource
|
20
|
+
builder.use Faraday::Response::ParseJson
|
21
|
+
builder.use Faraday::Response::RaiseHttpErrors
|
22
|
+
builder.adapter(adapter)
|
24
23
|
end
|
24
|
+
connection.basic_auth(username, password)
|
25
|
+
connection
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
data/lib/tropo_rest/version.rb
CHANGED
data/lib/tropo_rest.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/tropo_rest.gemspec
CHANGED
@@ -37,10 +37,10 @@ Gem::Specification.new do |s|
|
|
37
37
|
s.add_development_dependency "ruby-debug" unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "rbx"
|
38
38
|
end
|
39
39
|
|
40
|
-
s.add_runtime_dependency "faraday", "~> 0.
|
41
|
-
s.add_runtime_dependency "faraday_middleware", "~> 0.
|
42
|
-
s.add_runtime_dependency "multi_json", "~> 0.0
|
43
|
-
s.add_runtime_dependency "hashie", "~> 0.
|
40
|
+
s.add_runtime_dependency "faraday", "~> 0.6.0"
|
41
|
+
s.add_runtime_dependency "faraday_middleware", "~> 0.6.0"
|
42
|
+
s.add_runtime_dependency "multi_json", "~> 1.0.0"
|
43
|
+
s.add_runtime_dependency "hashie", "~> 1.0.0"
|
44
44
|
|
45
45
|
s.files = `git ls-files`.split("\n")
|
46
46
|
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: tropo_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0
|
5
|
+
version: 0.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Christopher Durtschi
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-06-04 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ~>
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: 0.
|
133
|
+
version: 0.6.0
|
134
134
|
type: :runtime
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: *id011
|
@@ -141,7 +141,7 @@ dependencies:
|
|
141
141
|
requirements:
|
142
142
|
- - ~>
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: 0.
|
144
|
+
version: 0.6.0
|
145
145
|
type: :runtime
|
146
146
|
prerelease: false
|
147
147
|
version_requirements: *id012
|
@@ -152,7 +152,7 @@ dependencies:
|
|
152
152
|
requirements:
|
153
153
|
- - ~>
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version: 0.0
|
155
|
+
version: 1.0.0
|
156
156
|
type: :runtime
|
157
157
|
prerelease: false
|
158
158
|
version_requirements: *id013
|
@@ -163,7 +163,7 @@ dependencies:
|
|
163
163
|
requirements:
|
164
164
|
- - ~>
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 1.0.0
|
167
167
|
type: :runtime
|
168
168
|
prerelease: false
|
169
169
|
version_requirements: *id014
|
@@ -231,7 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
231
231
|
requirements:
|
232
232
|
- - ">="
|
233
233
|
- !ruby/object:Gem::Version
|
234
|
-
hash:
|
234
|
+
hash: -4002703830484713363
|
235
235
|
segments:
|
236
236
|
- 0
|
237
237
|
version: "0"
|