Module: Octo::Helpers::ApiHelper
- Includes:
- Stats
- Defined in:
- lib/octocore/helpers/api_helper.rb
Constant Summary collapse
- KONG_HEADERS =
%w(HTTP_X_CONSUMER_ID HTTP_X_CONSUMER_CUSTOM_ID HTTP_X_CONSUMER_USERNAME)
Instance Method Summary collapse
-
#enterprise_details ⇒ Hash
Get enterprise details from the HTTP headers that Kong sets.
-
#post_params ⇒ Hash
Gets the POSTed parameters from rack env.
-
#process_request(event_name) ⇒ JSON
Process an incoming request.
-
#uuid ⇒ String
Generate a UUID for each response.
Methods included from Stats
Instance Method Details
#enterprise_details ⇒ Hash
Get enterprise details from the HTTP headers that Kong sets
14 15 16 17 18 19 20 |
# 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 ⇒ Hash
Gets the POSTed parameters from rack env
24 25 26 27 28 |
# 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) ⇒ JSON
Process an incoming request
39 40 41 42 43 44 45 46 47 48 49 |
# 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 ⇒ String
Generate a UUID for each response
32 33 34 |
# File 'lib/octocore/helpers/api_helper.rb', line 32 def uuid SecureRandom.uuid end |