aitch 1.2.0 → 1.2.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: a3f4cd3269e5b709f85e34148b2ed6aad4a9080f9903dc625d4840d8ffc2293a
4
- data.tar.gz: d97a344ec31e5f6ba528f1d359b96aa2860ab51e1cdde507d5cbc0557e9a75a4
3
+ metadata.gz: c49091163504e6a6587170951f8e4545b4474b1912c85c5bcfeb102763a214b7
4
+ data.tar.gz: 7fac91b61ee9ad82e8f880f25758b9f6a433ad8ed3bcc5134b261e64f5da61fc
5
5
  SHA512:
6
- metadata.gz: a11acc6e165677b372cd4c9a07b9fd33640611a056fb1c437917ffa1d89ab0520bcaf9943cd5e8f72a3f088942a8f7b9d968a59ec7207dc6a061f54364216aba
7
- data.tar.gz: a0228f9d4719ee0fddd2932fece69c454062d40f4526612b41044168198f7ec91478267163e343a995ceb5f8bbcdc1d4d228d8edb73a9845b5aa0d08145581c9
6
+ metadata.gz: 859bdbfb5f70d99646c628f16a2cea718385299ca1b48d32e0ecfb8c9598ad27b8cf3363498b50eaddf8585901212faa1f588dc9dc29ad1982891f2a3c26b1fa
7
+ data.tar.gz: a7045d8d2a6c9d172b2b90180cd4d2afb13a5ceac088b74b9cb7ccc63fa9050920df69310e0eef1ae745b44d0edd4c45f6779c9a6fe420c3951878be4ff3fbf1
data/.rubocop.yml CHANGED
@@ -4,6 +4,7 @@ inherit_gem:
4
4
 
5
5
  AllCops:
6
6
  TargetRubyVersion: 2.5
7
+ NewCops: enable
7
8
 
8
9
  Layout/LineLength:
9
10
  Exclude:
@@ -13,14 +14,11 @@ Naming/AccessorMethodName:
13
14
  Exclude:
14
15
  - lib/aitch/request.rb
15
16
 
16
- Metrics/ClassLength:
17
+ Style/DocumentDynamicEvalDefinition:
17
18
  Enabled: false
18
19
 
19
- Metrics/AbcSize:
20
+ Gemspec/DevelopmentDependencies:
20
21
  Enabled: false
21
22
 
22
- Metrics/MethodLength:
23
- Enabled: false
24
-
25
- Metrics/ParameterLists:
23
+ Minitest/MultipleAssertions:
26
24
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,40 +1,54 @@
1
1
  # Changelog
2
2
 
