reynard 0.0.4 → 0.0.5

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
  SHA256:
3
- metadata.gz: 73e8e17f725539aac5739311c093ac8ff851eab5c9bc3016cdd3839b29cdcc8b
4
- data.tar.gz: a8fc3ba0731ad45a5f92324d819d84b7bf5fb418d8f4eb3751b5a7b2814b6a19
3
+ metadata.gz: 1c84ca4accb44e6e4d25e67071ade066d2fad559eedff8726915da6736e05246
4
+ data.tar.gz: 1340cfef80c1464cf01d01e4509c0bdc2fa4831a3d8f6960a209fe6ee9f8b167
5
5
  SHA512:
6
- metadata.gz: e6b03cde95bd0bf69a03f860d3eaa57bf9d39f1deb6c9abfd719d4fdbaec728f1c8d5a2485493e5b403cdd0b57a80784c3dd48c02eef5d957eaf7638cacf91b0
7
- data.tar.gz: f56a52f52d041ce58b69e1d799072510131a4f471560a908b24bb1e01630ef1e971d07e1b88845fae298e90e1d9f6f6dc1ad7990375c35d9c0ae357c69644a0c
6
+ metadata.gz: 19e65638574e27c47310bad70a9b507aa6f5600ae7c05c3495c83ac7c58015b2f5d17d0c7d4592d2b6bf74852fe11782b796895bd4db552e96cd5ed80b85c895
7
+ data.tar.gz: f63952863a80039f1735bb53e27a1a15c670e4f80e8c2c5813e1880d4c33962d791ec9ed46d5f268f924725052ed831bf6a33f31b047a9d861d8b81645fc748d
data/README.md CHANGED
@@ -57,6 +57,15 @@ employee = reynard.
57
57
  execute
58
58
  ```
59
59
 
60
+ When an operation requires a body, you can add it as structured data.
61
+
62
+ ```ruby
63
+ employee = reynard.
64
+ operation('createEmployee').
65
+ body(name: 'Sam Seven').
66
+ execute
67
+ ```
68
+
60
69
  ## Copyright and other legal
61
70
 
62
71
  See LICENCE.
@@ -24,8 +24,20 @@ class Reynard
24
24
  copy(params: @specification.build_grouped_params(@request_context.operation.node, params))
25
25
  end
26
26
 
27
+ def body(...)
28
+ return unless @request_context.operation
29
+
30
+ serialized_body = @specification.build_body(@request_context.operation.node, ...)
31
+ return unless serialized_body
32
+
33
+ copy(
34
+ headers: @request_context.headers.merge(serialized_body.headers),
35
+ body: serialized_body.to_s
36
+ )
37
+ end
38
+
27
39
  def headers(headers)
28
- copy(headers: headers)
40
+ copy(headers: @request_context.merge(headers))
29
41
  end
30
42
 
31
43
  def execute
@@ -35,7 +47,7 @@ class Reynard
35
47
  private
36
48
 
37
49
  def build_request_context
38
- RequestContext.new(base_url: @specification.default_base_url)
50
+ RequestContext.new(base_url: @specification.default_base_url, headers: {})
39
51
  end
40
52
 
41
53
  def copy(**properties)
@@ -7,6 +7,7 @@ class Reynard
7
7
  :operation,
8
8
  :headers,
9
9
  :params,
10
+ :body,
10
11
  keyword_init: true
11
12
  ) do
12
13
  def verb
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Reynard
4
+ # Serializes a request body and returns headers appropriate for the request.
5
+ class SerializedBody
6
+ def initialize(content, data)
7
+ @content = content
8
+ @data = data
9
+ end
10
+
11
+ def content_type
12
+ 'application/json'
13
+ end
14
+
15
+ def headers
16
+ { 'Content-Type' => content_type }
17
+ end
18
+
19
+ def to_s
20
+ MultiJson.dump(@data)
21
+ end
22
+ end
23
+ end
@@ -33,6 +33,12 @@ class Reynard
33
33
  GroupedParameters.new(dig(*operation_node, 'parameters'), params).to_h
34
34
  end
35
35
 
36
+ # Returns a serialized body instance to serialize a request body and figure out the request
37
+ # headers.
38
+ def build_body(operation_node, ...)
39
+ SerializedBody.new(dig(*operation_node, 'requestBody', 'content'), ...)
40
+ end
41
+
36
42
  def operation(operation_name)
37
43
  dig('paths').each do |path, operations|
38
44
  operations.each do |verb, operation|
@@ -44,7 +50,7 @@ class Reynard
44
50
 
45
51
  def media_type(operation_node, response_code, media_type)
46
52
  responses = dig(*operation_node, 'responses')
47
- response_code = responses.key?(response_code) ? response_code : 'default'
53
+ response_code = 'default' unless responses.key?(response_code)
48
54
  response, media_type = media_type_response(responses, response_code, media_type)
49
55
  return unless response
50
56
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Reynard
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
data/lib/reynard.rb CHANGED
@@ -15,6 +15,7 @@ class Reynard
15
15
  def_delegators :@specification, :servers
16
16
 
17
17
  autoload :Context, 'reynard/context'
18
+ autoload :GroupedParameters, 'reynard/grouped_parameters'
18
19
  autoload :Http, 'reynard/http'
19
20
  autoload :MediaType, 'reynard/media_type'
20
21
  autoload :Model, 'reynard/model'
@@ -23,10 +24,10 @@ class Reynard
23
24
  autoload :Operation, 'reynard/operation'
24
25
  autoload :RequestContext, 'reynard/request_context'
25
26
  autoload :Schema, 'reynard/schema'
27
+ autoload :SerializedBody, 'reynard/serialized_body'
26
28
  autoload :Server, 'reynard/server'
27
29
  autoload :Specification, 'reynard/specification'
28
30
  autoload :Template, 'reynard/template'
29
- autoload :GroupedParameters, 'reynard/grouped_parameters'
30
31
  autoload :VERSION, 'reynard/version'
31
32
 
32
33
  def initialize(filename:)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reynard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-06 00:00:00.000000000 Z
11
+ date: 2021-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -131,6 +131,7 @@ files:
131
131
  - lib/reynard/operation.rb
132
132
  - lib/reynard/request_context.rb
133
133
  - lib/reynard/schema.rb
134
+ - lib/reynard/serialized_body.rb
134
135
  - lib/reynard/server.rb
135
136
  - lib/reynard/specification.rb
136
137
  - lib/reynard/template.rb