Class: SlackRTMReceiver::Starter
- Inherits:
-
Object
- Object
- SlackRTMReceiver::Starter
- Defined in:
- lib/slack-rtm-receiver/starter.rb
Overview
HTTP client to call rtm.start
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.start(session, opts = {}) ⇒ SlackRTMReceiver::Starter
Create and start a Starter.
Instance Method Summary collapse
-
#initialize(opts) ⇒ Starter
constructor
A new instance of Starter.
- #start(session) ⇒ Object
- #started? ⇒ Boolean
Constructor Details
#initialize(opts) ⇒ Starter
Returns a new instance of Starter.
29 30 31 32 33 34 35 |
# File 'lib/slack-rtm-receiver/starter.rb', line 29 def initialize(opts) @logger = SlackRTMReceiver.logger logger.debug 'Initializing Starter...' @options = opts @is_starting = false @session = nil end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
18 19 20 |
# File 'lib/slack-rtm-receiver/starter.rb', line 18 def logger @logger end |
#options ⇒ Object
Returns the value of attribute options.
19 20 21 |
# File 'lib/slack-rtm-receiver/starter.rb', line 19 def @options end |
Class Method Details
.start(session, opts = {}) ⇒ SlackRTMReceiver::Starter
Create and start a Starter
12 13 14 15 16 |
# File 'lib/slack-rtm-receiver/starter.rb', line 12 def self.start(session, opts = {}) starter = self.new(opts) starter.start(session) return starter end |
Instance Method Details
#start(session) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/slack-rtm-receiver/starter.rb', line 38 def start(session) if started? logger.debug 'Start requested but already running. Ignoring...' return nil end @is_starting = true @session = session logger.debug 'Starter is calling rtm.start...' baseurl = 'https://slack.com/api/rtm.start' http = EM::HttpRequest.new(baseurl).get(query: @options, redirects: 5) http.callback do callback(http, session) @is_starting = false end http.errback do errback(http) @is_starting = false end end |
#started? ⇒ Boolean
22 23 24 25 26 |
# File 'lib/slack-rtm-receiver/starter.rb', line 22 def started? return true if @is_starting return true if @session && @session.alive? return false end |