Class: BitlbeeConfig::Accounts::Facebook

Inherits:
Jabber show all
Defined in:
lib/bitlbee_config/accounts/facebook.rb

Constant Summary collapse

USERNAME_SUFFIX =
"@chat.facebook.com"

Instance Attribute Summary collapse

Attributes inherited from BitlbeeConfig::Account

#autoconnect, #cleartext_password, #handle, #password, #protocol, #server, #settings, #tag, #user

Instance Method Summary collapse

Methods inherited from BitlbeeConfig::Account

#build_xml, create_new_account, from_xml, #id, #regenerate_password_if_needed

Methods included from XmlBuildable

#to_xml_with_options

Constructor Details

#initialize(options = {}) ⇒ Facebook

Returns a new instance of Facebook.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bitlbee_config/accounts/facebook.rb', line 8

def initialize(options = {})
  # username needs to be downcased when not using OAuth. Just always downcase it, always works
  options[:handle] &&= options[:handle].downcase

  # unless otherwise specified, use oauth authentication
  @auth_strategy = options.delete(:auth_strategy) || :oauth

  options = add_auth_strategy_options(options)

  super({ tag: "fb",
          nick_format: "%full_name"
        }.merge(options))

  ensure_handle_is_suffixed if @handle
end

Instance Attribute Details

#auth_strategyObject

Returns the value of attribute auth_strategy.



4
5
6
# File 'lib/bitlbee_config/accounts/facebook.rb', line 4

def auth_strategy
  @auth_strategy
end

Instance Method Details

#add_auth_strategy_options(init_options) ⇒ Hash

Depending on the authentication strategy, we set a few things

Parameters:

  • init_options (Hash)

    The options passed to initialize

Returns:

  • (Hash)

    The original options, which may be modified now



33
34
35
36
37
38
39
40
41
# File 'lib/bitlbee_config/accounts/facebook.rb', line 33

def add_auth_strategy_options(init_options)
  case @auth_strategy
  when :oauth
    init_options[:oauth] = "on"
    init_options[:cleartext_password] ||= ""
  end

  init_options
end

#ensure_handle_is_suffixedObject

We don’t want the user to have to enter “@chat.facebook.com” with their handle, so we do it for them



25
26
27
# File 'lib/bitlbee_config/accounts/facebook.rb', line 25

def ensure_handle_is_suffixed
  @handle += USERNAME_SUFFIX unless @handle =~ /#{ USERNAME_SUFFIX }$/
end