aitch 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: daca7104634e48ff40f0d33174c701884d0cbab4
4
- data.tar.gz: 7d96817bec549c8764561efc84553859b6b6e29b
3
+ metadata.gz: 1608bb2a19cd498230af4c13ff13f5470c038b8c
4
+ data.tar.gz: 1dd7c3cde77b473060edfccb1865eed448de4cda
5
5
  SHA512:
6
- metadata.gz: a2c8b42241ec8b9af83c2452c0b2f7fe5c92be1254d91b1324afa39eb7643283ecb3c0f8125834baedbf13e04ad4ffd8a4adadccd235a59318a35c273ee511d0
7
- data.tar.gz: 7e7d759d48479efe4fb335a8a7ff1fd05434b34cb247f3b725bd6067391d8f05969fc8efd1b2fad976f1f1aeb385a74b37c943f4af167f3fa0987b76624d92ad
6
+ metadata.gz: 00029220787908d61ed6b1d64a8dcbe9e0dffdc3f450c3ce67d56b836d9967919fc12a1f18298919876478c5ef916146d529992d1008752b33eff1e36622573c
7
+ data.tar.gz: ff9e4b489b83f083d172e035a5440bd4db7ef36404c8f6fe728c408124a8a86927069e18183eea312038b7fb581668fe7e729d39a5e90bd4131811f46c0ee618
@@ -1,5 +1,7 @@
1
1
  # Changelog
2
2
 
3
+ * **1.0.1**
4
+ * Fix a bug when JSON encoding body in a POST request.
3
5
  * **1.0.0**
4
6
  * Use frozen string magic comments
5
7
  * 307 redirections will honor the HTTP request method
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.html.class
112
+ response.data.class
113
113
  #=> Nokogiri::HTML::Document
114
114
 
115
- response.html.css("h1").size
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.xml.class
120
+ response.data.class
121
121
  #=> Nokogiri::XML::Document
122
122
 
123
- response.xml.css("item").size
123
+ response.data.css("item").size
124
124
  #=> 10
125
125
 
126
126
  response = Aitch.get("https://api.github.com/users/fnando")
127
- response.json.class
127
+ response.data.class
128
128
  #=> Hash
129
129
 
130
- response.json["login"]
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
@@ -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 = options[:json_parser].dump(body_data) if content_type.to_s =~ /\bjson\b/
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
- ::JSON.load(source.to_s)
20
+ engine.load(source.to_s)
15
21
  end
16
22
  end
17
23
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Aitch
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
@@ -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.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-31 00:00:00.000000000 Z
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