3
- * **1.0.1**
4
- * Fix a bug when JSON encoding body in a POST request.
5
- * **1.0.0**
6
- * Use frozen string magic comments
7
- * 307 redirections will honor the HTTP request method
8
- * Fix issue with redirection; it was including the target url for one level redirection.
9
- * Methods `Aitch::Response#html`, `Aitch::Response#json`, `Aitch::Response#xml` were removed; use `Aitch::Response#data` instead.
10
- * Add support to response parsers
11
- * **0.5.0** - May 24, 2015
12
- * Remove hard dependency on ActiveSupport
13
- * Add response validation
14
- * **0.4.1** - December 20, 2014
15
- * Consider default headers when returning content type (fixes issue with body's JSON encoding)
16
- * **0.4.0** - December 18, 2014
17
- * Add accessor method for setting request's content type
18
- * Automatically encodes body as JSON when content type matches `json`
19
- * JSON encoding now uses a parser
20
- * **0.3.0** - April 28, 2014
21
- * Make list of redirections available
22
- * Make the request URL available on responses
23
- * **0.2.1** - July 30, 2013
24
- * Add alias for `response.success?` (`response.ok?`)
25
- * **0.2.0** - July 28, 2013
26
- * Add DSL support
27
- * Create aliases for `response.data` (`response.xml` and `response.json`)
28
- * **0.1.5** - June 26, 2013
29
- * Fix issue with jRuby and `to_h` protocol
30
- * **0.1.4** - June 13, 2013
31
- * Accept headers as callable objects
32
- * Fix XML encoding, always converting values to UTF-8
33
- * **0.1.3** - May 12, 2013
34
- * Add response HTML parsing into Nokogiri object
35
- * **0.1.2** - May 10, 2013
36
- * Add response error code helpers, like `response.bad_request?` and `response.not_found?`
37
- * **0.1.1** - April 30, 2013
38
- * Add support for namespaces
39
- * **0.1.0** - April 29, 2013
40
- * Initial release
3
+ - **1.2.2**
4
+ - Transform header key before assigning values.
5
+ - **1.2.1**
6
+ - Avoid calling `to_h` when params are array-like.
7
+ - **1.2.0**
8
+ - Add support to base url.
9
+ - **1.1.0**
10
+ - Add keyword argument interface to methods like `Aitch.get` and alike.
11
+ - **1.0.2**
12
+ - Use `JSON.parse` rather than `JSON.load`.
13
+ - **1.0.1**
14
+ - Fix a bug when JSON encoding body in a POST request.
15
+ - **1.0.0**
16
+ - Use frozen string magic comments
17
+ - 307 redirections will honor the HTTP request method
18
+ - Fix issue with redirection; it was including the target url for one level
19
+ redirection.
20
+ - Methods `Aitch::Response#html`, `Aitch::Response#json`,
21
+ `Aitch::Response#xml` were removed; use `Aitch::Response#data` instead.
22
+ - Add support to response parsers
23
+ - **0.5.0** - May 24, 2015
24
+ - Remove hard dependency on ActiveSupport
25
+ - Add response validation
26
+ - **0.4.1** - December 20, 2014
27
+ - Consider default headers when returning content type (fixes issue with
28
+ body's JSON encoding)
29
+ - **0.4.0** - December 18, 2014
30
+ - Add accessor method for setting request's content type
31
+ - Automatically encodes body as JSON when content type matches `json`
32
+ - JSON encoding now uses a parser
33
+ - **0.3.0** - April 28, 2014
34
+ - Make list of redirections available
35
+ - Make the request URL available on responses
36
+ - **0.2.1** - July 30, 2013
37
+ - Add alias for `response.success?` (`response.ok?`)
38
+ - **0.2.0** - July 28, 2013
39
+ - Add DSL support
40
+ - Create aliases for `response.data` (`response.xml` and `response.json`)
41
+ - **0.1.5** - June 26, 2013
42
+ - Fix issue with jRuby and `to_h` protocol
43
+ - **0.1.4** - June 13, 2013
44
+ - Accept headers as callable objects
45
+ - Fix XML encoding, always converting values to UTF-8
46
+ - **0.1.3** - May 12, 2013
47
+ - Add response HTML parsing into Nokogiri object
48
+ - **0.1.2** - May 10, 2013
49
+ - Add response error code helpers, like `response.bad_request?` and
50
+ `response.not_found?`
51
+ - **0.1.1** - April 30, 2013
52
+ - Add support for namespaces
53
+ - **0.1.0** - April 29, 2013
54
+ - Initial release
data/aitch.gemspec CHANGED
@@ -6,16 +6,16 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "aitch"
7
7
  spec.version = Aitch::VERSION
8
8
  spec.authors = ["Nando Vieira"]
9
- spec.email = ["fnando.vieira@gmail.com"]
9
+ spec.email = ["me@fnando.com"]
10
10
  spec.description = "A simple HTTP client"
11
11
  spec.summary = spec.description
12
12
  spec.homepage = "http://rubygems.org/gems/aitch"
13
13
  spec.license = "MIT"
14
14
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
15
+ spec.metadata["rubygems_mfa_required"] = "true"
15
16
 
16
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "nokogiri"
@@ -2,6 +2,8 @@
2
2
 
3
3
  module Aitch
4
4
  class Location
5
+ MATCHER = %r{\A/}.freeze
6
+
5
7
  attr_reader :redirect_stack, :current_url
6
8
 
7
9
  def initialize(redirect_stack, current_url)
@@ -10,7 +12,7 @@ module Aitch
10
12
  end
11
13
 
12
14
  def location
13
- return current_url unless current_url.match?(%r{\A/}) # rubocop:disable Performance/StartWith
15
+ return current_url unless current_url.match?(MATCHER)
14
16
 
15
17
  uri = find_uri_with_host
16
18
  url = ["#{uri.scheme}://#{uri.hostname}"]
data/lib/aitch/request.rb CHANGED
@@ -4,6 +4,14 @@ module Aitch
4
4
  class Request
5
5
  attr_accessor :request_method, :url, :data, :headers, :options, :redirects
6
6
 
7
+ CONTENT_TYPE = "Content-Type"
8
+ USER_AGENT = "User-Agent"
9
+ ACCEPT_ENCODING = "Accept-Encoding"
10
+ GZIP_DEFLATE = "gzip,deflate"
11
+ HTTPS = "https"
12
+ HEADER_SEPARATOR_RE = /[-_]/.freeze
13
+ JSON_RE = /\bjson\b/.freeze
14
+
7
15
  alias params= data=
8
16
  alias body= data=
9
17
 
@@ -30,12 +38,12 @@ module Aitch
30
38
  end
31
39
 
32
40
  def content_type=(content_type)
33
- headers["Content-Type"] = content_type
41
+ headers[CONTENT_TYPE] = content_type
34
42
  end
35
43
 
36
44
  def content_type
37
- headers["Content-Type"] ||
38
- options.fetch(:default_headers, {})["Content-Type"]
45
+ headers[CONTENT_TYPE] ||
46
+ options.fetch(:default_headers, {})[CONTENT_TYPE]
39
47
  end
40
48
 
41
49
  def request
@@ -77,9 +85,9 @@ module Aitch
77
85
 
78
86
  private def set_body(request)
79
87
  body_data = data
80
- body_data = data.to_h if data.respond_to?(:to_h)
88
+ body_data = data.to_h if data.respond_to?(:to_h) && !data.is_a?(Array)
81
89
 
82
- if content_type.to_s.match?(/\bjson\b/)
90
+ if content_type.to_s.match?(JSON_RE)
83
91
  body_data = ResponseParser::JSONParser.engine.dump(body_data)
84
92
  end
85
93
 
@@ -95,7 +103,8 @@ module Aitch
95
103
 
96
104
  all_headers.each do |name, value|
97
105
  value = value.respond_to?(:call) ? value.call : value
98
- request[name.to_s] = value.to_s
106
+ name = name.to_s.split(HEADER_SEPARATOR_RE).map(&:capitalize).join("-")
107
+ request[name] = value.to_s
99
108
  end
100
109
  end
101
110
 
@@ -106,7 +115,7 @@ module Aitch
106
115
  end
107
116
 
108
117
  private def set_https(client)
109
- client.use_ssl = uri.scheme == "https"
118
+ client.use_ssl = uri.scheme == HTTPS
110
119
  client.verify_mode = OpenSSL::SSL::VERIFY_PEER
111
120
  end
112
121
 
@@ -120,11 +129,11 @@ module Aitch
120
129
  end
121
130
 
122
131
  private def set_user_agent(request)
123
- request["User-Agent"] = options[:user_agent]
132
+ request[USER_AGENT] = options[:user_agent]
124
133
  end
125
134
 
126
135
  private def set_gzip(request)
127
- request["Accept-Encoding"] = "gzip,deflate"
136
+ request[ACCEPT_ENCODING] = GZIP_DEFLATE
128
137
  end
129
138
 
130
139
  def timeout_exception
@@ -4,11 +4,20 @@ module Aitch
4
4
  class Response
5
5
  extend Forwardable
6
6
 
7
+ JSON_STR = "json"
8
+ XML_STR = "xml"
9
+ HTML_STR = "html"
10
+ EMPTY_STR = ""
11
+ DOUBLE_COLON = "::"
12
+ SPACE_STR = " "
13
+ ERROR_SUFFIX = "_error"
14
+ X_RE = /^x-/.freeze
15
+
7
16
  def_delegators :@http_response, :content_type
8
17
  attr_accessor :redirected_from, :url
9
18
 
10
19
  def self.description_for_code(code)
11
- [code, DESCRIPTION[code]].compact.join(" ")
20
+ [code, DESCRIPTION[code]].compact.join(SPACE_STR)
12
21
  end
13
22
 
14
23
  def initialize(options, http_response)
@@ -19,8 +28,8 @@ module Aitch
19
28
 
20
29
  ERRORS.each do |status_code, exception|
21
30
  method_name = Utils
22
- .underscore(exception.name.split("::").last)
23
- .gsub("_error", "")
31
+ .underscore(exception.name.split(DOUBLE_COLON).last)
32
+ .gsub(ERROR_SUFFIX, EMPTY_STR)
24
33
 
25
34
  define_method "#{method_name}?" do
26
35
  code == status_code
@@ -53,15 +62,15 @@ module Aitch
53
62
  end
54
63
 
55
64
  def json?
56
- content_type =~ /json/
65
+ content_type.include?(JSON_STR)
57
66
  end
58
67
 
59
68
  def xml?
60
- content_type =~ /xml/
69
+ content_type.include?(XML_STR)
61
70
  end
62
71
 
63
72
  def html?
64
- content_type =~ /html/
73
+ content_type.include?(HTML_STR)
65
74
  end
66
75
 
67
76
  def data
@@ -71,7 +80,7 @@ module Aitch
71
80
  def headers
72
81
  @headers ||= {}.tap do |headers|
73
82
  @http_response.each_header do |name, value|
74
- headers[name.gsub(/^x-/, "")] = value
83
+ headers[name.gsub(X_RE, EMPTY_STR)] = value
75
84
  end
76
85
  end
77
86
  end
@@ -8,7 +8,7 @@ module Aitch
8
8
  end
9
9
 
10
10
  def self.match?(content_type)
11
- content_type =~ /html/
11
+ content_type.include?("html")
12
12
  end
13
13
 
14
14
  def self.load(source)
@@ -14,7 +14,7 @@ module Aitch
14
14
  end
15
15
 
16
16
  def self.match?(content_type)
17
- content_type =~ /json/
17
+ content_type.include?("json")
18
18
  end
19
19
 
20
20
  def self.load(source)
@@ -8,7 +8,7 @@ module Aitch
8
8
  end
9
9
 
10
10
  def self.match?(content_type)
11
- content_type =~ /xml/
11
+ content_type.include?("xml")
12
12
  end
13
13
 
14
14
  def self.load(source)
data/lib/aitch/uri.rb CHANGED
@@ -27,7 +27,7 @@ module Aitch
27
27
  end
28
28
 
29
29
  def request_uri
30
- [path, query, fragment].compact.join("")
30
+ [path, query, fragment].compact.join
31
31
  end
32
32
 
33
33
  def fragment
data/lib/aitch/utils.rb CHANGED
@@ -3,8 +3,11 @@
3
3
  module Aitch
4
4
  module Utils
5
5
  extend self
6
+
7
+ MATCHER = /(?<=.)(URI|[A-Z])/.freeze
8
+
6
9
  def underscore(string)
7
- string = string.gsub(/(?<=.)(URI|[A-Z])/) do |char|
10
+ string = string.gsub(MATCHER) do |char|
8
11
  "_#{char}"
9
12
  end
10
13
 
data/lib/aitch/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aitch
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.2"
5
5
  end
@@ -4,25 +4,25 @@ require "test_helper"
4
4
 
5
5
  class AitchTest < Minitest::Test
6
6
  test "defines public API" do
7
- assert Aitch.respond_to?(:get)
8
- assert Aitch.respond_to?(:get!)
9
- assert Aitch.respond_to?(:post)
10
- assert Aitch.respond_to?(:post!)
11
- assert Aitch.respond_to?(:put)
12
- assert Aitch.respond_to?(:put!)
13
- assert Aitch.respond_to?(:patch)
14
- assert Aitch.respond_to?(:patch!)
15
- assert Aitch.respond_to?(:delete)
16
- assert Aitch.respond_to?(:delete!)
17
- assert Aitch.respond_to?(:head)
18
- assert Aitch.respond_to?(:head!)
19
- assert Aitch.respond_to?(:options)
20
- assert Aitch.respond_to?(:options!)
21
- assert Aitch.respond_to?(:trace)
22
- assert Aitch.respond_to?(:trace!)
23
- assert Aitch.respond_to?(:execute)
24
- assert Aitch.respond_to?(:execute!)
25
- assert Aitch.respond_to?(:config)
26
- assert Aitch.respond_to?(:configuration)
7
+ assert_respond_to Aitch, :get
8
+ assert_respond_to Aitch, :get!
9
+ assert_respond_to Aitch, :post
10
+ assert_respond_to Aitch, :post!
11
+ assert_respond_to Aitch, :put
12
+ assert_respond_to Aitch, :put!
13
+ assert_respond_to Aitch, :patch
14
+ assert_respond_to Aitch, :patch!
15
+ assert_respond_to Aitch, :delete
16
+ assert_respond_to Aitch, :delete!
17
+ assert_respond_to Aitch, :head
18
+ assert_respond_to Aitch, :head!
19
+ assert_respond_to Aitch, :options
20
+ assert_respond_to Aitch, :options!
21
+ assert_respond_to Aitch, :trace
22
+ assert_respond_to Aitch, :trace!
23
+ assert_respond_to Aitch, :execute
24
+ assert_respond_to Aitch, :execute!
25
+ assert_respond_to Aitch, :config
26
+ assert_respond_to Aitch, :configuration
27
27
  end
28
28
  end
@@ -9,6 +9,7 @@ class ConfigurationTest < Minitest::Test
9
9
 
10
10
  test "sets default user agent" do
11
11
  user_agent = "Aitch/#{Aitch::VERSION} (http://rubygems.org/gems/aitch)"
12
+
12
13
  assert_equal user_agent, Aitch::Configuration.new.user_agent
13
14
  end
14
15
 
@@ -17,7 +18,7 @@ class ConfigurationTest < Minitest::Test
17
18
  end
18
19
 
19
20
  test "sets default headers" do
20
- assert_equal({}, Aitch::Configuration.new.default_headers)
21
+ assert_empty(Aitch::Configuration.new.default_headers)
21
22
  end
22
23
 
23
24
  test "configures aitch" do
@@ -7,31 +7,37 @@ class DslTest < Minitest::Test
7
7
 
8
8
  test "sets url" do
9
9
  dsl.url "URL"
10
+
10
11
  assert_equal "URL", dsl.url
11
12
  end
12
13
 
13
14
  test "sets options" do
14
15
  dsl.options "OPTIONS"
16
+
15
17
  assert_equal "OPTIONS", dsl.options
16
18
  end
17
19
 
18
20
  test "sets headers" do
19
21
  dsl.headers "HEADERS"
22
+
20
23
  assert_equal "HEADERS", dsl.headers
21
24
  end
22
25
 
23
26
  test "sets data" do
24
27
  dsl.data "DATA"
28
+
25
29
  assert_equal "DATA", dsl.data
26
30
  end
27
31
 
28
32
  test "sets data through params" do
29
33
  dsl.params "PARAMS"
34
+
30
35
  assert_equal "PARAMS", dsl.data
31
36
  end
32
37
 
33
38
  test "sets data through body" do
34
39
  dsl.body "BODY"
40
+
35
41
  assert_equal "BODY", dsl.data
36
42
  end
37
43
 
@@ -41,6 +41,6 @@ class ExecuteBangTest < Minitest::Test
41
41
  response = stub(error?: true, error: "ERROR")
42
42
  Aitch::Request.any_instance.stubs(:perform).returns(response)
43
43
 
44
- assert_raises("ERROR") { Aitch.get!("URL") }
44
+ assert_raises(StandardError, "ERROR") { Aitch.get!("URL") }
45
45
  end
46
46
  end
@@ -7,7 +7,7 @@ class ClientHttpsTest < Minitest::Test
7
7
  let(:client) { request.client }
8
8
 
9
9
  test "sets https" do
10
- assert client.use_ssl?
10
+ assert_predicate client, :use_ssl?
11
11
  end
12
12
 
13
13
  test "sets verification mode" do
@@ -16,6 +16,7 @@ class ClientHttpsTest < Minitest::Test
16
16
 
17
17
  test "sets timeout" do
18
18
  request.options[:timeout] = 20
19
+
19
20
  assert_equal 20, client.read_timeout
20
21
  end
21
22
  end
@@ -14,7 +14,7 @@ class FollowRedirectTest < Minitest::Test
14
14
 
15
15
  response = Aitch.get("http://example.org/")
16
16
 
17
- refute response.redirect?
17
+ refute_predicate response, :redirect?
18
18
  assert_equal "Hello", response.body
19
19
  assert_equal ["http://example.org/", "http://example.com/"], response.redirected_from
20
20
  assert_equal "http://www.example.com/", response.url
@@ -23,6 +23,7 @@ class RequestClassTest < Minitest::Test
23
23
  ].each do |method|
24
24
  test "instantiates #{method.upcase} method" do
25
25
  request = build_request(request_method: method).request
26
+
26
27
  assert_equal "Net::HTTP::#{method.capitalize}", request.class.name
27
28
  end
28
29
  end
@@ -5,6 +5,7 @@ require "test_helper"
5
5
  class RequestTest < Minitest::Test
6
6
  test "sets content type" do
7
7
  request = build_request(content_type: "application/json")
8
+
8
9
  assert_equal "application/json", request.content_type
9
10
  end
10
11
 
@@ -35,26 +36,31 @@ class RequestTest < Minitest::Test
35
36
 
36
37
  test "requests gzip encoding" do
37
38
  request = build_request.request
39
+
38
40
  assert_equal "gzip,deflate", request["Accept-Encoding"]
39
41
  end
40
42
 
41
43
  test "sets path" do
42
44
  request = build_request(url: "http://example.org/some/path").request
45
+
43
46
  assert_equal "/some/path", request.path
44
47
  end
45
48
 
46
49
  test "sets request body from hash" do
47
50
  request = build_request(request_method: "post", data: {a: 1}).request
51
+
48
52
  assert_equal "a=1", request.body
49
53
  end
50
54
 
51
55
  test "sets request body from string" do
52
56
  request = build_request(request_method: "post", data: "some body").request
57
+
53
58
  assert_equal "some body", request.body
54
59
  end
55
60
 
56
61
  test "sets request body from params key" do
57
62
  request = build_request(request_method: "post", params: "some body").request
63
+
58
64
  assert_equal "some body", request.body
59
65
  end
60
66
 
@@ -67,6 +73,7 @@ class RequestTest < Minitest::Test
67
73
  ).request
