Class: APIGatewayDSL::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/api_gateway_dsl/response.rb,
lib/api_gateway_dsl/response/collection.rb

Defined Under Namespace

Classes: Collection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, status_code, regexp, &block) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/api_gateway_dsl/response.rb', line 6

def initialize(operation, status_code, regexp, &block)
  @context = operation.context.dup.tap { |c| c.default_body_file = "response/#{status_code}" }

  @status_code = status_code.to_s
  @regexp      = regexp(regexp)

  @mappings  = Mapping::Collection.new
  @templates = Template::Collection.new(@context)

  DSL::ResponseNode.new(self, &block)
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/api_gateway_dsl/response.rb', line 4

def context
  @context
end

#mappingsObject (readonly)

Returns the value of attribute mappings.



4
5
6
# File 'lib/api_gateway_dsl/response.rb', line 4

def mappings
  @mappings
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



4
5
6
# File 'lib/api_gateway_dsl/response.rb', line 4

def status_code
  @status_code
end

#templatesObject (readonly)

Returns the value of attribute templates.



4
5
6
# File 'lib/api_gateway_dsl/response.rb', line 4

def templates
  @templates
end

Instance Method Details

#as_jsonObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/api_gateway_dsl/response.rb', line 22

def as_json
  {}.tap do |result|
    result[:description] = "#{status_code} response"

    if (headers = mappings.response_headers.as_json).present?
      result[:headers] = headers
    end

    if (template = templates.current)
      result[:schema] = template.schema_value
    end
  end
end

#content_typesObject



18
19
20
# File 'lib/api_gateway_dsl/response.rb', line 18

def content_types
  templates.content_types
end

#response_integrationObject



36
37
38
# File 'lib/api_gateway_dsl/response.rb', line 36

def response_integration
  ResponseIntegration.new(@regexp, status_code, mappings, templates)
end