Class: Kongrations::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/kongrations/request.rb

Constant Summary collapse

METHODS_MAPPER =
{
  post: Net::HTTP::Post,
  patch: Net::HTTP::Patch,
  delete: Net::HTTP::Delete
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#payloadObject

Returns the value of attribute payload.



12
13
14
# File 'lib/kongrations/request.rb', line 12

def payload
  @payload
end

Instance Method Details

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kongrations/request.rb', line 20

def execute
  http = Net::HTTP.new(CurrentEnvironment.kong_admin_url, 80)
  headers = {
    'Content-Type' => 'application/json',
    'apikey' => CurrentEnvironment.kong_admin_api_key
  }

  request = METHODS_MAPPER[method].new(path, headers)
  request.body = payload.to_json unless payload.nil?
  response = http.request(request)
  initialize_response_class(response)
end

#initialize_response_class(response) ⇒ Object



33
34
35
36
37
# File 'lib/kongrations/request.rb', line 33

def initialize_response_class(response)
  class_name = self.class.to_s.gsub('Request', 'Response')
  klass = Object.const_defined?(class_name) ? Object.const_get(class_name) : Response
  klass.new(response, self)
end

#migration_dataObject



39
40
41
# File 'lib/kongrations/request.rb', line 39

def migration_data
  MigrationData.data
end