Class: YATelegramBot::TelegramAPI::User
- Inherits:
-
Hash
- Object
- Hash
- YATelegramBot::TelegramAPI::User
- Defined in:
- lib/ya_telegram_bot/telegram_api/user.rb
Overview
represents Telegram User
Constant Summary collapse
- FIELDS =
[:id, :first_name, :last_name, :username].freeze
Instance Method Summary collapse
-
#initialize(hash, bot = nil) ⇒ User
constructor
A new instance of User.
- #method_missing(m, *args) ⇒ Object
-
#send_text(params = {}) ⇒ Object
uses bot to send text to this user.
Constructor Details
#initialize(hash, bot = nil) ⇒ User
Returns a new instance of User.
13 14 15 16 17 |
# File 'lib/ya_telegram_bot/telegram_api/user.rb', line 13 def initialize(hash, bot = nil) super() @bot = bot FIELDS.each { |f| self[f] = hash[f.to_s] if hash[f.to_s] } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
22 23 24 25 |
# File 'lib/ya_telegram_bot/telegram_api/user.rb', line 22 def method_missing(m, *args) return self[m] if self[m] && args.empty? super end |
Instance Method Details
#send_text(params = {}) ⇒ Object
uses bot to send text to this user.
32 33 34 35 36 37 |
# File 'lib/ya_telegram_bot/telegram_api/user.rb', line 32 def send_text(params = {}) fail InitWithoutBot unless @bot params[:chat] = id @bot.send_text params end |