aitch 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.github/workflows/tests.yml +50 -0
- data/.rubocop.yml +3 -11
- data/CHANGELOG.md +50 -38
- data/README.md +43 -14
- data/aitch.gemspec +3 -2
- data/lib/aitch/configuration.rb +4 -0
- data/lib/aitch/ext/to_query.rb +0 -6
- data/lib/aitch/location.rb +1 -1
- data/lib/aitch/namespace.rb +3 -5
- data/lib/aitch/request.rb +12 -9
- data/lib/aitch/response.rb +4 -4
- 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 +4 -4
- data/lib/aitch/version.rb +1 -1
- data/test/aitch/request_test.rb +27 -2
- data/test/aitch/response/custom_response_parser_test.rb +1 -5
- data/test/aitch/response/default_response_parser_test.rb +14 -0
- data/test/aitch/to_query_test.rb +28 -0
- metadata +15 -41
- data/.travis.yml +0 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac6be3c16c842bbd1555aed0de859b6e62bf59f511cce28a6c441efd980e5751
|
4
|
+
data.tar.gz: 2ebc4b41d63c9dd41756bb7fff03b52a6cbca2f56ed310183bc158a822bbdbd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602da6e2d0aaf3812e7f19b84b48b47eaeac59086345bceb76c601eba64f369ae0833c32980f66b0c026338bb098ad72563d1a4d2fdf8384fe50792856d281a1
|
7
|
+
data.tar.gz: b35ef25d1e59cd76923e626fdd6d60a735977a35d6560a32fe3313a8421eeccbce9524163775651da6fc017fcd47f7ef20c7ec8a40460d4a627e2d75d334fae8
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
---
|
2
|
+
name: Tests
|
3
|
+
|
4
|
+
on:
|
5
|
+
pull_request:
|
6
|
+
branches:
|
7
|
+
- main
|
8
|
+
push:
|
9
|
+
branches:
|
10
|
+
- main
|
11
|
+
jobs:
|
12
|
+
build:
|
13
|
+
name: Tests with Ruby ${{ matrix.ruby }}
|
14
|
+
runs-on: "ubuntu-latest"
|
15
|
+
strategy:
|
16
|
+
fail-fast: false
|
17
|
+
matrix:
|
18
|
+
ruby: ["2.7.x", "2.6.x", "2.5.x", "3.0.x", "3.1.x"]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v1
|
22
|
+
|
23
|
+
- uses: actions/cache@v2
|
24
|
+
with:
|
25
|
+
path: vendor/bundle
|
26
|
+
key: >
|
27
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-${{
|
28
|
+
hashFiles('aitch.gemspec') }}
|
29
|
+
restore-keys: >
|
30
|
+
${{ runner.os }}-${{ matrix.ruby }}-gems-${{
|
31
|
+
hashFiles('aitch.gemspec') }}
|
32
|
+
|
33
|
+
- name: Set up Ruby
|
34
|
+
uses: actions/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby }}
|
37
|
+
|
38
|
+
- name: Install gem dependencies
|
39
|
+
env:
|
40
|
+
RAILS_ENV: test
|
41
|
+
run: |
|
42
|
+
gem install bundler
|
43
|
+
bundle config path vendor/bundle
|
44
|
+
bundle update --jobs 4 --retry 3
|
45
|
+
|
46
|
+
- name: Run Tests
|
47
|
+
env:
|
48
|
+
RAILS_ENV: test
|
49
|
+
run: |
|
50
|
+
bundle exec rake
|
data/.rubocop.yml
CHANGED
@@ -3,7 +3,8 @@ inherit_gem:
|
|
3
3
|
rubocop-fnando: .rubocop.yml
|
4
4
|
|
5
5
|
AllCops:
|
6
|
-
TargetRubyVersion: 2.
|
6
|
+
TargetRubyVersion: 2.5
|
7
|
+
NewCops: enable
|
7
8
|
|
8
9
|
Layout/LineLength:
|
9
10
|
Exclude:
|
@@ -13,14 +14,5 @@ Naming/AccessorMethodName:
|
|
13
14
|
Exclude:
|
14
15
|
- lib/aitch/request.rb
|
15
16
|
|
16
|
-
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Metrics/AbcSize:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Metrics/MethodLength:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Metrics/ParameterLists:
|
17
|
+
Style/DocumentDynamicEvalDefinition:
|
26
18
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,40 +1,52 @@
|
|
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.1**
|
4
|
+
- Avoid calling `to_h` when params are array-like.
|
5
|
+
- **1.2.0**
|
6
|
+
- Add support to base url.
|
7
|
+
- **1.1.0**
|
8
|
+
- Add keyword argument interface to methods like `Aitch.get` and alike.
|
9
|
+
- **1.0.2**
|
10
|
+
- Use `JSON.parse` rather than `JSON.load`.
|
11
|
+
- **1.0.1**
|
12
|
+
- Fix a bug when JSON encoding body in a POST request.
|
13
|
+
- **1.0.0**
|
14
|
+
- Use frozen string magic comments
|
15
|
+
- 307 redirections will honor the HTTP request method
|
16
|
+
- Fix issue with redirection; it was including the target url for one level
|
17
|
+
redirection.
|
18
|
+
- Methods `Aitch::Response#html`, `Aitch::Response#json`,
|
19
|
+
`Aitch::Response#xml` were removed; use `Aitch::Response#data` instead.
|
20
|
+
- Add support to response parsers
|
21
|
+
- **0.5.0** - May 24, 2015
|
22
|
+
- Remove hard dependency on ActiveSupport
|
23
|
+
- Add response validation
|
24
|
+
- **0.4.1** - December 20, 2014
|
25
|
+
- Consider default headers when returning content type (fixes issue with
|
26
|
+
body's JSON encoding)
|
27
|
+
- **0.4.0** - December 18, 2014
|
28
|
+
- Add accessor method for setting request's content type
|
29
|
+
- Automatically encodes body as JSON when content type matches `json`
|
30
|
+
- JSON encoding now uses a parser
|
31
|
+
- **0.3.0** - April 28, 2014
|
32
|
+
- Make list of redirections available
|
33
|
+
- Make the request URL available on responses
|
34
|
+
- **0.2.1** - July 30, 2013
|
35
|
+
- Add alias for `response.success?` (`response.ok?`)
|
36
|
+
- **0.2.0** - July 28, 2013
|
37
|
+
- Add DSL support
|
38
|
+
- Create aliases for `response.data` (`response.xml` and `response.json`)
|
39
|
+
- **0.1.5** - June 26, 2013
|
40
|
+
- Fix issue with jRuby and `to_h` protocol
|
41
|
+
- **0.1.4** - June 13, 2013
|
42
|
+
- Accept headers as callable objects
|
43
|
+
- Fix XML encoding, always converting values to UTF-8
|
44
|
+
- **0.1.3** - May 12, 2013
|
45
|
+
- Add response HTML parsing into Nokogiri object
|
46
|
+
- **0.1.2** - May 10, 2013
|
47
|
+
- Add response error code helpers, like `response.bad_request?` and
|
48
|
+
`response.not_found?`
|
49
|
+
- **0.1.1** - April 30, 2013
|
50
|
+
- Add support for namespaces
|
51
|
+
- **0.1.0** - April 29, 2013
|
52
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
# Aitch
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Tests](https://github.com/fnando/aitch/workflows/Tests/badge.svg)](https://github.com/fnando/aitch)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fnando/aitch/badges/gpa.svg)](https://codeclimate.com/github/fnando/aitch)
|
5
|
-
[![
|
6
|
-
[![
|
5
|
+
[![Gem Version](https://img.shields.io/gem/v/aitch.svg)](https://rubygems.org/gems/aitch)
|
6
|
+
[![Gem Downloads](https://img.shields.io/gem/dt/aitch.svg)](https://rubygems.org/gems/aitch)
|
7
7
|
|
8
8
|
A simple HTTP client.
|
9
9
|
|
10
10
|
Features:
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
- Supports Gzip|Deflate response
|
13
|
+
- Automatically parses JSON, HTML and XML responses
|
14
|
+
- Automatically follows redirect
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
18
18
|
Add this line to your application's Gemfile:
|
19
19
|
|
20
20
|
```ruby
|
21
|
-
gem
|
21
|
+
gem "aitch"
|
22
22
|
```
|
23
23
|
|
24
24
|
And then execute:
|
@@ -54,6 +54,9 @@ Aitch.configure do |config|
|
|
54
54
|
|
55
55
|
# Set the logger.
|
56
56
|
config.logger = nil
|
57
|
+
|
58
|
+
# Set the base url.
|
59
|
+
config.base_url = nil
|
57
60
|
end
|
58
61
|
```
|
59
62
|
|
@@ -115,7 +118,8 @@ response.data # Parsed response body
|
|
115
118
|
|
116
119
|
#### Parsing JSON, XML and HTML with Nokogiri
|
117
120
|
|
118
|
-
If your response is a JSON, XML or a HTML content type, we'll automatically
|
121
|
+
If your response is a JSON, XML or a HTML content type, we'll automatically
|
122
|
+
convert the response into the appropriate object.
|
119
123
|
|
120
124
|
```ruby
|
121
125
|
response = Aitch.get("http://simplesideias.com.br")
|
@@ -159,7 +163,8 @@ The request:
|
|
159
163
|
Aitch.get("http://example.org")
|
160
164
|
```
|
161
165
|
|
162
|
-
If the redirect limit is exceeded, then the `Aitch::TooManyRedirectsError`
|
166
|
+
If the redirect limit is exceeded, then the `Aitch::TooManyRedirectsError`
|
167
|
+
exception is raised.
|
163
168
|
|
164
169
|
### Basic auth
|
165
170
|
|
@@ -207,7 +212,8 @@ Request.get("http://example.org")
|
|
207
212
|
|
208
213
|
### Validating responses
|
209
214
|
|
210
|
-
When you know the kind of response you're expecting, you can validate it by
|
215
|
+
When you know the kind of response you're expecting, you can validate it by
|
216
|
+
specifying the `expect` option.
|
211
217
|
|
212
218
|
```ruby
|
213
219
|
Aitch.get do
|
@@ -216,7 +222,8 @@ Aitch.get do
|
|
216
222
|
end
|
217
223
|
```
|
218
224
|
|
219
|
-
If this request receives anything other than `200`, it will raise a
|
225
|
+
If this request receives anything other than `200`, it will raise a
|
226
|
+
`Aitch::StatusCodeError` exception.
|
220
227
|
|
221
228
|
```
|
222
229
|
Expect(200 OK) <=> Actual(404 Not Found)
|
@@ -226,7 +233,10 @@ You can also provide a list of accepted statuses, like `expect: [200, 201]`.
|
|
226
233
|
|
227
234
|
### Response Parsers
|
228
235
|
|
229
|
-
You can register new response parsers by using
|
236
|
+
You can register new response parsers by using
|
237
|
+
`Aitch::ResponseParser.register(name, parser)`, where parser must implement the
|
238
|
+
methods `match?(content_type)` and `load(response_body)`. This is how you could
|
239
|
+
load CSV values.
|
230
240
|
|
231
241
|
```ruby
|
232
242
|
require "csv"
|
@@ -248,7 +258,8 @@ end
|
|
248
258
|
Aitch::ResponseParser.prepend(:csv, CSVParser)
|
249
259
|
```
|
250
260
|
|
251
|
-
The default behavior is returning the response body. You can replace it as the
|
261
|
+
The default behavior is returning the response body. You can replace it as the
|
262
|
+
following:
|
252
263
|
|
253
264
|
```ruby
|
254
265
|
module DefaultParser
|
@@ -272,13 +283,31 @@ Aitch::ResponseParser.append(:default, DefaultParser)
|
|
272
283
|
|
273
284
|
Aitch comes with response parsers for HTML, XML and JSON.
|
274
285
|
|
275
|
-
By default, the JSON parser will be `JSON`. To set it to something else, use
|
286
|
+
By default, the JSON parser will be `JSON`. To set it to something else, use
|
287
|
+
`Aitch::ResponseParser::JSONParser.engine`.
|
276
288
|
|
277
289
|
```ruby
|
278
290
|
require "oj"
|
279
291
|
Aitch::ResponseParser::JSONParser.engine = Oj
|
280
292
|
```
|
281
293
|
|
294
|
+
### Setting the base url
|
295
|
+
|
296
|
+
When you're creating a wrapper for an API, usually the hostname is the same for
|
297
|
+
the whole API. In this case, you can avoid having to pass it around all the time
|
298
|
+
by setting `Aitch::Configuration#base_url`. This option is meant to be used when
|
299
|
+
you instantiate a new namespace.
|
300
|
+
|
301
|
+
```ruby
|
302
|
+
Client = Aitch::Namespace.new
|
303
|
+
|
304
|
+
Client.configure do |config|
|
305
|
+
config.base_url = "https://api.example.com"
|
306
|
+
end
|
307
|
+
|
308
|
+
Client.get("/users")
|
309
|
+
```
|
310
|
+
|
282
311
|
## Contributing
|
283
312
|
|
284
313
|
1. Fork it
|
data/aitch.gemspec
CHANGED
@@ -6,15 +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
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
14
16
|
|
15
17
|
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
16
18
|
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
17
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
19
|
spec.require_paths = ["lib"]
|
19
20
|
|
20
21
|
spec.add_dependency "nokogiri"
|
data/lib/aitch/configuration.rb
CHANGED
@@ -23,12 +23,16 @@ module Aitch
|
|
23
23
|
# Set the logger.
|
24
24
|
attr_accessor :logger
|
25
25
|
|
26
|
+
# Set the base url.
|
27
|
+
attr_accessor :base_url
|
28
|
+
|
26
29
|
def initialize
|
27
30
|
@timeout = 10
|
28
31
|
@redirect_limit = 5
|
29
32
|
@follow_redirect = true
|
30
33
|
@user_agent = "Aitch/#{Aitch::VERSION} (http://rubygems.org/gems/aitch)"
|
31
34
|
@default_headers = {}
|
35
|
+
@base_url = nil
|
32
36
|
end
|
33
37
|
|
34
38
|
def to_h
|
data/lib/aitch/ext/to_query.rb
CHANGED
@@ -37,12 +37,6 @@ class FalseClass
|
|
37
37
|
end
|
38
38
|
|
39
39
|
class Array
|
40
|
-
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
41
|
-
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
42
|
-
def to_param
|
43
|
-
collect(&:to_param).join "/"
|
44
|
-
end
|
45
|
-
|
46
40
|
# Converts an array into a string suitable for use as a URL query string,
|
47
41
|
# using the given +key+ as the param name.
|
48
42
|
#
|
data/lib/aitch/location.rb
CHANGED
@@ -10,7 +10,7 @@ module Aitch
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def location
|
13
|
-
return current_url unless current_url.match(%r{\A/})
|
13
|
+
return current_url unless current_url.match?(%r{\A/}) # rubocop:disable Performance/StartWith
|
14
14
|
|
15
15
|
uri = find_uri_with_host
|
16
16
|
url = ["#{uri.scheme}://#{uri.hostname}"]
|
data/lib/aitch/namespace.rb
CHANGED
@@ -25,7 +25,7 @@ module Aitch
|
|
25
25
|
headers ||= {}
|
26
26
|
options ||= {}
|
27
27
|
|
28
|
-
if
|
28
|
+
if block
|
29
29
|
dsl = DSL.new
|
30
30
|
dsl.instance_eval(&block)
|
31
31
|
args = dsl.to_h
|
@@ -38,10 +38,8 @@ module Aitch
|
|
38
38
|
}
|
39
39
|
end
|
40
40
|
|
41
|
-
args
|
42
|
-
|
43
|
-
options: config.to_h.merge(Utils.symbolize_keys(args[:options]))
|
44
|
-
)
|
41
|
+
args[:request_method] = request_method
|
42
|
+
args[:options] = config.to_h.merge(Utils.symbolize_keys(args[:options]))
|
45
43
|
|
46
44
|
Request.new(args).perform
|
47
45
|
end
|
data/lib/aitch/request.rb
CHANGED
@@ -2,12 +2,7 @@
|
|
2
2
|
|
3
3
|
module Aitch
|
4
4
|
class Request
|
5
|
-
attr_accessor :request_method
|
6
|
-
attr_accessor :url
|
7
|
-
attr_accessor :data
|
8
|
-
attr_accessor :headers
|
9
|
-
attr_accessor :options
|
10
|
-
attr_accessor :redirects
|
5
|
+
attr_accessor :request_method, :url, :data, :headers, :options, :redirects
|
11
6
|
|
12
7
|
alias params= data=
|
13
8
|
alias body= data=
|
@@ -62,7 +57,15 @@ module Aitch
|
|
62
57
|
end
|
63
58
|
|
64
59
|
def uri
|
65
|
-
@uri ||=
|
60
|
+
@uri ||= begin
|
61
|
+
normalized_url = if url.start_with?("/") && options[:base_url]
|
62
|
+
File.join(options[:base_url], url)
|
63
|
+
else
|
64
|
+
url
|
65
|
+
end
|
66
|
+
|
67
|
+
URI.new(normalized_url, data, http_method_class::REQUEST_HAS_BODY)
|
68
|
+
end
|
66
69
|
end
|
67
70
|
|
68
71
|
def http_method_class
|
@@ -74,9 +77,9 @@ module Aitch
|
|
74
77
|
|
75
78
|
private def set_body(request)
|
76
79
|
body_data = data
|
77
|
-
body_data = data.to_h if data.respond_to?(:to_h)
|
80
|
+
body_data = data.to_h if data.respond_to?(:to_h) && !data.is_a?(Array)
|
78
81
|
|
79
|
-
if content_type.to_s
|
82
|
+
if content_type.to_s.match?(/\bjson\b/)
|
80
83
|
body_data = ResponseParser::JSONParser.engine.dump(body_data)
|
81
84
|
end
|
82
85
|
|
data/lib/aitch/response.rb
CHANGED
@@ -53,15 +53,15 @@ module Aitch
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def json?
|
56
|
-
content_type
|
56
|
+
content_type.include?("json")
|
57
57
|
end
|
58
58
|
|
59
59
|
def xml?
|
60
|
-
content_type
|
60
|
+
content_type.include?("xml")
|
61
61
|
end
|
62
62
|
|
63
63
|
def html?
|
64
|
-
content_type
|
64
|
+
content_type.include?("html")
|
65
65
|
end
|
66
66
|
|
67
67
|
def data
|
@@ -83,7 +83,7 @@ module Aitch
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def respond_to_missing?(name, _include_private = false)
|
86
|
-
headers.key?(name.to_s)
|
86
|
+
headers.key?(name.to_s) || super
|
87
87
|
end
|
88
88
|
|
89
89
|
def description
|
data/lib/aitch/uri.rb
CHANGED
@@ -6,15 +6,15 @@ module Aitch
|
|
6
6
|
|
7
7
|
def_delegators :@uri, :host, :port, :scheme
|
8
8
|
|
9
|
-
def initialize(url, data = {}, request_has_body = false)
|
9
|
+
def initialize(url, data = {}, request_has_body = false) # rubocop:disable Style/OptionalBooleanParameter
|
10
10
|
@url = url
|
11
11
|
@data = data
|
12
12
|
@request_has_body = request_has_body
|
13
13
|
|
14
14
|
begin
|
15
15
|
@uri = ::URI.parse(url)
|
16
|
-
rescue ::URI::InvalidURIError =>
|
17
|
-
raise InvalidURIError,
|
16
|
+
rescue ::URI::InvalidURIError => error
|
17
|
+
raise InvalidURIError, error
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -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/version.rb
CHANGED
data/test/aitch/request_test.rb
CHANGED
@@ -87,6 +87,18 @@ class RequestTest < Minitest::Test
|
|
87
87
|
assert_equal "a=1", request.body
|
88
88
|
end
|
89
89
|
|
90
|
+
test "sets json body from array" do
|
91
|
+
data = [1, 2, 3]
|
92
|
+
request = build_request(
|
93
|
+
request_method: "post",
|
94
|
+
data: data,
|
95
|
+
content_type: "application/json",
|
96
|
+
options: {json_parser: JSON}
|
97
|
+
).request
|
98
|
+
|
99
|
+
assert_equal "[1,2,3]", request.body
|
100
|
+
end
|
101
|
+
|
90
102
|
test "sets request body from to_s protocol" do
|
91
103
|
data = stub(to_s: "some body")
|
92
104
|
request = build_request(request_method: "post", data: data).request
|
@@ -140,7 +152,7 @@ class RequestTest < Minitest::Test
|
|
140
152
|
assert_equal :post, last_request.method
|
141
153
|
assert_equal "a=1&b=2", last_request.body
|
142
154
|
assert_equal "0.1", last_request.headers["Rendering"]
|
143
|
-
assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split
|
155
|
+
assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split.last)
|
144
156
|
end
|
145
157
|
|
146
158
|
test "performs request when using kwargs" do
|
@@ -157,6 +169,19 @@ class RequestTest < Minitest::Test
|
|
157
169
|
assert_equal :post, last_request.method
|
158
170
|
assert_equal "a=1&b=2", last_request.body
|
159
171
|
assert_equal "0.1", last_request.headers["Rendering"]
|
160
|
-
assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split
|
172
|
+
assert_equal "user:pass", Base64.decode64(last_request.headers["Authorization"].split.last)
|
173
|
+
end
|
174
|
+
|
175
|
+
test "uses base url" do
|
176
|
+
register_uri(:get, /.+/)
|
177
|
+
|
178
|
+
client = Aitch::Namespace.new
|
179
|
+
client.configure {|c| c.base_url = "https://example.com" }
|
180
|
+
|
181
|
+
client.get("/some/path")
|
182
|
+
|
183
|
+
assert_equal "/some/path", last_request.uri.request_uri
|
184
|
+
assert_equal "example.com", last_request.uri.host
|
185
|
+
assert_equal "https", last_request.uri.scheme
|
161
186
|
end
|
162
187
|
end
|
@@ -6,12 +6,8 @@ require "csv"
|
|
6
6
|
class CustomResponseParserTest < Minitest::Test
|
7
7
|
setup do
|
8
8
|
parser = Class.new do
|
9
|
-
def self.type
|
10
|
-
:csv
|
11
|
-
end
|
12
|
-
|
13
9
|
def self.match?(content_type)
|
14
|
-
content_type
|
10
|
+
content_type.include?("csv")
|
15
11
|
end
|
16
12
|
|
17
13
|
def self.load(source)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
require "csv"
|
5
|
+
|
6
|
+
class DefaultResponseParserTest < Minitest::Test
|
7
|
+
test "returns application/custom" do
|
8
|
+
register_uri(:get, "http://example.org/file.custom", body: "1,2,3", content_type: "application/custom")
|
9
|
+
response = Aitch.get("http://example.org/file.custom")
|
10
|
+
|
11
|
+
assert_instance_of String, response.data
|
12
|
+
assert_equal %[1,2,3], response.data
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class ToQueryTest < Minitest::Test
|
6
|
+
test "converts array" do
|
7
|
+
assert_equal "hobbies%5B%5D=Rails&hobbies%5B%5D=coding",
|
8
|
+
%w[Rails coding].to_query("hobbies")
|
9
|
+
assert_equal "hobbies%5B%5D=",
|
10
|
+
[].to_query("hobbies")
|
11
|
+
end
|
12
|
+
|
13
|
+
test "converts hash" do
|
14
|
+
assert_equal "name=David&nationality=Danish",
|
15
|
+
{name: "David", nationality: "Danish"}.to_query
|
16
|
+
|
17
|
+
assert_equal "user%5Bname%5D=David&user%5Bnationality%5D=Danish",
|
18
|
+
{name: "David", nationality: "Danish"}.to_query("user")
|
19
|
+
end
|
20
|
+
|
21
|
+
test "converts booleans" do
|
22
|
+
assert_equal "done=false&ready=true",
|
23
|
+
{ready: true, done: false}.to_query
|
24
|
+
|
25
|
+
assert_equal "states%5B%5D=true&states%5B%5D=false",
|
26
|
+
[true, false].to_query("states")
|
27
|
+
end
|
28
|
+
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.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -166,14 +166,15 @@ 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: []
|
173
173
|
files:
|
174
|
+
- ".github/FUNDING.yml"
|
175
|
+
- ".github/workflows/tests.yml"
|
174
176
|
- ".gitignore"
|
175
177
|
- ".rubocop.yml"
|
176
|
-
- ".travis.yml"
|
177
178
|
- CHANGELOG.md
|
178
179
|
- Gemfile
|
179
180
|
- LICENSE.txt
|
@@ -214,6 +215,7 @@ files:
|
|
214
215
|
- test/aitch/request/status_code_validation_test.rb
|
215
216
|
- test/aitch/request_test.rb
|
216
217
|
- test/aitch/response/custom_response_parser_test.rb
|
218
|
+
- test/aitch/response/default_response_parser_test.rb
|
217
219
|
- test/aitch/response/errors_test.rb
|
218
220
|
- test/aitch/response/html_response_test.rb
|
219
221
|
- test/aitch/response/json_response_test.rb
|
@@ -226,6 +228,7 @@ files:
|
|
226
228
|
- test/aitch/response_parser/json_parser_test.rb
|
227
229
|
- test/aitch/response_parser/xml_parser_test.rb
|
228
230
|
- test/aitch/response_test.rb
|
231
|
+
- test/aitch/to_query_test.rb
|
229
232
|
- test/aitch/uri_test.rb
|
230
233
|
- test/aitch/utils/symbolize_keys_test.rb
|
231
234
|
- test/aitch/utils/underscore_test.rb
|
@@ -235,8 +238,9 @@ files:
|
|
235
238
|
homepage: http://rubygems.org/gems/aitch
|
236
239
|
licenses:
|
237
240
|
- MIT
|
238
|
-
metadata:
|
239
|
-
|
241
|
+
metadata:
|
242
|
+
rubygems_mfa_required: 'true'
|
243
|
+
post_install_message:
|
240
244
|
rdoc_options: []
|
241
245
|
require_paths:
|
242
246
|
- lib
|
@@ -244,45 +248,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
244
248
|
requirements:
|
245
249
|
- - ">="
|
246
250
|
- !ruby/object:Gem::Version
|
247
|
-
version:
|
251
|
+
version: 2.5.0
|
248
252
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
249
253
|
requirements:
|
250
254
|
- - ">="
|
251
255
|
- !ruby/object:Gem::Version
|
252
256
|
version: '0'
|
253
257
|
requirements: []
|
254
|
-
rubygems_version: 3.
|
255
|
-
signing_key:
|
258
|
+
rubygems_version: 3.3.7
|
259
|
+
signing_key:
|
256
260
|
specification_version: 4
|
257
261
|
summary: A simple HTTP client
|
258
|
-
test_files:
|
259
|
-
- test/aitch/aitch_test.rb
|
260
|
-
- test/aitch/configuration_test.rb
|
261
|
-
- test/aitch/dsl_test.rb
|
262
|
-
- test/aitch/execute_test.rb
|
263
|
-
- test/aitch/namespace_test.rb
|
264
|
-
- test/aitch/request/client_https_test.rb
|
265
|
-
- test/aitch/request/follow_redirect_test.rb
|
266
|
-
- test/aitch/request/json_request_test.rb
|
267
|
-
- test/aitch/request/request_class_test.rb
|
268
|
-
- test/aitch/request/status_code_validation_test.rb
|
269
|
-
- test/aitch/request_test.rb
|
270
|
-
- test/aitch/response/custom_response_parser_test.rb
|
271
|
-
- test/aitch/response/errors_test.rb
|
272
|
-
- test/aitch/response/html_response_test.rb
|
273
|
-
- test/aitch/response/json_response_test.rb
|
274
|
-
- test/aitch/response/raw_response_test.rb
|
275
|
-
- test/aitch/response/status_3xx_test.rb
|
276
|
-
- test/aitch/response/status_4xx_test.rb
|
277
|
-
- test/aitch/response/status_5xx_test.rb
|
278
|
-
- test/aitch/response/xml_response_test.rb
|
279
|
-
- test/aitch/response_parser/html_parser_test.rb
|
280
|
-
- test/aitch/response_parser/json_parser_test.rb
|
281
|
-
- test/aitch/response_parser/xml_parser_test.rb
|
282
|
-
- test/aitch/response_test.rb
|
283
|
-
- test/aitch/uri_test.rb
|
284
|
-
- test/aitch/utils/symbolize_keys_test.rb
|
285
|
-
- test/aitch/utils/underscore_test.rb
|
286
|
-
- test/fixtures/iso8859-1.xml
|
287
|
-
- test/support/helpers.rb
|
288
|
-
- test/test_helper.rb
|
262
|
+
test_files: []
|
data/.travis.yml
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
---
|
2
|
-
language: ruby
|
3
|
-
script: "bundle exec rake"
|
4
|
-
before_install: gem install bundler
|
5
|
-
cache: bundler
|
6
|
-
sudo: false
|
7
|
-
|
8
|
-
rvm:
|
9
|
-
- "2.7"
|
10
|
-
|
11
|
-
gemfile:
|
12
|
-
- Gemfile
|
13
|
-
|
14
|
-
notifications:
|
15
|
-
email: false
|
16
|
-
|
17
|
-
addons:
|
18
|
-
code_climate:
|
19
|
-
repo_token:
|
20
|
-
secure: "j/AjAG1u7NtdldftKUXnTMKC7CPd2R/O55ejzZnJi5IlHKKKZgJla1Z0YHTsGr75JQS7Q00D0L3TOSY8fLhV6fXO3Gn+9ShKTFRV5+iUtzlV0AWKBw+uENKNJH4jn1FhCoV8Th0I6OKtq98PqZ/hLR2J+/Uv3oCBwyriyJqag2U="
|