jsonapi-consumer 1.0.1 → 2.0.0.pre

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
  SHA256:
3
- metadata.gz: 489b57d413d656c7108af99f5b9c088c71136b9b087c0ef17536c177e5639c5b
4
- data.tar.gz: 2c2729ab661f1c483b2f8766fbe3581a3b032eea13185fd3926aa908b928d2aa
3
+ metadata.gz: 49c9b2b9167f01b4d33a5ce21891370d71f87557fe7fa0bb2f2787ec56e981e9
4
+ data.tar.gz: 2cad24d981f207c6efa580cf1129ef99d11660565a93c8f28a7bd322725ffcc8
5
5
  SHA512:
6
- metadata.gz: 7a78edbddca4e3ffdc55cdde1e2eeac50833d7fb9d9863eb43f4455aa22b6bde8f2a6d7c7ef5990565986e04718a90d5fa120cbe1db1f0bf6724e37a1e5edea4
7
- data.tar.gz: 95a6c0d2619fa6fd8c309cdfd09e6d8e31944c82fb62f4ea9644c328fe390406d07399b693241ae49fbe86627b7b514272c214b86919a800cfc89be9e429d7c3
6
+ metadata.gz: 5a06900376b2b40d5f4adc8c74e23264d929b1b0c59a62b69b0a649cd2410c5a8b468f6c322134df2954495822ef6227924ec0ae259469d2fcf66731049e626c
7
+ data.tar.gz: 5cb4f6c0e2f999633fcb4b79f8071249fb244b4d7c57ff1fc6d75d663d0f631392eb58ff0e43394a44db267652a8596f443155d427136044c13a968575b91e27
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  An ActiveModel-compliant consumer framework for communicating with JSONAPI-based APIs.
4
4
 
