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.
@@ -1,40 +1,33 @@
1
1
  module Faraday
2
2
  class Response::RaiseHttpErrors < Response::Middleware
3
- def self.register_on_complete(env)
4
- env[:response].on_complete do |response|
5
- case response[:status].to_i
6
- when 400
7
- raise TropoRest::BadRequest, error_message(response)
8
- when 401
9
- raise TropoRest::NotAuthorized, error_message(response)
10
- when 403
11
- raise TropoRest::AccessDenied, error_message(response)
12
- when 404
13
- raise TropoRest::NotFound, error_message(response)
14
- when 405
15
- raise TropoRest::MethodNotAllowed, error_message(response)
16
- when 415
17
- raise TropoRest::UnsupportedMediaType, error_message(response)
18
- when 500
19
- raise TropoRest::InternalServerError, error_message(response)
20
- when 503
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
- def initialize(app)
27
- super
28
- @parser = nil
29
- end
30
-
31
- private
24
+ private
32
25
 
33
- def self.error_message(response)
34
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
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 self.error_body(body)
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
- class << self
4
- attr_accessor :resource
5
- end
6
-
7
- def self.register_on_complete(env)
8
- env[:response].on_complete do |response|
9
- if resource
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
- self.class.resource = resource
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 |connection|
18
- connection.use Faraday::Request::SerializeJson
19
- connection.adapter(adapter)
20
- connection.basic_auth(username, password)
21
- connection.use Faraday::Response::ParseJson
22
- connection.use Faraday::Response::Resource, resource
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
@@ -1,3 +1,3 @@
1
1
  module TropoRest
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/tropo_rest.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'hashie/mash'
1
2
  require 'hashie/twash'
2
3
 
3
4
  require 'tropo_rest/resource/address'
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,4 @@
1
- Bundler.require
1
+ require 'bundler/setup'
2
2
  require 'tropo_rest'
3
3
  require 'webmock/rspec'
4
4
 
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.5.3"
41
- s.add_runtime_dependency "faraday_middleware", "~> 0.3.1"
42
- s.add_runtime_dependency "multi_json", "~> 0.0.5"
43
- s.add_runtime_dependency "hashie", "~> 0.4.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
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-03-12 23:00:00 -07:00
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.5.3
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.3.1
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.5
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.4.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: 1958669569557374112
234
+ hash: -4002703830484713363
235
235
  segments:
236
236
  - 0
237
237
  version: "0"