| Total Complexity | 5 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
| 1 | require 'lita' |
||
| 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 |
||
| 55 | end |