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 +4 -4
- data/README.md +1 -1
- data/jsonapi-consumer.gemspec +1 -0
- data/lib/jsonapi/consumer/connection.rb +1 -1
- data/lib/jsonapi/consumer/errors.rb +14 -24
- data/lib/jsonapi/consumer/helpers/dynamic_attributes.rb +2 -2
- data/lib/jsonapi/consumer/middleware/status.rb +6 -6
- data/lib/jsonapi/consumer/query/builder.rb +1 -1
- data/lib/jsonapi/consumer/query/requestor.rb +1 -1
- data/lib/jsonapi/consumer/resource.rb +4 -4
- data/lib/jsonapi/consumer/version.rb +1 -1
- data/lib/jsonapi/consumer.rb +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49c9b2b9167f01b4d33a5ce21891370d71f87557fe7fa0bb2f2787ec56e981e9
|
4
|
+
data.tar.gz: 2cad24d981f207c6efa580cf1129ef99d11660565a93c8f28a7bd322725ffcc8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/jsonapi-consumer.gemspec
CHANGED
@@ -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"
|
@@ -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
|
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
|
-
|
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
|
-
|
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
|
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
|
@@ -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
|
-
|
320
|
+
RequestStore.store["jsonapi-consumer-#{resource_name}"] = headers
|
321
321
|
end
|
322
322
|
|
323
323
|
def _header_store
|
324
|
-
|
324
|
+
RequestStore.store["jsonapi-consumer-#{resource_name}"] ||= {}
|
325
325
|
end
|
326
326
|
|
327
327
|
def _build_connection(rebuild = false)
|
data/lib/jsonapi/consumer.rb
CHANGED
@@ -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:
|
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-
|
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:
|
190
|
+
version: 1.3.1
|
177
191
|
requirements: []
|
178
192
|
rubyforge_project:
|
179
193
|
rubygems_version: 2.7.6
|