Class: ApiBlueprint::Blueprint

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

Instance Method Summary collapse

Instance Method Details

#all_request_options(options = {}) ⇒ Object



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

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



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

def run(options = {}, runner = nil)
  if options.delete :validate
    result = build from: options[:body]
    return result.errors if result.invalid?
  end

  response = call_api all_request_options(options)

  if creates.present?
    created = build from: response.body, headers: response.headers, status: response.status
  else
    created = response
  end

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