rb-net_http-client 1.1.1 → 1.1.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 +4 -4
- data/lib/client/ext.rb +4 -0
- data/lib/core/utilities.rb +23 -2
- data/lib/request/request.rb +43 -32
- data/lib/request/schema.rb +1 -1
- data/lib/response/response.rb +0 -2
- data/lib/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: dca512c41b7ef3a50b1bcaeb52c5f4a24fc516f78f616ecefa336f7c1d840c43
         | 
| 4 | 
            +
              data.tar.gz: ccd78d9a1c8a7be03f7542650bf1051ebaa4fd74d131dc464db1705d65b1f7c9
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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],
         | 
    
        data/lib/core/utilities.rb
    CHANGED
    
    | @@ -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 =  | 
| 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)
         | 
    
        data/lib/request/request.rb
    CHANGED
    
    | @@ -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 => ' +  | 
| 43 | 
            +
                  logger.debug('Request Path => ' + path)
         | 
| 38 44 | 
             
                  NetHTTP::Response.new(
         | 
| 39 45 | 
             
                    response: client.delete(
         | 
| 40 | 
            -
                       | 
| 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 => ' +  | 
| 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 | 
            -
                       | 
| 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 => ' +  | 
| 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 | 
            -
                       | 
| 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 => ' +  | 
| 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 | 
            -
                       | 
| 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 => ' +  | 
| 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 | 
            -
                       | 
| 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 =  | 
| 147 | 
            -
             | 
| 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
         | 
    
        data/lib/request/schema.rb
    CHANGED
    
    | @@ -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 | 
| 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?))
         | 
    
        data/lib/response/response.rb
    CHANGED
    
    
    
        data/lib/version.rb
    CHANGED
    
    
    
        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. | 
| 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- | 
| 11 | 
            +
            date: 2019-05-03 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         |