api-blueprint 0.6.5 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/api-blueprint/blueprint.rb +14 -13
- data/lib/api-blueprint/model.rb +3 -1
- 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: 9f6f2c0e18a173e006f4a694af709f8839420d06
|
4
|
+
data.tar.gz: 88458d370dfe5ee1ebc14ec619686482e558b00a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2a2d17f6d6bab0de23514debb8de5f308119b5e9a74076157245e3cd98f03eac1d5fd4d63f3ffffde2779e208e8f92205cd19cb6e88f87e0a4c980c101dc24
|
7
|
+
data.tar.gz: 42c96d768641b2e6be0eaa4dbaba645f0a9fc0823669d06e95c1b0301e6fdb7d0e34a3e44083de0e91b97b5d705a2dfdc68c17f85e25c2fceac364fbc9b41cbd
|
data/README.md
CHANGED
@@ -224,6 +224,24 @@ blueprint :get, "/endpoint" do |runner, result|
|
|
224
224
|
end
|
225
225
|
```
|
226
226
|
|
227
|
+
## Response logging
|
228
|
+
|
229
|
+
Response logging can be enabled on a per-blueprint level, or by setting `config.log_responses = true` on an `ApiBlueprint::Model`:
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
class AstronautsInSpace < ApiBlueprint::Model
|
233
|
+
configure do |config|
|
234
|
+
# enable logging for all blueprints
|
235
|
+
config.log_responses = true
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.fetch
|
239
|
+
# enable logging for just one blueprint
|
240
|
+
blueprint :get, "http://api.open-notify.org/astros.json", log_responses: true
|
241
|
+
end
|
242
|
+
end
|
243
|
+
```
|
244
|
+
|
227
245
|
## A note on Dry::Struct immutability
|
228
246
|
|
229
247
|
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:
|
@@ -10,6 +10,7 @@ module ApiBlueprint
|
|
10
10
|
attribute :replacements, Types::Hash.default(Hash.new)
|
11
11
|
attribute :after_build, Types::Instance(Proc).optional
|
12
12
|
attribute :builder, Types.Instance(ApiBlueprint::Builder).default(ApiBlueprint::Builder.new)
|
13
|
+
attribute :log_responses, Types::Strict::Bool.default(false)
|
13
14
|
|
14
15
|
def all_request_options(options = {})
|
15
16
|
{
|
@@ -38,6 +39,19 @@ module ApiBlueprint
|
|
38
39
|
after_build.present? ? after_build.call(runner, created) : created
|
39
40
|
end
|
40
41
|
|
42
|
+
def connection
|
43
|
+
Faraday.new do |conn|
|
44
|
+
conn.use ApiBlueprint::ResponseMiddleware
|
45
|
+
conn.response :json, content_type: /\bjson$/
|
46
|
+
conn.response :logger if log_responses
|
47
|
+
|
48
|
+
conn.adapter Faraday.default_adapter
|
49
|
+
conn.headers = {
|
50
|
+
"User-Agent": "ApiBlueprint"
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
41
55
|
private
|
42
56
|
|
43
57
|
def build(from:, headers: {}, status: nil)
|
@@ -63,19 +77,6 @@ module ApiBlueprint
|
|
63
77
|
end
|
64
78
|
end
|
65
79
|
|
66
|
-
def connection
|
67
|
-
Faraday.new do |conn|
|
68
|
-
conn.use ApiBlueprint::ResponseMiddleware
|
69
|
-
conn.response :json, content_type: /\bjson$/
|
70
|
-
# conn.response :logger
|
71
|
-
|
72
|
-
conn.adapter Faraday.default_adapter
|
73
|
-
conn.headers = {
|
74
|
-
"User-Agent": "ApiBlueprint"
|
75
|
-
}
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
80
|
def set_errors(obj, body)
|
80
81
|
if obj.respond_to?(:errors) && body.is_a?(Hash)
|
81
82
|
errors = body.with_indifferent_access.fetch :errors, {}
|
data/lib/api-blueprint/model.rb
CHANGED
@@ -12,6 +12,7 @@ module ApiBlueprint
|
|
12
12
|
setting :parser, Parser.new
|
13
13
|
setting :builder, Builder.new
|
14
14
|
setting :replacements, {}
|
15
|
+
setting :log_responses, false
|
15
16
|
|
16
17
|
attribute :response_headers, Types::Hash.optional
|
17
18
|
attribute :response_status, Types::Integer.optional
|
@@ -23,7 +24,8 @@ module ApiBlueprint
|
|
23
24
|
creates: self,
|
24
25
|
parser: config.parser,
|
25
26
|
replacements: config.replacements,
|
26
|
-
builder: config.builder
|
27
|
+
builder: config.builder,
|
28
|
+
log_responses: config.log_responses
|
27
29
|
}.merge(options)
|
28
30
|
|
29
31
|
if block_given?
|
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.7.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-05-
|
11
|
+
date: 2018-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|