class Talktome::App

Constants

VALIDATION_SCHEMA

Private Instance Methods

fail!(message, status = 400) click to toggle source
# File lib/talktome/app.rb, line 69
def fail!(message, status = 400)
  halt([ status, { "Content-Type" => "text/plain"}, [message] ])
end
info() click to toggle source
# File lib/talktome/app.rb, line 52
def info
  @info ||= VALIDATION_SCHEMA.dress(JSON.parse(request.body.read)).tap{|info|
    not_a_robot!(info)
  }
end
load_user_from_info!() click to toggle source
# File lib/talktome/app.rb, line 58
def load_user_from_info!
  if to = info[:to]
    secret = Talktome.env('TALKTOME_BEARER_SECRET')
    fail!("Missing secret", 400) unless secret
    fail!("Invalid secret", 401) unless "Bearer #{secret}" == env["HTTP_AUTHORIZATION"]
    { email: info[:to] }
  else
    {}
  end
end
not_a_robot!(info) click to toggle source
# File lib/talktome/app.rb, line 73
def not_a_robot!(info)
  # `reply_to_confirm` is a honeypot field, if it's filled it means it's a bot and an error is thrown
  raise ::Talktome::InvalidEmailError if info[:reply_to_confirm] && info[:reply_to_confirm] =~ /^[^@]+@[^@]+$/
end