5
- [![CircleCI](https://circleci.com/gh/jsmestad/jsonapi-consumer.svg?style=svg)](https://circleci.com/gh/jsmestad/jsonapi-consumer)
5
+ [![CircleCI](https://circleci.com/gh/jsmestad/jsonapi-consumer/tree/master.svg?style=svg)](https://circleci.com/gh/jsmestad/jsonapi-consumer/tree/master)
6
6
 
7
7
  ## Installation
8
8
 
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency "faraday_middleware"
26
26
  spec.add_runtime_dependency "addressable", '~> 2.5.2'
27
27
  spec.add_runtime_dependency "activemodel", '>= 3.2'
28
+ spec.add_runtime_dependency "request_store", '>= 1.4'
28
29
 
29
30
  spec.add_development_dependency "webmock"
30
31
  spec.add_development_dependency "mocha"
@@ -29,7 +29,7 @@ module JSONAPI::Consumer
29
29
  end
30
30
 
31
31
  def run(request_method, path, params = {}, headers = {})
32
- faraday.send(request_method, path, params, headers)
32
+ faraday.public_send(request_method, path, params, headers)
33
33
  end
34
34
 
35
35
  end
@@ -2,55 +2,45 @@ module JSONAPI::Consumer
2
2
  module Errors
3
3
  class ApiError < StandardError
4
4
  attr_reader :env
5
- def initialize(env)
5
+ def initialize(message, env=nil)
6
+ super(message)
6
7
  @env = env
7
8
  end
8
9
  end
9
10
 
10
- class ClientError < ApiError
11
- end
12
-
13
- class AccessDenied < ClientError
14
- end
15
-
16
- class NotAuthorized < ClientError
17
- end
18
-
19
- class ConnectionError < ApiError
20
- end
11
+ class ClientError < ApiError; end
12
+ class AccessDenied < ClientError; end
13
+ class NotAuthorized < ClientError; end
14
+ class ConnectionError < ApiError; end
21
15
 
22
16
  class ServerError < ApiError
23
- def message
24
- "Internal server error"
17
+ def initialize(message, env=nil)
18
+ super("Internal server error", env)
25
19
  end
26
20
  end
27
21
 
28
22
  class Conflict < ServerError
29
- def message
30
- "Resource already exists"
23
+ def initialize(message, env=nil)
24
+ super("Resource already exists", env)
31
25
  end
32
26
  end
33
27
 
34
28
  class NotFound < ServerError
35
29
  attr_reader :uri
36
- def initialize(uri)
30
+
31
+ def initialize(message, uri=nil)
32
+ super("Couldn't find resource at: #{uri.to_s}")
37
33
  @uri = uri
38
34
  end
39
- def message
40
- "Couldn't find resource at: #{uri.to_s}"
41
- end
42
35
  end
43
36
 
44
37
  class UnexpectedStatus < ServerError
45
38
  attr_reader :code, :uri
46
39
  def initialize(code, uri)
40
+ super("Unexpected response status: #{code} from: #{uri.to_s}")
47
41
  @code = code
48
42
  @uri = uri
49
43
  end
50
- def message
51
- "Unexpected response status: #{code} from: #{uri.to_s}"
52
- end
53
44
  end
54
-
55
45
  end
56
46
  end
@@ -11,7 +11,7 @@ module JSONAPI::Consumer
11
11
 
12
12
  return @attributes unless attrs.present?
13
13
  attrs.each do |key, value|
14
- send("#{key}=", value)
14
+ public_send("#{key}=", value)
15
15
  end
16
16
  end
17
17
 
@@ -44,7 +44,7 @@ module JSONAPI::Consumer
44
44
  attributes[method]
45
45
  end
46
46
  end
47
- return send(method)
47
+ return public_send(method)
48
48
  end
49
49
 
50
50
  normalized_method = safe_key_formatter.unformat(method.to_s)
@@ -12,7 +12,7 @@ module JSONAPI::Consumer
12
12
  end
13
13
  end
14
14
  rescue Faraday::ConnectionFailed, Faraday::TimeoutError
15
- raise Errors::ConnectionError, environment
15
+ raise Errors::ConnectionError.new(nil, environment)
16
16
  end
17
17
 
18
18
  protected
@@ -21,17 +21,17 @@ module JSONAPI::Consumer
21
21
  case code
22
22
  when 200..399
23
23
  when 401
24
- raise Errors::NotAuthorized, env
24
+ raise Errors::NotAuthorized.new(nil, env)
25
25
  when 403
26
- raise Errors::AccessDenied, env
26
+ raise Errors::AccessDenied.new(nil, env)
27
27
  when 404
28
- raise Errors::NotFound, env[:url]
28
+ raise Errors::NotFound.new(nil, env[:url])
29
29
  when 409
30
- raise Errors::Conflict, env
30
+ raise Errors::Conflict.new(nil, env)
31
31
  when 400..499
32
32
  # some other error
33
33
  when 500..599
34
- raise Errors::ServerError, env
34
+ raise Errors::ServerError.new(nil, env)
35
35
  else
36
36
  raise Errors::UnexpectedStatus.new(code, env[:url])
37
37
  end
@@ -102,7 +102,7 @@ module JSONAPI::Consumer
102
102
  end
103
103
 
104
104
  def method_missing(method_name, *args, &block)
105
- to_a.send(method_name, *args, &block)
105
+ to_a.public_send(method_name, *args, &block)
106
106
  end
107
107
 
108
108
  private
@@ -39,7 +39,7 @@ module JSONAPI::Consumer
39
39
  def custom(method_name, options, params)
40
40
  path = resource_path(params)
41
41
  params.delete(klass.primary_key)
42
- path = File.join(path, method_name.to_s)
42
+ path = File.join(path, klass.route_formatter.format(method_name.to_s))
43
43
 
44
44
  request(options.fetch(:request_method, :get), path, params)
45
45
  end
@@ -1,4 +1,3 @@
1
-
2
1
  module JSONAPI::Consumer
3
2
  class Resource
4
3
  extend ActiveModel::Naming
@@ -142,10 +141,11 @@ module JSONAPI::Consumer
142
141
  # @param headers [Hash] The headers to send along
143
142
  # @param block [Block] The block where headers will be set for
144
143
  def with_headers(headers)
144
+ existing_headers = self.custom_headers
145
145
  self._custom_headers = headers
146
146
  yield
147
147
  ensure
148
- self._custom_headers = {}
148
+ self._custom_headers = existing_headers
149
149
  end
150
150
 
151
151
  # The current custom headers to send with any request made by this
@@ -317,11 +317,11 @@ module JSONAPI::Consumer
317
317
  end
318
318
 
319
319
  def _custom_headers=(headers)
320
- _header_store.replace(headers)
320
+ RequestStore.store["jsonapi-consumer-#{resource_name}"] = headers
321
321
  end
322
322
 
323
323
  def _header_store
324
- Thread.current["json_api_client-#{resource_name}"] ||= {}
324
+ RequestStore.store["jsonapi-consumer-#{resource_name}"] ||= {}
325
325
  end
326
326
 
327
327
  def _build_connection(rebuild = false)
@@ -1,5 +1,5 @@
1
1
  module Jsonapi
2
2
  module Consumer
3
- VERSION = "1.0.1"
3
+ VERSION = "2.0.0.pre"
4
4
  end
5
5
  end
@@ -8,6 +8,7 @@ require "forwardable"
8
8
  require "faraday"
9
9
  require "faraday_middleware"
10
10
  require "addressable/uri"
11
+ require "request_store"
11
12
 
12
13
  module JSONAPI
13
14
  module Consumer
@@ -67,4 +68,4 @@ module JSONAPI
67
68
  autoload :Schema, 'jsonapi/consumer/schema'
68
69
  autoload :Utils, 'jsonapi/consumer/utils'
69
70
  end
70
- end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonapi-consumer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Smestad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: request_store
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '1.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '1.4'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: webmock
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -171,9 +185,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
185
  version: '0'
172
186
  required_rubygems_version: !ruby/object:Gem::Requirement
173
187
  requirements:
174
- - - ">="
188
+ - - ">"
175
189
  - !ruby/object:Gem::Version
176
- version: '0'
190
+ version: 1.3.1
177
191
  requirements: []
178
192
  rubyforge_project:
179
193
  rubygems_version: 2.7.6