ez_http 1.0.0
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/.gitignore +41 -0
- data/README.md +20 -0
- data/doc/EZHttp.html +386 -0
- data/doc/_index.html +106 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +55 -0
- data/doc/css/style.css +322 -0
- data/doc/file_list.html +49 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +88 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +173 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +54 -0
- data/doc/top-level-namespace.html +105 -0
- data/ez_http.gemspec +18 -0
- data/lib/ez_http.rb +62 -0
- metadata +98 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<base id="base_target" target="_parent" />
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<script type="text/javascript" charset="utf-8">
|
22
|
+
if (window.top.frames.main) {
|
23
|
+
document.getElementById('base_target').target = 'main';
|
24
|
+
document.body.className = 'frames';
|
25
|
+
}
|
26
|
+
</script>
|
27
|
+
<div id="content">
|
28
|
+
<h1 id="full_list_header">Method List</h1>
|
29
|
+
<div id="nav">
|
30
|
+
|
31
|
+
<a target="_self" href="class_list.html">Classes</a>
|
32
|
+
|
33
|
+
<a target="_self" href="method_list.html">Methods</a>
|
34
|
+
|
35
|
+
<a target="_self" href="file_list.html">Files</a>
|
36
|
+
|
37
|
+
</div>
|
38
|
+
<div id="search">Search: <input type="text" /></div>
|
39
|
+
|
40
|
+
<ul id="full_list" class="methods">
|
41
|
+
|
42
|
+
|
43
|
+
<li class="r1 ">
|
44
|
+
<span class='object_link'><a href="EZHttp.html#Send-class_method" title="EZHttp.Send (method)">Send</a></span>
|
45
|
+
|
46
|
+
<small>EZHttp</small>
|
47
|
+
|
48
|
+
</li>
|
49
|
+
|
50
|
+
|
51
|
+
</ul>
|
52
|
+
</div>
|
53
|
+
</body>
|
54
|
+
</html>
|
@@ -0,0 +1,105 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.7.5
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
relpath = '';
|
19
|
+
if (relpath != '') relpath += '/';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
25
|
+
|
26
|
+
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type="text/javascript" charset="utf-8">
|
30
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="header">
|
34
|
+
<div id="menu">
|
35
|
+
|
36
|
+
<a href="_index.html">Index</a> »
|
37
|
+
|
38
|
+
|
39
|
+
<span class="title">Top Level Namespace</span>
|
40
|
+
|
41
|
+
|
42
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="search">
|
46
|
+
|
47
|
+
<a id="class_list_link" href="#">Class List</a>
|
48
|
+
|
49
|
+
<a id="method_list_link" href="#">Method List</a>
|
50
|
+
|
51
|
+
<a id="file_list_link" href="#">File List</a>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
<div class="clear"></div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<iframe id="search_frame"></iframe>
|
58
|
+
|
59
|
+
<div id="content"><h1>Top Level Namespace
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
</h1>
|
64
|
+
|
65
|
+
<dl class="box">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
</dl>
|
75
|
+
<div class="clear"></div>
|
76
|
+
|
77
|
+
<h2>Defined Under Namespace</h2>
|
78
|
+
<p class="children">
|
79
|
+
|
80
|
+
|
81
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="EZHttp.html" title="EZHttp (module)">EZHttp</a></span>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
</p>
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
</div>
|
97
|
+
|
98
|
+
<div id="footer">
|
99
|
+
Generated on Sat Mar 31 14:47:49 2012 by
|
100
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
101
|
+
0.7.5 (ruby-1.9.3).
|
102
|
+
</div>
|
103
|
+
|
104
|
+
</body>
|
105
|
+
</html>
|
data/ez_http.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'ez_http'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.date = '2012-03-30'
|
6
|
+
s.summary = "Make http/https request easier"
|
7
|
+
s.description = "A helper wrapper around net/http, supports http/https(with/without certificate), post/get requests, one method call does everything."
|
8
|
+
s.authors = ["Tianyu Huang"]
|
9
|
+
s.email = 'tianhsky@yahoo.com'
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.homepage = 'http://rubygems.org/gems/ez_http'
|
12
|
+
s.extra_rdoc_files = ["doc/index.html"]
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.add_development_dependency "openssl"
|
16
|
+
s.add_development_dependency "net/http"
|
17
|
+
s.add_development_dependency "uri"
|
18
|
+
end
|
data/lib/ez_http.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "uri"
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
# A helper wrapper around net/http, supports http/https(with/without certificate), post/get requests, one method call does everything.
|
6
|
+
# How to use:
|
7
|
+
# response = EZHttp.Send("https://www.example.com:83/api", "post", {"key1"=>"value1"}, "application/json", nil)
|
8
|
+
# puts response.body
|
9
|
+
#
|
10
|
+
# @author Tianyu Huang [tianhsky@yahoo.com]
|
11
|
+
#
|
12
|
+
module EZHttp
|
13
|
+
|
14
|
+
# Send request to specified url and will return responses
|
15
|
+
# @param [String] url: to send request to
|
16
|
+
# @param [String] method: is "get" or "post", if nil default is "post"
|
17
|
+
# @param [Hash] data: to send
|
18
|
+
# @param [String] content_type: if nil default is "application/json"
|
19
|
+
# @param [String] cert_path: to the certificate file, set nil if none
|
20
|
+
# @return [Net::HTTPResponse] response from remote server, example to access its fields: response.body, response.status
|
21
|
+
#
|
22
|
+
def self.Send(url, method, data, content_type, cert_path)
|
23
|
+
# Parse url
|
24
|
+
uri = URI.parse(url)
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
|
27
|
+
if (url.match(/^https/))
|
28
|
+
http.use_ssl = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# Create request obj
|
32
|
+
request = nil
|
33
|
+
|
34
|
+
method = method || "post"
|
35
|
+
case method.downcase
|
36
|
+
when "post"
|
37
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
38
|
+
when "get"
|
39
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
40
|
+
else
|
41
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
42
|
+
end
|
43
|
+
|
44
|
+
request.set_form_data(data)
|
45
|
+
request["Content-Type"] = content_type || "application/json"
|
46
|
+
|
47
|
+
# Add cert if any
|
48
|
+
if (cert_path.nil?)
|
49
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
50
|
+
else
|
51
|
+
http.use_ssl = true
|
52
|
+
pem = File.read(cert_path)
|
53
|
+
http.cert = OpenSSL::X509::Certificate.new(pem)
|
54
|
+
http.key = OpenSSL::PKey::RSA.new(pem)
|
55
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
56
|
+
end
|
57
|
+
|
58
|
+
# Send request and return response
|
59
|
+
response = http.request(request)
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ez_http
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tianyu Huang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-03-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: openssl
|
16
|
+
requirement: &75435180 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *75435180
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: net/http
|
27
|
+
requirement: &75434950 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *75434950
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: uri
|
38
|
+
requirement: &75434740 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *75434740
|
47
|
+
description: A helper wrapper around net/http, supports http/https(with/without certificate),
|
48
|
+
post/get requests, one method call does everything.
|
49
|
+
email: tianhsky@yahoo.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files:
|
53
|
+
- doc/index.html
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- README.md
|
57
|
+
- doc/EZHttp.html
|
58
|
+
- doc/_index.html
|
59
|
+
- doc/class_list.html
|
60
|
+
- doc/css/common.css
|
61
|
+
- doc/css/full_list.css
|
62
|
+
- doc/css/style.css
|
63
|
+
- doc/file_list.html
|
64
|
+
- doc/frames.html
|
65
|
+
- doc/index.html
|
66
|
+
- doc/js/app.js
|
67
|
+
- doc/js/full_list.js
|
68
|
+
- doc/js/jquery.js
|
69
|
+
- doc/method_list.html
|
70
|
+
- doc/top-level-namespace.html
|
71
|
+
- ez_http.gemspec
|
72
|
+
- lib/ez_http.rb
|
73
|
+
homepage: http://rubygems.org/gems/ez_http
|
74
|
+
licenses: []
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.3.6
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.17
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Make http/https request easier
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|