Class: Hephaestus::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ActionController::MimeResponds, Headers, Responses
Defined in:
app/controllers/hephaestus/application_controller.rb

Constant Summary

Constants included from Headers

Headers::EVENT_AFTER_CREATE, Headers::EVENT_AFTER_DESTROY, Headers::EVENT_AFTER_RENAME, Headers::EVENT_AFTER_UPDATE, Headers::EVENT_AFTER_VIEW, Headers::HEADER_EVENT, Headers::HEADER_RECORD_TYPE, Headers::HEADER_SIGNATURE, Headers::RECORD_TYPE_CONVERSATION, Headers::RECORD_TYPE_INBOX, Headers::RECORD_TYPE_MESSAGE, Headers::RECORD_TYPE_ORGANIZATION, Headers::RECORD_TYPE_PLUG_INSTALLATION, Headers::YETTO_DELIVERY_ID

Instance Method Summary collapse

Methods included from Responses

#bad_gateway, #bad_request, #created, #forbidden, #internal_server_error, #no_content, #not_acceptable, #not_found, #okay, #service_unavailable

Instance Method Details

#ensure_json_requestObject



16
17
18
19
20
# File 'app/controllers/hephaestus/application_controller.rb', line 16

def ensure_json_request
  return if request.format.json?

  not_acceptable
end

#parse_state(state) ⇒ Object

Yetto sends a unique state parameter as part of the OAuth installation process. This decodes that into something the plug can use.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/hephaestus/application_controller.rb', line 24

def parse_state(state)
  decoded_state = Base64.urlsafe_decode64(state)
  state = JSON.parse(decoded_state)

  {
    version: state["version"],
    salt: state["salt"],
    nonce: state["nonce"] || "",
    plug_installation_id: state["plug_installation_id"],
    membership_id: state["membership_id"], # optional, used for conversation.viewed events
    redirect_to: state["redirect_to"],
  }
rescue ArgumentError # invalid base64
  {}
rescue JSON::ParserError # invalid JSON
  {}
end