http_request.rb 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/Changelog +3 -0
  2. data/README.rdoc +2 -1
  3. data/lib/http_request.rb +14 -5
  4. metadata +6 -4
data/Changelog CHANGED
@@ -1,3 +1,6 @@
1
+ v1.0.5
2
+ * add 2 options ":xhr" and ":ajax", can send a request looks like AJAX calling.
3
+
1
4
  v1.0.4
2
5
  * support gzipped content only if the zlib library is loaded
3
6
  * post xml data via the POST method
data/README.rdoc CHANGED
@@ -12,6 +12,7 @@ The HttpRequest class is based on the 'net/http' and 'net/ftp' libraries, so the
12
12
  :ssl_port => Fixnum, ssl port, default is 443
13
13
  :headers => Hash, you can add some custom http headers
14
14
  :files => for upload files
15
+ :ajax or :xhr => send request looks like AJAX calling (since 1.0.5)
15
16
 
16
17
  # proxy settings
17
18
  :proxy_addr => String, proxy address
@@ -224,7 +225,7 @@ download multiple files from a directory
224
225
  bug fixing, testing and testing...
225
226
 
226
227
  == LATEST VERSION
227
- 1.0.3
228
+ 1.0.5
228
229
 
229
230
  == Author
230
231
 
data/lib/http_request.rb CHANGED
@@ -11,9 +11,9 @@
11
11
  #
12
12
  # == Version
13
13
  #
14
- # v1.0.4
14
+ # v1.0.5
15
15
  #
16
- # Last Change: 9 June, 2009
16
+ # Last Change: 6 July, 2009
17
17
  #
18
18
  # == Author
19
19
  #
@@ -33,7 +33,7 @@ class HttpRequest
33
33
  include Singleton
34
34
 
35
35
  # version
36
- VERSION = '1.0.4'.freeze
36
+ VERSION = '1.0.5'.freeze
37
37
  def self.version;VERSION;end
38
38
 
39
39
  # avaiabled http methods
@@ -43,6 +43,7 @@ class HttpRequest
43
43
 
44
44
  # return data with or without block
45
45
  def self.data(response, &block)
46
+ response.url = @@__url if defined? @@__url
46
47
  block_given? ? block.call(response) : response
47
48
  end
48
49
 
@@ -132,7 +133,7 @@ class HttpRequest
132
133
  def self.ftp(method, options, &block)
133
134
  options = {:url => options} if options.is_a? String
134
135
  options = {:close => true}.merge(options)
135
- options[:url] = "ftp://#{options[:url]}" unless options[:url] =~ /^ftp:\/\//
136
+ @@__url = options[:url] = "ftp://#{options[:url]}" unless options[:url] =~ /^ftp:\/\//
136
137
  uri = URI(options[:url])
137
138
  guest_name, guest_pass = 'anonymous', "guest@#{uri.host}"
138
139
  unless options[:username]
@@ -185,9 +186,12 @@ class HttpRequest
185
186
  :ssl_port => 443,
186
187
  :redirect_limits => 5,
187
188
  :redirect => true,
188
- :url => nil
189
+ :url => nil,
190
+ :ajax => false,
191
+ :xhr => false
189
192
  }
190
193
  @options.merge!(options)
194
+ @@__url = @options[:url]
191
195
  @uri = URI(@options[:url])
192
196
  @uri.path = '/' if @uri.path.empty?
193
197
  @headers = {
@@ -200,6 +204,9 @@ class HttpRequest
200
204
  begin; require 'zlib'; rescue LoadError; end
201
205
  @headers['Accept-Encoding'] = 'gzip,deflate' if defined? Zlib
202
206
 
207
+ # ajax calls?
208
+ @headers['X_REQUESTED_WITH'] = 'XmlHttpRequest' if @options[:ajax] or @options[:xhr]
209
+
203
210
  # Basic Authenication
204
211
  @headers['Authorization'] = "Basic " + [@uri.userinfo].pack('m').delete!("\r\n") if @uri.userinfo
205
212
 
@@ -291,6 +298,8 @@ end
291
298
  module Net
292
299
  class HTTPResponse
293
300
 
301
+ attr :url
302
+
294
303
  # get cookies as a hash
295
304
  def cookies
296
305
  cookies = {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_request.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - xianhua.zhou
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-13 00:00:00 +08:00
12
+ date: 2009-07-06 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,6 +27,8 @@ files:
27
27
  - lib/http_request.rb
28
28
  has_rdoc: true
29
29
  homepage: http://my.cnzxh.net
30
+ licenses: []
31
+
30
32
  post_install_message:
31
33
  rdoc_options: []
32
34
 
@@ -47,9 +49,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
49
  requirements: []
48
50
 
49
51
  rubyforge_project: http_request.rb
50
- rubygems_version: 1.3.1
52
+ rubygems_version: 1.3.4
51
53
  signing_key:
52
- specification_version: 2
54
+ specification_version: 3
53
55
  summary: http_request.rb is a small, lightweight, powerful HttpRequest class based on the 'net/http' and 'net/ftp' libraries
54
56
  test_files: []
55
57