aitch 1.0.0 → 1.0.1
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/CHANGELOG.md +2 -0
- data/README.md +13 -6
- data/lib/aitch/request.rb +1 -1
- data/lib/aitch/response_parser/json_parser.rb +7 -1
- data/lib/aitch/version.rb +1 -1
- data/test/aitch/request/json_request_test.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1608bb2a19cd498230af4c13ff13f5470c038b8c
|
4
|
+
data.tar.gz: 1dd7c3cde77b473060edfccb1865eed448de4cda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00029220787908d61ed6b1d64a8dcbe9e0dffdc3f450c3ce67d56b836d9967919fc12a1f18298919876478c5ef916146d529992d1008752b33eff1e36622573c
|
7
|
+
data.tar.gz: ff9e4b489b83f083d172e035a5440bd4db7ef36404c8f6fe728c408124a8a86927069e18183eea312038b7fb581668fe7e729d39a5e90bd4131811f46c0ee618
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -109,25 +109,25 @@ If your response is a JSON, XML or a HTML content type, we'll automatically conv
|
|
109
109
|
```ruby
|
110
110
|
response = Aitch.get("http://simplesideias.com.br")
|
111
111
|
|
112
|
-
response.
|
112
|
+
response.data.class
|
113
113
|
#=> Nokogiri::HTML::Document
|
114
114
|
|
115
|
-
response.
|
115
|
+
response.data.css("h1").size
|
116
116
|
#=> 69
|
117
117
|
|
118
118
|
response = Aitch.get("http://simplesideias.com.br/feed")
|
119
119
|
|
120
|
-
response.
|
120
|
+
response.data.class
|
121
121
|
#=> Nokogiri::XML::Document
|
122
122
|
|
123
|
-
response.
|
123
|
+
response.data.css("item").size
|
124
124
|
#=> 10
|
125
125
|
|
126
126
|
response = Aitch.get("https://api.github.com/users/fnando")
|
127
|
-
response.
|
127
|
+
response.data.class
|
128
128
|
#=> Hash
|
129
129
|
|
130
|
-
response.
|
130
|
+
response.data["login"]
|
131
131
|
#=> fnando
|
132
132
|
```
|
133
133
|
|
@@ -261,6 +261,13 @@ Aitch::ResponseParser.append(:default, DefaultParser)
|
|
261
261
|
|
262
262
|
Aitch comes with response parsers for HTML, XML and JSON.
|
263
263
|
|
264
|
+
By default, the JSON parser will be `JSON`. To set it to something else, use `Aitch::ResponseParser::JSONParser.engine`.
|
265
|
+
|
266
|
+
```ruby
|
267
|
+
require "oj"
|
268
|
+
Aitch::ResponseParser::JSONParser.engine = Oj
|
269
|
+
```
|
270
|
+
|
264
271
|
## Contributing
|
265
272
|
|
266
273
|
1. Fork it
|
data/lib/aitch/request.rb
CHANGED
@@ -70,7 +70,7 @@ module Aitch
|
|
70
70
|
def set_body(request)
|
71
71
|
body_data = data
|
72
72
|
body_data = data.to_h if data.respond_to?(:to_h)
|
73
|
-
body_data =
|
73
|
+
body_data = ResponseParser::JSONParser.engine.dump(body_data) if content_type.to_s =~ /\bjson\b/
|
74
74
|
|
75
75
|
if body_data.kind_of?(Hash)
|
76
76
|
request.body = Utils.build_query(body_data)
|
@@ -2,6 +2,12 @@
|
|
2
2
|
module Aitch
|
3
3
|
module ResponseParser
|
4
4
|
module JSONParser
|
5
|
+
class << self
|
6
|
+
attr_accessor :engine
|
7
|
+
end
|
8
|
+
|
9
|
+
self.engine = ::JSON
|
10
|
+
|
5
11
|
def self.type
|
6
12
|
:json
|
7
13
|
end
|
@@ -11,7 +17,7 @@ module Aitch
|
|
11
17
|
end
|
12
18
|
|
13
19
|
def self.load(source)
|
14
|
-
|
20
|
+
engine.load(source.to_s)
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/aitch/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "test_helper"
|
3
|
+
|
4
|
+
class JsonRequestTest < Minitest::Test
|
5
|
+
test "uses json parser" do
|
6
|
+
register_uri(:post, "http://example.org/", status: 200)
|
7
|
+
Aitch.post do
|
8
|
+
url "http://example.org/"
|
9
|
+
body a: 1
|
10
|
+
headers "Content-Type" => "application/json"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03
|
11
|
+
date: 2016-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- test/aitch/namespace_test.rb
|
152
152
|
- test/aitch/request/client_https_test.rb
|
153
153
|
- test/aitch/request/follow_redirect_test.rb
|
154
|
+
- test/aitch/request/json_request_test.rb
|
154
155
|
- test/aitch/request/request_class_test.rb
|
155
156
|
- test/aitch/request/status_code_validation_test.rb
|
156
157
|
- test/aitch/request_test.rb
|
@@ -205,6 +206,7 @@ test_files:
|
|
205
206
|
- test/aitch/namespace_test.rb
|
206
207
|
- test/aitch/request/client_https_test.rb
|
207
208
|
- test/aitch/request/follow_redirect_test.rb
|
209
|
+
- test/aitch/request/json_request_test.rb
|
208
210
|
- test/aitch/request/request_class_test.rb
|
209
211
|
- test/aitch/request/status_code_validation_test.rb
|
210
212
|
- test/aitch/request_test.rb
|