activeresource-response 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/README.rdoc +25 -5
- data/activeresource-response.gemspec +5 -1
- data/lib/activeresource-response.rb +2 -0
- data/lib/activeresource-response/connection.rb +6 -1
- data/lib/activeresource-response/http_response.rb +28 -0
- data/lib/activeresource-response/version.rb +1 -1
- metadata +41 -54
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Activeresource-response
|
2
2
|
|
3
|
-
This gem adds possibility to access http response object from result (single object or collection) of activeresource call (methods : find, all, first, last )
|
3
|
+
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
4
|
|
5
5
|
|
6
6
|
|
@@ -60,8 +60,8 @@ Client Side
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
|
64
|
-
==
|
63
|
+
|
64
|
+
== Every time when http connection invoked ActiveResource connection object stores http response. You can access it with http_response method.
|
65
65
|
Example
|
66
66
|
|
67
67
|
class Order < ActiveResource::Base
|
@@ -80,7 +80,24 @@ Example
|
|
80
80
|
Order.connection.http_response.to_hash
|
81
81
|
# => {"content-type"=>["application/json; charset=utf-8"], "x-ua-compatible"=>["IE=Edge"], "etag"=>["\"573cabd02b2f1f90405f7f4f77995fab\""], "cache-control"=>["max-age=0, private, must-revalidate"], "x-request-id"=>["2911c13a0c781044c474450ed789613d"], "x-runtime"=>["0.071018"], "content-length"=>["260"], "server"=>["WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)"], "date"=>["Sun, 19 Feb 2012 10:21:29 GMT"], "connection"=>["close"]}
|
82
82
|
|
83
|
-
|
83
|
+
|
84
|
+
|
85
|
+
== Headers and cookies methods to get symbolized collections
|
86
|
+
You can get cookies and headers from response
|
87
|
+
Example
|
88
|
+
|
89
|
+
class Country < ActiveResource::Base
|
90
|
+
self.site = 'http://0.0.0.0:3000/'
|
91
|
+
add_response_method :my_response # our new method
|
92
|
+
end
|
93
|
+
countries = Country.all
|
94
|
+
countries.my_response.headers
|
95
|
+
|
96
|
+
# => {:content_type=>["application/json; charset=utf-8"], :x_ua_compatible=>["IE=Edge"], ..., :set_cookie=>["bar=foo; path=/", "foo=bar; path=/"]}
|
97
|
+
|
98
|
+
|
99
|
+
countries.my_response.cookies
|
100
|
+
# => {:bar=>"foo", :foo=>"bar"}
|
84
101
|
|
85
102
|
== About Http response
|
86
103
|
http response is object of Net::HTTPOK, Net::HTTPClientError or one of other subclasses
|
@@ -91,4 +108,7 @@ of Net::HTTPResponse class. For more information see documentation http://www.r
|
|
91
108
|
|
92
109
|
http://phpblog.com.ua/2012/01/rails-activeresource-i-zagolovki/
|
93
110
|
|
94
|
-
http://stackoverflow.com/questions/5972429/active-resource-responses-how-to-get-them
|
111
|
+
http://stackoverflow.com/questions/5972429/active-resource-responses-how-to-get-them
|
112
|
+
|
113
|
+
|
114
|
+
== Please, feel free to contact me if you have any questions
|
@@ -14,7 +14,11 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency('activeresource', '>= 3.0')
|
16
16
|
|
17
|
-
|
17
|
+
|
18
|
+
|
19
|
+
s.extra_rdoc_files = %w( README.rdoc )
|
20
|
+
s.rdoc_options.concat ['--main', 'README.rdoc']
|
21
|
+
|
18
22
|
|
19
23
|
s.files = `git ls-files`.split("\n")
|
20
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'cgi'
|
1
2
|
require "activeresource-response/version"
|
3
|
+
require "activeresource-response/http_response"
|
2
4
|
require "activeresource-response/connection"
|
3
5
|
require "activeresource-response/response_method"
|
4
6
|
ActiveResource::Connection.send :include, ActiveresourceResponse::Connection
|
@@ -4,8 +4,13 @@ module ActiveresourceResponse
|
|
4
4
|
base.class_eval do
|
5
5
|
alias_method :origin_handle_response, :handle_response
|
6
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)
|
7
13
|
Thread.current[:ActiveResourceHttpResponse] = response
|
8
|
-
origin_handle_response(response)
|
9
14
|
end
|
10
15
|
def http_response
|
11
16
|
Thread.current[:ActiveResourceHttpResponse]
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActiveresourceResponse
|
2
|
+
module HttpResponse
|
3
|
+
def headers
|
4
|
+
@_active_resource_response_headers || symbolize_keys(to_hash)
|
5
|
+
end
|
6
|
+
def cookies
|
7
|
+
unless @_active_resource_response_cookies
|
8
|
+
cookies = (self.headers[:set_cookie] || {}).inject({}) do |out, cookie_str|
|
9
|
+
CGI::Cookie::parse(cookie_str).each do |key, cookie|
|
10
|
+
out[key] = cookie.value.first unless ['expires', 'path'].include? key
|
11
|
+
end
|
12
|
+
out
|
13
|
+
end
|
14
|
+
@_active_resource_response_cookies = symbolize_keys(cookies)
|
15
|
+
end
|
16
|
+
@_active_resource_response_cookies
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def symbolize_keys(hash)
|
21
|
+
hash.inject({}) do |out, (key, value)|
|
22
|
+
out[key.gsub(/-/, '_').downcase.to_sym] = value
|
23
|
+
out
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,45 +1,36 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource-response
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 7
|
9
|
-
version: 0.0.7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Igor Fedoronchuk
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-04-03 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
21
15
|
name: activeresource
|
22
|
-
|
23
|
-
|
24
|
-
requirements:
|
25
|
-
- -
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
- 3
|
29
|
-
- 0
|
30
|
-
version: "3.0"
|
16
|
+
requirement: &70107787486000 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
31
22
|
type: :runtime
|
32
|
-
|
33
|
-
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70107787486000
|
25
|
+
description: ! 'This gem adds possibility to access http response object from result
|
26
|
+
of ActiveResource::Base find method '
|
27
|
+
email:
|
35
28
|
- fedoronchuk@gmail.com
|
36
29
|
executables: []
|
37
|
-
|
38
30
|
extensions: []
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
files:
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
files:
|
43
34
|
- .gitignore
|
44
35
|
- Gemfile
|
45
36
|
- LICENSE
|
@@ -48,37 +39,33 @@ files:
|
|
48
39
|
- activeresource-response.gemspec
|
49
40
|
- lib/activeresource-response.rb
|
50
41
|
- lib/activeresource-response/connection.rb
|
42
|
+
- lib/activeresource-response/http_response.rb
|
51
43
|
- lib/activeresource-response/response_method.rb
|
52
44
|
- lib/activeresource-response/version.rb
|
53
|
-
has_rdoc: true
|
54
45
|
homepage: https://github.com/Fivell/activeresource-response
|
55
46
|
licenses: []
|
56
|
-
|
57
47
|
post_install_message:
|
58
|
-
rdoc_options:
|
59
|
-
|
60
|
-
|
48
|
+
rdoc_options:
|
49
|
+
- --main
|
50
|
+
- README.rdoc
|
51
|
+
require_paths:
|
61
52
|
- lib
|
62
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
- 0
|
75
|
-
version: "0"
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
76
65
|
requirements: []
|
77
|
-
|
78
|
-
|
79
|
-
rubygems_version: 1.3.6
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.17
|
80
68
|
signing_key:
|
81
69
|
specification_version: 3
|
82
70
|
summary: activeresource extension
|
83
71
|
test_files: []
|
84
|
-
|