simple-http-helper 0.0.1 → 0.0.2

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: a4c5c31988ebdb707ce4b547d289c40ddb90ba05
4
- data.tar.gz: 72ec3c6de6af4efaade98f989ffd1b21b66593eb
3
+ metadata.gz: c2c043c04da6398be133aceb004867ee5e033652
4
+ data.tar.gz: 6d08d4cadacd49007fb6aab3c06071d8d8bea936
5
5
  SHA512:
6
- metadata.gz: f12ed4091005e4226c65b4629f31a652c49ec872f8e20da767b2fc382c96ebe19e4834fb49afa9833597df3a26101f178ca8d2ad49189178b4685b2636b6888c
7
- data.tar.gz: f552c417989d4e9de934062f283e102e8e5ef41c7a52eb5047f0473eef328c0fc6e5ed726c69126d993469173b4bd92019c4e9b91eddeed04c6acace5f6d1d7e
6
+ metadata.gz: 667f44c6f771931780490295097ce899652fd887367fb4bd6b95830be283f69f9f8cfd4e86ab583146270b56e8b8c21528acf0af5c224208cf2eea77979dee3d
7
+ data.tar.gz: 10923d5da3a0037905a19d708ffa9190016742b3c0171bc651d157daa0d8f64a8a1a3753a319a006bbd1af42c2d0cb79f8ce3d5335020ca957ef2d64f65a1bf0
@@ -1,10 +1,10 @@
1
1
  require 'net/http'
2
2
  require 'net/https'
3
3
  require 'json'
4
+ require 'ostruct'
4
5
 
5
6
  module HelperModule
6
7
 
7
- # TODO: add SimpleHttpsHelper to support https requests
8
8
  class SimpleRequestHelper
9
9
  attr_reader :host, :port, :path
10
10
  attr_accessor :_debug
@@ -13,6 +13,12 @@ module HelperModule
13
13
  @host, @port, @path = host, port, path
14
14
  end
15
15
 
16
+ def set_auth(username, password)
17
+ @auth = OpenStruct.new
18
+ @auth.username = username
19
+ @auth.password = password
20
+ end
21
+
16
22
  def _request_prefix
17
23
  raise NotImplementedError
18
24
  end
@@ -42,7 +48,9 @@ module HelperModule
42
48
  end
43
49
 
44
50
  response = _create_request_sender(@host, @port).start do |http|
45
- http.request(content.get_request)
51
+ request = content.get_request
52
+ request.basic_auth(@auth.username, @auth.password) if @auth
53
+ http.request(request)
46
54
  end
47
55
 
48
56
  return SimpleHttpResult.new(response)
@@ -222,7 +230,7 @@ module HelperModule
222
230
  end
223
231
 
224
232
  def is_success?
225
- @response.code.to_i == 200
233
+ @response.code.to_i == 200 || @response.code.to_i == 201
226
234
  end
227
235
 
228
236
  def error_message
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-http-helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukai Jin
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.6.12
40
+ rubygems_version: 2.6.14
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: A simple http(s) request helper