activeresource-response 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +12 -0
- data/README.rdoc +2 -2
- data/activeresource-response.gemspec +3 -3
- data/lib/active_resource_response.rb +35 -0
- data/lib/active_resource_response/connection.rb +47 -0
- data/lib/active_resource_response/http_response.rb +54 -0
- data/lib/active_resource_response/response.rb +15 -0
- data/lib/active_resource_response/response_method.rb +74 -0
- data/lib/active_resource_response/version.rb +28 -0
- data/lib/activeresource-response.rb +23 -11
- data/test/active_resource_response_test.rb +25 -4
- metadata +15 -7
- data/lib/activeresource-response/active_resource_response.rb +0 -15
- data/lib/activeresource-response/connection.rb +0 -22
- data/lib/activeresource-response/http_response.rb +0 -32
- data/lib/activeresource-response/response_method.rb +0 -41
- data/lib/activeresource-response/version.rb +0 -5
data/.travis.yml
ADDED
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
= Activeresource-response
|
2
|
-
|
1
|
+
= Activeresource-response
|
3
2
|
This gem adds possibility to access http response object from result (single object or collection) of activeresource call (methods : find, all, first, last, get )
|
4
3
|
|
4
|
+
== Build status {<img src="https://secure.travis-ci.org/Fivell/activeresource-response.png" />}[http://travis-ci.org/Fivell/activeresource-response]
|
5
5
|
|
6
6
|
|
7
7
|
== Why It can be used?
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "active_resource_response/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
|
7
7
|
s.name = "activeresource-response"
|
8
|
-
s.version =
|
8
|
+
s.version = ActiveResourceResponse::Version::VERSION
|
9
9
|
s.authors = ["Igor Fedoronchuk"]
|
10
10
|
s.email = ["fedoronchuk@gmail.com"]
|
11
11
|
s.homepage = "http://fivell.github.com/activeresource-response/"
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
|
16
16
|
s.add_dependency('activeresource', '>= 3.0')
|
17
|
-
|
17
|
+
s.add_dependency "jruby-openssl" if RUBY_PLATFORM == "java"
|
18
18
|
s.add_development_dependency "test-unit"
|
19
19
|
s.add_development_dependency 'rake'
|
20
20
|
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Igor Fedoronchuk
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
require 'cgi'
|
24
|
+
require 'active_resource'
|
25
|
+
require "active_resource_response/version"
|
26
|
+
require "active_resource_response/http_response"
|
27
|
+
require "active_resource_response/connection"
|
28
|
+
require "active_resource_response/response_method"
|
29
|
+
ActiveResource::Connection.send :include, ActiveResourceResponse::Connection
|
30
|
+
ActiveResource::Base.send :include, ActiveResourceResponse::ResponseMethod
|
31
|
+
if defined? ActiveResource::Response
|
32
|
+
require "active_resource_response/response"
|
33
|
+
ActiveResource::Response.send :include, ActiveResourceResponse::Response
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Igor Fedoronchuk
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
module ActiveResourceResponse
|
24
|
+
module Connection
|
25
|
+
def self.included(base)
|
26
|
+
base.class_eval do
|
27
|
+
alias_method :origin_handle_response, :handle_response
|
28
|
+
def handle_response(response)
|
29
|
+
|
30
|
+
begin
|
31
|
+
origin_handle_response(response)
|
32
|
+
rescue
|
33
|
+
|
34
|
+
raise
|
35
|
+
ensure
|
36
|
+
|
37
|
+
response.extend HttpResponse
|
38
|
+
Thread.current[:ActiveResourceResponse] = response
|
39
|
+
end
|
40
|
+
end
|
41
|
+
def http_response
|
42
|
+
Thread.current[:ActiveResourceResponse]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Igor Fedoronchuk
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
module ActiveResourceResponse
|
24
|
+
module HttpResponse
|
25
|
+
|
26
|
+
def headers
|
27
|
+
unless defined? @_active_resource_response_headers
|
28
|
+
@_active_resource_response_headers = symbolize_keys(to_hash)
|
29
|
+
end
|
30
|
+
@_active_resource_response_headers
|
31
|
+
end
|
32
|
+
|
33
|
+
def cookies
|
34
|
+
unless defined? @_active_resource_response_cookies
|
35
|
+
@_active_resource_response_cookies = (self.headers[:set_cookie] || {}).inject({}) do |out, cookie_str|
|
36
|
+
CGI::Cookie::parse(cookie_str).each do |key, cookie|
|
37
|
+
out[key] = cookie.value.first unless ['expires', 'path'].include? key
|
38
|
+
end
|
39
|
+
out
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@_active_resource_response_cookies
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def symbolize_keys(hash)
|
47
|
+
hash.inject({}) do |out, (key, value)|
|
48
|
+
out[key.gsub(/-/, '_').downcase.to_sym] = value
|
49
|
+
out
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveResourceResponse
|
2
|
+
module Response
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
def to_hash
|
6
|
+
@headers
|
7
|
+
end
|
8
|
+
# to avoid method name conflict with Response:HttpResponse:headers
|
9
|
+
def [](key)
|
10
|
+
@headers[key]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Igor Fedoronchuk
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
module ActiveResourceResponse
|
24
|
+
|
25
|
+
module ResponseMethod
|
26
|
+
|
27
|
+
def self.included(base)
|
28
|
+
base.extend ClassMethods
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
|
33
|
+
def http_response
|
34
|
+
connection.http_response
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def add_response_method(method_name = :http_response)
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
remove_response_method if methods.map(&:to_sym).include?(:find_without_http_response)
|
44
|
+
[:find, :get].each do |method|
|
45
|
+
instance_eval <<-EOS
|
46
|
+
alias #{method}_without_http_response #{method}
|
47
|
+
def #{method}(*arguments)
|
48
|
+
result = #{method}_without_http_response(*arguments)
|
49
|
+
result.instance_variable_set(:@http_response, connection.http_response)
|
50
|
+
def result.#{method_name}
|
51
|
+
@http_response
|
52
|
+
end
|
53
|
+
result
|
54
|
+
end
|
55
|
+
EOS
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def remove_response_method
|
60
|
+
|
61
|
+
|
62
|
+
[:find, :get].each do |method|
|
63
|
+
instance_eval <<-EOS
|
64
|
+
undef :#{method}
|
65
|
+
alias :#{method} :#{method}_without_http_response
|
66
|
+
undef :#{method}_without_http_response
|
67
|
+
EOS
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Igor Fedoronchuk
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
module ActiveResourceResponse
|
25
|
+
module Version
|
26
|
+
VERSION = "0.3.0"
|
27
|
+
end
|
28
|
+
end
|
@@ -1,12 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2012 Igor Fedoronchuk
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
11
23
|
|
12
|
-
|
24
|
+
require 'active_resource_response'
|
@@ -1,12 +1,12 @@
|
|
1
1
|
lib = File.expand_path("#{File.dirname(__FILE__)}/../lib")
|
2
|
-
|
2
|
+
unit_tests = File.expand_path("#{File.dirname(__FILE__)}/../test")
|
3
3
|
$:.unshift(lib)
|
4
|
-
$:.unshift(
|
4
|
+
$:.unshift(unit_tests)
|
5
5
|
|
6
6
|
require 'test/unit'
|
7
7
|
require 'active_resource'
|
8
8
|
require 'active_resource/http_mock'
|
9
|
-
require '
|
9
|
+
require 'active_resource_response'
|
10
10
|
require "fixtures/country"
|
11
11
|
|
12
12
|
|
@@ -16,11 +16,12 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
|
|
16
16
|
def setup
|
17
17
|
|
18
18
|
@country = {:country => {:id => 1, :name => "Ukraine", :iso=>"UA"}}
|
19
|
+
|
19
20
|
ActiveResource::HttpMock.respond_to do |mock|
|
20
21
|
mock.get "/countries.json", {}, [@country].to_json, 200, {"X-total"=>'1'}
|
21
22
|
mock.get "/countries/1.json", {}, @country.to_json, 200, {"X-total"=>'1', 'Set-Cookie'=>['path=/; expires=Tue, 20-Jan-2015 15:03:14 GMT, foo=bar, bar=foo']}
|
22
23
|
mock.get "/countries/1/count.json", {}, {:count => 1155}.to_json, 200, {"X-total"=>'1'}
|
23
|
-
|
24
|
+
mock.post "/countries.json" , {}, @country.to_json, 422, {"X-total"=>'1'}
|
24
25
|
|
25
26
|
end
|
26
27
|
|
@@ -33,6 +34,7 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
|
|
33
34
|
assert countries.respond_to?(:http)
|
34
35
|
assert countries.http.respond_to?(:cookies)
|
35
36
|
assert countries.http.respond_to?(:headers)
|
37
|
+
assert Country.respond_to?(:http_response)
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_get_headers_from_all
|
@@ -51,6 +53,8 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
|
|
51
53
|
assert_equal count.to_i, 1155
|
52
54
|
assert_equal Country.connection.http_response['X-total'].to_i, 1
|
53
55
|
assert_equal Country.connection.http_response.headers[:x_total].to_i, 1
|
56
|
+
assert_equal Country.http_response['X-total'].to_i ,1
|
57
|
+
|
54
58
|
|
55
59
|
end
|
56
60
|
|
@@ -67,6 +71,23 @@ class ActiveResourceResponseTest < Test::Unit::TestCase
|
|
67
71
|
country = Country.find(1)
|
68
72
|
assert_equal country.http.cookies['foo'] , 'bar'
|
69
73
|
assert_equal country.http.cookies['bar'] , 'foo'
|
74
|
+
#from class
|
75
|
+
assert_equal Country.http_response.cookies['foo'] , 'bar'
|
76
|
+
assert_equal Country.http_response.cookies['bar'] , 'foo'
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def test_get_headers_after_exception
|
82
|
+
|
83
|
+
Country.create(@country[:country])
|
84
|
+
|
85
|
+
assert_equal Country.http_response['X-total'].to_i, 1
|
86
|
+
|
87
|
+
assert_equal Country.http_response.code, 422
|
88
|
+
|
89
|
+
|
90
|
+
|
70
91
|
end
|
71
92
|
|
72
93
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource-response
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
@@ -68,17 +68,19 @@ extensions: []
|
|
68
68
|
extra_rdoc_files:
|
69
69
|
- README.rdoc
|
70
70
|
files:
|
71
|
+
- .travis.yml
|
71
72
|
- Gemfile
|
72
73
|
- LICENSE
|
73
74
|
- README.rdoc
|
74
75
|
- Rakefile
|
75
76
|
- activeresource-response.gemspec
|
77
|
+
- lib/active_resource_response.rb
|
78
|
+
- lib/active_resource_response/connection.rb
|
79
|
+
- lib/active_resource_response/http_response.rb
|
80
|
+
- lib/active_resource_response/response.rb
|
81
|
+
- lib/active_resource_response/response_method.rb
|
82
|
+
- lib/active_resource_response/version.rb
|
76
83
|
- lib/activeresource-response.rb
|
77
|
-
- lib/activeresource-response/active_resource_response.rb
|
78
|
-
- lib/activeresource-response/connection.rb
|
79
|
-
- lib/activeresource-response/http_response.rb
|
80
|
-
- lib/activeresource-response/response_method.rb
|
81
|
-
- lib/activeresource-response/version.rb
|
82
84
|
- test/active_resource_response_test.rb
|
83
85
|
- test/fixtures/country.rb
|
84
86
|
homepage: http://fivell.github.com/activeresource-response/
|
@@ -95,12 +97,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
97
|
- - ! '>='
|
96
98
|
- !ruby/object:Gem::Version
|
97
99
|
version: '0'
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
hash: 3062498070536117201
|
98
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
104
|
none: false
|
100
105
|
requirements:
|
101
106
|
- - ! '>='
|
102
107
|
- !ruby/object:Gem::Version
|
103
108
|
version: '0'
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
hash: 3062498070536117201
|
104
112
|
requirements: []
|
105
113
|
rubyforge_project:
|
106
114
|
rubygems_version: 1.8.24
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module ActiveResourceResponse
|
2
|
-
module Response
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
def to_hash
|
6
|
-
@headers
|
7
|
-
end
|
8
|
-
# to avoid method name conflict with ActiveresourceResponse:HttpResponse:headers
|
9
|
-
def [](key)
|
10
|
-
@headers[key]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module ActiveresourceResponse
|
2
|
-
module Connection
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
alias_method :origin_handle_response, :handle_response
|
6
|
-
def handle_response(response)
|
7
|
-
begin
|
8
|
-
origin_handle_response(response)
|
9
|
-
rescue StandardError => e
|
10
|
-
raise e
|
11
|
-
end
|
12
|
-
response.extend(ActiveresourceResponse::HttpResponse)
|
13
|
-
|
14
|
-
Thread.current[:ActiveResourceHttpResponse] = response
|
15
|
-
end
|
16
|
-
def http_response
|
17
|
-
Thread.current[:ActiveResourceHttpResponse]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module ActiveresourceResponse
|
2
|
-
module HttpResponse
|
3
|
-
|
4
|
-
def headers
|
5
|
-
unless defined? @_active_resource_response_headers
|
6
|
-
@_active_resource_response_headers = symbolize_keys(to_hash)
|
7
|
-
end
|
8
|
-
@_active_resource_response_headers
|
9
|
-
end
|
10
|
-
|
11
|
-
def cookies
|
12
|
-
unless defined? @_active_resource_response_cookies
|
13
|
-
@_active_resource_response_cookies = (self.headers[:set_cookie] || {}).inject({}) do |out, cookie_str|
|
14
|
-
CGI::Cookie::parse(cookie_str).each do |key, cookie|
|
15
|
-
out[key] = cookie.value.first unless ['expires', 'path'].include? key
|
16
|
-
end
|
17
|
-
out
|
18
|
-
end
|
19
|
-
end
|
20
|
-
@_active_resource_response_cookies
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
def symbolize_keys(hash)
|
25
|
-
hash.inject({}) do |out, (key, value)|
|
26
|
-
out[key.gsub(/-/, '_').downcase.to_sym] = value
|
27
|
-
out
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module ActiveresourceResponse
|
2
|
-
|
3
|
-
module ResponseMethod
|
4
|
-
|
5
|
-
def self.included(base)
|
6
|
-
base.extend ClassMethods
|
7
|
-
end
|
8
|
-
|
9
|
-
module ClassMethods
|
10
|
-
def add_response_method(method_name = :http_response)
|
11
|
-
|
12
|
-
remove_response_method if methods.map(&:to_sym).include?(:find_without_http_response)
|
13
|
-
[:find, :get].each do |method|
|
14
|
-
instance_eval <<-EOS
|
15
|
-
alias #{method}_without_http_response #{method}
|
16
|
-
def #{method}(*arguments)
|
17
|
-
result = #{method}_without_http_response(*arguments)
|
18
|
-
result.instance_variable_set(:@http_response, connection.http_response)
|
19
|
-
def result.#{method_name}
|
20
|
-
@http_response
|
21
|
-
end
|
22
|
-
result
|
23
|
-
end
|
24
|
-
EOS
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def remove_response_method
|
29
|
-
[:find, :get].each do |method|
|
30
|
-
instance_eval <<-EOS
|
31
|
-
undef :#{method}
|
32
|
-
alias :#{method} :#{method}_without_http_response
|
33
|
-
undef :#{method}_without_http_response
|
34
|
-
EOS
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|