Sha256: f942bd5c9b9950417303b590ff753641f9e249814a4525dfa95e9cbc399b12f1
Contents?: true
Size: 1.79 KB
Versions: 1
Compression:
Stored size: 1.79 KB
Contents
require 'glip_sdk' require 'ringcentral_sdk' require 'multi_json' require 'lita/adapters/glip/message_handler' require 'lita/adapters/glip/room_creator' require 'lita/adapters/glip/user_creator' module Lita module Adapters class Glip < Adapter class Connector attr_reader :robot def initialize(robot, app_key, app_secret, server, username, extension, password, token) @robot = robot @logger_prefix = " -- #{self.class.name}: " @rc_sdk = RingCentralSdk::REST::Client.new do |config| config.app_key = app_key config.app_secret = app_secret config.server_url = server config.logger = Lita.logger end @glip_sdk = GlipSdk::REST::Client.new @rc_sdk @username = username @extension = extension @password = password @token = token end def connect client_connect end def client_connect Lita.logger.info("#{@logger_prefix}Authorizing with RingCentral.") if @token.nil? @rc_sdk.authorize_password @username, @extension, @password token = MultiJson.encode @rc_sdk.token.to_hash Lita.logger.debug("#{@logger_prefix}Authorized with token: #{token}.") else @rc_sdk.set_token @token end @glip_sdk = GlipSdk::REST::Client.new @rc_sdk observer = Lita::Adapters::Glip::MessageHandler.new @robot, @glip_sdk @glip_sdk.posts.observe observer end def message(group_id, strings) strings.each do |s| Lita.logger.debug("#{@logger_prefix}Send Message To Glip From Lita: #{s}.") @glip_sdk.posts.post groupId: group_id, text: s end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lita-glip-0.1.0 | lib/lita/adapters/glip/connector.rb |