aitch 1.2.2 → 2.0.0

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: c49091163504e6a6587170951f8e4545b4474b1912c85c5bcfeb102763a214b7
4
- data.tar.gz: 7fac91b61ee9ad82e8f880f25758b9f6a433ad8ed3bcc5134b261e64f5da61fc
3
+ metadata.gz: ac06612095a2a08635037c6113a7cb93ce1e22463192ba8f1381e1c7b5657f85
4
+ data.tar.gz: 50b0cfb79bc02cf46ff4f4fd4b762fd06bb44d577c6c6afd9640f1a0141f3dfd
5
5
  SHA512:
6
- metadata.gz: 859bdbfb5f70d99646c628f16a2cea718385299ca1b48d32e0ecfb8c9598ad27b8cf3363498b50eaddf8585901212faa1f588dc9dc29ad1982891f2a3c26b1fa
7
- data.tar.gz: a7045d8d2a6c9d172b2b90180cd4d2afb13a5ceac088b74b9cb7ccc63fa9050920df69310e0eef1ae745b44d0edd4c45f6779c9a6fe420c3951878be4ff3fbf1
6
+ metadata.gz: cfc6752814d6b44d4cf455a8cbb269cf8aaabcf3afa6379e34e7fae3a2bc53f2a3218ec33537a05bc8c5cf50c442f95cb126b0f011452caa811f9c2e74c4df5d
7
+ data.tar.gz: b2b1bee33eca007e77e36d687476eb8b3c34f6fa0d5d9d434feabeddef13a42a23bddabe2122000a47d5514b3b16581195cbd9f8fc5d4330dfe6b771c38346c1
@@ -15,12 +15,12 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- ruby: ["2.7.x", "2.6.x", "2.5.x", "3.0.x", "3.1.x"]
18
+ ruby: ["3.0", "3.1", "3.2"]
19
19
 
20
20
  steps:
21
- - uses: actions/checkout@v1
21
+ - uses: actions/checkout@v4
22
22
 
23
- - uses: actions/cache@v2
23
+ - uses: actions/cache@v3
24
24
  with:
25
25
  path: vendor/bundle
26
26
  key: >
@@ -31,7 +31,7 @@ jobs:
31
31
  hashFiles('aitch.gemspec') }}
32
32
 
33
33
  - name: Set up Ruby
34
- uses: actions/setup-ruby@v1
34
+ uses: ruby/setup-ruby@v1
35
35
  with:
36
36
  ruby-version: ${{ matrix.ruby }}
37
37
 
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.5
6
+ TargetRubyVersion: 3.0
7
7
  NewCops: enable
8
8
 
9
9
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ - **2.0.0**
4
+ - Fix error when content type is not available on response.
5
+ - Stop supporting old ruby versions (require 3.0+).
3
6
  - **1.2.2**
4
7
  - Transform header key before assigning values.
5
8
  - **1.2.1**
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Aitch
2
2
 