68
74
 
69
75
  expected = {a: 1}.to_json
76
+
70
77
  assert_equal expected, request.body
71
78
  end
72
79
 
@@ -78,15 +85,29 @@ class RequestTest < Minitest::Test
78
85
  ).request
79
86
 
80
87
  expected = {a: 1}.to_json
88
+
81
89
  assert_equal expected, request.body
82
90
  end
83
91
 
84
92
  test "sets request body from to_h protocol" do
85
93
  data = stub(to_h: {a: 1})
86
94
  request = build_request(request_method: "post", data: data).request
95
+
87
96
  assert_equal "a=1", request.body
88
97
  end
89
98
 
99
+ test "sets json body from array" do
100
+ data = [1, 2, 3]
101
+ request = build_request(
102
+ request_method: "post",
103
+ data: data,
104
+ content_type: "application/json",
105
+ options: {json_parser: JSON}
106
+ ).request
107
+
108
+ assert_equal "[1,2,3]", request.body
109
+ end
110
+
90
111
  test "sets request body from to_s protocol" do
91
112
  data = stub(to_s: "some body")
92
113
  request = build_request(request_method: "post", data: data).request
@@ -111,11 +132,19 @@ class RequestTest < Minitest::Test
111
132
 
112
133
  test "sets custom headers" do
