rb-net_http-client 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b3cdc38ddadcecc511dd7a354829600cb24508403d8a8acc2901cf2b1f8e0c3
4
- data.tar.gz: 0e4c2c646e2bdfe6e0f77810292d9bf4f7e5a5277e6b8957161930a26ff8d3a2
3
+ metadata.gz: dca512c41b7ef3a50b1bcaeb52c5f4a24fc516f78f616ecefa336f7c1d840c43
4
+ data.tar.gz: ccd78d9a1c8a7be03f7542650bf1051ebaa4fd74d131dc464db1705d65b1f7c9
5
5
  SHA512:
6
- metadata.gz: 4a4fe6a7b7ac48cb71c6ab98f3b3ea2f907604dee229b5a160989b57aeaa99003048f56c8c774945a0ec0df8621cc164714609ffd4fcadaed0f62721b2bfd7ef
7
- data.tar.gz: f16e89e2c4fdd38cdce09c896bfb743690ce7792403ef0cc88bf9d8f702d5cc3df61b3831baddc55da2bbc4079b0da74dce7796e205473f37630ed7c9216947b
6
+ metadata.gz: fcb564bae3120591d9ebedf8177e1ebc723421548e76ab98ffb61196cf3e1de61cdc8486ac8bd938dcf3bad1546b03b5e4d2c10c32fada1f92d05b676caf6e64
7
+ data.tar.gz: 5ed36d3dd20e8505970ef371dcf4747c8b061f97a880af9567b324d1bcaf3f434ea269033f1e09eaf1ed03fb5708e51a8ffdcc8ec6f441365aa4081866b17173
data/lib/client/ext.rb CHANGED
@@ -12,6 +12,8 @@ module NetHTTP
12
12
  @proxy_uri = Core::Utilities.parse_uri(
13
13
  Core::Utilities.construct_uri(
14
14
  scheme: opts[:proxy_uri_scheme],
15
+ user: opts[:proxy_uri_user],
16
+ password: opts[:proxy_uri_password],
15
17
  host: opts[:proxy_uri_host],
16
18
  port: opts[:proxy_uri_port],
17
19
  path: opts[:proxy_uri_path],
@@ -34,6 +36,8 @@ module NetHTTP
34
36
  @uri = Core::Utilities.parse_uri(
35
37
  Core::Utilities.construct_uri(
36
38
  scheme: opts[:scheme],
39
+ user: opts[:user],
40
+ password: opts[:password],
37
41
  host: opts[:host],
38
42
  port: opts[:port],
39
43
  path: opts[:path],
@@ -35,18 +35,39 @@ module NetHTTP
35
35
  end
36
36
  end
37
37
 
38
+ if uri[:user].to_s.empty? || uri[:password].to_s.empty?
39
+ user_pass = nil
40
+ else
41
+ user_pass = "#{uri[:user]}:#{uri[:password]}@"
42
+ end
43
+
38
44
  scheme = "#{scheme}://"
39
45
  host = uri[:host]
40
46
  port = ":#{port}"
41
47
  path = uri[:path]
42
- query = "?#{uri[:query]}"
48
+ query = parse_query(uri[:query])
43
49
 
44
50
  scheme = nil if scheme.to_s.empty?
45
51
  port = nil if port.to_s.empty?
46
52
  path = nil if uri[:path].to_s.empty?
47
53
  query = nil if uri[:query].to_s.empty?
48
54
 
49
- URI("#{scheme}#{host}#{port}#{path}#{query}").to_s
55
+ URI("#{scheme}#{user_pass}#{host}#{port}#{path}#{query}").to_s
56
+ end
57
+
58
+ def self.parse_query(query)
59
+ # todo: may need to update this as URI.escape is considered obsolete
60
+ case query
61
+ when String
62
+ query = query[1..-1] if query.start_with?('?')
63
+ URI.escape("?#{query}")
64
+ when Hash
65
+ query = query.map { |k, v| "#{k}=#{v}" }
66
+ query = query.join('&')
67
+ URI.escape("?#{query}")
68
+ else
69
+ nil
70
+ end
50
71
  end
51
72
 
52
73
  def self.parse_uri(uri)
@@ -31,13 +31,19 @@ module NetHTTP
31
31
 
32
32
  opts[:method] = 'delete'
33
33
  request_opts = request_opts(opts)
34
+ path = if request_opts[:query]
35
+ request_opts[:path] + request_opts[:query]
36
+ else
37
+ request_opts[:path]
38
+ end
39
+
34
40
  logger.debug('Request Method => ' + request_opts[:method].to_s.upcase)
35
41
  logger.debug('Request Host => ' + request_opts[:uri].scheme.to_s + '://' + request_opts[:uri].host.to_s)
36
42
  logger.debug('Request Port => ' + request_opts[:uri].port.to_s)
37
- logger.debug('Request Path => ' + request_opts[:path])
43
+ logger.debug('Request Path => ' + path)
38
44
  NetHTTP::Response.new(
39
45
  response: client.delete(
40
- request_opts[:path]
46
+ path
41
47
  ),
42
48
  logger: logger
43
49
  )
@@ -48,15 +54,21 @@ module NetHTTP
48
54
 
49
55
  opts[:method] = 'get'
50
56
  request_opts = request_opts(opts)
57
+ path = if request_opts[:query]
58
+ request_opts[:path] + request_opts[:query]
59
+ else
60
+ request_opts[:path]
61
+ end
62
+
51
63
  logger.debug('Request Method => ' + request_opts[:method].to_s.upcase)
52
64
  logger.debug('Request Host => ' + request_opts[:uri].scheme.to_s + '://' + request_opts[:uri].host.to_s)
53
65
  logger.debug('Request Port => ' + request_opts[:uri].port.to_s)
54
- logger.debug('Request Path => ' + request_opts[:path])
66
+ logger.debug('Request Path => ' + path)
55
67
  logger.debug('Request Headers =>')
56
68
  logger.debug(request_opts[:headers])
57
69
  NetHTTP::Response.new(
58
70
  response: client.get(
59
- request_opts[:path],
71
+ path,
60
72
  request_opts[:headers]
61
73
  ),
62
74
  logger: logger
@@ -68,17 +80,23 @@ module NetHTTP
68
80
 
69
81
  opts[:method] = 'post'
70
82
  request_opts = request_opts(opts)
83
+ path = if request_opts[:query]
84
+ request_opts[:path] + request_opts[:query]
85
+ else
86
+ request_opts[:path]
87
+ end
88
+
71
89
  logger.debug('Request Method => ' + request_opts[:method].to_s.upcase)
72
90
  logger.debug('Request Host => ' + request_opts[:uri].scheme.to_s + '://' + request_opts[:uri].host.to_s)
73
91
  logger.debug('Request Port => ' + request_opts[:uri].port.to_s)
74
- logger.debug('Request Path => ' + request_opts[:path])
92
+ logger.debug('Request Path => ' + path)
75
93
  logger.debug('Request Headers =>')
76
94
  logger.debug(request_opts[:headers])
77
95
  logger.debug('Request Body =>')
78
96
  logger.debug(request_opts[:body])
79
97
  NetHTTP::Response.new(
80
98
  response: client.post(
81
- request_opts[:path],
99
+ path,
82
100
  request_opts[:body],
83
101
  request_opts[:headers]
84
102
  ),
@@ -91,17 +109,23 @@ module NetHTTP
91
109
 
92
110
  opts[:method] = 'post_form'
93
111
  request_opts = request_opts(opts)
112
+ path = if request_opts[:query]
113
+ request_opts[:path] + request_opts[:query]
114
+ else
115
+ request_opts[:path]
116
+ end
117
+
94
118
  logger.debug('Request Method => ' + request_opts[:method].to_s.upcase)
95
119
  logger.debug('Request Host => ' + request_opts[:uri].scheme.to_s + '://' + request_opts[:uri].host.to_s)
96
120
  logger.debug('Request Port => ' + request_opts[:uri].port.to_s)
97
- logger.debug('Request Path => ' + request_opts[:path])
121
+ logger.debug('Request Path => ' + path)
98
122
  logger.debug('Request Headers =>')
99
123
  logger.debug(request_opts[:headers])
100
124
  logger.debug('Request Body =>')
101
125
  logger.debug(URI.encode_www_form(request_opts[:body]))
102
126
  NetHTTP::Response.new(
103
127
  response: client.post(
104
- uri,
128
+ path,
105
129
  URI.encode_www_form(request_opts[:body]),
106
130
  request_opts[:headers]
107
131
  ),
@@ -116,17 +140,23 @@ module NetHTTP
116
140
 
117
141
  opts[:method] = 'put'
118
142
  request_opts = request_opts(opts)
143
+ path = if request_opts[:query]
144
+ request_opts[:path] + request_opts[:query]
145
+ else
146
+ request_opts[:path]
147
+ end
148
+
119
149
  logger.debug('Request Method => ' + request_opts[:method].to_s.upcase)
120
150
  logger.debug('Request Host => ' + request_opts[:uri].scheme.to_s + '://' + request_opts[:uri].host.to_s)
121
151
  logger.debug('Request Port => ' + request_opts[:uri].port.to_s)
122
- logger.debug('Request Path => ' + request_opts[:path])
152
+ logger.debug('Request Path => ' + path)
123
153
  logger.debug('Request Headers =>')
124
154
  logger.debug(request_opts[:headers])
125
155
  logger.debug('Request Body =>')
126
156
  logger.debug(request_opts[:body])
127
157
  NetHTTP::Response.new(
128
158
  response: client.put(
129
- request_opts[:path],
159
+ path,
130
160
  request_opts[:body],
131
161
  request_opts[:headers]
132
162
  ),
@@ -143,10 +173,8 @@ module NetHTTP
143
173
 
144
174
  request_method = opts[:method] ||= 'post'
145
175
  request_uri = Core::Utilities.parse_uri(opts[:uri] || opts[:url] || uri)
146
- request_path = request_path(
147
- path: (opts[:path] || request_uri.path || path),
148
- query: (opts[:query] || request_uri.query || query)
149
- )
176
+ request_path = (opts[:path] || request_uri.path || path).chomp('?')
177
+ request_query = Core::Utilities.parse_query((opts[:query] || request_uri.query || query))
150
178
  request_headers = opts[:headers] ||= {}
151
179
  request_body = opts[:body] ||= nil
152
180
 
@@ -154,27 +182,10 @@ module NetHTTP
154
182
  method: request_method,
155
183
  uri: request_uri,
156
184
  path: request_path,
185
+ query: request_query,
157
186
  headers: request_headers,
158
187
  body: request_body
159
188
  }
160
189
  end
161
-
162
- def request_path(opts)
163
- # i.e. URI('https://www.google.com')
164
- # uri.path defaults to "" if empty / not set
165
- # uri.query defaults to nil if empty / not set
166
- path = opts[:path].to_s.chomp('?')
167
- if opts[:query].to_s.start_with?('?')
168
- query = opts[:query][1..-1]
169
- else
170
- query = opts[:query].to_s
171
- end
172
-
173
- return '' if path.empty? && query.empty?
174
- return path if query.empty?
175
- return '/' + query if path.empty?
176
-
177
- path + '?' + query
178
- end
179
190
  end
180
191
  end
@@ -14,7 +14,7 @@ module NetHTTP
14
14
  required(:method).filled(type?: String)
15
15
  optional(:headers).maybe(type?: Hash)
16
16
  optional(:body).maybe
17
- optional(:query).filled(type?: String)
17
+ optional(:query).filled
18
18
 
19
19
  rule(if_url_and_uri_are_nil_must_provide_path: [:uri, :url, :path]) do |uri, url, path|
20
20
  uri.empty?.then(url.empty?.then(path.filled?))
@@ -61,8 +61,6 @@ module NetHTTP
61
61
  end
62
62
  end
63
63
 
64
- # TODO: remove this eventually
65
- alias body_hash body_obj
66
64
  alias resp_body_obj body_obj
67
65
  alias response_body_obj body_obj
68
66
 
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NetHTTP
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-net_http-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Bostian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport