Class: Sentiero::Web::IngestApp

Inherits:
Object
  • Object
show all
Defined in:
lib/sentiero/web/ingest_app.rb

Overview

Base class for the authenticated server-lane ingest apps (eg ErrorsApp, TrackApp). Subclasses implement #handle(env, project, data).

Unlike EventsApp (the public browser lane), these require a per-project write-only ingest key: Authorization: Bearer . Keys map to a project via Sentiero.configuration.ingest_keys ({ "" => "" }).

Direct Known Subclasses

ErrorsApp, TrackApp

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sentiero/web/ingest_app.rb', line 17

def call(env)
  return json_response(405, {error: "method not allowed"}) unless env["REQUEST_METHOD"] == "POST"

  project = authenticate(env)
  return json_response(401, {error: "invalid or missing ingest key"}) unless project

  body, error = read_body(env)
  return error if error

  begin
    data = JSON.parse(body)
  rescue JSON::ParserError
    return json_response(400, {error: "invalid JSON body"})
  end
  return json_response(400, {error: "body must be a JSON object"}) unless data.is_a?(Hash)

  handle(env, project, data)
end