113
134
  request = build_request(headers: {"HEADER" => "VALUE"}).request
135
+
114
136
  assert_equal "VALUE", request["HEADER"]
115
137
  end
116
138
 
139
+ test "sets headers from underscored headers" do
140
+ request = build_request(headers: {content_type: "text/plain"}).request
141
+
142
+ assert_equal "text/plain", request["Content-Type"]
143
+ end
144
+
117
145
  test "executes headers with callable protocol" do
118
146
  request = build_request(headers: {"HEADER" => -> { "VALUE" }}).request
147
+
119
148
  assert_equal "VALUE", request["HEADER"]
120
149
  end
121
150
 
@@ -140,7 +169,7 @@ class RequestTest < Minitest::Test
140
169
  assert_equal :post, last_request.method
141
170
  assert_equal "a=1&b=2", last_request.body
142
171
  assert_equal "0.1", last_request.headers["Rendering"]
143
- assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split(" ").last)
172
+ assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split.last)
144
173
  end
145
174
 
146
175
  test "performs request when using kwargs" do
@@ -157,7 +186,7 @@ class RequestTest < Minitest::Test
157
186
  assert_equal :post, last_request.method
158
187
  assert_equal "a=1&b=2", last_request.body
159
188
  assert_equal "0.1", last_request.headers["Rendering"]
