http-requestor 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -6
- data/lib/http-requestor.rb +27 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
= http-requestor
|
2
2
|
|
3
|
-
A Wrapper around Net/HTTP which allows you to perform HTTP Requests.
|
3
|
+
A Wrapper around Net/HTTP which allows you to perform HTTP Requests in a simple way.
|
4
4
|
|
5
5
|
= Usage
|
6
6
|
|
7
|
-
http = HttpRequestor.new("http://www.mydomain.com")
|
7
|
+
http = HttpRequestor.new("http://www.mydomain.com") # This will initialize the HttpRequestor class
|
8
8
|
|
9
|
-
response = http.get("/get_path")
|
9
|
+
[Sending Calls to the initialized domain] response = http.get("/get_path")
|
10
10
|
|
11
|
-
response = http.post("/post_path")
|
11
|
+
response = http.post("/post_path")
|
12
12
|
|
13
|
-
response = http.put("/put_path")
|
13
|
+
response = http.put("/put_path")
|
14
14
|
|
15
|
-
response = http.delete("/delete_path")
|
15
|
+
response = http.delete("/delete_path")
|
16
|
+
|
17
|
+
The above methods also accept optional parameters, for
|
18
|
+
|
19
|
+
* Parameters to be sent to the request
|
20
|
+
* Headers to be sent to the request
|
21
|
+
|
22
|
+
[Alternatively you can also use the method] HttpRequestor.request
|
23
|
+
|
24
|
+
which takes the paramters in order
|
25
|
+
* domain #=> for example: "http://www.some_domain.com"
|
26
|
+
* request_type #=> GET|POST|PUT|DELETE
|
27
|
+
* path #=> for example: "/some_path"
|
28
|
+
* parameters #=> this is an optional parameter, if you want to send some parameters alongwith the request, you can pass a hash with
|
29
|
+
* headers #=> this is also an optional parameter, you can pass a hash with stringified keys
|
data/lib/http-requestor.rb
CHANGED
@@ -52,7 +52,7 @@ class HttpRequestor
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.request(domain, request_type, request_path, data={}, headers={})
|
55
|
-
data = data.to_query
|
55
|
+
data = data.to_query
|
56
56
|
request = HttpRequestor.new(domain)
|
57
57
|
if request_type == "GET"
|
58
58
|
return request.get(request_path, data, headers)
|
@@ -64,4 +64,30 @@ class HttpRequestor
|
|
64
64
|
return request.delete(request_path, data, headers)
|
65
65
|
end
|
66
66
|
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Hash
|
70
|
+
def to_query(namespace = nil)
|
71
|
+
collect do |key, value|
|
72
|
+
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
73
|
+
end.sort * '&'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
class Array
|
78
|
+
def to_query(key)
|
79
|
+
prefix = "#{key}[]"
|
80
|
+
collect { |value| value.to_query(prefix) }.join '&'
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class String
|
85
|
+
def to_query(key)
|
86
|
+
require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
|
87
|
+
"#{CGI.escape(key.to_param)}=#{CGI.escape(to_param.to_s)}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_param
|
91
|
+
to_s
|
92
|
+
end
|
67
93
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http-requestor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-12 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Wrapper around Net/HTTP which allows you to perform HTTP Requests.
|
15
15
|
email: rohit0981989@gmail.com
|