Class: BitlbeeConfig::Account
- Inherits:
-
Object
- Object
- BitlbeeConfig::Account
- Includes:
- XmlBuildable
- Defined in:
- lib/bitlbee_config/account.rb
Overview
An account with an IM service, e.g. an ICQ or Skype account
Direct Known Subclasses
BitlbeeConfig::Accounts::Icq, BitlbeeConfig::Accounts::Jabber, BitlbeeConfig::Accounts::Steam
Instance Attribute Summary collapse
-
#autoconnect ⇒ Object
Returns the value of attribute autoconnect.
-
#cleartext_password ⇒ Object
Returns the value of attribute cleartext_password.
-
#handle ⇒ Object
Returns the value of attribute handle.
-
#password ⇒ Object
Returns the value of attribute password.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#server ⇒ Object
Returns the value of attribute server.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.create_new_account(account = {}) ⇒ BitlbeeConfig::Account|BitlbeeConfig::Accounts::Icq
Creates a new account.
-
.from_xml(xml) ⇒ BitlbeeConfig::Account|BitlbeeConfig::Accounts::Icq
The newly created account.
Instance Method Summary collapse
- #build_xml(xml_builder) ⇒ Object
-
#id ⇒ Object
Uniquely identify this account - currently by protocol and handle.
-
#initialize(options = {}) ⇒ Account
constructor
A new instance of Account.
-
#regenerate_password_if_needed ⇒ Object
When a cleartext password and the user’s cleartext password are given, encrypt the cleartext_password with the user’s cleartext password.
Methods included from XmlBuildable
Constructor Details
#initialize(options = {}) ⇒ Account
Returns a new instance of Account.
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/bitlbee_config/account.rb', line 60 def initialize( = {}) @protocol ||= .delete(:protocol) @handle ||= .delete(:handle) @tag ||= .delete(:tag) @autoconnect ||= .delete(:autoconnect) @server ||= .delete(:server) @password ||= .delete(:password) @cleartext_password ||= .delete(:cleartext_password) @user ||= .delete(:user) @settings = || {} end |
Instance Attribute Details
#autoconnect ⇒ Object
Returns the value of attribute autoconnect.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def autoconnect @autoconnect end |
#cleartext_password ⇒ Object
Returns the value of attribute cleartext_password.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def cleartext_password @cleartext_password end |
#handle ⇒ Object
Returns the value of attribute handle.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def handle @handle end |
#password ⇒ Object
Returns the value of attribute password.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def password @password end |
#protocol ⇒ Object
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def protocol @protocol end |
#server ⇒ Object
Returns the value of attribute server.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def server @server end |
#settings ⇒ Object
Returns the value of attribute settings.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def settings @settings end |
#tag ⇒ Object
Returns the value of attribute tag.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def tag @tag end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/bitlbee_config/account.rb', line 6 def user @user end |
Class Method Details
.create_new_account(account = {}) ⇒ BitlbeeConfig::Account|BitlbeeConfig::Accounts::Icq
Creates a new account. The class of the account varies by the attributes.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bitlbee_config/account.rb', line 31 def create_new_account(account = {}) account_class = case when account[:handle] =~ /#{ BitlbeeConfig::Accounts::Facebook::USERNAME_SUFFIX }$/ BitlbeeConfig::Accounts::Facebook when account[:server] == BitlbeeConfig::Accounts::Gtalk::DEFAULT_GTALK_SERVER BitlbeeConfig::Accounts::Gtalk when account[:protocol].to_s == "jabber" BitlbeeConfig::Accounts::Jabber when account[:protocol].to_s == "steam" BitlbeeConfig::Accounts::Steam when account[:protocol].to_s == "oscar" BitlbeeConfig::Accounts::Icq else BitlbeeConfig::Account end account_class.new(account) end |
.from_xml(xml) ⇒ BitlbeeConfig::Account|BitlbeeConfig::Accounts::Icq
Returns The newly created account.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bitlbee_config/account.rb', line 11 def from_xml(xml) new_account = {} # get setting attributes xml.attributes.each do |att_name, att_value| new_account[att_name.to_sym] = att_value.text end # get setting children xml.children.select { |node| node.is_a?(Nokogiri::XML::Element) }.each do |setting_element| new_account[setting_element.values.first.to_sym] = setting_element.text end create_new_account(new_account) end |
Instance Method Details
#build_xml(xml_builder) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/bitlbee_config/account.rb', line 83 def build_xml(xml_builder) regenerate_password_if_needed = [:password, :protocol, :handle, :autoconnect, :tag, :server].each_with_object({}) do |option, | value = instance_variable_get("@#{ option }") [option] = value unless value.nil? || value.empty? end (xml_builder, ) end |
#id ⇒ Object
Uniquely identify this account - currently by protocol and handle
73 74 75 |
# File 'lib/bitlbee_config/account.rb', line 73 def id "#{ @protocol }##{ @handle }" end |
#regenerate_password_if_needed ⇒ Object
When a cleartext password and the user’s cleartext password are given, encrypt the cleartext_password with the user’s cleartext password
78 79 80 |
# File 'lib/bitlbee_config/account.rb', line 78 def regenerate_password_if_needed @password = @cleartext_password.encrypt_bitlbee_password(@user.cleartext_password) if @user && @user.cleartext_password && @cleartext_password end |