Class: CrispClient::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty, ListWebsites, UserAvailability, WebsitePeople
Defined in:
lib/crisp_client.rb

Instance Method Summary collapse

Methods included from WebsitePeople

#add_new_people_profile, #get_people_statistics, #list_people_profiles, #remove_people_profile

Methods included from ListWebsites

#find_website_id_by_name, #list_websites

Methods included from UserAvailability

#get_user_availability

Constructor Details

#initialize(email:, password:) ⇒ Base

Returns a new instance of Base.



16
17
18
19
# File 'lib/crisp_client.rb', line 16

def initialize(email:, password:)
  @email = email
  @password = password
end

Instance Method Details

#authenticateObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/crisp_client.rb', line 21

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}" }
end