json_api_client 0.2.1 → 0.2.2

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: 04df1b6b993e798bab8a46fe194ade5c9021c7c1
4
- data.tar.gz: bf6a0a9c89b8cc8c36458e560e4c113d70977e5e
3
+ metadata.gz: cd3a5cd09cfe62026ca92b0f96bdf96bbbf448fa
4
+ data.tar.gz: fff1f331e95db8247b97220be4be16b8d5b89b2a
5
5
  SHA512:
6
- metadata.gz: 4a112dc70bdf54b4140a0fafdd613950c92c5493939010040d098e61d835ab125cac11dc4647963f057df1eb186a7ca627a05c5c5d2d280d7403ab53cc211ece
7
- data.tar.gz: a07f7dae424b11d9a17459a3da5027623ec1ffd840de6541ac2b772bb30dd93fec75b837a7d72c21bffed67d1d3b3b92053ca0c2f47d2cbc29b1d75ce9dae668
6
+ metadata.gz: 2c4abe201352dd98b06d362c88a0b44ef57a048000835bce3d43524bce91dfccba953d238de9329ac0f2869d30fe4ed8e6d358fc92675ca99f5c7f2546c62b51
7
+ data.tar.gz: f5e3c21c58d71b682372da6c550030c8176a3d56d9d6c7f7dfb8a167031f21d1a38335c359ceb9a7ce519e5df39c673b30c5b17ad279584beeb9c0828d9a63aa
@@ -8,7 +8,7 @@ module JsonApiClient
8
8
  builder.request :url_encoded
9
9
  builder.use Middleware::JsonRequest
10
10
  builder.use Middleware::Status
11
- builder.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
11
+ builder.use Middleware::ParseJson
12
12
  builder.adapter Faraday.default_adapter
13
13
  end
14
14
  yield(self) if block_given?
@@ -17,7 +17,7 @@ module JsonApiClient
17
17
  # insert middleware before ParseJson - middleware executed in reverse order -
18
18
  # inserted middleware will run after json parsed
19
19
  def use(middleware, *args, &block)
20
- faraday.builder.insert_before(FaradayMiddleware::ParseJson, middleware, *args, &block)
20
+ faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block)
21
21
  end
22
22
 
23
23
  def delete(middleware)
@@ -0,0 +1,31 @@
1
+ module JsonApiClient
2
+ module Middleware
3
+ class ParseJson < Faraday::Middleware
4
+
5
+ def call(environment)
6
+ @app.call(environment).on_complete do |env|
7
+ if process_response_type?(response_type(env))
8
+ env[:raw_body] = env[:body]
9
+ env[:body] = parse(env[:body])
10
+ end
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def parse(body)
17
+ ::JSON.parse(body) unless body.strip.empty?
18
+ end
19
+
20
+ def response_type(env)
21
+ type = env[:response_headers]['Content-Type'].to_s
22
+ type = type.split(';', 2).first if type.index(';')
23
+ type
24
+ end
25
+
26
+ def process_response_type?(type)
27
+ !!type.match(/\bjson$/)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,6 +1,7 @@
1
1
  module JsonApiClient
2
2
  module Middleware
3
3
  autoload :JsonRequest, 'json_api_client/middleware/json_request'
4
+ autoload :ParseJson, 'json_api_client/middleware/parse_json'
4
5
  autoload :Status, 'json_api_client/middleware/status'
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,5 +1,4 @@
1
1
  require 'faraday'
2
- require 'faraday_middleware'
3
2
  require 'json'
4
3
 
5
4
  module JsonApiClient
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.8.0
41
- - !ruby/object:Gem::Dependency
42
- name: faraday_middleware
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.9.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.9.0
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: webmock
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,7 @@ files:
94
80
  - lib/json_api_client/helpers/serializable.rb
95
81
  - lib/json_api_client/middleware.rb
96
82
  - lib/json_api_client/middleware/json_request.rb
83
+ - lib/json_api_client/middleware/parse_json.rb
97
84
  - lib/json_api_client/middleware/status.rb
98
85
  - lib/json_api_client/parser.rb
99
86
  - lib/json_api_client/query.rb