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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f0804c4e6d31ad1428ff8d3d6f0a546004fbb051
4
- data.tar.gz: 4f4f2fd187c9a8d809a40e7d45e993d9a4f71115
3
+ metadata.gz: 9f5a761747e034608b31ff107a8776dea71a9dfa
4
+ data.tar.gz: 615a6cc84e650314a9df78bae957c28b7ff5da8b
5
5
  SHA512:
6
- metadata.gz: d913c7ec288c7fb4a222e2fc417f374c9ed6a8c98234c5d0e3fc2e04c090ea367d5e08093ef0b8f6bdd768056aa6385ab3cd9747288de2b2a4d1d0a279f45571
7
- data.tar.gz: ce3d11d88e80b2074f703dacdbca507f9618794c24240614602e238d069c2b457c374707edda283d6598ade73403c831684f19ec79903dc70636069a7771c988
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 uses 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.
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
- "Basic #{Base64.encode64(username + ':' + password)}".chomp
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
- raise ArgumentError, 'http_webrequest is not a subclass of HttpRequest'
55
- unless http_webrequest.is_a? HttpRequest
56
- do_http_request(http_webrequest.path,
57
- http_webrequest.http_method,
58
- http_webrequest.content_type,
59
- http_webrequest.accept, http_webrequest.content)
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
- 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 request.set_form_data(content)
143
- else request.set_form_data(content)
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
- when 'POST' then Net::HTTP::Post.new(uri)
167
- when 'GET' then Net::HTTP::Get.new(uri)
168
- when 'DELETE' then Net::HTTP::Delete.new(uri)
169
- when 'PUT' then Net::HTTP::Put.new(uri)
170
- else raise 'invalid http method'
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
- when Net::HTTPSuccess, Net::HTTPRedirection then
180
- HttpConnect::HttpResponse.new(response.code.to_i,
181
- response.body, response.to_hash)
182
- else
183
- response.value
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 += '?' + URI.encode_www_form(@content) if %w[GET DELETE].include? @http_method
19
+ @path << "? #{URI.encode_www_form(@content)}" if %w[GET DELETE].include? @http_method
20
20
  end
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module HttpConnect
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
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.0
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-15 00:00:00.000000000 Z
11
+ date: 2017-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler