aitch 1.0.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.github/FUNDING.yml +3 -0
  3. data/.github/workflows/tests.yml +50 -0
  4. data/.rubocop.yml +26 -0
  5. data/Gemfile +2 -2
  6. data/README.md +54 -14
  7. data/Rakefile +5 -1
  8. data/aitch.gemspec +12 -7
  9. data/lib/aitch/configuration.rb +5 -0
  10. data/lib/aitch/dsl.rb +4 -3
  11. data/lib/aitch/engines/json.rb +15 -0
  12. data/lib/aitch/errors.rb +1 -0
  13. data/lib/aitch/ext/to_query.rb +6 -10
  14. data/lib/aitch/location.rb +4 -3
  15. data/lib/aitch/namespace.rb +38 -14
  16. data/lib/aitch/redirect.rb +1 -0
  17. data/lib/aitch/request.rb +40 -28
  18. data/lib/aitch/response/body.rb +1 -0
  19. data/lib/aitch/response/description.rb +3 -2
  20. data/lib/aitch/response/errors.rb +2 -1
  21. data/lib/aitch/response.rb +9 -5
  22. data/lib/aitch/response_parser/default_parser.rb +2 -1
  23. data/lib/aitch/response_parser/html_parser.rb +1 -0
  24. data/lib/aitch/response_parser/json_parser.rb +2 -1
  25. data/lib/aitch/response_parser/xml_parser.rb +1 -0
  26. data/lib/aitch/response_parser.rb +8 -5
  27. data/lib/aitch/uri.rb +5 -2
  28. data/lib/aitch/utils.rb +3 -1
  29. data/lib/aitch/version.rb +2 -1
  30. data/lib/aitch.rb +13 -13
  31. data/test/aitch/aitch_test.rb +1 -0
  32. data/test/aitch/configuration_test.rb +2 -1
  33. data/test/aitch/dsl_test.rb +1 -0
  34. data/test/aitch/execute_test.rb +1 -0
  35. data/test/aitch/namespace_test.rb +2 -1
  36. data/test/aitch/request/client_https_test.rb +1 -0
  37. data/test/aitch/request/follow_redirect_test.rb +4 -3
  38. data/test/aitch/request/json_request_test.rb +1 -0
  39. data/test/aitch/request/request_class_test.rb +3 -2
  40. data/test/aitch/request/status_code_validation_test.rb +3 -2
  41. data/test/aitch/request_test.rb +45 -8
  42. data/test/aitch/response/custom_response_parser_test.rb +1 -4
  43. data/test/aitch/response/default_response_parser_test.rb +14 -0
  44. data/test/aitch/response/errors_test.rb +1 -0
  45. data/test/aitch/response/html_response_test.rb +1 -0
  46. data/test/aitch/response/json_response_test.rb +2 -1
  47. data/test/aitch/response/raw_response_test.rb +1 -0
  48. data/test/aitch/response/status_3xx_test.rb +1 -0
  49. data/test/aitch/response/status_4xx_test.rb +1 -0
  50. data/test/aitch/response/status_5xx_test.rb +1 -0
  51. data/test/aitch/response/xml_response_test.rb +1 -0
  52. data/test/aitch/response_parser/html_parser_test.rb +1 -0
  53. data/test/aitch/response_parser/json_parser_test.rb +2 -1
  54. data/test/aitch/response_parser/xml_parser_test.rb +1 -1
  55. data/test/aitch/response_test.rb +1 -1
  56. data/test/aitch/to_query_test.rb +28 -0
  57. data/test/aitch/uri_test.rb +2 -1
  58. data/test/aitch/utils/symbolize_keys_test.rb +1 -0
  59. data/test/aitch/utils/underscore_test.rb +1 -0
  60. data/test/support/helpers.rb +5 -4
  61. data/test/test_helper.rb +3 -2
  62. metadata +77 -15
  63. data/.travis.yml +0 -23
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class JsonResponseTest < Minitest::Test
@@ -13,6 +14,6 @@ class JsonResponseTest < Minitest::Test
13
14
  register_uri(:get, "http://example.org/", body: "[1,2,3]", content_type: "application/json")
14
15
  response = Aitch.get("http://example.org/")
15
16
 
16
- assert_equal [1,2,3], response.data
17
+ assert_equal [1, 2, 3], response.data
17
18
  end
18
19
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class RawResponseTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class Status3xxTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class Status4xxTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class Status5xxTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class XmlResponseTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class HtmlParserTest < Minitest::Test
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class JsonParserTest < Minitest::Test
5
6
  test "loads JSON" do
6
- JSON.expects(:load).with(%[{"a":1}])
7
+ JSON.expects(:parse).with(%[{"a":1}])
7
8
  Aitch::ResponseParser::JSONParser.load(%[{"a":1}])
8
9
  end
9
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # encoding: utf-8
2
+
3
3
  require "test_helper"
4
4
 
5
5
  class XmlParserTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class ResponseTest < Minitest::Test
@@ -27,7 +28,6 @@ class ResponseTest < Minitest::Test
27
28
  end
28
29
 
29
30
  test "deflates response" do
30
- stdio = StringIO.new
31
31
  deflated = Zlib::Deflate.deflate("Hello")
32
32
 
33
33
  register_uri(:get, "http://example.org/", body: deflated, content_encoding: "deflate")
@@ -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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class UriTest < Minitest::Test
@@ -27,7 +28,7 @@ class UriTest < Minitest::Test
27
28
  end
28
29
 
29
30
  test "ignores data when request has body" do
30
- assert_equal nil, Aitch::URI.new("http://example.org/", {c: 3}, true).query
31
+ assert_nil Aitch::URI.new("http://example.org/", {c: 3}, true).query
31
32
  end
32
33
 
33
34
  test "returns request uri" do
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class SymbolizeKeysTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require "test_helper"
3
4
 
4
5
  class UnderscoreTest < Minitest::Test
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Minitest
3
4
  class Test
4
5
  def add_hash_entry(source, target, from, to)
@@ -6,13 +7,13 @@ module Minitest
6
7
  end
7
8
 
8
9
  def register_uri(http_method, url, options = {})
9
- body = options.fetch(:body, '')
10
+ body = options.fetch(:body, "")
10
11
  status = options.fetch(:status, 200)
11
12
  headers = options.fetch(:headers, {})
12
13
 
13
- add_hash_entry(options, headers, :location, 'Location')
14
- add_hash_entry(options, headers, :content_type, 'Content-Type')
15
- add_hash_entry(options, headers, :content_encoding, 'Content-Encoding')
14
+ add_hash_entry(options, headers, :location, "Location")
15
+ add_hash_entry(options, headers, :content_type, "Content-Type")
16
+ add_hash_entry(options, headers, :content_encoding, "Content-Encoding")
16
17
 
17
18
  stub_request(http_method, url)
18
19
  .to_return(status: status, body: body, headers: headers)
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
- require "codeclimate-test-reporter"
3
- CodeClimate::TestReporter.start
2
+
3
+ require "simplecov"
4
+ SimpleCov.start
4
5
 
5
6
  require "bundler/setup"
6
7
 
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.0.1
4
+ version: 1.2.0
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: 2016-04-03 00:00:00.000000000 Z
11
+ date: 2022-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -16,16 +16,16 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.0
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.0
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: codeclimate-test-reporter
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,49 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-meta
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - ">="
@@ -67,7 +109,7 @@ dependencies:
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: minitest-utils
112
+ name: rubocop
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - ">="
@@ -81,7 +123,21 @@ dependencies:
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
125
  - !ruby/object:Gem::Dependency
84
- name: mocha
126
+ name: rubocop-fnando
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
85
141
  requirement: !ruby/object:Gem::Requirement
86
142
  requirements:
87
143
  - - ">="
@@ -115,8 +171,10 @@ executables: []
115
171
  extensions: []
116
172
  extra_rdoc_files: []
117
173
  files:
174
+ - ".github/FUNDING.yml"
175
+ - ".github/workflows/tests.yml"
118
176
  - ".gitignore"
119
- - ".travis.yml"
177
+ - ".rubocop.yml"
120
178
  - CHANGELOG.md
121
179
  - Gemfile
