Class: ApiBlueprint::Blueprint

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/api-blueprint/blueprint.rb

Instance Method Summary collapse

Instance Method Details

#all_request_options(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/api-blueprint/blueprint.rb', line 16

def all_request_options(options = {})
  {
    http_method: http_method,
    url: url,
    headers: headers.merge(options.fetch(:headers, {})),
    params: params.merge(options.fetch(:params, {})),
    body: body.merge(options.fetch(:body, {}))
  }
end

#run(options = {}, runner = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/api-blueprint/blueprint.rb', line 26

def run(options = {}, runner = nil)
  response = call_api all_request_options(options)

  if creates.present?
    builder_options = {
      body: parser.parse(response.body),
      headers: response.headers,
      replacements: replacements,
      creates: creates
    }

    created = builder.new(builder_options).build
  else
    created = response
  end

  after_build.present? ? after_build.call(runner, created) : created
end