Class: Facebooker::AdapterBase

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::CoreExtensions::String::Inflections
Defined in:
lib/facebooker/adapters/adapter_base.rb

Direct Known Subclasses

BeboAdapter, FacebookAdapter

Defined Under Namespace

Classes: UnableToLoadAdapter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ AdapterBase

Returns a new instance of AdapterBase.



27
28
29
# File 'lib/facebooker/adapters/adapter_base.rb', line 27

def initialize(config)
  @config = config
end

Class Method Details

.default_adapter(params = {}) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/facebooker/adapters/adapter_base.rb', line 73

def self.default_adapter(params = {})
  if facebooker_config.nil? || (facebooker_config.blank? rescue nil)
    config = { "api_key" => ENV['FACEBOOK_API_KEY'], "secret_key" =>  ENV['FACEBOOK_SECRET_KEY']}
  else
    config = facebooker_config
  end
 FacebookAdapter.new(config)
end

.facebooker_configObject



31
32
33
# File 'lib/facebooker/adapters/adapter_base.rb', line 31

def  self.facebooker_config
  Facebooker.facebooker_config
end

.load_adapter(params) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/facebooker/adapters/adapter_base.rb', line 36

def self.load_adapter(params)

  config_key_base = params[:config_key_base] # This allows for loading of a aspecific adapter
  config_key_base += "_" unless config_key_base.blank?

  unless api_key = (params[:fb_sig_api_key] || facebooker_config["#{config_key_base}api_key"])
    raise Facebooker::AdapterBase::UnableToLoadAdapter
  end

  unless facebooker_config
    return self.default_adapter(params)
  end

  facebooker_config.each do |key,value|
    next unless value == api_key

    key_base = key.match(/(.*)[_]?api_key/)[1]

    adapter_class_name = if key_base.blank?
       "FacebookAdapter"
    else
      facebooker_config[key_base + "adapter"]
    end

    adapter_class = "Facebooker::#{adapter_class_name}".constantize

    # Collect the rest of the configuration
    adapter_config = {}
    facebooker_config.each do |key,value|
      if (match = key.match(/#{key_base}[_]?(.*)/))
        adapter_config[match[1]] = value
      end
    end
    return adapter_class.new(adapter_config)
  end
end

Instance Method Details

#api_server_base_urlObject



19
20
21
# File 'lib/facebooker/adapters/adapter_base.rb', line 19

def api_server_base_url
  "http://" + api_server_base
end

#facebook_path_prefixObject



7
8
9
# File 'lib/facebooker/adapters/adapter_base.rb', line 7

def facebook_path_prefix
  "/" + (@facebook_path_prefix || canvas_page_name || ENV['FACEBOOK_CANVAS_PATH'] || ENV['FACEBOOKER_RELATIVE_URL_ROOT'])
end

#facebook_path_prefix=(prefix) ⇒ Object



11
12
13
# File 'lib/facebooker/adapters/adapter_base.rb', line 11

def facebook_path_prefix=(prefix)
  @facebook_path_prefix = prefix
end

#facebooker_configObject



15
16
17
# File 'lib/facebooker/adapters/adapter_base.rb', line 15

def  facebooker_config
  @config
end

#is_for?(application_context) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/facebooker/adapters/adapter_base.rb', line 23

def is_for?(application_context)
  raise "SubClassShouldDefine"
end