rfacebook 0.9.7 → 0.9.8

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.
@@ -0,0 +1,216 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require 'mocha'
4
+ require 'rfacebook'
5
+
6
+
7
+ module RFacebook
8
+ module Dummy
9
+
10
+ API_KEY = "dummykey123"
11
+ API_SECRET = "dummysecret456"
12
+
13
+ AUTH_CREATETOKEN_RESPONSE = <<-EOF
14
+ <?xml version="1.0" encoding="UTF-8"?>
15
+ <auth_createToken_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">3e4a22bb2f5ed75114b0fc9995ea85f1</auth_createToken_response>
16
+ EOF
17
+
18
+ ERROR_RESPONSE = <<-EOF
19
+ <?xml version="1.0" encoding="UTF-8"?>
20
+ <error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
21
+ <error_code>5</error_code>
22
+ <error_msg>Unauthorized source IP address (ip was: 10.1.2.3)</error_msg>
23
+ <request_args list="true">
24
+ <arg>
25
+ <key>method</key>
26
+ <value>facebook.friends.get</value>
27
+ </arg>
28
+ <arg>
29
+ <key>session_key</key>
30
+ <value>373443c857fcda2e410e349c-i7nF4PqX4IW4.</value>
31
+ </arg>
32
+ <arg>
33
+ <key>api_key</key>
34
+ <value>0289b21f46b2ee642d5c42145df5489f</value>
35
+ </arg>
36
+ <arg>
37
+ <key>call_id</key>
38
+ <value>1170813376.3544</value>
39
+ </arg>
40
+ <arg>
41
+ <key>v</key>
42
+ <value>1.0</value>
43
+ </arg>
44
+ <arg>
45
+ <key>sig</key>
46
+ <value>570dcc2b764578af350ea1e1622349a0</value>
47
+ </arg>
48
+ </request_args>
49
+ </error_response>
50
+ EOF
51
+
52
+ ERROR_RESPONSE_3 = <<-EOF
53
+ <?xml version="1.0" encoding="UTF-8"?>
54
+ <error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
55
+ <error_code>3</error_code>
56
+ <error_msg>method does not exist</error_msg>
57
+ </error_response>
58
+ EOF
59
+
60
+ ERROR_RESPONSE_100 = <<-EOF
61
+ <?xml version="1.0" encoding="UTF-8"?>
62
+ <error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
63
+ <error_code>100</error_code>
64
+ <error_msg>bad arguments</error_msg>
65
+ </error_response>
66
+ EOF
67
+
68
+ ERROR_RESPONSE_102 = <<-EOF
69
+ <?xml version="1.0" encoding="UTF-8"?>
70
+ <error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
71
+ <error_code>102</error_code>
72
+ <error_msg>expired session</error_msg>
73
+ </error_response>
74
+ EOF
75
+
76
+ ERROR_RESPONSE_606 = <<-EOF
77
+ <?xml version="1.0" encoding="UTF-8"?>
78
+ <error_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
79
+ <error_code>606</error_code>
80
+ <error_msg>wrong number of arguments</error_msg>
81
+ </error_response>
82
+ EOF
83
+
84
+ AUTH_GETSESSION_RESPONSE = <<-EOF
85
+ <?xml version="1.0" encoding="UTF-8"?>
86
+ <auth_getSession_response
87
+ xmlns="http://api.facebook.com/1.0/"
88
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
89
+ xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
90
+ <session_key>5f34e11bfb97c762e439e6a5-8055</session_key>
91
+ <uid>8055</uid>
92
+ <expires>1173309298</expires>
93
+ </auth_getSession_response>
94
+ EOF
95
+
96
+ GROUP_GETMEMBERS_RESPONSE = <<-EOF
97
+ <?xml version="1.0" encoding="UTF-8"?>
98
+ <groups_getMembers_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">
99
+ <members list="true">
100
+ <uid>4567</uid>
101
+ <uid>5678</uid>
102
+ <uid>6789</uid>
103
+ <uid>7890</uid>
104
+ </members>
105
+ <admins list="true">
106
+ <uid>1234567</uid>
107
+ </admins>
108
+ <officers list="true"/>
109
+ <not_replied list="true"/>
110
+ </groups_getMembers_response>
111
+ EOF
112
+
113
+ USERS_GETLOGGEDINUSER_RESPONSE = <<-EOF
114
+ <?xml version="1.0" encoding="UTF-8"?>
115
+ <users_getLoggedInUser_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1234567</users_getLoggedInUser_response>
116
+ EOF
117
+
118
+ USERS_GETINFO_RESPONSE = <<-EOF
119
+ <?xml version="1.0" encoding="UTF-8"?>
120
+ <users_getInfo_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
121
+ <user>
122
+ <uid>8055</uid>
123
+ <about_me>This field perpetuates the glorification of the ego. Also, it has a character limit.</about_me>
124
+ <activities>Here: facebook, etc. There: Glee Club, a capella, teaching.</activities>
125
+ <affiliations list="true">
126
+ <affiliation>
127
+ <nid>50453093</nid>
128
+ <name>Facebook Developers</name>
129
+ <type>work</type>
130
+ <status/>
131
+ <year/>
132
+ </affiliation>
133
+ </affiliations>
134
+ <birthday>November 3</birthday>
135
+ <books>The Brothers K, GEB, Ken Wilber, Zen and the Art, Fitzgerald, The Emporer's New Mind, The Wonderful Story of Henry Sugar</books>
136
+ <current_location>
137
+ <city>Palo Alto</city>
138
+ <state>CA</state>
139
+ <country>United States</country>
140
+ <zip>94303</zip>
141
+ </current_location>
142
+ <education_history list="true">
143
+ <education_info>
144
+ <name>Harvard</name>
145
+ <year>2003</year>
146
+ <concentrations list="true">
147
+ <concentration>Applied Mathematics</concentration>
148
+ <concentration>Computer Science</concentration>
149
+ </concentrations>
150
+ </education_info>
151
+ </education_history>
152
+ <first_name>Dave</first_name>
153
+ <hometown_location>
154
+ <city>York</city>
155
+ <state>PA</state>
156
+ <country>United States</country>
157
+ <zip>0</zip>
158
+ </hometown_location>
159
+ <hs_info>
160
+ <hs1_name>Central York High School</hs1_name>
161
+ <hs2_name/>
162
+ <grad_year>1999</grad_year>
163
+ <hs1_id>21846</hs1_id>
164
+ <hs2_id>0</hs2_id>
165
+ </hs_info>
166
+ <is_app_user>1</is_app_user>
167
+ <has_added_app>1</has_added_app>
168
+ <interests>coffee, computers, the funny, architecture, code breaking,snowboarding, philosophy, soccer, talking to strangers</interests>
169
+ <last_name>Fetterman</last_name>
170
+ <meeting_for list="true">
171
+ <seeking>Friendship</seeking>
172
+ </meeting_for>
173
+ <meeting_sex list="true">
174
+ <sex>female</sex>
175
+ </meeting_sex>
176
+ <movies>Tommy Boy, Billy Madison, Fight Club, Dirty Work, Meet the Parents, My Blue Heaven, Office Space </movies>
177
+ <music>New Found Glory, Daft Punk, Weezer, The Crystal Method, Rage, the KLF, Green Day, Live, Coldplay, Panic at the Disco, Family Force 5</music>
178
+ <name>Dave Fetterman</name>
179
+ <notes_count>0</notes_count>
180
+ <pic>http://photos-055.facebook.com/ip007/profile3/1271/65/s8055_39735.jpg</pic>
181
+ <pic_big>http://photos-055.facebook.com/ip007/profile3/1271/65/n8055_39735.jpg</pic>
182
+ <pic_small>http://photos-055.facebook.com/ip007/profile3/1271/65/t8055_39735.jpg</pic>
183
+ <pic_square>http://photos-055.facebook.com/ip007/profile3/1271/65/q8055_39735.jpg</pic>
184
+ <political>Moderate</political>
185
+ <profile_update_time>1170414620</profile_update_time>
186
+ <quotes/>
187
+ <relationship_status>In a Relationship</relationship_status>
188
+ <religion/>
189
+ <sex>male</sex>
190
+ <significant_other_id xsi:nil="true"/>
191
+ <status>
192
+ <message/>
193
+ <time>0</time>
194
+ </status>
195
+ <timezone>-8</timezone>
196
+ <tv>cf. Bob Trahan</tv>
197
+ <wall_count>121</wall_count>
198
+ <work_history list="true">
199
+ <work_info>
200
+ <location>
201
+ <city>Palo Alto</city>
202
+ <state>CA</state>
203
+ <country>United States</country>
204
+ </location>
205
+ <company_name>Facebook</company_name>
206
+ <position>Software Engineer</position>
207
+ <description>Tech Lead, Facebook Platform</description>
208
+ <start_date>2006-01</start_date>
209
+ <end_date/>
210
+ </work_info>
211
+ </work_history>
212
+ </user>
213
+ </users_getInfo_response>
214
+ EOF
215
+ end
216
+ end
metadata CHANGED
@@ -1,73 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: rfacebook
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.9.7
7
- date: 2007-09-29 00:00:00 -04:00
8
- summary: A Ruby interface to the Facebook API v1.0+. Works with RFacebook on Rails plugin (see http://rfacebook.rubyforge.org).
9
- require_paths:
10
- - lib
11
- email: matt@livelearncode.com
12
- homepage: http://livelearncode.com/
13
- rubyforge_project: rfacebook
14
- description:
15
- autorequire: rfacebook
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.9.8
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Matt Pizzimenti
31
- files:
32
- - lib/facebook_desktop_session.rb
33
- - lib/facebook_rails_controller_extensions.rb
34
- - lib/facebook_session.rb
35
- - lib/facebook_web_session.rb
36
- - lib/facepricot.rb
37
- - lib/rfacebook_on_rails
38
- - lib/rfacebook_on_rails/controller_extensions.rb
39
- - lib/rfacebook_on_rails/model_extensions.rb
40
- - lib/rfacebook_on_rails/plugin
41
- - lib/rfacebook_on_rails/session_extensions.rb
42
- - lib/rfacebook_on_rails/status_manager.rb
43
- - lib/rfacebook_on_rails/templates
44
- - lib/rfacebook_on_rails/view_extensions.rb
45
- - lib/rfacebook_on_rails/plugin/init.rb
46
- - lib/rfacebook_on_rails/plugin/install.rb
47
- - lib/rfacebook_on_rails/plugin/rake.rb
48
- - lib/rfacebook_on_rails/plugin/Rakefile.rb
49
- - lib/rfacebook_on_rails/plugin/uninstall.rb
50
- - lib/rfacebook_on_rails/templates/debug_panel.rhtml
51
- - lib/rfacebook_on_rails/templates/exception_backtrace.rhtml
52
- - README
53
- test_files: []
54
-
55
- rdoc_options: []
56
-
57
- extra_rdoc_files:
58
- - README
59
- executables: []
60
-
61
- extensions: []
8
+ autorequire: rfacebook
9
+ bindir: bin
10
+ cert_chain: []
62
11
 
63
- requirements:
64
- - Hpricot version >= 0.6.0 (has better handling of XML than previous versions)
65
- - Mocha version >= 0.5.3 (used for unit testing of the Gem and Rails Plugin)
12
+ date: 2008-01-08 00:00:00 -05:00
13
+ default_executable:
66
14
  dependencies:
67
15
  - !ruby/object:Gem::Dependency
68
16
  name: hpricot
69
17
  version_requirement:
70
- version_requirements: !ruby/object:Gem::Version::Requirement
18
+ version_requirements: !ruby/object:Gem::Requirement
71
19
  requirements:
72
20
  - - ">="
73
21
  - !ruby/object:Gem::Version
@@ -76,9 +24,56 @@ dependencies:
76
24
  - !ruby/object:Gem::Dependency
77
25
  name: mocha
78
26
  version_requirement:
79
- version_requirements: !ruby/object:Gem::Version::Requirement
27
+ version_requirements: !ruby/object:Gem::Requirement
80
28
  requirements:
81
29
  - - ">="
82
30
  - !ruby/object:Gem::Version
83
31
  version: 0.5.3
84
32
  version:
33
+ description:
34
+ email: matt@livelearncode.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ files:
42
+ - lib/facebook_desktop_session.rb
43
+ - lib/facebook_session.rb
44
+ - lib/facebook_web_session.rb
45
+ - lib/facepricot.rb
46
+ - lib/rfacebook.rb
47
+ - README
48
+ has_rdoc: true
49
+ homepage: http://www.livelearncode.com/
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements:
68
+ - Hpricot version >= 0.6.0 (has better handling of XML than previous versions)
69
+ - Mocha version >= 0.5.3 (used for unit testing of the Gem and Rails Plugin)
70
+ rubyforge_project: rfacebook
71
+ rubygems_version: 1.0.1
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: A Ruby interface to the Facebook API v1.0+. Works with RFacebook on Rails plugin (see http://rfacebook.rubyforge.org).
75
+ test_files:
76
+ - test/facebook_desktop_session_test.rb
77
+ - test/facebook_session_test_methods.rb
78
+ - test/facebook_web_session_test.rb
79
+ - test/test_helper.rb
@@ -1,10 +0,0 @@
1
- # This file is deprecated, but remains here for backward compatibility
2
- require "rfacebook_on_rails/controller_extensions"
3
- module RFacebook
4
- module RailsControllerExtensions
5
- def self.included(base)
6
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK DEPRECATION NOTICE: direct use of RFacebook::RailsControllerExtensions (from facebook_rails_controller_extensions.rb) is deprecated, use the RFacebook on Rails plugin instead (http://rfacebook.rubyforge.org)"
7
- base.send(:include, RFacebook::Rails::ControllerExtensions)
8
- end
9
- end
10
- end
@@ -1,543 +0,0 @@
1
- # Copyright (c) 2007, Matt Pizzimenti (www.livelearncode.com)
2
- # All rights reserved.
3
- #
4
- # Redistribution and use in source and binary forms, with or without modification,
5
- # are permitted provided that the following conditions are met:
6
- #
7
- # Redistributions of source code must retain the above copyright notice,
8
- # this list of conditions and the following disclaimer.
9
- #
10
- # Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- #
14
- # Neither the name of the original author nor the names of contributors
15
- # may be used to endorse or promote products derived from this software
16
- # without specific prior written permission.
17
- #
18
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
- # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
- # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
- # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
- # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
- # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
- #
29
-
30
- require "facebook_web_session"
31
- require "rfacebook_on_rails/status_manager"
32
-
33
- module RFacebook
34
- module Rails
35
- module ControllerExtensions
36
-
37
- # :section: StandardErrors
38
-
39
- class APIKeyNeededStandardError < StandardError; end # :nodoc:
40
- class APISecretNeededStandardError < StandardError; end # :nodoc:
41
- class APICanvasPathNeededStandardError < StandardError; end # :nodoc:
42
- class APICallbackNeededStandardError < StandardError; end # :nodoc:
43
- class APIFinisherNeededStandardError < StandardError; end # :nodoc:
44
-
45
- # :section: Template Methods (must be implemented by concrete subclass)
46
-
47
- def facebook_api_key
48
- raise APIKeyNeededStandardError, "RFACEBOOK ERROR: when using the RFacebook on Rails plugin, please be sure that you have a facebook.yml file with 'key' defined"
49
- end
50
-
51
- def facebook_api_secret
52
- raise APISecretNeededStandardError, "RFACEBOOK ERROR: when using the RFacebook on Rails plugin, please be sure that you have a facebook.yml file with 'secret' defined"
53
- end
54
-
55
- def facebook_canvas_path
56
- raise APICanvasPathNeededStandardError, "RFACEBOOK ERROR: when using the RFacebook on Rails plugin, please be sure that you have a facebook.yml file with 'canvas_path' defined"
57
- end
58
-
59
- def facebook_callback_path
60
- raise APICallbackNeededStandardError, "RFACEBOOK ERROR: when using the RFacebook on Rails plugin, please be sure that you have a facebook.yml file with 'callback_path' defined"
61
- end
62
-
63
- def finish_facebook_login
64
- raise APIFinisherNeededStandardError, "RFACEBOOK ERROR: in an external Facebook application, you should define finish_facebook_login in your controller (often this is used to redirect to a 'login success' page, but it can also simply do nothing)"
65
- end
66
-
67
-
68
-
69
- # :section: Special Variables
70
-
71
- # Function: fbparams
72
- # Accessor for all params beginning with "fb_sig_"
73
- #
74
- # Returns:
75
- # A Hash of those parameters, with the fb_sig_ stripped from the keys
76
- def fbparams
77
-
78
- # try to get fbparams from the params hash
79
- if (!@fbparams || @fbparams.length <= 0)
80
- dup_params = (self.params || {}).dup
81
- @fbparams = rfacebook_session_holder.get_fb_sig_params(dup_params)
82
- end
83
-
84
- # else, try to get fbparams from the cookies hash
85
- if (!@fbparams || @fbparams.length <= 0)
86
- dup_cookies = (self.cookies || {}).dup
87
- @fbparams = rfacebook_session_holder.get_fb_sig_params(dup_cookies)
88
- end
89
-
90
- # finally, if we are an iframe app we may have saved the fbparams
91
- # to the session for safekeeping
92
- if (!@fbparams || @fbparams.length <= 0)
93
- @fbparams = session[:rfacebook_session_iframe_fbparams] || {}
94
- end
95
-
96
- return @fbparams
97
-
98
- end
99
-
100
- # Function: fbsession
101
- # Accessor for a FacebookWebSession that has been activated, either in the Canvas
102
- # (via fb_sig parameters) or in an external app (via an auth_token).
103
- #
104
- # Returns:
105
- # A FacebookWebSession. You may want to check is_valid? before using it.
106
- def fbsession
107
-
108
- # do a check to ensure that we nil out the rfacebook_session in case there is a new user visiting
109
- if session[:rfacebook_session] and fbparams["session_key"] and session[:rfacebook_session].session_key != fbparams["session_key"]
110
- session[:rfacebook_session] = nil
111
- end
112
-
113
- # if we are in the canvas, iframe, or mock ajax, we should be able to activate the session here
114
- if (!rfacebook_session_holder.is_valid? and (in_facebook_canvas? or in_facebook_frame? or in_mock_ajax?))
115
-
116
- # then try to activate it somehow (or retrieve from previous state)
117
- # these might be nil
118
- facebookUid = fbparams["user"]
119
- facebookSessionKey = fbparams["session_key"]
120
- expirationTime = fbparams["expires"]
121
-
122
- if (facebookUid and facebookSessionKey and expirationTime)
123
- # we have the user id and key from the fb_sig_ params, activate the session
124
- rfacebook_session_holder.activate_with_previous_session(facebookSessionKey, facebookUid, expirationTime)
125
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Activated session from inside the canvas (user=#{facebookUid}, session_key=#{facebookSessionKey}, expires=#{expirationTime})"
126
- else
127
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK WARNING: Tried to get a valid Facebook session from POST params, but failed"
128
- end
129
-
130
- end
131
-
132
- # if we still don't have a session, check the Rails session
133
- # (used for external and iframe apps when fb_sig POST params weren't present)
134
- if (!rfacebook_session_holder.is_valid? and session[:rfacebook_session] and session[:rfacebook_session].is_valid?)
135
-
136
- # grab saved Facebook session from Rails session
137
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: grabbing Facebook session from Rails session"
138
- @rfacebook_session_holder = session[:rfacebook_session]
139
- @rfacebook_session_holder.logger = RAILS_DEFAULT_LOGGER
140
-
141
- end
142
-
143
- # if all went well, we should definitely have a valid Facebook session object
144
- return rfacebook_session_holder
145
-
146
- end
147
-
148
- # :section: Helpful Methods
149
-
150
- # DEPRECATED
151
- def facebook_redirect_to(url) # :nodoc:
152
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK DEPRECATION NOTICE: facebook_redirect_to is deprecated in RFacebook. Instead, you can use redirect_to like any Rails app."
153
- if in_facebook_canvas?
154
- render :text => "<fb:redirect url=\"#{url}\" />"
155
- elsif url =~ /^https?:\/\/([^\/]*\.)?facebook\.com(:\d+)?/i
156
- render :text => "<script type=\"text/javascript\">\ntop.location.href = \"#{url}\";\n</script>";
157
- else
158
- redirect_to url
159
- end
160
- end
161
-
162
- def in_facebook_canvas?
163
- in_canvas = params["fb_sig_in_canvas"] || fbparams["in_canvas"]
164
- return (in_canvas == "1" || in_canvas == true)
165
- end
166
-
167
- def in_facebook_frame?
168
- in_iframe = params["fb_sig_in_iframe"] || fbparams["in_iframe"]
169
- return (in_iframe == "1" || in_iframe == true)
170
- end
171
-
172
- def in_mock_ajax?
173
- is_mockajax = params["fb_sig_is_mockajax"]
174
- return (is_mockajax == "1" || is_mockajax == true || params["fb_mockajax_url"] != nil)
175
- end
176
-
177
- def in_ajax?
178
- is_ajax = params["fb_sig_is_ajax"]
179
- return (is_ajax == "1" || is_ajax == true)
180
- end
181
-
182
- def in_external_app?
183
- # FIXME: once you click away in an iframe app, you are considered to be an external app
184
- # TODO: read up on the hacks for avoiding nested iframes
185
- return (params["fb_sig"] == nil and !in_facebook_frame?)
186
- end
187
-
188
- def added_facebook_application?
189
- addedApp = params["fb_sig_added"] || fbparams["added"]
190
- return (addedApp == "1" || addedApp == true)
191
- end
192
-
193
- def facebook_platform_signature_verified?
194
- return (fbparams and fbparams.size > 0)
195
- end
196
-
197
- # TODO: define something along the lines of is_logged_in_to_facebook? that returns fbsession.is_ready? perhaps
198
-
199
- ################################################################################################
200
- ################################################################################################
201
- # :section: before_filters
202
- ################################################################################################
203
-
204
- def handle_facebook_login
205
-
206
- # we only do this when we don't have the fb_sig to give us a session
207
- # in these cases, we always check to see if we got an auth_token
208
- # from redirecting to login to facebook
209
- if (!facebook_platform_signature_verified? and params["auth_token"])
210
-
211
- # activate with the auth token
212
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: attempting to create a new Facebook session from auth_token"
213
- staleToken = false
214
- begin
215
-
216
- # try to use the auth_token
217
- rfacebook_session_holder.activate_with_token(params["auth_token"])
218
-
219
- rescue StandardError => e
220
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Tried to use a stale auth_token"
221
- staleToken = true
222
- end
223
-
224
- # template method call upon success
225
- if (rfacebook_session_holder.is_valid? and !staleToken)
226
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Login was successful, calling finish_facebook_login"
227
- if in_external_app?
228
- finish_facebook_login
229
- end
230
- end
231
-
232
- # warning logs
233
- if !rfacebook_session_holder.is_valid?
234
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: Facebook session could not be activated with auth_token"
235
- end
236
-
237
- end
238
-
239
- return true
240
- end
241
-
242
- def require_facebook_login
243
-
244
- # now finish it off depending on whether we are in canvas, iframe, or external app
245
- if !performed?
246
-
247
- # try to get the session
248
- sess = fbsession
249
-
250
- # handle invalid sessions by forcing the user to log in
251
- if !sess.is_valid?
252
-
253
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Session is not valid"
254
-
255
- if in_external_app?
256
-
257
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Redirecting to login for external app"
258
- redirect_to sess.get_login_url
259
- return false
260
-
261
- elsif (!fbparams or fbparams.size == 0)
262
-
263
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK WARNING: Failed to activate due to a bad API key or API secret"
264
- render :text => facebook_debug_panel
265
- return false
266
-
267
- else
268
-
269
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Redirecting to login for canvas app"
270
- redirect_to sess.get_login_url(:canvas=>true)
271
- return false
272
-
273
- end
274
- end
275
- end
276
-
277
- return true
278
- end
279
-
280
- def require_facebook_install
281
- if (in_facebook_canvas? or in_facebook_frame?)
282
- if (!fbsession.is_valid? or !added_facebook_application?)
283
- redirect_to fbsession.get_install_url
284
- return false
285
- end
286
- else
287
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: require_facebook_install is not intended for external applications, using require_facebook_login instead"
288
- return require_facebook_login
289
- end
290
- return true
291
- end
292
-
293
- # TODO: check this out
294
- # def require_facebook_install
295
- # if in_facebook_frame? and not added_facebook_application?
296
- # render :text => %Q(<script language="javascript">top.location.href="#{fbsession.get_install_url}&next=#{request.path.gsub(/#{facebook_callback_path}/, "")}"</script>)
297
- # end
298
- # end
299
-
300
- ################################################################################################
301
- ################################################################################################
302
- # :section: Facebook Debug Panel
303
- ################################################################################################
304
-
305
- def render_with_facebook_debug_panel(options={})
306
- begin
307
- renderedOutput = render_to_string(options)
308
- rescue Exception => e
309
- renderedOutput = facebook_canvas_backtrace(e)
310
- end
311
- render_text "#{facebook_debug_panel}#{renderedOutput}"
312
- end
313
-
314
- def facebook_debug_panel(options={})
315
- template = File.read(File.dirname(__FILE__) + "/templates/debug_panel.rhtml")
316
- return ERB.new(template).result(Proc.new{})
317
- end
318
-
319
- # TODO: implement this in version 1.0
320
- # def rescue_action(exception)
321
- # # TODO: for security, we only do this in development in the canvas
322
- # if (in_facebook_canvas? and RAILS_ENV == "development")
323
- # render_text "#{facebook_debug_panel}#{facebook_canvas_backtrace(exception)}"
324
- # else
325
- # # otherwise, do the default
326
- # super
327
- # end
328
- # end
329
-
330
- def facebook_canvas_backtrace(exception)
331
-
332
- # TODO: potentially integrate features from Evan Weaver's facebook_exceptions
333
- rfacebookBacktraceLines = []
334
- exception.backtrace.each do |line|
335
-
336
- # escape HTML
337
- cleanLine = line.gsub(RAILS_ROOT, "").gsub("<", "&lt;").gsub(">", "&gt;")
338
-
339
- # split up these lines by carriage return
340
- pieces = cleanLine.split("\n")
341
- if (pieces and pieces.size> 0)
342
- pieces.each do |piece|
343
- if matches = /.*[\/\\]+((.*)\:([0-9]+)\:\s*in\s*\`(.*)\')/.match(piece)
344
- # for each parsed line, add to the array for later rendering in the template
345
- rfacebookBacktraceLines << {
346
- :filename => matches[2],
347
- :line => matches[3],
348
- :method => matches[4],
349
- :rawsummary => piece,
350
- }
351
- end
352
- end
353
- end
354
- end
355
-
356
- # render to the ERB template
357
- template = File.read(File.dirname(__FILE__) + "/templates/exception_backtrace.rhtml")
358
- return ERB.new(template).result(Proc.new{})
359
-
360
- end
361
-
362
- def facebook_status_manager # :nodoc:
363
- checks = [
364
- SessionStatusCheck.new(self),
365
- (FacebookParamsStatusCheck.new(self) unless (!in_facebook_canvas? and !in_facebook_frame?)),
366
- InCanvasStatusCheck.new(self),
367
- InFrameStatusCheck.new(self),
368
- (CanvasPathStatusCheck.new(self) unless (!in_facebook_canvas? or !in_facebook_frame?)),
369
- (CallbackPathStatusCheck.new(self) unless (!in_facebook_canvas? or !in_facebook_frame?)),
370
- (FinishFacebookLoginStatusCheck.new(self) unless (in_facebook_canvas? or in_facebook_frame?)),
371
- APIKeyStatusCheck.new(self),
372
- APISecretStatusCheck.new(self)
373
- ].compact
374
- return StatusManager.new(checks)
375
- end
376
-
377
- ################################################################################################
378
- ################################################################################################
379
- # :section: RFacebook Private Methods
380
- ################################################################################################
381
-
382
- def rfacebook_session_holder # :nodoc:
383
-
384
- if (@rfacebook_session_holder == nil)
385
- @rfacebook_session_holder = FacebookWebSession.new(facebook_api_key, facebook_api_secret)
386
- @rfacebook_session_holder.logger = RAILS_DEFAULT_LOGGER
387
- end
388
-
389
- return @rfacebook_session_holder
390
-
391
- end
392
-
393
- def rfacebook_persist_session_to_rails # :nodoc:
394
- if (!in_facebook_canvas? and rfacebook_session_holder.is_valid?)
395
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: persisting Facebook session information into Rails session"
396
- session[:rfacebook_session] = @rfacebook_session_holder.dup # TODO: do we need dup here anymore?
397
- if in_facebook_frame?
398
- # we need iframe apps to remember they are iframe apps
399
- session[:rfacebook_session_iframe_fbparams] = fbparams
400
- end
401
- end
402
- end
403
-
404
-
405
- ################################################################################################
406
- ################################################################################################
407
- # :section: URL Management
408
- ################################################################################################
409
-
410
- def url_for__RFACEBOOK(options={}, *parameters) # :nodoc:
411
-
412
- # fix problems that some Rails installations had with sending nil options
413
- options ||= {}
414
-
415
- # use special URL rewriting when inside the canvas
416
- # setting the full_callback option to true will override this
417
- # and force usage of regular Rails rewriting
418
- if options.is_a? Hash
419
- if options[:mock_ajax]
420
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK DEPRECATION WARNING: don't use :mock_ajax => true in your link_to anymore. Instead, use :full_callback => true."
421
- end
422
- fullCallback = (options[:full_callback] == true) ? true : false
423
- options.delete(:full_callback)
424
- end
425
-
426
- if ((in_facebook_canvas? or in_mock_ajax? or in_ajax?) and !fullCallback) #TODO: do something separate for in_facebook_frame?
427
-
428
- if options.is_a? Hash
429
- options[:only_path] = true if options[:only_path].nil?
430
- end
431
-
432
- # try to get a regular URL
433
- path = url_for__ALIASED(options, *parameters)
434
-
435
- # replace anything that references the callback with the
436
- # Facebook canvas equivalent (apps.facebook.com/*)
437
- if path.starts_with?(self.facebook_callback_path)
438
- path.sub!(self.facebook_callback_path, self.facebook_canvas_path)
439
- path = "http://apps.facebook.com#{path}"
440
- elsif "#{path}/".starts_with?(self.facebook_callback_path)
441
- path.sub!(self.facebook_callback_path.chop, self.facebook_canvas_path.chop)
442
- path = "http://apps.facebook.com#{path}"
443
- elsif (path.starts_with?("http://www.facebook.com") or path.starts_with?("https://www.facebook.com"))
444
- # be sure that URLs that go to some other Facebook service redirect back to the canvas
445
- if path.include?("?")
446
- path = "#{path}&canvas=true"
447
- else
448
- path = "#{path}?canvas=true"
449
- end
450
- elsif (!path.starts_with?("http://") and !path.starts_with?("https://"))
451
- # default to a full URL (will link externally)
452
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to get canvas-friendly URL ("+path+") for ["+options.inspect+"], creating an external URL instead"
453
- path = "#{request.protocol}#{request.host}:#{request.port}#{path}"
454
- end
455
-
456
- # full callback rewriting
457
- elsif fullCallback
458
- options[:only_path] = true
459
- path = "#{request.protocol}#{request.host}:#{request.port}#{url_for__ALIASED(options, *parameters)}"
460
-
461
- # regular Rails rewriting
462
- else
463
- path = url_for__ALIASED(options, *parameters)
464
- end
465
-
466
- return path
467
- end
468
-
469
- def redirect_to__RFACEBOOK(options = {}, *parameters) # :nodoc:
470
-
471
- # get the url
472
- redirectUrl = url_for(options, *parameters)
473
-
474
- # canvas redirect
475
- if in_facebook_canvas?
476
-
477
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Canvas redirect to #{redirectUrl}"
478
- render :text => "<fb:redirect url=\"#{redirectUrl}\" />"
479
-
480
- # iframe redirect
481
- elsif redirectUrl.match(/^https?:\/\/([^\/]*\.)?facebook\.com(:\d+)?/i)
482
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: iframe redirect to #{redirectUrl}"
483
- render :text => %Q(<script type="text/javascript">\ntop.location.href='#{redirectUrl}';\n</script>)
484
-
485
- # otherwise, we only need to do a standard redirect
486
- else
487
- RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: Regular redirect_to"
488
- redirect_to__ALIASED(options, *parameters)
489
- end
490
- end
491
-
492
-
493
- ################################################################################################
494
- ################################################################################################
495
- # :section: Extension Helpers
496
- ################################################################################################
497
-
498
- CLASSES_EXTENDED = [] # :nodoc:
499
-
500
- def self.included(base) # :nodoc:
501
-
502
- # check for a double include
503
- doubleInclude = false
504
- CLASSES_EXTENDED.each do |klass|
505
- if base.allocate.is_a?(klass)
506
- doubleInclude = true
507
- end
508
- end
509
-
510
- if doubleInclude
511
- RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: detected double-include of RFacebook controller extensions. Please see instructions for RFacebook on Rails plugin usage (http://rfacebook.rubyforge.org). You may be including the deprecated RFacebook::RailsControllerExtensions in addition to the plugin."
512
-
513
- else
514
-
515
- # keep track that we have already extended this class
516
- CLASSES_EXTENDED << base
517
-
518
- # we need to use an eval since we will be overriding ActionController::Base methods
519
- # and we need to be able to call the originals
520
- base.class_eval '
521
- alias_method(:url_for__ALIASED, :url_for)
522
- alias_method(:url_for, :url_for__RFACEBOOK)
523
-
524
- alias_method(:redirect_to__ALIASED, :redirect_to)
525
- alias_method(:redirect_to, :redirect_to__RFACEBOOK)
526
- '
527
-
528
- # ensure that every action handles facebook login
529
- base.before_filter(:handle_facebook_login)
530
-
531
- # ensure that we persist the Facebook session into the Rails session (if possible)
532
- base.after_filter(:rfacebook_persist_session_to_rails)
533
-
534
- # fix third party cookies in IE
535
- base.before_filter{ |c| c.headers['P3P'] = %|CP="NOI DSP COR NID ADMa OPTa OUR NOR"| }
536
-
537
- end
538
- end
539
-
540
-
541
- end
542
- end
543
- end