aitch 1.2.0 → 1.2.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/.rubocop.yml +4 -6
- data/CHANGELOG.md +52 -38
- data/aitch.gemspec +2 -2
- data/lib/aitch/location.rb +3 -1
- data/lib/aitch/request.rb +18 -9
- data/lib/aitch/response.rb +16 -7
- data/lib/aitch/response_parser/html_parser.rb +1 -1
- data/lib/aitch/response_parser/json_parser.rb +1 -1
- data/lib/aitch/response_parser/xml_parser.rb +1 -1
- data/lib/aitch/uri.rb +1 -1
- 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 +31 -2
- data/test/aitch/response/custom_response_parser_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 +6 -4
- 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 +7 -38
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c49091163504e6a6587170951f8e4545b4474b1912c85c5bcfeb102763a214b7
|
|
4
|
+
data.tar.gz: 7fac91b61ee9ad82e8f880f25758b9f6a433ad8ed3bcc5134b261e64f5da61fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
17
|
+
Style/DocumentDynamicEvalDefinition:
|
|
17
18
|
Enabled: false
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Gemspec/DevelopmentDependencies:
|
|
20
21
|
Enabled: false
|
|
21
22
|
|
|
22
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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.
|
|
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"
|
data/lib/aitch/location.rb
CHANGED
|
@@ -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?(
|
|
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[
|
|
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
|
|
@@ -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?(
|
|
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
|
-
|
|
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
|
@@ -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(
|
|
23
|
-
.gsub(
|
|
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
|
|
65
|
+
content_type.include?(JSON_STR)
|
|
57
66
|
end
|
|
58
67
|
|
|
59
68
|
def xml?
|
|
60
|
-
content_type
|
|
69
|
+
content_type.include?(XML_STR)
|
|
61
70
|
end
|
|
62
71
|
|
|
63
72
|
def html?
|
|
64
|
-
content_type
|
|
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(
|
|
83
|
+
headers[name.gsub(X_RE, EMPTY_STR)] = value
|
|
75
84
|
end
|
|
76
85
|
end
|
|
77
86
|
end
|
data/lib/aitch/uri.rb
CHANGED
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,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
|
|
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
|
|
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 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,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
|
-
|
|
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
|
-
|
|
27
|
-
|
|
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
|
-
|
|
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 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: 1.2.
|
|
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:
|
|
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.
|
|
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
|
|
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: []
|