class CrispClient::Base
Public Class Methods
new(options)
click to toggle source
# File lib/crisp_client.rb, line 19 def initialize(options) if options[:stored_key] @auth = { "Authorization" => "Basic #{options[:stored_key]}" } else @email = options[:email] @password = options[:password] end end
Public Instance Methods
authenticate()
click to toggle source
# File lib/crisp_client.rb, line 28 def authenticate res = self.class.post("/user/session/login", body: { email: @email, password: @password }.to_json, headers: { 'Content-Type' => 'application/json' }) identifier = res.parsed_response["data"]["identifier"] key = res.parsed_response["data"]["key"] base64 = Base64.strict_encode64 [identifier, key].join(":") @auth = { "Authorization" => "Basic #{base64}" } return base64 end
Private Instance Methods
client_get(path)
click to toggle source
# File lib/crisp_client.rb, line 41 def client_get(path) self.class.get(path, headers: @auth).parsed_response end