http-requestor 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -58,7 +58,25 @@ OR you can do it the other way
58
58
  http = HTTP::Requestor.new("http://www.mydomain.com")
59
59
  response = http.post_multipart(some_path, {:file => File.open("testfile.txt")})
60
60
  response = http.put_multipart(some_path, {:file => File.open("testfile.txt")})
61
-
61
+
62
+ === More HTTP Verbs
63
+
64
+ You can also use other HTTP Verbs such as OPTIONS, PATCH, MOVE, HEAD, TRACE
65
+
66
+ * By instantiating the HTTP::Requestor class
67
+
68
+ http = HTTP::Requestor.new("http://www.mydomain.com")
69
+
70
+ http.options(path, parameters, headers)
71
+ http.patch(path, parameters, headers)
72
+ http.move(path, parameters, headers)
73
+ http.head(path, parameters, headers)
74
+ http.trace(path, parameters, headers)
75
+
76
+ * Directly calling the request method
77
+
78
+ HTTP::Requestor.request(domain, request_type, path, parameters, headers)
79
+ # where request type can be any value within GET, POST, PUT, DELETE, OPTIONS, PATCH, MOVE, HEAD, TRACE
62
80
 
63
81
  == Issues and Suggestions
64
82
 
@@ -60,6 +60,56 @@ module HTTP
60
60
  response
61
61
  end
62
62
 
63
+ def options(path,data={},headers=nil)
64
+ data_to_query(data)
65
+ if headers == nil
66
+ response = @http.send_request('OPTIONS', path, @defaults[:data])
67
+ else
68
+ response = @http.send_request('OPTIONS', path, @defaults[:data], headers)
69
+ end
70
+ response
71
+ end
72
+
73
+ def patch(path,data={},headers=nil)
74
+ data_to_query(data)
75
+ if headers == nil
76
+ response = @http.send_request('PATCH', path, @defaults[:data])
77
+ else
78
+ response = @http.send_request('PATCH', path, @defaults[:data], headers)
79
+ end
80
+ response
81
+ end
82
+
83
+ def move(path,data={},headers=nil)
84
+ data_to_query(data)
85
+ if headers == nil
86
+ response = @http.send_request('MOVE', path, @defaults[:data])
87
+ else
88
+ response = @http.send_request('MOVE', path, @defaults[:data], headers)
89
+ end
90
+ response
91
+ end
92
+
93
+ def head(path,data={},headers=nil)
94
+ data_to_query(data)
95
+ if headers == nil
96
+ response = @http.send_request('HEAD', path, @defaults[:data])
97
+ else
98
+ response = @http.send_request('HEAD', path, @defaults[:data], headers)
99
+ end
100
+ response
101
+ end
102
+
103
+ def trace(path,data={},headers=nil)
104
+ data_to_query(data)
105
+ if headers == nil
106
+ response = @http.send_request('TRACE', path, @defaults[:data])
107
+ else
108
+ response = @http.send_request('TRACE', path, @defaults[:data], headers)
109
+ end
110
+ response
111
+ end
112
+
63
113
  def data_to_query(data)
64
114
  @defaults[:data] = (data.nil? || data.empty?) ? "" : data.to_query
65
115
  end
@@ -77,6 +127,16 @@ module HTTP
77
127
  return req.put(request_path, data, headers)
78
128
  elsif request_type == "DELETE"
79
129
  return req.delete(request_path, data, headers)
130
+ elsif request_type == "OPTIONS"
131
+ return req.options(request_path, data, headers)
132
+ elsif request_type == "PATCH"
133
+ return req.patch(request_path, data, headers)
134
+ elsif request_type == "MOVE"
135
+ return req.move(request_path, data, headers)
136
+ elsif request_type == "HEAD"
137
+ return req.head(request_path, data, headers)
138
+ elsif request_type == "TRACE"
139
+ return req.trace(request_path, data, headers)
80
140
  end
81
141
  end
82
142
 
@@ -95,7 +155,7 @@ module HTTP
95
155
  end
96
156
 
97
157
  def self.valid_request_types
98
- ["GET", "POST", "PUT", "DELETE"]
158
+ ["GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "MOVE", "HEAD", "TRACE"]
99
159
  end
100
160
  end
101
161
  end
@@ -28,7 +28,7 @@ module HTTP
28
28
 
29
29
  def self.multipart_request(domain, request_type, data={}, headers={}, options={})
30
30
  request_type.to_s.upcase!
31
- request_type = valid_request_types[0] unless valid_request_types.include?(request_type)
31
+ request_type = "POST" unless ["POST", "PUT"].include?(request_type)
32
32
  req = self.new(domain, options)
33
33
 
34
34
  if request_type == "POST"
@@ -24,9 +24,13 @@ class HttpRequestorTest < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def test_should_post_multiple_files
27
- uri = "http://www.imaaage.com/upload.php"
28
- data = {:image => [File.open("images.jpg"), File.open("images.jpg")]}
29
-
30
- assert_equal("200", HTTP::Requestor.multipart_request(uri, "post", data).code)
27
+ uri = "https://www.google.co.in/searchbyimage/upload"
28
+ data = {:q => [File.open("images.jpg"), File.open("images.jpg")]}
29
+ assert_equal("302", HTTP::Requestor.multipart_request(uri, "post", data).code)
30
+ end
31
+
32
+ def test_should_send_options_request
33
+ http = HTTP::Requestor.new("http://www.askapache.com")
34
+ assert_equal("200", http.options("/online-tools/request-method-scanner/").code)
31
35
  end
32
36
  end
@@ -0,0 +1,4 @@
1
+ require "../lib/http_requestor"
2
+
3
+ http = HTTP::Requestor.new("https://code-bltdev.cloudthis.com")
4
+ puts http.options("/")
@@ -0,0 +1 @@
1
+ This is testing
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: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-28 00:00:00.000000000Z
12
+ date: 2013-01-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
16
- requirement: &28054152 !ruby/object:Gem::Requirement
16
+ requirement: &29189424 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,9 +21,10 @@ dependencies:
21
21
  version: 1.17.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *28054152
24
+ version_requirements: *29189424
25
25
  description: ! " A Wrapper around Net/HTTP which allows you to perform HTTP Requests.\n
26
- \ Gives you a simple API interface to send multipart requests.\n"
26
+ \ Gives you a simple API interface to send multipart requests.\n\n You can
27
+ also send HTTP calls using the verbs OPTIONS, PATCH, MOVE, HEAD, TRACE\n"
27
28
  email: rohit0981989@gmail.com
28
29
  executables: []
29
30
  extensions: []
@@ -35,6 +36,8 @@ files:
35
36
  - README.rdoc
36
37
  - test/http_requestor_test.rb
37
38
  - test/images.jpg
39
+ - test/manual_test.rb
40
+ - test/testfile.txt
38
41
  homepage: http://github.com/rohit9889/http-requestor
39
42
  licenses:
40
43
  - MIT
@@ -63,3 +66,5 @@ summary: A Wrapper around Net/HTTP which allows you to perform HTTP Requests.
63
66
  test_files:
64
67
  - test/http_requestor_test.rb
65
68
  - test/images.jpg
69
+ - test/manual_test.rb
70
+ - test/testfile.txt