160
- assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split(" ").last)
189
+ assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split.last)
161
190
  end
162
191
 
163
192
  test "uses base url" do
@@ -7,7 +7,7 @@ class CustomResponseParserTest < Minitest::Test
7
7
  setup do
8
8
  parser = Class.new do
9
9
  def self.match?(content_type)
10
- content_type =~ /csv/
10
+ content_type.include?("csv")
11
11
  end
12
12
 
13
13
  def self.load(source)
@@ -7,7 +7,7 @@ class HtmlResponseTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", body: "", content_type: "text/html")
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.html?
10
+ assert_predicate response, :html?
11
11
  end
12
12
 
13
13
  test "returns html" do
@@ -7,7 +7,7 @@ class JsonResponseTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", body: "[]", content_type: "application/json")
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.json?
10
+ assert_predicate response, :json?
11
11
  end
12
12
 
13
13
  test "returns json" do
@@ -6,7 +6,7 @@ class Status3xxTest < Minitest::Test
6
6
  setup { Aitch.configuration.follow_redirect = false }
7
7
 
8
8
  test "sets default redirected from" do
9
- assert_equal [], Aitch::Response.new({}, stub("response")).redirected_from
9
+ assert_empty Aitch::Response.new({}, stub("response")).redirected_from
10
10
  end
