Class: BitlbeeConfig::Account

Inherits:
Object
  • Object
show all
Includes:
XmlBuildable
Defined in:
lib/bitlbee_config/account.rb

Overview

An account with an IM service, e.g. an ICQ or Skype account

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlBuildable

#to_xml_with_options

Constructor Details

#initialize(options = {}) ⇒ Account

Returns a new instance of Account.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :protocol (String)

    Protocol used for the account

  • :handle (String)

    The handle / login for the account, e.g. your ICQ number

  • :tag (String)

    A label for easy recognition of your account, e.g. “jabber-work”

  • :autoconnect (String)

    Autoconnect to account on identify?

  • :server (String)

    Overwrite server to connect to - for example if you use a proxy, or stunnel

  • :cleartext_password (String)

    Cleartext password for this account. Will be encrypted before written

  • :password (String)

    The encrypted password of the account, as it appears in the XML document (encrypted_password with the users password

  • :user (String)

    User this account belongs to. Needed for it’s cleartext password



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/bitlbee_config/account.rb', line 60

def initialize(options = {})
  @protocol ||= options.delete(:protocol)
  @handle ||= options.delete(:handle)
  @tag ||= options.delete(:tag)
  @autoconnect ||= options.delete(:autoconnect)
  @server ||= options.delete(:server)
  @password ||= options.delete(:password)
  @cleartext_password ||= options.delete(:cleartext_password)
  @user ||= options.delete(:user)
  @settings = options || {}
end

Instance Attribute Details

#autoconnectObject

Returns the value of attribute autoconnect.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def autoconnect
  @autoconnect
end

#cleartext_passwordObject

Returns the value of attribute cleartext_password.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def cleartext_password
  @cleartext_password
end

#handleObject

Returns the value of attribute handle.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def handle
  @handle
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def password
  @password
end

#protocolObject

Returns the value of attribute protocol.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def protocol
  @protocol
end

#serverObject

Returns the value of attribute server.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def server
  @server
end

#settingsObject

Returns the value of attribute settings.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def settings
  @settings
end

#tagObject

Returns the value of attribute tag.



6
7
8
# File 'lib/bitlbee_config/account.rb', line 6

def tag
  @tag
end

#userObject

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.

Parameters:

  • account (Hash) (defaults to: {})

    Attributes for the account the be created

Returns:



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 ( = {})
   = case
                  when [:handle] =~ /#{ BitlbeeConfig::Accounts::Facebook::USERNAME_SUFFIX }$/
                    BitlbeeConfig::Accounts::Facebook
                  when [:server] == BitlbeeConfig::Accounts::Gtalk::DEFAULT_GTALK_SERVER
                    BitlbeeConfig::Accounts::Gtalk
                  when [:protocol].to_s == "jabber"
                    BitlbeeConfig::Accounts::Jabber
                  when [:protocol].to_s == "steam"
                    BitlbeeConfig::Accounts::Steam
                  when [:protocol].to_s == "oscar"
                    BitlbeeConfig::Accounts::Icq
                  else
                    BitlbeeConfig::Account
                  end

  .new()
end

.from_xml(xml) ⇒ BitlbeeConfig::Account|BitlbeeConfig::Accounts::Icq

Returns The newly created account.

Parameters:

  • xml (Nokogiri::XML::Element)

    XML element to create account from

Returns:



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)
   = {}

  # get setting attributes
  xml.attributes.each do |att_name, att_value|
    [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|
    [setting_element.values.first.to_sym] = setting_element.text
  end

  ()
end

Instance Method Details

#build_xml(xml_builder) ⇒ Object

Parameters:

  • xml_builder (Nokogiri::XML::Builder)

    All XML will be added to this builder



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, options_hash|
    value = instance_variable_get("@#{ option }")
    options_hash[option] = value unless value.nil? || value.empty?
  end

  to_xml_with_options(xml_builder, )
end

#idObject

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_neededObject

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