module Octo::Helpers::ApiHelper

Constants

KONG_HEADERS

Public Instance Methods

enterprise_details() click to toggle source

Get enterprise details from the HTTP headers that Kong sets @return [Hash] The hash of enterprise details

# File lib/octocore/helpers/api_helper.rb, line 14
def enterprise_details
  KONG_HEADERS.inject({}) do |r, header|
    key = header.gsub('HTTP_X_CONSUMER_', '').downcase
    r[key] = request.env.fetch(header, nil)
    r
  end
end
post_params() click to toggle source

Gets the POSTed parameters from rack env @return [Hash] A hash of POSTed parameters

# File lib/octocore/helpers/api_helper.rb, line 24
def post_params
  instrument(:json_parse) do
   JSON.parse(request.env['rack.input'].read)
  end
end
process_request(event_name) click to toggle source

Process an incoming request @param [String] event_name The name of the event @return [JSON] The json return value after processing

# File lib/octocore/helpers/api_helper.rb, line 39
def process_request(event_name)
  postparams = post_params
  opts = {
    event_name: event_name,
    enterprise: enterprise_details,
    uuid: uuid
  }
  postparams.merge!(opts)
  settings.kafka_bridge.push(postparams)
  { eventId: opts[:uuid] }.to_json
end
uuid() click to toggle source

Generate a UUID for each response @return [String] UUID

# File lib/octocore/helpers/api_helper.rb, line 32
def uuid
  SecureRandom.uuid
end