3
- [![Tests](https://github.com/fnando/aitch/workflows/Tests/badge.svg)](https://github.com/fnando/aitch)
3
+ [![Tests](https://github.com/fnando/aitch/actions/workflows/tests.yml/badge.svg)](https://github.com/fnando/aitch/actions/workflows/tests.yml)
4
4
  [![Code Climate](https://codeclimate.com/github/fnando/aitch/badges/gpa.svg)](https://codeclimate.com/github/fnando/aitch)
5
5
  [![Gem Version](https://img.shields.io/gem/v/aitch.svg)](https://rubygems.org/gems/aitch)
6
6
  [![Gem Downloads](https://img.shields.io/gem/dt/aitch.svg)](https://rubygems.org/gems/aitch)
data/aitch.gemspec CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = spec.description
12
12
  spec.homepage = "http://rubygems.org/gems/aitch"
13
13
  spec.license = "MIT"
14
- spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
15
15
  spec.metadata["rubygems_mfa_required"] = "true"
16
16
 
17
17
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
@@ -70,11 +70,11 @@ class Hash
70
70
  #
71
71
  # This method is also aliased as +to_param+.
72
72
  def to_query(namespace = nil)
73
- collect do |key, value|
73
+ filter_map do |key, value|
74
74
  unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
75
75
  value.to_query(namespace ? "#{namespace}[#{key}]" : key)
76
76
  end
77
- end.compact.sort! * "&"
77
+ end.sort! * "&"
78
78
  end
79
79
 
80
80
  alias to_param to_query
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Aitch
4
4
  class Location
5
- MATCHER = %r{\A/}.freeze
5
+ MATCHER = %r{\A/}
6
6
 
7
7
  attr_reader :redirect_stack, :current_url
8
8
 
data/lib/aitch/request.rb CHANGED
@@ -9,8 +9,8 @@ module Aitch
9
9
  ACCEPT_ENCODING = "Accept-Encoding"
10
10
  GZIP_DEFLATE = "gzip,deflate"
11
11
  HTTPS = "https"
12
- HEADER_SEPARATOR_RE = /[-_]/.freeze
13
- JSON_RE = /\bjson\b/.freeze
12
+ HEADER_SEPARATOR_RE = /[-_]/
13
+ JSON_RE = /\bjson\b/
14
14
 
15
15
  alias params= data=
16
16
  alias body= data=
@@ -102,7 +102,7 @@ module Aitch
102
102
  all_headers = options.fetch(:default_headers, {}).merge(headers)
103
103
 
104
104
  all_headers.each do |name, value|
105
- value = value.respond_to?(:call) ? value.call : value
105
+ value = value.call if value.respond_to?(:call)
106
106
  name = name.to_s.split(HEADER_SEPARATOR_RE).map(&:capitalize).join("-")
107
107
  request[name] = value.to_s
108
108
  end
@@ -2,8 +2,6 @@
2
2
 
3
3
  module Aitch
4
4
  class Response
5
- extend Forwardable
6
-
7
5
  JSON_STR = "json"
8
6
  XML_STR = "xml"
9
7
  HTML_STR = "html"
@@ -11,10 +9,9 @@ module Aitch
11
9
  DOUBLE_COLON = "::"
12
10
  SPACE_STR = " "
13
11
  ERROR_SUFFIX = "_error"
14
- X_RE = /^x-/.freeze
12
+ X_RE = /^x-/
15
13
 
16
- def_delegators :@http_response, :content_type
17
- attr_accessor :redirected_from, :url
14
+ attr_accessor :redirected_from, :url, :content_type
18
15
 
19
16
  def self.description_for_code(code)
20
17
  [code, DESCRIPTION[code]].compact.join(SPACE_STR)
@@ -24,6 +21,7 @@ module Aitch
24
21
  @options = options
25
22
  @http_response = http_response
26
23
  @redirected_from = options.fetch(:redirected_from, [])
24
+ @content_type = http_response.content_type.to_s
27
25
  end
28
26
 
29
27
  ERRORS.each do |status_code, exception|
data/lib/aitch/utils.rb CHANGED
@@ -4,7 +4,7 @@ module Aitch
4
4
  module Utils
5
5
  extend self
6
6
 
7
- MATCHER = /(?<=.)(URI|[A-Z])/.freeze
7
+ MATCHER = /(?<=.)(URI|[A-Z])/
8
8
 
9
9
  def underscore(string)
10
10
  string = string.gsub(MATCHER) do |char|
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.2"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -150,7 +150,7 @@ class RequestTest < Minitest::Test
150
150
 
151
151
  test "sets basic auth credentials" do
152
152
  request = build_request(options: {user: "USER", password: "PASS"}).request
153
- credentials = Base64.decode64(request["Authorization"].gsub(/Basic /, ""))
153
+ credentials = Base64.decode64(request["Authorization"].gsub("Basic ", ""))
154
154
 
155
155
  assert_equal "USER:PASS", credentials
156
156
  end
@@ -8,7 +8,7 @@ class ErrorsTest < Minitest::Test
8
8
 
9
9
  test "detects response as #{name}" do
10
10
  config = {}
11
- http_response = stub(code: code)
11
+ http_response = stub(code: code, content_type: "text/html")
12
12
  response = Aitch::Response.new(config, http_response)
13
13
 
14
14
  assert response.public_send("#{name}?")
@@ -6,11 +6,20 @@ class Status3xxTest < Minitest::Test
6
6
  setup { Aitch.configuration.follow_redirect = false }
7
7
 
8
8
  test "sets default redirected from" do
9
- assert_empty Aitch::Response.new({}, stub("response")).redirected_from
9
+ response =
10
+ Aitch::Response.new({}, stub("response", content_type: "text/html"))
11
+
12
+ assert_empty response.redirected_from
10
13
  end
11
14
 
12
15
  test "uses provided redirected from" do
13
- assert_equal ["URL"], Aitch::Response.new({redirected_from: ["URL"]}, stub("response")).redirected_from
16
+ response =
17
+ Aitch::Response.new(
18
+ {redirected_from: ["URL"]},
19
+ stub("response", content_type: "text/html")
20
+ )
21
+
22
+ assert_equal ["URL"], response.redirected_from
14
23
  end
15
24
 
16
25
  test "has body" do
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.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-02 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -248,14 +248,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
248
248
  requirements:
249
249
  - - ">="
250
250
  - !ruby/object:Gem::Version
251
- version: 2.5.0
251
+ version: 3.0.0
252
252
  required_rubygems_version: !ruby/object:Gem::Requirement
253
253
  requirements:
254
254
  - - ">="
255
255
  - !ruby/object:Gem::Version
256
256
  version: '0'
257
257
  requirements: []
258
- rubygems_version: 3.4.3
258
+ rubygems_version: 3.4.6
259
259
  signing_key:
260
260
  specification_version: 4
261
261
  summary: A simple HTTP client