11
11
 
12
12
  test "uses provided redirected from" do
@@ -16,6 +16,7 @@ class Status3xxTest < Minitest::Test
16
16
  test "has body" do
17
17
  register_uri(:get, "http://example.org/", body: "Hello", status: 301)
18
18
  response = Aitch.get("http://example.org/")
19
+
19
20
  assert_equal "Hello", response.body
20
21
  end
21
22
 
@@ -23,20 +24,21 @@ class Status3xxTest < Minitest::Test
23
24
  register_uri(:get, "http://example.org/", status: 301)
24
25
  response = Aitch.get("http://example.org/")
25
26
 
26
- assert response.success?
27
- assert response.ok?
27
+ assert_predicate response, :success?
28
+ assert_predicate response, :ok?
28
29
  end
29
30
 
30
31
  test "detects as redirect" do
31
32
  register_uri(:get, "http://example.org/", status: 301)
32
33
  response = Aitch.get("http://example.org/")
33
34
 
34
- assert response.redirect?
35
+ assert_predicate response, :redirect?
35
36
  end
36
37
 
37
38
  test "returns location" do
38
39
  register_uri(:get, "http://example.org/", status: 301, location: "https://example.com/")
39
40
  response = Aitch.get("http://example.org/")
41
+
40
42
  assert_equal "https://example.com/", response.location
