http_request.rb 1.1.13 → 1.1.14
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.
- data/Changelog +4 -0
- data/README.rdoc +5 -3
- data/lib/http_request.rb +14 -12
- data/spec/http_request_spec.rb +14 -0
- metadata +20 -28
data/Changelog
CHANGED
data/README.rdoc
CHANGED
@@ -24,10 +24,11 @@ The HttpRequest class is based on the 'net/http' and 'net/ftp' libraries, so the
|
|
24
24
|
|
25
25
|
include http_request.rb first
|
26
26
|
require '/path/to/http_request.rb'
|
27
|
-
or install it
|
27
|
+
or install it `gem install http_request.rb`, then `require 'http_request'`
|
28
28
|
|
29
29
|
get
|
30
|
-
puts HttpRequest.get('http://
|
30
|
+
puts HttpRequest.get('http://github.com').body
|
31
|
+
puts HttpRequest.get('https://github.com').body
|
31
32
|
|
32
33
|
get with query string, 4 are same
|
33
34
|
puts HttpRequest.get('http://www.google.com/search?hl=en&q=ruby&start=0&sa=N').body
|
@@ -219,6 +220,7 @@ download multiple files from a directory
|
|
219
220
|
HttpRequest.head('http://www.ruby-lang.org/').code_200? # true
|
220
221
|
|
221
222
|
supported methods: code_1xx? code_2xx? code_3xx? code_4xx? code_5xx? code_101? code_200? ...
|
223
|
+
or status_1xx? statux_2xx? ...
|
222
224
|
|
223
225
|
== check whether or not the remote site is available (since v1.0.3)
|
224
226
|
|
@@ -241,4 +243,4 @@ download multiple files from a directory
|
|
241
243
|
bug fixing, testing and testing...
|
242
244
|
|
243
245
|
== LATEST VERSION
|
244
|
-
1.1.
|
246
|
+
1.1.14
|
data/lib/http_request.rb
CHANGED
@@ -11,14 +11,8 @@
|
|
11
11
|
#
|
12
12
|
# == Version
|
13
13
|
#
|
14
|
-
# v1.1.
|
15
|
-
#
|
16
|
-
# Last Change: 29 July, 2012
|
17
|
-
#
|
18
|
-
# == Author
|
19
|
-
#
|
20
|
-
# xianhua.zhou<xianhua.zhou@gmail.com>
|
21
|
-
#
|
14
|
+
# v1.1.14
|
15
|
+
# Last Change: 20 December 2012
|
22
16
|
#
|
23
17
|
require 'cgi'
|
24
18
|
require 'net/http'
|
@@ -32,7 +26,7 @@ class HttpRequest
|
|
32
26
|
include Singleton
|
33
27
|
class << self
|
34
28
|
# version
|
35
|
-
VERSION = '1.1.
|
29
|
+
VERSION = '1.1.14'.freeze
|
36
30
|
def version;VERSION;end
|
37
31
|
|
38
32
|
# available http methods
|
@@ -310,8 +304,13 @@ class HttpRequest
|
|
310
304
|
# parse parameters for the options[:parameters] and @uri.query
|
311
305
|
def parse_parameters
|
312
306
|
if @options[:parameters].is_a?(Hash)
|
313
|
-
@options[:parameters] = @options[:parameters].collect{|k, v|
|
314
|
-
|
307
|
+
@options[:parameters] = @options[:parameters].collect{|k, v|
|
308
|
+
unless v.is_a?(Array)
|
309
|
+
"#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
|
310
|
+
else
|
311
|
+
prefix = "#{k}[]"
|
312
|
+
v.collect { |value| "#{CGI.escape(prefix)}=#{CGI.escape(value.to_s)}" }.join('&')
|
313
|
+
end
|
315
314
|
}.join('&')
|
316
315
|
end
|
317
316
|
@options[:parameters] = '' if @options[:parameters].nil?
|
@@ -381,7 +380,10 @@ class HttpRequest
|
|
381
380
|
end
|
382
381
|
|
383
382
|
# ssl support
|
384
|
-
|
383
|
+
if @uri.scheme =~ /^https$/i
|
384
|
+
http.use_ssl = true
|
385
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
386
|
+
end
|
385
387
|
|
386
388
|
# sending request and get response
|
387
389
|
send_request http
|
data/spec/http_request_spec.rb
CHANGED
@@ -110,6 +110,16 @@ describe HttpRequest do
|
|
110
110
|
hr.get(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"ids"=>{')
|
111
111
|
hr.get(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"a"=>"1"')
|
112
112
|
hr.get(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"b"=>"2"')
|
113
|
+
|
114
|
+
hr.get(:url => URL + '/get', :parameters => {:ids => ['1', '2']}).body.should == {
|
115
|
+
'ids' => ['1', '2']
|
116
|
+
}.inspect
|
117
|
+
end
|
118
|
+
|
119
|
+
it "can work with https" do
|
120
|
+
body = hr.get("https://github.com").body
|
121
|
+
body.should include('Git')
|
122
|
+
body.should include('<!DOCTYPE html>')
|
113
123
|
end
|
114
124
|
|
115
125
|
it "should work with the post method" do
|
@@ -155,6 +165,10 @@ describe HttpRequest do
|
|
155
165
|
hr.post(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"ids"=>{')
|
156
166
|
hr.post(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"a"=>"1"')
|
157
167
|
hr.post(:url => URL + '/get', :parameters => {'ids[a]' => 1, 'ids[b]' => 2}).body.should include('"b"=>"2"')
|
168
|
+
|
169
|
+
hr.post(:url => URL + '/get', :parameters => {:ids => ['1','2']}).body.should == {
|
170
|
+
'ids' => ['1', '2']
|
171
|
+
}.inspect
|
158
172
|
end
|
159
173
|
|
160
174
|
end
|
metadata
CHANGED
@@ -1,27 +1,22 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_request.rb
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.14
|
4
5
|
prerelease:
|
5
|
-
version: 1.1.13
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- xianhua.zhou
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
date: 2012-07-29 00:00:00 Z
|
12
|
+
date: 2012-12-20 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
14
|
description:
|
17
15
|
email: xianhua.zhou@gmail.com
|
18
16
|
executables: []
|
19
|
-
|
20
17
|
extensions: []
|
21
|
-
|
22
18
|
extra_rdoc_files: []
|
23
|
-
|
24
|
-
files:
|
19
|
+
files:
|
25
20
|
- Changelog
|
26
21
|
- README.rdoc
|
27
22
|
- Gemfile
|
@@ -31,30 +26,27 @@ files:
|
|
31
26
|
- spec/web_server.rb
|
32
27
|
homepage: http://github.com/xianhuazhou
|
33
28
|
licenses: []
|
34
|
-
|
35
29
|
post_install_message:
|
36
30
|
rdoc_options: []
|
37
|
-
|
38
|
-
require_paths:
|
31
|
+
require_paths:
|
39
32
|
- lib
|
40
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
34
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
46
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
40
|
none: false
|
48
|
-
requirements:
|
49
|
-
- -
|
50
|
-
- !ruby/object:Gem::Version
|
51
|
-
version:
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
52
45
|
requirements: []
|
53
|
-
|
54
46
|
rubyforge_project: http_request.rb
|
55
|
-
rubygems_version: 1.8.
|
47
|
+
rubygems_version: 1.8.24
|
56
48
|
signing_key:
|
57
49
|
specification_version: 3
|
58
|
-
summary: http_request.rb is a small, lightweight, powerful HttpRequest class based
|
50
|
+
summary: http_request.rb is a small, lightweight, powerful HttpRequest class based
|
51
|
+
on the 'net/http' and 'net/ftp' libraries
|
59
52
|
test_files: []
|
60
|
-
|