122
180
  - LICENSE.txt
@@ -126,6 +184,7 @@ files:
126
184
  - lib/aitch.rb
127
185
  - lib/aitch/configuration.rb
128
186
  - lib/aitch/dsl.rb
187
+ - lib/aitch/engines/json.rb
129
188
  - lib/aitch/errors.rb
130
189
  - lib/aitch/ext/to_query.rb
131
190
  - lib/aitch/location.rb
@@ -156,6 +215,7 @@ files:
156
215
  - test/aitch/request/status_code_validation_test.rb
157
216
  - test/aitch/request_test.rb
158
217
  - test/aitch/response/custom_response_parser_test.rb
218
+ - test/aitch/response/default_response_parser_test.rb
159
219
  - test/aitch/response/errors_test.rb
160
220
  - test/aitch/response/html_response_test.rb
161
221
  - test/aitch/response/json_response_test.rb
@@ -168,6 +228,7 @@ files:
168
228
  - test/aitch/response_parser/json_parser_test.rb
169
229
  - test/aitch/response_parser/xml_parser_test.rb
170
230
  - test/aitch/response_test.rb
231
+ - test/aitch/to_query_test.rb
171
232
  - test/aitch/uri_test.rb
172
233
  - test/aitch/utils/symbolize_keys_test.rb
173
234
  - test/aitch/utils/underscore_test.rb
@@ -178,7 +239,7 @@ homepage: http://rubygems.org/gems/aitch
178
239
  licenses:
179
240
  - MIT
180
241
  metadata: {}
181
- post_install_message:
242
+ post_install_message:
182
243
  rdoc_options: []
183
244
  require_paths:
184
245
  - lib
@@ -186,16 +247,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
247
  requirements:
187
248
  - - ">="
188
249
  - !ruby/object:Gem::Version
189
- version: '2.0'
250
+ version: 2.5.0
190
251
  required_rubygems_version: !ruby/object:Gem::Requirement
191
252
  requirements:
192
253
  - - ">="
193
254
  - !ruby/object:Gem::Version
194
255
  version: '0'
195
256
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.5.1
198
- signing_key:
257
+ rubygems_version: 3.3.17
258
+ signing_key:
199
259
  specification_version: 4
200
260
  summary: A simple HTTP client
201
261
  test_files:
@@ -211,6 +271,7 @@ test_files:
211
271
  - test/aitch/request/status_code_validation_test.rb
212
272
  - test/aitch/request_test.rb
213
273
  - test/aitch/response/custom_response_parser_test.rb
274
+ - test/aitch/response/default_response_parser_test.rb
214
275
  - test/aitch/response/errors_test.rb
215
276
  - test/aitch/response/html_response_test.rb
216
277
  - test/aitch/response/json_response_test.rb
@@ -223,6 +284,7 @@ test_files:
223
284
  - test/aitch/response_parser/json_parser_test.rb
224
285
  - test/aitch/response_parser/xml_parser_test.rb
225
286
  - test/aitch/response_test.rb
287
+ - test/aitch/to_query_test.rb
226
288
  - test/aitch/uri_test.rb
227
289
  - test/aitch/utils/symbolize_keys_test.rb
228
290
  - test/aitch/utils/underscore_test.rb
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- language: ruby
2
- script: "bundle exec rake"
3
- before_install: gem install bundler
4
- cache: bundler
5
- sudo: false
6
-
7
- rvm:
8
- - "2.3.0"
9
- - "2.2"
10
- - "2.1"
11
- - "2.0"
12
- - jruby-head
13
-
14
- gemfile:
15
- - Gemfile
16
-
17
- notifications:
18
- email: false
19
-
20
- addons:
21
- code_climate:
22
- repo_token:
23
- secure: "j/AjAG1u7NtdldftKUXnTMKC7CPd2R/O55ejzZnJi5IlHKKKZgJla1Z0YHTsGr75JQS7Q00D0L3TOSY8fLhV6fXO3Gn+9ShKTFRV5+iUtzlV0AWKBw+uENKNJH4jn1FhCoV8Th0I6OKtq98PqZ/hLR2J+/Uv3oCBwyriyJqag2U="