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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c71a6912bd0d28aacda1dcc3e9270f589c27bd1a
4
- data.tar.gz: c1a7c264ad6a56025a7a92bde195dc450c0a188b
3
+ metadata.gz: 562502f7f7f1db1dce275f3387dad4f4d5ec4443
4
+ data.tar.gz: 71241b573762d13fedeca6a3a2ca2e5e4fe76a45
5
5
  SHA512:
6
- metadata.gz: 62c236b537499de0c80d39489c61ae7bdc86235279000a14f86aa0d3db66cacab2eada10b40b38733648263653ce7341c7aa73f75f27d00999f24484ac8169ff
7
- data.tar.gz: 6142c601a95a4fa9eefb25653d1e9fc8b459591d8128241ff3ac5d1cf240189bc795a261d2d8ee9e2258fd2012af59c6a2c0e00a0080b5185fa5797dd2d28601
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:
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module ApiBlueprint
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.0'
3
3
  end
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.10.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-04 00:00:00.000000000 Z
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types