api-blueprint 0.10.0 → 0.11.0
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/README.md +10 -0
- data/lib/api-blueprint.rb +1 -0
- data/lib/api-blueprint/blueprint.rb +4 -0
- data/lib/api-blueprint/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 562502f7f7f1db1dce275f3387dad4f4d5ec4443
|
4
|
+
data.tar.gz: 71241b573762d13fedeca6a3a2ca2e5e4fe76a45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c5e3aa626d930c43fe997dd0f80b5aa58f98c6ff11a99e43007875a72b2228b89488e0f803bdec8999812024321bbaee31ca97b2ab1889c8589099c8c2d7a9a
|
7
|
+
data.tar.gz: c2e8018eeb9c49f6f5b69f7a85ac5432abaad29a97e4f5385252dc502eeff8c436b24c5795a3600cafd583e1d869c7e19eb584bb21756cc57cfa658fe7b18df9
|
data/README.md
CHANGED
@@ -177,6 +177,8 @@ Certain response statuses will also cause ApiBlueprint to behave in different wa
|
|
177
177
|
| 402 - 499 | raises `ApiBlueprint::ClientError` |
|
178
178
|
| 500 - 599 | raises `ApiBlueprint::ServerError` |
|
179
179
|
|
180
|
+
Additionally, if the request timesout or some other error occurs which prevents the request from ever receiving a response, an `ApiBlueprint::ConnectionFailed` error will be raised.
|
181
|
+
|
180
182
|
## Access to response headers and status codes
|
181
183
|
|
182
184
|
By default, ApiBlueprint tries to set `response_headers` and `response_status` on the model which is created from an API response. `ApiBlueprint::Model` also has a convenience method `api_request_success?` which can be used to easily assert whether a response was in the 200-399 range. This makes it simple to render different responses in controllers. For example:
|
@@ -278,6 +280,14 @@ class AstronautsInSpace < ApiBlueprint::Model
|
|
278
280
|
end
|
279
281
|
```
|
280
282
|
|
283
|
+
## Timeouts
|
284
|
+
|
285
|
+
The default request timeout is set to 5 seconds. You can change this on a per-blueprint basis by passing the `timeout` option to the blueprint:
|
286
|
+
|
287
|
+
```ruby
|
288
|
+
blueprint :get, "/endpoint", timeout: 10.seconds
|
289
|
+
```
|
290
|
+
|
281
291
|
## A note on Dry::Struct immutability
|
282
292
|
|
283
293
|
Models you create use `Dry::Struct` to handle initialization and assignment. `Dry::Struct` is designed with immutability in mind, so if you need to mutate the objects you have, there are two possibilities; explicitly define an `attr_writer` for the attributes which you want to mutate, or do things the "Dry::Struct way" and use the current instance to initialize a new instance:
|
data/lib/api-blueprint.rb
CHANGED
@@ -38,6 +38,7 @@ module ApiBlueprint
|
|
38
38
|
|
39
39
|
class DefinitionError < StandardError; end
|
40
40
|
class BuilderError < StandardError; end
|
41
|
+
class ConnectionFailed < StandardError; end
|
41
42
|
class ServerError < ResponseError; end
|
42
43
|
class UnauthenticatedError < ResponseError; end
|
43
44
|
class ClientError < ResponseError; end
|
@@ -11,6 +11,7 @@ module ApiBlueprint
|
|
11
11
|
attribute :after_build, Types::Instance(Proc).optional
|
12
12
|
attribute :builder, Types.Instance(ApiBlueprint::Builder).default(ApiBlueprint::Builder.new)
|
13
13
|
attribute :log_responses, Types::Strict::Bool.default(false)
|
14
|
+
attribute :timeout, Types::Strict::Integer.default(5)
|
14
15
|
|
15
16
|
def all_request_options(options = {})
|
16
17
|
{
|
@@ -37,6 +38,8 @@ module ApiBlueprint
|
|
37
38
|
end
|
38
39
|
|
39
40
|
after_build.present? ? after_build.call(runner, created) : created
|
41
|
+
rescue Faraday::ConnectionFailed
|
42
|
+
raise ApiBlueprint::ConnectionFailed
|
40
43
|
end
|
41
44
|
|
42
45
|
def connection
|
@@ -78,6 +81,7 @@ module ApiBlueprint
|
|
78
81
|
req.headers.merge!({ "Content-Type": "application/json" }.merge(options[:headers]))
|
79
82
|
req.params = options[:params]
|
80
83
|
req.body = options[:body].to_json
|
84
|
+
req.options.timeout = timeout.to_i
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-blueprint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|