aitch 1.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +4 -4
- data/.rubocop.yml +7 -1
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/aitch.gemspec +1 -1
- data/lib/aitch/ext/to_query.rb +2 -2
- data/lib/aitch/location.rb +3 -1
- data/lib/aitch/request.rb +18 -9
- data/lib/aitch/response.rb +17 -10
- data/lib/aitch/utils.rb +4 -1
- data/lib/aitch/version.rb +1 -1
- data/test/aitch/aitch_test.rb +20 -20
- data/test/aitch/configuration_test.rb +2 -1
- data/test/aitch/dsl_test.rb +6 -0
- data/test/aitch/execute_test.rb +1 -1
- data/test/aitch/request/client_https_test.rb +2 -1
- data/test/aitch/request/follow_redirect_test.rb +1 -1
- data/test/aitch/request/request_class_test.rb +1 -0
- data/test/aitch/request_test.rb +18 -1
- data/test/aitch/response/errors_test.rb +1 -1
- data/test/aitch/response/html_response_test.rb +1 -1
- data/test/aitch/response/json_response_test.rb +1 -1
- data/test/aitch/response/status_3xx_test.rb +16 -5
- data/test/aitch/response/status_4xx_test.rb +1 -1
- data/test/aitch/response/status_5xx_test.rb +1 -1
- data/test/aitch/response/xml_response_test.rb +1 -1
- data/test/aitch/response_test.rb +7 -2
- data/test/aitch/uri_test.rb +1 -0
- data/test/aitch/utils/symbolize_keys_test.rb +1 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac06612095a2a08635037c6113a7cb93ce1e22463192ba8f1381e1c7b5657f85
|
4
|
+
data.tar.gz: 50b0cfb79bc02cf46ff4f4fd4b762fd06bb44d577c6c6afd9640f1a0141f3dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfc6752814d6b44d4cf455a8cbb269cf8aaabcf3afa6379e34e7fae3a2bc53f2a3218ec33537a05bc8c5cf50c442f95cb126b0f011452caa811f9c2e74c4df5d
|
7
|
+
data.tar.gz: b2b1bee33eca007e77e36d687476eb8b3c34f6fa0d5d9d434feabeddef13a42a23bddabe2122000a47d5514b3b16581195cbd9f8fc5d4330dfe6b771c38346c1
|
data/.github/workflows/tests.yml
CHANGED
@@ -15,12 +15,12 @@ jobs:
|
|
15
15
|
strategy:
|
16
16
|
fail-fast: false
|
17
17
|
matrix:
|
18
|
-
ruby: ["
|
18
|
+
ruby: ["3.0", "3.1", "3.2"]
|
19
19
|
|
20
20
|
steps:
|
21
|
-
- uses: actions/checkout@
|
21
|
+
- uses: actions/checkout@v4
|
22
22
|
|
23
|
-
- uses: actions/cache@
|
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:
|
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:
|
6
|
+
TargetRubyVersion: 3.0
|
7
7
|
NewCops: enable
|
8
8
|
|
9
9
|
Layout/LineLength:
|
@@ -16,3 +16,9 @@ Naming/AccessorMethodName:
|
|
16
16
|
|
17
17
|
Style/DocumentDynamicEvalDefinition:
|
18
18
|
Enabled: false
|
19
|
+
|
20
|
+
Gemspec/DevelopmentDependencies:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Minitest/MultipleAssertions:
|
24
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
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+).
|
6
|
+
- **1.2.2**
|
7
|
+
- Transform header key before assigning values.
|
3
8
|
- **1.2.1**
|
4
9
|
- Avoid calling `to_h` when params are array-like.
|
5
10
|
- **1.2.0**
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Aitch
|
2
2
|
|
3
|
-
[![Tests](https://github.com/fnando/aitch/workflows/
|
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(">=
|
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)
|
data/lib/aitch/ext/to_query.rb
CHANGED
@@ -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
|
-
|
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.
|
77
|
+
end.sort! * "&"
|
78
78
|
end
|
79
79
|
|
80
80
|
alias to_param to_query
|
data/lib/aitch/location.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Aitch
|
4
4
|
class Location
|
5
|
+
MATCHER = %r{\A/}
|
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?(
|
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 = /[-_]/
|
13
|
+
JSON_RE = /\bjson\b/
|
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[
|
41
|
+
headers[CONTENT_TYPE] = content_type
|
34
42
|
end
|
35
43
|
|
36
44
|
def content_type
|
37
|
-
headers[
|
38
|
-
options.fetch(:default_headers, {})[
|
45
|
+
headers[CONTENT_TYPE] ||
|
46
|
+
options.fetch(:default_headers, {})[CONTENT_TYPE]
|
39
47
|
end
|
40
48
|
|
41
49
|
def request
|
@@ -79,7 +87,7 @@ module Aitch
|
|
79
87
|
body_data = data
|
80
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?(
|
90
|
+
if content_type.to_s.match?(JSON_RE)
|
83
91
|
body_data = ResponseParser::JSONParser.engine.dump(body_data)
|
84
92
|
end
|
85
93
|
|
@@ -94,8 +102,9 @@ module Aitch
|
|
94
102
|
all_headers = options.fetch(:default_headers, {}).merge(headers)
|
95
103
|
|
96
104
|
all_headers.each do |name, value|
|
97
|
-
value = value.respond_to?(:call)
|
98
|
-
|
105
|
+
value = value.call if value.respond_to?(:call)
|
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 ==
|
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[
|
132
|
+
request[USER_AGENT] = options[:user_agent]
|
124
133
|
end
|
125
134
|
|
126
135
|
private def set_gzip(request)
|
127
|
-
request[
|
136
|
+
request[ACCEPT_ENCODING] = GZIP_DEFLATE
|
128
137
|
end
|
129
138
|
|
130
139
|
def timeout_exception
|
data/lib/aitch/response.rb
CHANGED
@@ -2,25 +2,32 @@
|
|
2
2
|
|
3
3
|
module Aitch
|
4
4
|
class Response
|
5
|
-
|
5
|
+
JSON_STR = "json"
|
6
|
+
XML_STR = "xml"
|
7
|
+
HTML_STR = "html"
|
8
|
+
EMPTY_STR = ""
|
9
|
+
DOUBLE_COLON = "::"
|
10
|
+
SPACE_STR = " "
|
11
|
+
ERROR_SUFFIX = "_error"
|
12
|
+
X_RE = /^x-/
|
6
13
|
|
7
|
-
|
8
|
-
attr_accessor :redirected_from, :url
|
14
|
+
attr_accessor :redirected_from, :url, :content_type
|
9
15
|
|
10
16
|
def self.description_for_code(code)
|
11
|
-
[code, DESCRIPTION[code]].compact.join(
|
17
|
+
[code, DESCRIPTION[code]].compact.join(SPACE_STR)
|
12
18
|
end
|
13
19
|
|
14
20
|
def initialize(options, http_response)
|
15
21
|
@options = options
|
16
22
|
@http_response = http_response
|
17
23
|
@redirected_from = options.fetch(:redirected_from, [])
|
24
|
+
@content_type = http_response.content_type.to_s
|
18
25
|
end
|
19
26
|
|
20
27
|
ERRORS.each do |status_code, exception|
|
21
28
|
method_name = Utils
|
22
|
-
.underscore(exception.name.split(
|
23
|
-
.gsub(
|
29
|
+
.underscore(exception.name.split(DOUBLE_COLON).last)
|
30
|
+
.gsub(ERROR_SUFFIX, EMPTY_STR)
|
24
31
|
|
25
32
|
define_method "#{method_name}?" do
|
26
33
|
code == status_code
|
@@ -53,15 +60,15 @@ module Aitch
|
|
53
60
|
end
|
54
61
|
|
55
62
|
def json?
|
56
|
-
content_type.include?(
|
63
|
+
content_type.include?(JSON_STR)
|
57
64
|
end
|
58
65
|
|
59
66
|
def xml?
|
60
|
-
content_type.include?(
|
67
|
+
content_type.include?(XML_STR)
|
61
68
|
end
|
62
69
|
|
63
70
|
def html?
|
64
|
-
content_type.include?(
|
71
|
+
content_type.include?(HTML_STR)
|
65
72
|
end
|
66
73
|
|
67
74
|
def data
|
@@ -71,7 +78,7 @@ module Aitch
|
|
71
78
|
def headers
|
72
79
|
@headers ||= {}.tap do |headers|
|
73
80
|
@http_response.each_header do |name, value|
|
74
|
-
headers[name.gsub(
|
81
|
+
headers[name.gsub(X_RE, EMPTY_STR)] = value
|
75
82
|
end
|
76
83
|
end
|
77
84
|
end
|
data/lib/aitch/utils.rb
CHANGED
data/lib/aitch/version.rb
CHANGED
data/test/aitch/aitch_test.rb
CHANGED
@@ -4,25 +4,25 @@ require "test_helper"
|
|
4
4
|
|
5
5
|
class AitchTest < Minitest::Test
|
6
6
|
test "defines public API" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
21
|
+
assert_empty(Aitch::Configuration.new.default_headers)
|
21
22
|
end
|
22
23
|
|
23
24
|
test "configures aitch" do
|
data/test/aitch/dsl_test.rb
CHANGED
@@ -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
|
|
data/test/aitch/execute_test.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/test/aitch/request_test.rb
CHANGED
@@ -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,12 +85,14 @@ 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
|
|
@@ -123,17 +132,25 @@ class RequestTest < Minitest::Test
|
|
123
132
|
|
124
133
|
test "sets custom headers" do
|
125
134
|
request = build_request(headers: {"HEADER" => "VALUE"}).request
|
135
|
+
|
126
136
|
assert_equal "VALUE", request["HEADER"]
|
127
137
|
end
|
128
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
|
+
|
129
145
|
test "executes headers with callable protocol" do
|
130
146
|
request = build_request(headers: {"HEADER" => -> { "VALUE" }}).request
|
147
|
+
|
131
148
|
assert_equal "VALUE", request["HEADER"]
|
132
149
|
end
|
133
150
|
|
134
151
|
test "sets basic auth credentials" do
|
135
152
|
request = build_request(options: {user: "USER", password: "PASS"}).request
|
136
|
-
credentials = Base64.decode64(request["Authorization"].gsub(
|
153
|
+
credentials = Base64.decode64(request["Authorization"].gsub("Basic ", ""))
|
137
154
|
|
138
155
|
assert_equal "USER:PASS", credentials
|
139
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}?")
|
@@ -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
|
-
|
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
|
-
|
10
|
+
assert_predicate response, :json?
|
11
11
|
end
|
12
12
|
|
13
13
|
test "returns json" do
|
@@ -6,16 +6,26 @@ class Status3xxTest < Minitest::Test
|
|
6
6
|
setup { Aitch.configuration.follow_redirect = false }
|
7
7
|
|
8
8
|
test "sets default redirected from" do
|
9
|
-
|
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
|
-
|
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
|
17
26
|
register_uri(:get, "http://example.org/", body: "Hello", status: 301)
|
18
27
|
response = Aitch.get("http://example.org/")
|
28
|
+
|
19
29
|
assert_equal "Hello", response.body
|
20
30
|
end
|
21
31
|
|
@@ -23,20 +33,21 @@ class Status3xxTest < Minitest::Test
|
|
23
33
|
register_uri(:get, "http://example.org/", status: 301)
|
24
34
|
response = Aitch.get("http://example.org/")
|
25
35
|
|
26
|
-
|
27
|
-
|
36
|
+
assert_predicate response, :success?
|
37
|
+
assert_predicate response, :ok?
|
28
38
|
end
|
29
39
|
|
30
40
|
test "detects as redirect" do
|
31
41
|
register_uri(:get, "http://example.org/", status: 301)
|
32
42
|
response = Aitch.get("http://example.org/")
|
33
43
|
|
34
|
-
|
44
|
+
assert_predicate response, :redirect?
|
35
45
|
end
|
36
46
|
|
37
47
|
test "returns location" do
|
38
48
|
register_uri(:get, "http://example.org/", status: 301, location: "https://example.com/")
|
39
49
|
response = Aitch.get("http://example.org/")
|
50
|
+
|
40
51
|
assert_equal "https://example.com/", response.location
|
41
52
|
end
|
42
53
|
|
@@ -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
|
-
|
10
|
+
assert_predicate response, :xml?
|
11
11
|
end
|
12
12
|
|
13
13
|
test "returns xml" do
|
data/test/aitch/response_test.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
82
|
+
assert_respond_to response, :runtime
|
78
83
|
end
|
79
84
|
|
80
85
|
test "raises when have no method" do
|
data/test/aitch/uri_test.rb
CHANGED
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:
|
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:
|
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:
|
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.
|
258
|
+
rubygems_version: 3.4.6
|
259
259
|
signing_key:
|
260
260
|
specification_version: 4
|
261
261
|
summary: A simple HTTP client
|