Class: SlackRubyBot::Server
- Inherits:
-
Object
- Object
- SlackRubyBot::Server
- Includes:
- Hooks::Hello, Hooks::Message
- Defined in:
- lib/slack-ruby-bot/server.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #auth! ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #restart!(wait = 1) ⇒ Object
- #run ⇒ Object
- #start! ⇒ Object
- #start_async ⇒ Object
- #stop! ⇒ Object
Methods included from Hooks::Message
Methods included from Hooks::Base
Methods included from Hooks::Hello
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
9 10 11 |
# File 'lib/slack-ruby-bot/server.rb', line 9 def initialize( = {}) @token = [:token] end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
4 5 6 |
# File 'lib/slack-ruby-bot/server.rb', line 4 def token @token end |
Instance Method Details
#auth! ⇒ Object
38 39 40 41 |
# File 'lib/slack-ruby-bot/server.rb', line 38 def auth! client.auth = client.web_client.auth_test logger.info "Welcome '#{client.auth['user']}' to the '#{client.auth['team']}' team at #{client.auth['url']}." end |
#restart!(wait = 1) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/slack-ruby-bot/server.rb', line 58 def restart!(wait = 1) start! rescue StandardError => e sleep wait logger.error "#{e.}, reconnecting in #{wait} second(s)." logger.debug e restart! [wait * 2, 60].min end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/slack-ruby-bot/server.rb', line 13 def run auth! loop do begin start! rescue Slack::Web::Api::Error => e logger.error e case e. when 'migration_in_progress' sleep 1 # ignore, try again else raise e end rescue Faraday::Error::TimeoutError, Faraday::Error::ConnectionFailed, Faraday::Error::SSLError => e logger.error e sleep 1 # ignore, try again rescue StandardError => e logger.error e raise e ensure @client = nil end end end |
#start! ⇒ Object
43 44 45 46 |
# File 'lib/slack-ruby-bot/server.rb', line 43 def start! @stopping = false client.start! end |
#start_async ⇒ Object
48 49 50 51 |
# File 'lib/slack-ruby-bot/server.rb', line 48 def start_async @stopping = false client.start_async end |
#stop! ⇒ Object
53 54 55 56 |
# File 'lib/slack-ruby-bot/server.rb', line 53 def stop! @stopping = true client.stop! if @client end |