http_connect 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/http_connect.rb +29 -22
- data/lib/http_connect/http_request.rb +1 -1
- data/lib/http_connect/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f5a761747e034608b31ff107a8776dea71a9dfa
|
|
4
|
+
data.tar.gz: 615a6cc84e650314a9df78bae957c28b7ff5da8b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 071714d8b35cbb176ca222f170196c47ea93b683ffaf523dda9032dc2c72f4c9bd1f91310996dfeead3b6347652a227e9bfcca2cc95ac9edd5684a7740788a4d
|
|
7
|
+
data.tar.gz: 6da1f874b562531042843af91dfe67878fe503622f7a2299e9360266b2138dec222650246d6e628631bf368ff32d62b54f2c8f2f2ad8c6e6a9702cec97608578
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# HttpConnect
|
|
2
2
|
|
|
3
|
-
A minimal ruby Rest client that
|
|
3
|
+
A minimal ruby Rest client that is built around the ruby Net::Http library to make requests. It features a simple interface for making Web requests. It has been written and tested on an environment using ruby 2.0 or later.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
data/lib/http_connect.rb
CHANGED
|
@@ -39,7 +39,7 @@ module HttpConnect
|
|
|
39
39
|
# @param password the password credential
|
|
40
40
|
def set_basic_auth(username, password)
|
|
41
41
|
@custom_headers['Authorization'] =
|
|
42
|
-
|
|
42
|
+
"Basic #{Base64.encode64(username + ':' + password)}".chomp
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# execute(). It helps execute an Http request
|
|
@@ -51,12 +51,12 @@ module HttpConnect
|
|
|
51
51
|
# @param http_webrequest the HttpRequest object
|
|
52
52
|
# @return HttpResponse object or an Http Error object
|
|
53
53
|
def execute(http_webrequest)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
54
|
+
(http_webrequest.is_a? HttpRequest) ?
|
|
55
|
+
do_http_request(http_webrequest.path,
|
|
56
|
+
http_webrequest.http_method,
|
|
57
|
+
http_webrequest.content_type,
|
|
58
|
+
http_webrequest.accept, http_webrequest.content) :
|
|
59
|
+
raise('http_webrequest is not a subclass of HttpRequest')
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
# post(). It helps send an HTTP POST request
|
|
@@ -136,11 +136,13 @@ module HttpConnect
|
|
|
136
136
|
|
|
137
137
|
def handle_content(request, content_type, content)
|
|
138
138
|
case content_type
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
when DEFAULT_CONTENT_TYPE then
|
|
140
|
+
request.body = content.to_json
|
|
141
|
+
request.add_field 'Content-Length', request.body.size
|
|
142
|
+
when FORM_DATA then
|
|
143
|
+
request.set_form_data(content)
|
|
144
|
+
else
|
|
145
|
+
request.set_form_data(content)
|
|
144
146
|
end
|
|
145
147
|
end
|
|
146
148
|
|
|
@@ -163,11 +165,16 @@ module HttpConnect
|
|
|
163
165
|
# @return the http request object
|
|
164
166
|
def extract_request(uri, http_method)
|
|
165
167
|
request = case http_method
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
168
|
+
when 'POST' then
|
|
169
|
+
Net::HTTP::Post.new(uri)
|
|
170
|
+
when 'GET' then
|
|
171
|
+
Net::HTTP::Get.new(uri)
|
|
172
|
+
when 'DELETE' then
|
|
173
|
+
Net::HTTP::Delete.new(uri)
|
|
174
|
+
when 'PUT' then
|
|
175
|
+
Net::HTTP::Put.new(uri)
|
|
176
|
+
else
|
|
177
|
+
raise 'invalid http method'
|
|
171
178
|
end
|
|
172
179
|
request
|
|
173
180
|
end
|
|
@@ -176,11 +183,11 @@ module HttpConnect
|
|
|
176
183
|
# @param response the Net::HTTPResponse object to extract
|
|
177
184
|
def extract_response(response)
|
|
178
185
|
case response
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
when Net::HTTPSuccess, Net::HTTPRedirection then
|
|
187
|
+
HttpConnect::HttpResponse.new(response.code.to_i,
|
|
188
|
+
response.body, response.to_hash)
|
|
189
|
+
else
|
|
190
|
+
response.value
|
|
184
191
|
end
|
|
185
192
|
end
|
|
186
193
|
end
|
|
@@ -16,7 +16,7 @@ module HttpConnect
|
|
|
16
16
|
@content = content
|
|
17
17
|
@content_type = content_type
|
|
18
18
|
|
|
19
|
-
@path
|
|
19
|
+
@path << "? #{URI.encode_www_form(@content)}" if %w[GET DELETE].include? @http_method
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
end
|
data/lib/http_connect/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: http_connect
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arsene Tochemey GANDOTE
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-07-
|
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|