Class: GTalk::Bot
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#jabber_client ⇒ Object
readonly
Returns the value of attribute jabber_client.
-
#jid ⇒ Object
readonly
Returns the value of attribute jid.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Instance Method Summary collapse
- #accept_invitation(inviter) ⇒ Object
- #get_online ⇒ Object
-
#initialize(account_data) ⇒ Bot
constructor
A new instance of Bot.
- #invite(invitee) ⇒ Object
- #message(to, text) ⇒ Object
- #on_invitation(&block) ⇒ Object
- #on_message(&block) ⇒ Object
Constructor Details
#initialize(account_data) ⇒ Bot
Returns a new instance of Bot.
22 23 24 25 26 27 28 |
# File 'lib/easy-gtalk-bot.rb', line 22 def initialize(account_data) @email = account_data[:email] @password = account_data[:password] @jid = JID::new(self.email) @jabber_client = Client.new(self.jid) end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
19 20 21 |
# File 'lib/easy-gtalk-bot.rb', line 19 def email @email end |
#jabber_client ⇒ Object (readonly)
Returns the value of attribute jabber_client.
20 21 22 |
# File 'lib/easy-gtalk-bot.rb', line 20 def jabber_client @jabber_client end |
#jid ⇒ Object (readonly)
Returns the value of attribute jid.
20 21 22 |
# File 'lib/easy-gtalk-bot.rb', line 20 def jid @jid end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
19 20 21 |
# File 'lib/easy-gtalk-bot.rb', line 19 def password @password end |
Instance Method Details
#accept_invitation(inviter) ⇒ Object
41 42 43 44 45 |
# File 'lib/easy-gtalk-bot.rb', line 41 def accept_invitation(inviter) inviter = JID::new(inviter) self.roster.accept_subscription(inviter) invite(JID::new(inviter)) end |
#get_online ⇒ Object
30 31 32 33 34 |
# File 'lib/easy-gtalk-bot.rb', line 30 def get_online self.jabber_client.connect self.jabber_client.auth(self.password) self.jabber_client.send(Presence.new.set_type(:available)) end |
#invite(invitee) ⇒ Object
36 37 38 39 |
# File 'lib/easy-gtalk-bot.rb', line 36 def invite(invitee) subscription_request = Presence.new.set_type(:subscribe).set_to(JID::new(invitee)) self.jabber_client.send(subscription_request) end |
#message(to, text) ⇒ Object
47 48 49 50 51 |
# File 'lib/easy-gtalk-bot.rb', line 47 def (to, text) = Message::new(JID::new(to), text) .type = :chat self.jabber_client.send() end |
#on_invitation(&block) ⇒ Object
53 54 55 56 57 |
# File 'lib/easy-gtalk-bot.rb', line 53 def on_invitation(&block) self.roster.add_subscription_request_callback do |_, presence| block.call(presence.from.to_email) end end |
#on_message(&block) ⇒ Object
59 60 61 62 63 |
# File 'lib/easy-gtalk-bot.rb', line 59 def (&block) self.jabber_client. do || block.call(.from.to_email, .body) end end |