rplatform-rails 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +0 -0
- data/History.txt +2 -0
- data/Manifest.txt +22 -0
- data/README.txt +33 -0
- data/Rakefile +15 -0
- data/init.rb +22 -0
- data/lib/rplatform-rails.rb +45 -0
- data/lib/rplatform_rails/controller_extensions.rb +572 -0
- data/lib/rplatform_rails/model_extensions.rb +218 -0
- data/lib/rplatform_rails/session_extensions.rb +198 -0
- data/lib/rplatform_rails/status_manager.rb +312 -0
- data/lib/rplatform_rails/view_extensions.rb +93 -0
- data/tasks/all.rake +176 -0
- data/templates/debug_panel.rhtml +220 -0
- data/templates/exception_backtrace.rhtml +105 -0
- data/test/api_test.rb +203 -0
- data/test/controller_test.rb +257 -0
- data/test/initialization_test.rb +29 -0
- data/test/model_test.rb +142 -0
- data/test/session_test.rb +64 -0
- data/test/test_helper.rb +105 -0
- data/test/view_test.rb +30 -0
- metadata +92 -0
@@ -0,0 +1,218 @@
|
|
1
|
+
# AUTHORS:
|
2
|
+
# - Curtis Edmond (www.okwithfailure.com)
|
3
|
+
# thanks to matt for rfacebook
|
4
|
+
# - Matt Pizzimenti (www.livelearncode.com)
|
5
|
+
|
6
|
+
# LICENSE:
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# Neither the name of the original author nor the names of contributors
|
18
|
+
# may be used to endorse or promote products derived from this software
|
19
|
+
# without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
24
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
25
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
29
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
32
|
+
|
33
|
+
module RPlatform
|
34
|
+
module Rails
|
35
|
+
module ModelExtensions
|
36
|
+
|
37
|
+
################################################################################################
|
38
|
+
################################################################################################
|
39
|
+
# :section: Core API variables
|
40
|
+
################################################################################################
|
41
|
+
|
42
|
+
def facebook_api_key(network)
|
43
|
+
NETWORKS[network]["key"] || super
|
44
|
+
end
|
45
|
+
|
46
|
+
def facebook_api_secret(network)
|
47
|
+
NETWORKS[network]["secret"] || super
|
48
|
+
end
|
49
|
+
|
50
|
+
################################################################################################
|
51
|
+
################################################################################################
|
52
|
+
# :section: Method mixing
|
53
|
+
################################################################################################
|
54
|
+
|
55
|
+
def self.included(base) # :nodoc:
|
56
|
+
base.extend ActsAsMethods
|
57
|
+
end
|
58
|
+
|
59
|
+
module ActsAsMethods # :nodoc:all
|
60
|
+
def acts_as_facebook_user
|
61
|
+
RAILS_DEFAULT_LOGGER.info "** RFACEBOOK DEPRECATION WARNING: acts_as_facebook_user will probably be deprecated in a future version of the RFacebook plugin"
|
62
|
+
# TODO: remove the acts_as_facebook_user or at least update it
|
63
|
+
include RPlatform::Rails::ModelExtensions::ActsAsFacebookUser::InstanceMethods
|
64
|
+
extend RPlatform::Rails::ModelExtensions::ActsAsFacebookUser::ClassMethods
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
##################################################################
|
70
|
+
##################################################################
|
71
|
+
# :section: Acts As Facebook User
|
72
|
+
##################################################################
|
73
|
+
module ActsAsFacebookUser
|
74
|
+
|
75
|
+
ACTORS = [] # holds a reference to all classes that have ActsAsFacebookUser injected
|
76
|
+
|
77
|
+
FIELDS = [
|
78
|
+
"about_me",
|
79
|
+
"activities",
|
80
|
+
"affiliations",
|
81
|
+
"birthday",
|
82
|
+
"books",
|
83
|
+
"current_location",
|
84
|
+
"education_history",
|
85
|
+
"name",
|
86
|
+
"first_name",
|
87
|
+
"last_name",
|
88
|
+
"hometown_location",
|
89
|
+
"hs_info",
|
90
|
+
"interests",
|
91
|
+
"relationship_status",
|
92
|
+
"meeting_for",
|
93
|
+
"meeting_sex",
|
94
|
+
"movies",
|
95
|
+
"music",
|
96
|
+
"notes_count",
|
97
|
+
"political",
|
98
|
+
"profile_update_time",
|
99
|
+
"quotes",
|
100
|
+
"religion",
|
101
|
+
"sex",
|
102
|
+
"significant_other_id",
|
103
|
+
"status",
|
104
|
+
"timezone",
|
105
|
+
"tv",
|
106
|
+
"wall_count",
|
107
|
+
"work_history",
|
108
|
+
"pic",
|
109
|
+
"pic_big",
|
110
|
+
"pic_small",
|
111
|
+
"pic_square"
|
112
|
+
]
|
113
|
+
|
114
|
+
|
115
|
+
######################
|
116
|
+
module ClassMethods
|
117
|
+
|
118
|
+
def find_or_create_by_facebook_session(options={})
|
119
|
+
RAILS_DEFAULT_LOGGER.info "** RFACEBOOK DEPRECATION WARNING: acts_as_facebook_user will probably be deprecated in a future version of the RFacebook plugin"
|
120
|
+
|
121
|
+
# parse the options (for backwards compatibility, options MIGHT be a FacebookWebSession)
|
122
|
+
if options.is_a?(RPlatform::FacebookWebSession)
|
123
|
+
fbsession = options
|
124
|
+
options = {}
|
125
|
+
else
|
126
|
+
fbsession = options[:facebook_session]
|
127
|
+
end
|
128
|
+
|
129
|
+
# check that we have an fbsession
|
130
|
+
unless fbsession.is_a?(Rplatform::FacebookWebSession)
|
131
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: find_or_create_by_facebook_session needs a :facebook_session specified"
|
132
|
+
return nil
|
133
|
+
end
|
134
|
+
|
135
|
+
# if the session is ready to use...
|
136
|
+
if fbsession.ready?
|
137
|
+
|
138
|
+
# find or create a user
|
139
|
+
instance = find_by_facebook_uid(fbsession.session_user_id) || self.new(options)
|
140
|
+
|
141
|
+
# update session info
|
142
|
+
instance.facebook_session = fbsession
|
143
|
+
|
144
|
+
# update (or create) the object and return it
|
145
|
+
if !instance.save
|
146
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to update or create the Facebook user object in the database"
|
147
|
+
return nil
|
148
|
+
end
|
149
|
+
return instance
|
150
|
+
|
151
|
+
# session was not ready
|
152
|
+
else
|
153
|
+
RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: tried to use an inactive session for acts_as_facebook_user (in find_or_create_by_facebook_session)"
|
154
|
+
return nil
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
######################
|
162
|
+
module InstanceMethods
|
163
|
+
|
164
|
+
# TODO: to help developers stay within the TOS, we should have a method in here like "with_facebook_scope(fbsession){...}"
|
165
|
+
|
166
|
+
def facebook_session(network='facebook')
|
167
|
+
if !@facebook_session
|
168
|
+
@facebook_session = FacebookWebSession.new(self.facebook_api_key(network), self.facebook_api_secret(network))
|
169
|
+
begin
|
170
|
+
@facebook_session.activate_with_previous_session(self.facebook_session_key, self.facebook_uid)
|
171
|
+
rescue
|
172
|
+
# not a valid facebook session, should we nil it out?
|
173
|
+
end
|
174
|
+
end
|
175
|
+
return @facebook_session
|
176
|
+
end
|
177
|
+
|
178
|
+
def facebook_session=(sess)
|
179
|
+
@facebook_session = sess
|
180
|
+
self.facebook_session_key = @facebook_session.session_key
|
181
|
+
self.facebook_uid = @facebook_session.session_user_id
|
182
|
+
end
|
183
|
+
|
184
|
+
def has_infinite_session_key?
|
185
|
+
# TODO: this check should really look at expires
|
186
|
+
return self.facebook_session_key != nil
|
187
|
+
end
|
188
|
+
|
189
|
+
def self.included(base) # :nodoc:
|
190
|
+
ActsAsFacebookUser::ACTORS << base
|
191
|
+
ActsAsFacebookUser::FIELDS.each do |fieldname|
|
192
|
+
# TODO: do getInfo caching
|
193
|
+
base.class_eval <<-EOF
|
194
|
+
|
195
|
+
def #{fieldname}
|
196
|
+
if facebook_session.ready?
|
197
|
+
return facebook_session.users_getInfo(
|
198
|
+
:uids => [facebook_uid],
|
199
|
+
:fields => ActsAsFacebookUser::FIELDS).user.send(:#{fieldname})
|
200
|
+
else
|
201
|
+
return nil
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
EOF
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
end
|
212
|
+
##################################################################
|
213
|
+
##################################################################
|
214
|
+
|
215
|
+
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -0,0 +1,198 @@
|
|
1
|
+
# AUTHORS:
|
2
|
+
# - Curtis Edmond (www.okwithfailure.com)
|
3
|
+
# thanks to matt for rfacebook
|
4
|
+
# - Matt Pizzimenti (www.livelearncode.com)
|
5
|
+
|
6
|
+
# LICENSE:
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# Neither the name of the original author nor the names of contributors
|
18
|
+
# may be used to endorse or promote products derived from this software
|
19
|
+
# without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
24
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
25
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
29
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
32
|
+
require "digest/md5"
|
33
|
+
require "cgi"
|
34
|
+
|
35
|
+
module RPlatform::Rails::SessionExtensions # :nodoc:
|
36
|
+
|
37
|
+
# :section: New Methods
|
38
|
+
def force_to_be_new! # :nodoc:
|
39
|
+
@force_to_be_new = true
|
40
|
+
end
|
41
|
+
|
42
|
+
def using_facebook_session_id? # :nodoc:
|
43
|
+
return (@fb_sig_session_id != nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
# :section: Base Overrides
|
47
|
+
|
48
|
+
def new_session_with_rplatform # :nodoc:
|
49
|
+
if @force_to_be_new
|
50
|
+
return true
|
51
|
+
else
|
52
|
+
return new_session_without_rplatform
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def initialize_with_rplatform(request, options = {}) # :nodoc:
|
57
|
+
|
58
|
+
# only try to use the sig when we don't have a cookie (i.e., in the canvas)
|
59
|
+
if session_id_available?(request)
|
60
|
+
|
61
|
+
# try a few different ways
|
62
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Attempting to use fb_sig_session_key as a session key, since we are inside the canvas"
|
63
|
+
@fb_sig_session_id = lookup_request_parameter(request, "fb_sig_session_key")
|
64
|
+
|
65
|
+
# we only want to change the session_id if we got one from the fb_sig
|
66
|
+
if @fb_sig_session_id
|
67
|
+
options["session_id"] = Digest::MD5.hexdigest(@fb_sig_session_id)
|
68
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using MD5 of fb_sig_session_key [#{options['session_id']}] for the Rails session id"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# now call the default Rails session initialization
|
73
|
+
initialize_without_rplatform(request, options)
|
74
|
+
end
|
75
|
+
|
76
|
+
# :section: Extension Helpers
|
77
|
+
|
78
|
+
def self.included(base) # :nodoc:
|
79
|
+
base.class_eval do
|
80
|
+
alias_method_chain :initialize, :rplatform
|
81
|
+
alias_method_chain :new_session, :rplatform
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# :section: Private Helpers
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
# TODO: it seems that there should be a better way to just get raw parameters
|
90
|
+
# (not sure why the nil key bug doesn't seem to be fixed in my installation)
|
91
|
+
# ...also, there seems to be some interaction with Mongrel as well that can
|
92
|
+
# cause the parameters to fail
|
93
|
+
def lookup_request_parameter(request, key) # :nodoc:
|
94
|
+
|
95
|
+
# Depending on the user's version of Rails, this may fail due to a bug in Rails parsing of
|
96
|
+
# nil keys: http://dev.rubyonrails.org/ticket/5137, so we have a backup plan
|
97
|
+
begin
|
98
|
+
|
99
|
+
# this should work on most Rails installations
|
100
|
+
return request[key]
|
101
|
+
|
102
|
+
rescue
|
103
|
+
|
104
|
+
# this saves most other Rails installations
|
105
|
+
begin
|
106
|
+
|
107
|
+
retval = nil
|
108
|
+
|
109
|
+
# try accessing raw_post (doesn't work in some mongrel installations)
|
110
|
+
if request.respond_to?(:raw_post)
|
111
|
+
return CGI::parse(request.send(:raw_post)).fetch(key){[]}.first
|
112
|
+
end
|
113
|
+
|
114
|
+
# try accessing the raw environment table
|
115
|
+
if !retval
|
116
|
+
envTable = nil
|
117
|
+
|
118
|
+
envTable = request.send(:env_table) if request.respond_to?(:env_table)
|
119
|
+
if !envTable
|
120
|
+
envTable = request.send(:env) if request.respond_to?(:env)
|
121
|
+
end
|
122
|
+
|
123
|
+
if envTable
|
124
|
+
# credit: Blake Carlson and David Troy
|
125
|
+
["RAW_POST_DATA", "QUERY_STRING"].each do |tableSource|
|
126
|
+
if envTable[tableSource]
|
127
|
+
retval = CGI::parse(envTable[tableSource]).fetch(key){[]}.first
|
128
|
+
end
|
129
|
+
break if retval
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# hopefully we got a parameter
|
135
|
+
return retval
|
136
|
+
|
137
|
+
rescue
|
138
|
+
|
139
|
+
# for some reason, we just can't get the parameters
|
140
|
+
RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: failed to access request.parameters"
|
141
|
+
return nil
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def session_id_available?(request) # :nodoc:
|
148
|
+
# TODO: we should probably be checking the fb_sig for validity here (template method needed)
|
149
|
+
# ...we can only do this if we can grab the equivalent of a params hash
|
150
|
+
return (!lookup_request_parameter(request, "fb_sig_in_canvas").blank? or !lookup_request_parameter(request, "fb_sig_is_ajax").blank?)
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
# Special initialize method that attempts to force any session store to use the Facebook session
|
156
|
+
module RPlatform::Rails::SessionStoreExtensions # :nodoc:all
|
157
|
+
|
158
|
+
# :section: Base Overrides
|
159
|
+
|
160
|
+
def initialize_with_rplatform(session, options, *extraParams) # :nodoc:
|
161
|
+
|
162
|
+
if session.using_facebook_session_id?
|
163
|
+
|
164
|
+
# we got the fb_sig_session_key, so alter Rails' behavior to use that key to make a session
|
165
|
+
begin
|
166
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using fb_sig_session_key for the #{self.class.to_s} session (session_id=#{session.session_id})"
|
167
|
+
initialize_without_rplatform(session, options, *extraParams)
|
168
|
+
rescue Exception => e
|
169
|
+
begin
|
170
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to initialize session (session_id=#{session.session_id}), trying to force a new session"
|
171
|
+
if session.session_id
|
172
|
+
session.force_to_be_new!
|
173
|
+
end
|
174
|
+
initialize_without_rplatform(session, options, *extraParams)
|
175
|
+
rescue Exception => e
|
176
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to force a new session, falling back to default Rails behavior"
|
177
|
+
raise e
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
else
|
182
|
+
|
183
|
+
# we didn't get the fb_sig_session_key, do not alter Rails' behavior
|
184
|
+
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: using default Rails sessions (since we didn't find an fb_sig_session_key in the environment)"
|
185
|
+
initialize_without_rplatform(session, options, *extraParams)
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# :section: Extension Helpers
|
191
|
+
|
192
|
+
def self.included(base) # :nodoc:
|
193
|
+
base.class_eval do
|
194
|
+
alias_method_chain :initialize, :rplatform
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
@@ -0,0 +1,312 @@
|
|
1
|
+
# AUTHORS:
|
2
|
+
# - Curtis Edmond (www.okwithfailure.com)
|
3
|
+
# thanks to matt for rfacebook
|
4
|
+
# - Matt Pizzimenti (www.livelearncode.com)
|
5
|
+
|
6
|
+
# LICENSE:
|
7
|
+
# Redistribution and use in source and binary forms, with or without modification,
|
8
|
+
# are permitted provided that the following conditions are met:
|
9
|
+
#
|
10
|
+
# Redistributions of source code must retain the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer.
|
12
|
+
#
|
13
|
+
# Redistributions in binary form must reproduce the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer in the documentation
|
15
|
+
# and/or other materials provided with the distribution.
|
16
|
+
#
|
17
|
+
# Neither the name of the original author nor the names of contributors
|
18
|
+
# may be used to endorse or promote products derived from this software
|
19
|
+
# without specific prior written permission.
|
20
|
+
#
|
21
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
22
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
23
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
24
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
25
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
26
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
27
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
28
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
29
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
32
|
+
module RPlatform
|
33
|
+
module Rails
|
34
|
+
|
35
|
+
class StatusManager
|
36
|
+
|
37
|
+
def initialize(checks)
|
38
|
+
@checks = checks
|
39
|
+
end
|
40
|
+
|
41
|
+
def all_valid?
|
42
|
+
allValid = true
|
43
|
+
@checks.each do |check|
|
44
|
+
allValid = false if !check.valid?
|
45
|
+
end
|
46
|
+
return allValid
|
47
|
+
end
|
48
|
+
|
49
|
+
def each_status_check
|
50
|
+
@checks.each do |check|
|
51
|
+
yield(check)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
###########################################
|
58
|
+
class StatusCheck
|
59
|
+
def valid?
|
60
|
+
return @valid
|
61
|
+
end
|
62
|
+
def message
|
63
|
+
if valid?
|
64
|
+
return valid_message
|
65
|
+
else
|
66
|
+
return invalid_message
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
###########################################
|
72
|
+
class SessionStatusCheck < StatusCheck
|
73
|
+
def initialize(controller)
|
74
|
+
@controller = controller
|
75
|
+
@valid = false
|
76
|
+
begin
|
77
|
+
if controller.fbsession.ready?
|
78
|
+
@valid = true
|
79
|
+
end
|
80
|
+
rescue
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def title
|
85
|
+
"fbsession"
|
86
|
+
end
|
87
|
+
|
88
|
+
def valid_message
|
89
|
+
"session is ready to make API calls"
|
90
|
+
end
|
91
|
+
|
92
|
+
def invalid_message
|
93
|
+
"session is invalid, you will not be able to make API calls (possibly due to a bad API key or secret)"
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
###########################################
|
98
|
+
class FacebookParamsStatusCheck < StatusCheck
|
99
|
+
def initialize(controller)
|
100
|
+
@controller = controller
|
101
|
+
@valid = false
|
102
|
+
begin
|
103
|
+
if @controller.fbparams.size > 0
|
104
|
+
@valid = true
|
105
|
+
end
|
106
|
+
rescue
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def title
|
111
|
+
"fbparams"
|
112
|
+
end
|
113
|
+
|
114
|
+
def valid_message
|
115
|
+
@controller.fbparams
|
116
|
+
end
|
117
|
+
|
118
|
+
def invalid_message
|
119
|
+
"fbparams is not populated since we weren't able to validate the signature (possibly due to a bad API key or secret)"
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
###########################################
|
124
|
+
class InCanvasStatusCheck < StatusCheck
|
125
|
+
def initialize(controller)
|
126
|
+
@controller = controller
|
127
|
+
@valid = true
|
128
|
+
end
|
129
|
+
|
130
|
+
def title
|
131
|
+
"in_facebook_canvas?"
|
132
|
+
end
|
133
|
+
|
134
|
+
def valid_message
|
135
|
+
@controller.in_facebook_canvas? ? "yes" : "no"
|
136
|
+
end
|
137
|
+
|
138
|
+
def invalid_message
|
139
|
+
"this should never be invalid"
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
###########################################
|
144
|
+
class InFrameStatusCheck < StatusCheck
|
145
|
+
def initialize(controller)
|
146
|
+
@controller = controller
|
147
|
+
@valid = true
|
148
|
+
end
|
149
|
+
|
150
|
+
def title
|
151
|
+
"in_facebook_frame?"
|
152
|
+
end
|
153
|
+
|
154
|
+
def valid_message
|
155
|
+
@controller.in_facebook_frame? ? "yes" : "no"
|
156
|
+
end
|
157
|
+
|
158
|
+
def invalid_message
|
159
|
+
"this should never be invalid"
|
160
|
+
end
|
161
|
+
|
162
|
+
end
|
163
|
+
###########################################
|
164
|
+
class CanvasPathStatusCheck < StatusCheck
|
165
|
+
def initialize(controller)
|
166
|
+
@controller = controller
|
167
|
+
@valid = false
|
168
|
+
begin
|
169
|
+
@valid = @controller.facebook_canvas_path.size > 0
|
170
|
+
rescue
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def title
|
175
|
+
"facebook_canvas_path"
|
176
|
+
end
|
177
|
+
|
178
|
+
def valid_message
|
179
|
+
@controller.facebook_canvas_path
|
180
|
+
end
|
181
|
+
|
182
|
+
def invalid_message
|
183
|
+
begin
|
184
|
+
FACEBOOK[:test]
|
185
|
+
return "you need to define <strong>canvas_path</strong> in facebook.yml"
|
186
|
+
rescue
|
187
|
+
return "you need to define s<strong>facebook_canvas_path</strong> in your controller"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
###########################################
|
193
|
+
class CallbackPathStatusCheck < StatusCheck
|
194
|
+
def initialize(controller)
|
195
|
+
@controller = controller
|
196
|
+
@valid = false
|
197
|
+
begin
|
198
|
+
@valid = @controller.facebook_callback_path.size > 0
|
199
|
+
rescue
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
def title
|
204
|
+
"facebook_callback_path"
|
205
|
+
end
|
206
|
+
|
207
|
+
def valid_message
|
208
|
+
@controller.facebook_callback_path
|
209
|
+
end
|
210
|
+
|
211
|
+
def invalid_message
|
212
|
+
begin
|
213
|
+
FACEBOOK[:test]
|
214
|
+
return "you need to define <strong>callback_path</strong> in facebook.yml"
|
215
|
+
rescue
|
216
|
+
return "you need to define s<strong>facebook_callback_path</strong> in your controller"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
###########################################
|
222
|
+
class APIKeyStatusCheck < StatusCheck
|
223
|
+
def initialize(controller)
|
224
|
+
@controller = controller
|
225
|
+
@valid = false
|
226
|
+
begin
|
227
|
+
if @controller.facebook_api_key.size > 0
|
228
|
+
@valid = true
|
229
|
+
end
|
230
|
+
rescue
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def title
|
235
|
+
"facebook_api_key"
|
236
|
+
end
|
237
|
+
|
238
|
+
def valid_message
|
239
|
+
"XXXXXXXXXXXXXXXXXX#{@controller.facebook_api_key[-4,4]}"
|
240
|
+
end
|
241
|
+
|
242
|
+
def invalid_message
|
243
|
+
begin
|
244
|
+
FACEBOOK[:test]
|
245
|
+
return "you need to put your API <strong>key</strong> in facebook.yml"
|
246
|
+
rescue
|
247
|
+
return "you need to define s<strong>facebook_api_key</strong> in your controller"
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|
252
|
+
###########################################
|
253
|
+
class APISecretStatusCheck < StatusCheck
|
254
|
+
def initialize(controller)
|
255
|
+
@controller = controller
|
256
|
+
@valid = false
|
257
|
+
begin
|
258
|
+
if @controller.facebook_api_secret.size > 0
|
259
|
+
@valid = true
|
260
|
+
end
|
261
|
+
rescue
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def title
|
266
|
+
"facebook_api_secret"
|
267
|
+
end
|
268
|
+
|
269
|
+
def valid_message
|
270
|
+
"XXXXXXXXXXXXXXXXXX#{@controller.facebook_api_secret[-4,4]}"
|
271
|
+
end
|
272
|
+
|
273
|
+
def invalid_message
|
274
|
+
begin
|
275
|
+
FACEBOOK[:test]
|
276
|
+
return "you need to put your API <strong>secret</strong> in facebook.yml"
|
277
|
+
rescue
|
278
|
+
return "you need to define s<strong>facebook_api_secret</strong> in your controller"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
###########################################
|
285
|
+
class FinishFacebookLoginStatusCheck < StatusCheck
|
286
|
+
def initialize(controller)
|
287
|
+
@controller = controller
|
288
|
+
@valid = false
|
289
|
+
begin
|
290
|
+
@controller.finish_facebook_login
|
291
|
+
@valid = true
|
292
|
+
rescue
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def title
|
297
|
+
"finish_facebook_login"
|
298
|
+
end
|
299
|
+
|
300
|
+
def valid_message
|
301
|
+
"finisher method is defined (this is only for external web apps)"
|
302
|
+
end
|
303
|
+
|
304
|
+
def invalid_message
|
305
|
+
"you need to define <strong>finish_facebook_login</strong> in your controller (this is only for external web apps)"
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
|
311
|
+
end
|
312
|
+
end
|