Sha256: db76b9dbf4015e390c27595e74ffc6cb1c429b96da6e0f5a6505e09877f980ea

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bot-0.0.41 lib/bot/adapters/kik.rb
bot-0.0.40 lib/bot/adapters/kik.rb
bot-0.0.38 lib/bot/adapters/kik.rb
bot-0.0.37 lib/bot/adapters/kik.rb