require 'rest-client' module Bot module Adapter class Kik < Base AUTH_URL = "https://auth.kik.com/verification/v1/check".freeze MESSAGING_URL = "https://engine.apikik.com/api/v1/message".freeze PROFILE_URL = 'https://api.kik.com/v1/user'.freeze def send_messages(messages, from) Rails.logger.error "\n\n\nSending:\n" Rails.logger.error messages.to_json Rails.logger.error "\n\n\n" RestClient::Request.execute({ method: :post, user: config(from)[:bot_user], password: config(from)[:bot_token], url: MESSAGING_URL, payload: { messages: messages }.to_json, headers: { content_type: :json } }) rescue Exception => e Rails.logger.error "\n\n\nError:\n" Rails.logger.error e.response Rails.logger.error "\n\n\n" raise e end def get_profile_image(username, as_user) profile = get_profile(username, as_user) profile['profilePicUrl'] || '' end def verify_signature(signature, body, from) digest = OpenSSL::Digest.new('sha1') key = config(from)[:bot_token] signature == OpenSSL::HMAC.hexdigest(digest, key, body).upcase end protected def get_profile(username, from) response = RestClient::Request.execute( method: :get, url: "#{PROFILE_URL}/#{username}", user: config(from)[:bot_user], password: config(from)[:bot_token], headers: { content_type: :json } ) JSON.parse(response) end end end end