Class: CrispClient::Base
- Inherits:
-
Object
- Object
- CrispClient::Base
- Includes:
- HTTParty, ListWebsites, UserAvailability, WebsiteConversation, WebsitePeople
- Defined in:
- lib/crisp_client.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(options) ⇒ Base
constructor
A new instance of Base.
Methods included from WebsiteConversation
#create_a_new_conversation, #update_conversation_metas
Methods included from WebsitePeople
#add_new_people_profile, #get_people_statistics, #list_people_profiles, #remove_people_profile, #save_people_data, #update_people_profile
Methods included from ListWebsites
#find_website_id_by_name, #list_websites
Methods included from UserAvailability
Constructor Details
#initialize(options) ⇒ Base
Returns a new instance of Base.
19 20 21 22 23 24 25 26 |
# File 'lib/crisp_client.rb', line 19 def initialize() if [:stored_key] @auth = { "Authorization" => "Basic #{options[:stored_key]}" } else @email = [:email] @password = [:password] end end |
Instance Method Details
#authenticate ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# 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 |