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.
Files changed (4) hide show
  1. data/Changelog +4 -0
  2. data/README.rdoc +1 -1
  3. data/lib/http_request.rb +30 -19
  4. metadata +3 -3
data/Changelog CHANGED
@@ -1,3 +1,7 @@
1
+ v1.1.11
2
+ * define http methods such as "get", "post" etc. dynamiclly instead of
3
+ using "method_missing".
4
+
1
5
  v1.1.10
2
6
  * make it wroks on Ruby1.9.2
3
7
 
data/README.rdoc CHANGED
@@ -228,4 +228,4 @@ download multiple files from a directory
228
228
  bug fixing, testing and testing...
229
229
 
230
230
  == LATEST VERSION
231
- 1.1.10
231
+ 1.1.11
data/lib/http_request.rb CHANGED
@@ -11,9 +11,9 @@
11
11
  #
12
12
  # == Version
13
13
  #
14
- # v1.1.10
14
+ # v1.1.11
15
15
  #
16
- # Last Change: 13 Sep, 2010
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
- - 10
9
- version: 1.1.10
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-09-14 00:00:00 +08:00
17
+ date: 2010-10-28 00:00:00 +08:00
18
18
  default_executable:
19
19
  dependencies: []
20
20