41
43
  end
42
44
 
@@ -7,7 +7,7 @@ class Status4xxTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", status: 404)
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.error?
10
+ assert_predicate response, :error?
11
11
  end
12
12
 
13
13
  test "sets error" do
@@ -7,7 +7,7 @@ class Status5xxTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", status: 500)
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.error?
10
+ assert_predicate response, :error?
11
11
  end
12
12
 
13
13
  test "sets error" do
@@ -7,7 +7,7 @@ class XmlResponseTest < Minitest::Test
7
7
  register_uri(:get, "http://example.org/", body: "[]", content_type: "application/xml")
8
8
  response = Aitch.get("http://example.org/")
9
9
 
10
- assert response.xml?
10
+ assert_predicate response, :xml?
11
11
  end
12
12
 
13
13
  test "returns xml" do
@@ -6,12 +6,14 @@ class ResponseTest < Minitest::Test
6
6
  test "has body" do
7
7
  register_uri(:get, "http://example.org/", body: "Hello")
8
8
  response = Aitch.get("http://example.org/")
9
+
9
10
  assert_equal "Hello", response.body
10
11
  end
11
12
 
12
13
  test "sets current url" do
13
14
  register_uri(:get, "http://example.org/", body: "Hello")
14
15
  response = Aitch.get("http://example.org/")
16
+
15
17
  assert_equal "http://example.org/", response.url
16
18
  end
17
19
 
@@ -39,19 +41,22 @@ class ResponseTest < Minitest::Test
39
41
  test "returns status code" do
40
42
  register_uri(:get, "http://example.org/", body: "")
41
43
  response = Aitch.get("http://example.org/")
44
+
42
45
  assert_equal 200, response.code
43
46
  end
44
47
 
45
48
  test "returns content type" do
