RingCentral.run()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
1
require 'lita'
2
require 'lita/adapters/ringcentral/connector'
3
4
module Lita
5
  module Adapters
6
    class RingCentral < Adapter
7
      namespace 'ringcentral'
8
9
      # Required attributes
10
      config :app_key, type: String, required: true
11
      config :app_secret, type: String, required: true
12
      config :sms_number, type: String, required: true
13
14
      # Optional attributes
15
      config :server, type: String, default: 'platform.devtest.ringcentral.com'
16
      config :username, type: String
17
      config :extension, type: String
18
      config :password, type: String
19
      config :token, type: String
20
21
      attr_reader :connector
22
23
      def initialize(robot)
24
        super
25
        @connector = Connector.new(
26
          robot,
27
          config.app_key,
28
          config.app_secret,
29
          config.server,
30
          config.username,
31
          config.extension,
32
          config.password,
33
          config.token,
34
          config.sms_number)
35
      end
36
37
      def run
38
        @connector.connect
39
        sleep
40
      rescue Interrupt
41
        shut_down
42
      end
43
44
      def send_messages(target, strings)
45
        Lita.logger.info 'Sending Message'
46
        @connector.message target.user.id, strings
47
      end
48
49
      def shut_down
50
        robot.trigger :disconnected
51
      end
52
    end
53
    Lita.register_adapter :ringcentral, RingCentral
54
  end
55
end