Class: Facebooker::AdapterBase
- Inherits:
-
Object
- Object
- Facebooker::AdapterBase
show all
- Includes:
- ActiveSupport::CoreExtensions::String::Inflections
- Defined in:
- lib/facebooker/adapters/adapter_base.rb
Defined Under Namespace
Classes: UnableToLoadAdapter
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of AdapterBase.
27
28
29
30
|
# File 'lib/facebooker/adapters/adapter_base.rb', line 27
def initialize(config)
@config = config
@facebook_path_prefix = nil
end
|
Class Method Details
.default_adapter(params = {}) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/facebooker/adapters/adapter_base.rb', line 77
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_config ⇒ Object
.load_adapter(params) ⇒ Object
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
72
73
74
75
|
# File 'lib/facebooker/adapters/adapter_base.rb', line 37
def self.load_adapter(params)
config_key_base = params[:config_key_base] config_key_base += "_" if config_key_base && config_key_base.length > 0
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 || key_base.length == 0
"FacebookAdapter"
else
facebooker_config[key_base + "adapter"]
end
adapter_class = "Facebooker::#{adapter_class_name}".constantize
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
return self.default_adapter(params)
end
|
Instance Method Details
#api_server_base_url ⇒ Object
19
20
21
|
# File 'lib/facebooker/adapters/adapter_base.rb', line 19
def api_server_base_url
"http://" + api_server_base
end
|
#facebook_path_prefix ⇒ Object
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_config ⇒ Object
15
16
17
|
# File 'lib/facebooker/adapters/adapter_base.rb', line 15
def facebooker_config
@config
end
|
#is_for?(application_context) ⇒ Boolean
23
24
25
|
# File 'lib/facebooker/adapters/adapter_base.rb', line 23
def is_for?(application_context)
raise "SubClassShouldDefine"
end
|