Class: Igni::Bot
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Igni::Bot
- Includes:
- API
- Defined in:
- lib/igni/bot.rb
Instance Attribute Summary collapse
-
#API ⇒ Object
readonly
Returns the value of attribute API.
-
#hook ⇒ Object
readonly
Returns the value of attribute hook.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #handle(&block) ⇒ Object
- #handler ⇒ Object
-
#initialize(hash) ⇒ Bot
constructor
A new instance of Bot.
- #register_webhook ⇒ Object
Methods included from API
#getMe, #getUpdates, #request, #sendMessage, #setWebhook
Constructor Details
#initialize(hash) ⇒ Bot
Returns a new instance of Bot.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/igni/bot.rb', line 13 def initialize(hash) abort 'No token specified' if hash[:token] == nil abort 'No domain specified' if hash[:domain] == nil @token = hash[:token] @hook = hash[:domain] @handler = proc { || } puts 'Registering webhook' if self.register_webhook puts 'Done!' else abort 'Error while registering webhook!' end abort 'Wrong token' if @API.getMe['ok'] != true end |
Instance Attribute Details
#API ⇒ Object (readonly)
Returns the value of attribute API.
11 12 13 |
# File 'lib/igni/bot.rb', line 11 def API @API end |
#hook ⇒ Object (readonly)
Returns the value of attribute hook.
10 11 12 |
# File 'lib/igni/bot.rb', line 10 def hook @hook end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
9 10 11 |
# File 'lib/igni/bot.rb', line 9 def token @token end |
Instance Method Details
#handle(&block) ⇒ Object
31 32 33 |
# File 'lib/igni/bot.rb', line 31 def handle(&block) @handler = proc { || block.call() } end |
#handler ⇒ Object
35 36 37 |
# File 'lib/igni/bot.rb', line 35 def handler @handler end |