lib/bot/adapters/kik.rb in bot-0.0.23 vs lib/bot/adapters/kik.rb in bot-0.0.26
- old
+ new
@@ -2,30 +2,50 @@
module Bot
module Adapter
class Kik < Base
- AUTH_URL = "https://auth.kik.com/verification/v1/check"
- MESSAGING_URL = "https://engine.apikik.com/api/v1/message"
+ 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)
+ 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[:bot_user],
- password: config[:bot_token],
+ 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
+
+ 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