http_request.rb 1.1.10 → 1.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +4 -0
- data/README.rdoc +1 -1
- data/lib/http_request.rb +30 -19
- metadata +3 -3
data/Changelog
CHANGED
data/README.rdoc
CHANGED
data/lib/http_request.rb
CHANGED
@@ -11,9 +11,9 @@
|
|
11
11
|
#
|
12
12
|
# == Version
|
13
13
|
#
|
14
|
-
# v1.1.
|
14
|
+
# v1.1.11
|
15
15
|
#
|
16
|
-
# Last Change:
|
16
|
+
# Last Change: 28 Oct, 2010
|
17
17
|
#
|
18
18
|
# == Author
|
19
19
|
#
|
@@ -70,7 +70,34 @@ class HttpRequest
|
|
70
70
|
return true
|
71
71
|
rescue Exception => e
|
72
72
|
return false
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def call_request_method(method_name, *options, &block)
|
77
|
+
options = if options.size.eql? 2
|
78
|
+
options.last.merge({:url => options.first})
|
79
|
+
else
|
80
|
+
options.first
|
81
|
+
end
|
82
|
+
|
83
|
+
# we need to retrieve the cookies from last http response before reset cookies if it's a Net::HTTPResponse
|
84
|
+
options[:cookies] = options[:cookies].cookies if options.is_a?(Hash) and options[:cookies].is_a?(Net::HTTPResponse)
|
85
|
+
|
86
|
+
# reset
|
87
|
+
@@__cookies = {}
|
88
|
+
@@redirect_times = 0
|
89
|
+
self.instance.request(method_name, options, &block)
|
73
90
|
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# define some http methods
|
95
|
+
self.http_methods.each do |method_name|
|
96
|
+
instance_eval %Q{
|
97
|
+
def #{method_name}(*options, &block)
|
98
|
+
call_request_method('#{method_name}', *options, &block)
|
99
|
+
end
|
100
|
+
}
|
74
101
|
end
|
75
102
|
|
76
103
|
def data(response, &block)
|
@@ -93,23 +120,7 @@ class HttpRequest
|
|
93
120
|
|
94
121
|
# redirect?
|
95
122
|
process_redirection response, &block
|
96
|
-
end
|
97
|
-
|
98
|
-
# catch all available http requests
|
99
|
-
def self.method_missing(method_name, *options, &block)
|
100
|
-
options = if options.size.eql? 2
|
101
|
-
options.last.merge({:url => options.first})
|
102
|
-
else
|
103
|
-
options.first
|
104
|
-
end
|
105
|
-
@@redirect_times = 0
|
106
|
-
# we need to retrieve the cookies from last http response before reset cookies if it's a Net::HTTPResponse
|
107
|
-
options[:cookies] = options[:cookies].cookies if options.is_a?(Hash) and options[:cookies].is_a?(Net::HTTPResponse)
|
108
|
-
@@__cookies = {}
|
109
|
-
method_name = method_name.to_s.downcase
|
110
|
-
raise NoHttpMethodException, "No such http method can be called: #{method_name}" unless self.http_methods.include?(method_name)
|
111
|
-
self.instance.request(method_name, options, &block)
|
112
|
-
end
|
123
|
+
end
|
113
124
|
|
114
125
|
# for ftp, no plan to add new features to this method except bug fixing
|
115
126
|
def self.ftp(method, options, &block)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 11
|
9
|
+
version: 1.1.11
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- xianhua.zhou
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-10-28 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|