Class: Bot::Adapter::Kik

Inherits:
Base
  • Object
show all
Defined in:
lib/bot/adapters/kik.rb

Constant Summary collapse

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

Instance Method Summary collapse

Methods inherited from Base

#config, #initialize

Constructor Details

This class inherits a constructor from Bot::Adapter::Base

Instance Method Details

#get_profile_image(username, as_user) ⇒ Object



31
32
33
34
# File 'lib/bot/adapters/kik.rb', line 31

def get_profile_image(username, as_user)
  profile = get_profile(username, as_user)
  profile['profilePicUrl'] || ''
end

#send_messages(messages, from) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bot/adapters/kik.rb', line 11

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

#verify_request(request) ⇒ Object



36
37
38
39
40
# File 'lib/bot/adapters/kik.rb', line 36

def verify_request(request)
  digest = OpenSSL::Digest.new('sha1')
  key = config(request.headers["HTTP_X_KIK_USERNAME"])[:bot_token]
  request.headers["HTTP_X_KIK_SIGNATURE"] == OpenSSL::HMAC.hexdigest(digest, key, request.raw_post).upcase
end