46
49
  register_uri(:get, "http://example.org/", content_type: "text/html")
47
50
  response = Aitch.get("http://example.org/")
51
+
48
52
  assert_equal "text/html", response.content_type
49
53
  end
50
54
 
51
55
  test "detects as successful response" do
52
56
  register_uri(:get, "http://example.org/", content_type: "text/html")
53
57
  response = Aitch.get("http://example.org/")
54
- assert response.success?
58
+
59
+ assert_predicate response, :success?
55
60
  end
56
61
 
57
62
  test "returns headers" do
@@ -74,7 +79,7 @@ class ResponseTest < Minitest::Test
74
79
  response = Aitch.get("http://example.org/")
75
80
 
76
81
  assert_equal "0.003", response.runtime
77
- assert response.respond_to?(:runtime)
82
+ assert_respond_to response, :runtime
78
83
  end
79
84
 
80
85
  test "raises when have no method" do
@@ -33,6 +33,7 @@ class UriTest < Minitest::Test
33
33
 
34
34
  test "returns request uri" do
35
35
  uri = Aitch::URI.new("http://example.org/some/path?a=1&b=2#hello", c: 3)
36
+
36
37
  assert_equal "/some/path?a=1&b=2&c=3#hello", uri.request_uri
37
38
  end
38
39
  end
@@ -5,6 +5,7 @@ require "test_helper"
5
5
  class SymbolizeKeysTest < Minitest::Test
6
6
  test "converts keys to symbols" do
7
7
  expected = {a: 1}
8
+
8
9
  assert_equal expected, Aitch::Utils.symbolize_keys("a" => 1)
9
10
  end
10
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-18 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -166,7 +166,7 @@ dependencies:
166
166
  version: '0'
167
167
  description: A simple HTTP client
168
168
  email:
169
- - fnando.vieira@gmail.com
169
+ - me@fnando.com
170
170
  executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
@@ -238,7 +238,8 @@ files:
238
238
  homepage: http://rubygems.org/gems/aitch
239
239
  licenses:
240
240
  - MIT
241
- metadata: {}
241
+ metadata:
242
+ rubygems_mfa_required: 'true'
242
243
  post_install_message:
243
244
  rdoc_options: []
244
245
  require_paths:
@@ -254,40 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
255
  - !ruby/object:Gem::Version
255
256
  version: '0'
256
257
  requirements: []
257
- rubygems_version: 3.3.17
258
+ rubygems_version: 3.4.3
258
259
  signing_key:
259
260
  specification_version: 4
260
261
  summary: A simple HTTP client
261
- test_files:
262
- - test/aitch/aitch_test.rb
263
- - test/aitch/configuration_test.rb
264
- - test/aitch/dsl_test.rb
265
- - test/aitch/execute_test.rb
266
- - test/aitch/namespace_test.rb
267
- - test/aitch/request/client_https_test.rb
268
- - test/aitch/request/follow_redirect_test.rb
269
- - test/aitch/request/json_request_test.rb
270
- - test/aitch/request/request_class_test.rb
271
- - test/aitch/request/status_code_validation_test.rb
272
- - test/aitch/request_test.rb
273
- - test/aitch/response/custom_response_parser_test.rb
274
- - test/aitch/response/default_response_parser_test.rb
275
- - test/aitch/response/errors_test.rb
276
- - test/aitch/response/html_response_test.rb
277
- - test/aitch/response/json_response_test.rb
278
- - test/aitch/response/raw_response_test.rb
279
- - test/aitch/response/status_3xx_test.rb
280
- - test/aitch/response/status_4xx_test.rb
281
- - test/aitch/response/status_5xx_test.rb
282
- - test/aitch/response/xml_response_test.rb
283
- - test/aitch/response_parser/html_parser_test.rb
284
- - test/aitch/response_parser/json_parser_test.rb
285
- - test/aitch/response_parser/xml_parser_test.rb
286
- - test/aitch/response_test.rb
287
- - test/aitch/to_query_test.rb
288
- - test/aitch/uri_test.rb
289
- - test/aitch/utils/symbolize_keys_test.rb
290
- - test/aitch/utils/underscore_test.rb
291
- - test/fixtures/iso8859-1.xml
292
- - test/support/helpers.rb
293
- - test/test_helper.rb
262
+ test_files: []