forked from mmangino/facebooker2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfacebooker2.rb
79 lines (59 loc) · 2.07 KB
/
facebooker2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
72
73
74
75
76
77
78
79
# Facebooker2
require "mogli"
module Facebooker2
class NotConfigured < Exception; end
class << self
attr_accessor :api_key, :secret, :app_id, :canvas_page_name, :callback_url, :callback_domain
end
def self.secret
@secret || raise_unconfigured_exception
end
def self.app_id
@app_id || raise_unconfigured_exception
end
def self.canvas_page_url(protocol = nil)
"#{ protocol || 'http://' }apps.facebook.com/#{canvas_page_name}"
end
def self.callback_url(protocol = nil)
@callback_domain ? "#{ protocol || 'http://' }#{@callback_domain}" : @callback_url
end
def self.raise_unconfigured_exception
raise NotConfigured.new("No configuration provided for Facebooker2. Either set the app_id and secret or call Facebooker2.load_facebooker_yaml in an initializer")
end
def self.configuration=(hash)
self.api_key = hash[:api_key]
self.secret = hash[:secret]
self.app_id = hash[:app_id]
self.canvas_page_name = hash[:canvas_page_name]
self.callback_url = hash[:callback_url]
self.callback_domain = hash[:callback_domain]
end
def self.load_facebooker_yaml
config = YAML.load(
ERB.new(
File.read(::Rails.root.join("config", "facebooker.yml"))
).result
)[::Rails.env]
raise NotConfigured.new("Unable to load configuration for #{::Rails.env} from facebooker.yml. Is it set up?") if config.nil?
self.configuration = config.with_indifferent_access
end
def self.cast_to_facebook_id(object)
if object.kind_of?(Mogli::Profile)
object.id
elsif object.respond_to?(:facebook_id)
object.facebook_id
else
object
end
end
end
require "facebooker2/rails/controller"
require "facebooker2/rails/controller/canvas_oauth"
require "facebooker2/rails/controller/url_rewriting"
require "facebooker2/rails/helpers/facebook_connect"
require "facebooker2/rails/helpers/javascript"
require "facebooker2/rails/helpers/request_forms"
require "facebooker2/rails/helpers/user"
require "facebooker2/rails/helpers"
require "facebooker2/rack/post_canvas"
require "facebooker2/oauth_exception"