http-requestor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +15 -0
- data/lib/http-requestor.rb +67 -0
- metadata +47 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Rohit Sharma - rohit0981989@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
= http-requestor
|
2
|
+
|
3
|
+
A Wrapper around Net/HTTP which allows you to perform HTTP Requests.
|
4
|
+
|
5
|
+
= Usage
|
6
|
+
|
7
|
+
http = HttpRequestor.new("http://www.mydomain.com")
|
8
|
+
|
9
|
+
response = http.get("/get_path")
|
10
|
+
|
11
|
+
response = http.post("/post_path")
|
12
|
+
|
13
|
+
response = http.put("/put_path")
|
14
|
+
|
15
|
+
response = http.delete("/delete_path")
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "net/http"
|
2
|
+
|
3
|
+
class HttpRequestor
|
4
|
+
def initialize(domain)
|
5
|
+
@defaults = {:domain => domain}
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(path,data,headers=nil)
|
9
|
+
uri = URI.parse(@defaults[:domain])
|
10
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
11
|
+
if headers == nil
|
12
|
+
response = http.send_request('GET',path,data)
|
13
|
+
else
|
14
|
+
response = http.send_request('GET',path,data,headers)
|
15
|
+
end
|
16
|
+
response
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(path,data,headers=nil)
|
20
|
+
uri = URI.parse(@defaults[:domain])
|
21
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
22
|
+
if headers == nil
|
23
|
+
response = http.send_request('POST',path,data)
|
24
|
+
else
|
25
|
+
response = http.send_request('POST',path,data,headers)
|
26
|
+
end
|
27
|
+
response
|
28
|
+
end
|
29
|
+
|
30
|
+
def put(path,data,headers=nil)
|
31
|
+
uri = URI.parse(@defaults[:domain])
|
32
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
33
|
+
|
34
|
+
if headers == nil
|
35
|
+
response = http.send_request('PUT',path,data)
|
36
|
+
else
|
37
|
+
response = http.send_request('PUT',path,data,headers)
|
38
|
+
end
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
def delete(path,data,headers=nil)
|
43
|
+
uri = URI.parse(@defaults[:domain])
|
44
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
45
|
+
|
46
|
+
if headers == nil
|
47
|
+
response = http.send_request('DELETE',path,data)
|
48
|
+
else
|
49
|
+
response = http.send_request('DELETE',path,data,headers)
|
50
|
+
end
|
51
|
+
response
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.request(domain, request_type, request_path, data={}, headers={})
|
55
|
+
data = data.to_query if data.is_a?(Hash)
|
56
|
+
request = HttpRequestor.new(domain)
|
57
|
+
if request_type == "GET"
|
58
|
+
return request.get(request_path, data, headers)
|
59
|
+
elsif request_type == "POST"
|
60
|
+
return request.post(request_path, data, headers)
|
61
|
+
elsif request_type == "PUT"
|
62
|
+
return request.put(request_path, data, headers)
|
63
|
+
elsif request_type == "DELETE"
|
64
|
+
return request.delete(request_path, data, headers)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: http-requestor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rohit Sharma
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-03 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: A Wrapper around Net/HTTP which allows you to perform HTTP Requests.
|
15
|
+
email: rohit0981989@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/http-requestor.rb
|
21
|
+
- MIT-LICENSE
|
22
|
+
- README.rdoc
|
23
|
+
homepage: http://github.com/rohit9889/http-requestor
|
24
|
+
licenses: []
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.5
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: A Wrapper around Net/HTTP which allows you to perform HTTP Requests.
|
47
|
+
test_files: []
|