Class: Lita::Handlers::Glip

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/glip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot) ⇒ Glip

Returns a new instance of Glip.



19
20
21
# File 'lib/lita/handlers/glip.rb', line 19

def initialize(robot)
  @robot = robot
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



8
9
10
# File 'lib/lita/handlers/glip.rb', line 8

def client
  @client
end

#robotObject (readonly)

Returns the value of attribute robot.



9
10
11
# File 'lib/lita/handlers/glip.rb', line 9

def robot
  @robot
end

Instance Method Details

#callback_oauth(request, response) ⇒ Object



27
28
29
30
31
# File 'lib/lita/handlers/glip.rb', line 27

def callback_oauth(request, response)
  pp request

  response.finish
end

#callback_webhook(request, response) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/lita/handlers/glip.rb', line 33

def callback_webhook(request, response)
  Lita.logger.info 'Lita Glip Webhook called'
  Lita.logger.info "Request Class #{request.class.name}"
  Lita.logger.info "QSR #{request.query_string}"
  params = CGI::parse(request.query_string)
  message = {'type' => 'rc-oauth2', 'body' => params }
  message = MultiJson.encode message
  Lita.logger.info "QSJ #{MultiJson.encode(params)}"
  code = params['code'][0]||''
  #Lita.logger.info "QS #{params['code'][0]} #{params['code'][0].length}"
  Lita.logger.info "QSF #{code} #{code.length}"

  #source = Lita::Source.new(user: 'rc-oauth2')

  user = Lita::User.create(
    'glip-oauth',
    name: 'glip-oauth'
  )

  source = Lita::Source.new user: user #user#, room: room
  message = Lita::Message.new(robot, message, source)
  robot.receive(message)
=begin
client = RingCentralSdk::REST::Client.new do |config|
  config.load_env = false
  config.client_id = ENV['RC_CLIENT_ID']
  config.client_secret = ENV['RC_CLIENT_SECRET']
  config.server_url = RingCentralSdk::RC_SERVER_PRODUCTION
  config.username = ENV['RC_USER_USERNAME']
  config.extension = ENV['RC_USER_EXTENSION']
  config.password = ENV['RC_USER_PASSWORD']
  config.logger = log
end
=end
  response.finish
end

#logObject



23
24
25
# File 'lib/lita/handlers/glip.rb', line 23

def log
  Lita.logger
end