rfacebook 0.9.7 → 0.9.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README +12 -3
- data/lib/facebook_desktop_session.rb +77 -116
- data/lib/facebook_session.rb +282 -334
- data/lib/facebook_web_session.rb +28 -103
- data/lib/facepricot.rb +20 -22
- data/lib/rfacebook.rb +2 -0
- data/{lib/rfacebook_on_rails/view_extensions.rb → test/facebook_desktop_session_test.rb} +23 -39
- data/test/facebook_session_test_methods.rb +106 -0
- data/test/facebook_web_session_test.rb +48 -0
- data/test/test_helper.rb +216 -0
- metadata +55 -60
- data/lib/facebook_rails_controller_extensions.rb +0 -10
- data/lib/rfacebook_on_rails/controller_extensions.rb +0 -543
- data/lib/rfacebook_on_rails/model_extensions.rb +0 -203
- data/lib/rfacebook_on_rails/plugin/Rakefile.rb +0 -1
- data/lib/rfacebook_on_rails/plugin/init.rb +0 -139
- data/lib/rfacebook_on_rails/plugin/install.rb +0 -1
- data/lib/rfacebook_on_rails/plugin/rake.rb +0 -141
- data/lib/rfacebook_on_rails/plugin/uninstall.rb +0 -1
- data/lib/rfacebook_on_rails/session_extensions.rb +0 -202
- data/lib/rfacebook_on_rails/status_manager.rb +0 -309
- data/lib/rfacebook_on_rails/templates/debug_panel.rhtml +0 -220
- data/lib/rfacebook_on_rails/templates/exception_backtrace.rhtml +0 -97
@@ -1,203 +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
|
-
|
31
|
-
module RFacebook
|
32
|
-
module Rails
|
33
|
-
module ModelExtensions
|
34
|
-
|
35
|
-
##################################################################
|
36
|
-
##################################################################
|
37
|
-
# :section: Errors
|
38
|
-
##################################################################
|
39
|
-
|
40
|
-
class APIKeyNeededStandardError < StandardError; end # :nodoc:
|
41
|
-
class APISecretNeededStandardError < StandardError; end # :nodoc:
|
42
|
-
|
43
|
-
##################################################################
|
44
|
-
##################################################################
|
45
|
-
# :section: Template Methods (must be implemented by concrete subclass)
|
46
|
-
##################################################################
|
47
|
-
|
48
|
-
def facebook_api_key
|
49
|
-
raise APIKeyNeededStandardError, "RFACEBOOK ERROR: when using the RFacebook on Rails plugin, please be sure that you have a facebook.yml file with 'key' defined"
|
50
|
-
end
|
51
|
-
|
52
|
-
def facebook_api_secret
|
53
|
-
raise APISecretNeededStandardError, "RFACEBOOK ERROR: when using the RFacebook on Rails plugin, please be sure that you have a facebook.yml file with 'secret' defined"
|
54
|
-
end
|
55
|
-
|
56
|
-
# :section: ActsAs method mixing
|
57
|
-
|
58
|
-
def self.included(base) # :nodoc:
|
59
|
-
base.extend ActsAsMethods
|
60
|
-
end
|
61
|
-
|
62
|
-
module ActsAsMethods # :nodoc:all
|
63
|
-
def acts_as_facebook_user
|
64
|
-
include RFacebook::Rails::ModelExtensions::ActsAsFacebookUser::InstanceMethods
|
65
|
-
extend RFacebook::Rails::ModelExtensions::ActsAsFacebookUser::ClassMethods
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
##################################################################
|
71
|
-
##################################################################
|
72
|
-
# :section: Acts As Facebook User
|
73
|
-
##################################################################
|
74
|
-
module ActsAsFacebookUser
|
75
|
-
|
76
|
-
ACTORS = [] # holds a reference to all classes that have ActsAsFacebookUser injected
|
77
|
-
|
78
|
-
FIELDS = [
|
79
|
-
"about_me",
|
80
|
-
"activities",
|
81
|
-
"affiliations",
|
82
|
-
"birthday",
|
83
|
-
"books",
|
84
|
-
"current_location",
|
85
|
-
"education_history",
|
86
|
-
"name",
|
87
|
-
"first_name",
|
88
|
-
"last_name",
|
89
|
-
"hometown_location",
|
90
|
-
"hs_info",
|
91
|
-
"interests",
|
92
|
-
"relationship_status",
|
93
|
-
"meeting_for",
|
94
|
-
"meeting_sex",
|
95
|
-
"movies",
|
96
|
-
"music",
|
97
|
-
"notes_count",
|
98
|
-
"political",
|
99
|
-
"profile_update_time",
|
100
|
-
"quotes",
|
101
|
-
"religion",
|
102
|
-
"sex",
|
103
|
-
"significant_other_id",
|
104
|
-
"status",
|
105
|
-
"timezone",
|
106
|
-
"tv",
|
107
|
-
"wall_count",
|
108
|
-
"work_history",
|
109
|
-
"pic",
|
110
|
-
"pic_big",
|
111
|
-
"pic_small",
|
112
|
-
"pic_square"
|
113
|
-
]
|
114
|
-
|
115
|
-
|
116
|
-
######################
|
117
|
-
module ClassMethods
|
118
|
-
|
119
|
-
def find_or_create_by_facebook_session(sess)
|
120
|
-
if sess.is_ready?
|
121
|
-
|
122
|
-
# try to find, else create
|
123
|
-
instance = find_by_facebook_uid(sess.session_user_id)
|
124
|
-
if !instance
|
125
|
-
instance = self.new
|
126
|
-
end
|
127
|
-
|
128
|
-
# update session info
|
129
|
-
instance.facebook_session = sess
|
130
|
-
|
131
|
-
# update (or create) the object and return it
|
132
|
-
if !instance.save
|
133
|
-
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to update or create the Facebook user object in the database"
|
134
|
-
return nil
|
135
|
-
end
|
136
|
-
return instance
|
137
|
-
|
138
|
-
else
|
139
|
-
RAILS_DEFAULT_LOGGER.info "** RFACEBOOK WARNING: tried to use an inactive session for acts_as_facebook_user (in find_or_create_by_facebook_session)"
|
140
|
-
return nil
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
######################
|
148
|
-
module InstanceMethods
|
149
|
-
|
150
|
-
# TODO: to help developers stay within the TOS, we should have a method in here like "with_facebook_scope(fbsession){...}"
|
151
|
-
|
152
|
-
def facebook_session
|
153
|
-
if !@facebook_session
|
154
|
-
@facebook_session = FacebookWebSession.new(self.facebook_api_key, self.facebook_api_secret)
|
155
|
-
begin
|
156
|
-
@facebook_session.activate_with_previous_session(self.facebook_session_key, self.facebook_uid)
|
157
|
-
rescue
|
158
|
-
# not a valid facebook session, should we nil it out?
|
159
|
-
end
|
160
|
-
end
|
161
|
-
return @facebook_session
|
162
|
-
end
|
163
|
-
|
164
|
-
def facebook_session=(sess)
|
165
|
-
@facebook_session = sess
|
166
|
-
self.facebook_session_key = @facebook_session.session_key
|
167
|
-
self.facebook_uid = @facebook_session.session_user_id
|
168
|
-
end
|
169
|
-
|
170
|
-
def has_infinite_session_key?
|
171
|
-
# TODO: this check should really look at expires
|
172
|
-
return self.facebook_session_key != nil
|
173
|
-
end
|
174
|
-
|
175
|
-
def self.included(base) # :nodoc:
|
176
|
-
ActsAsFacebookUser::ACTORS << base
|
177
|
-
ActsAsFacebookUser::FIELDS.each do |fieldname|
|
178
|
-
base.class_eval <<-EOF
|
179
|
-
|
180
|
-
def #{fieldname}
|
181
|
-
if facebook_session.is_ready?
|
182
|
-
return facebook_session.cached_users_getInfo(
|
183
|
-
:uids => [facebook_uid],
|
184
|
-
:fields => ActsAsFacebookUser::FIELDS).user.send(:#{fieldname})
|
185
|
-
else
|
186
|
-
return nil
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
EOF
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
|
-
##################################################################
|
198
|
-
##################################################################
|
199
|
-
|
200
|
-
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
# no rakefile yet
|
@@ -1,139 +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 "rfacebook_on_rails/view_extensions"
|
31
|
-
require "rfacebook_on_rails/controller_extensions"
|
32
|
-
require "rfacebook_on_rails/model_extensions"
|
33
|
-
require "rfacebook_on_rails/session_extensions"
|
34
|
-
|
35
|
-
module RFacebook::Rails::Plugin
|
36
|
-
|
37
|
-
module ControllerExtensions
|
38
|
-
def facebook_api_key
|
39
|
-
# TODO: pull these overrides up into the original module, and make a FACEBOOK global in the backwards-compatibility file
|
40
|
-
FACEBOOK["key"] || super
|
41
|
-
end
|
42
|
-
def facebook_api_secret
|
43
|
-
FACEBOOK["secret"] || super
|
44
|
-
end
|
45
|
-
def facebook_canvas_path
|
46
|
-
FACEBOOK["canvas_path"] || super
|
47
|
-
end
|
48
|
-
def facebook_callback_path
|
49
|
-
FACEBOOK["callback_path"] || super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module ModelExtensions
|
54
|
-
def facebook_api_key
|
55
|
-
FACEBOOK["key"] || super
|
56
|
-
end
|
57
|
-
def facebook_api_secret
|
58
|
-
FACEBOOK["secret"] || super
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
module ViewExtensions
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
# inject methods to Rails MVC classes
|
68
|
-
ActionView::Base.send(:include, RFacebook::Rails::ViewExtensions)
|
69
|
-
ActionView::Base.send(:include, RFacebook::Rails::Plugin::ViewExtensions)
|
70
|
-
|
71
|
-
ActionController::Base.send(:include, RFacebook::Rails::ControllerExtensions)
|
72
|
-
ActionController::Base.send(:include, RFacebook::Rails::Plugin::ControllerExtensions)
|
73
|
-
|
74
|
-
ActiveRecord::Base.send(:include, RFacebook::Rails::ModelExtensions)
|
75
|
-
ActiveRecord::Base.send(:include, RFacebook::Rails::Plugin::ModelExtensions)
|
76
|
-
|
77
|
-
# inject methods to Rails session management classes
|
78
|
-
CGI::Session.send(:include, RFacebook::Rails::SessionExtensions)
|
79
|
-
|
80
|
-
# TODO: document SessionStoreExtensions as API so that anyone can patch their own custom session container in addition to these
|
81
|
-
CGI::Session::PStore.send(:include, RFacebook::Rails::SessionStoreExtensions)
|
82
|
-
CGI::Session::ActiveRecordStore.send(:include, RFacebook::Rails::SessionStoreExtensions)
|
83
|
-
CGI::Session::DRbStore.send(:include, RFacebook::Rails::SessionStoreExtensions)
|
84
|
-
CGI::Session::FileStore.send(:include, RFacebook::Rails::SessionStoreExtensions)
|
85
|
-
CGI::Session::MemoryStore.send(:include, RFacebook::Rails::SessionStoreExtensions)
|
86
|
-
begin
|
87
|
-
CGI::Session::MemCacheStore.send(:include, RFacebook::Rails::SessionStoreExtensions)
|
88
|
-
rescue
|
89
|
-
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: It looks like you don't have memcache-client, so MemCacheStore was not extended"
|
90
|
-
end
|
91
|
-
|
92
|
-
# load Facebook configuration file (credit: Evan Weaver)
|
93
|
-
begin
|
94
|
-
yamlFile = YAML.load_file("#{RAILS_ROOT}/config/facebook.yml")
|
95
|
-
rescue Exception => e
|
96
|
-
raise StandardError, "config/facebook.yml could not be loaded."
|
97
|
-
end
|
98
|
-
|
99
|
-
if yamlFile
|
100
|
-
if yamlFile[RAILS_ENV]
|
101
|
-
FACEBOOK = yamlFile[RAILS_ENV]
|
102
|
-
else
|
103
|
-
raise StandardError, "config/facebook.yml exists, but doesn't have a configuration for RAILS_ENV=#{RAILS_ENV}."
|
104
|
-
end
|
105
|
-
else
|
106
|
-
raise StandardError, "config/facebook.yml does not exist."
|
107
|
-
end
|
108
|
-
|
109
|
-
# parse for full URLs in facebook.yml (multiple people have made this mistake)
|
110
|
-
def ensureRelativePath(path)
|
111
|
-
if matchData = /(\w+)(\:\/\/)([\w0-9\.]+)([\:0-9]*)(.*)/.match(path)
|
112
|
-
relativePath = matchData.captures[4]
|
113
|
-
RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: It looks like you used a full URL (#{path}) in facebook.yml. RFacebook expected a relative path and has automatically converted this URL to #{relativePath}."
|
114
|
-
return relativePath
|
115
|
-
else
|
116
|
-
return path
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
FACEBOOK["canvas_path"] = ensureRelativePath(FACEBOOK["canvas_path"])
|
121
|
-
FACEBOOK["callback_path"] = ensureRelativePath(FACEBOOK["callback_path"])
|
122
|
-
|
123
|
-
# make sure the paths have leading and trailing slashes
|
124
|
-
def ensureLeadingAndTrailingSlashesForPath(path)
|
125
|
-
if (path and path.size>0)
|
126
|
-
if !path.starts_with?("/")
|
127
|
-
path = "/#{path}"
|
128
|
-
end
|
129
|
-
if !path.reverse.starts_with?("/")
|
130
|
-
path = "#{path}/"
|
131
|
-
end
|
132
|
-
return path.strip
|
133
|
-
else
|
134
|
-
return nil
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
FACEBOOK["canvas_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["canvas_path"])
|
139
|
-
FACEBOOK["callback_path"] = ensureLeadingAndTrailingSlashesForPath(FACEBOOK["callback_path"])
|
@@ -1 +0,0 @@
|
|
1
|
-
# no installation yet
|
@@ -1,141 +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
|
-
# Rake tasks modified from Evan Weaver's article
|
31
|
-
# http://blog.evanweaver.com/articles/2007/07/13/developing-a-facebook-app-locally
|
32
|
-
|
33
|
-
namespace "facebook" do
|
34
|
-
|
35
|
-
######################################################################################
|
36
|
-
######################################################################################
|
37
|
-
desc "Sets up the RFacebook Rails Plugin. Right now, this simply copies facebook.yml into your config directory."
|
38
|
-
task "setup" do
|
39
|
-
|
40
|
-
filename = "#{RAILS_ROOT}/config/facebook.yml"
|
41
|
-
puts "======================================================"
|
42
|
-
puts "Setting up RFacebook on Rails Plugin"
|
43
|
-
|
44
|
-
###### Install sample facebook.yml
|
45
|
-
file = File.new(filename, "w")
|
46
|
-
file <<
|
47
|
-
"
|
48
|
-
development:
|
49
|
-
key: YOUR_API_KEY_HERE
|
50
|
-
secret: YOUR_API_SECRET_HERE
|
51
|
-
canvas_path: /yourAppName/
|
52
|
-
callback_path: /path/to/your/callback/
|
53
|
-
tunnel:
|
54
|
-
username: yourLoginName
|
55
|
-
host: www.yourexternaldomain.com
|
56
|
-
port: 1234
|
57
|
-
local_port: 5678
|
58
|
-
|
59
|
-
test:
|
60
|
-
key: YOUR_API_KEY_HERE
|
61
|
-
secret: YOUR_API_SECRET_HERE
|
62
|
-
canvas_path: /yourAppName/
|
63
|
-
callback_path: /path/to/your/callback/
|
64
|
-
tunnel:
|
65
|
-
username: yourLoginName
|
66
|
-
host: www.yourexternaldomain.com
|
67
|
-
port: 1234
|
68
|
-
local_port: 5678
|
69
|
-
|
70
|
-
production:
|
71
|
-
key: YOUR_API_KEY_HERE
|
72
|
-
secret: YOUR_API_SECRET_HERE
|
73
|
-
canvas_path: /yourAppName/
|
74
|
-
callback_path: /path/to/your/callback/
|
75
|
-
tunnel:
|
76
|
-
username: yourLoginName
|
77
|
-
host: www.yourexternaldomain.com
|
78
|
-
port: 1234
|
79
|
-
local_port: 5678
|
80
|
-
"
|
81
|
-
file.close_write
|
82
|
-
puts " [1] Created config/facebook.yml <-- BE SURE TO CHANGE THE API KEY AND SECRET"
|
83
|
-
|
84
|
-
###### Finished
|
85
|
-
puts "Done."
|
86
|
-
puts "======================================================"
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
namespace "tunnel" do
|
91
|
-
|
92
|
-
######################################################################################
|
93
|
-
######################################################################################
|
94
|
-
desc "Start a reverse tunnel to develop from localhost. Please ensure that you have a properly configured config/facebook.yml file."
|
95
|
-
task "start" => "environment" do
|
96
|
-
|
97
|
-
remoteUsername = FACEBOOK['tunnel']['username']
|
98
|
-
remoteHost = FACEBOOK['tunnel']['host']
|
99
|
-
remotePort = FACEBOOK['tunnel']['port']
|
100
|
-
localPort = FACEBOOK['tunnel']['local_port']
|
101
|
-
|
102
|
-
puts "======================================================"
|
103
|
-
puts "Tunneling #{remoteHost}:#{remotePort} to 0.0.0.0:#{localPort}"
|
104
|
-
|
105
|
-
puts
|
106
|
-
puts "NOTES:"
|
107
|
-
puts "* ensure that you have Rails running on your local machine at port #{localPort}"
|
108
|
-
puts "* once logged in to the tunnel, you can visit http://#{remoteHost}:#{remotePort} to view your site"
|
109
|
-
puts "* use ctrl-c to quit the tunnel"
|
110
|
-
puts "* if you have problems creating the tunnel, you may need to add the following to /etc/ssh/sshd_config on your server:"
|
111
|
-
puts "
|
112
|
-
GatewayPorts clientspecified
|
113
|
-
|
114
|
-
"
|
115
|
-
puts "* if you have problems with #{remoteHost} timing out your ssh connection, add the following lines to your '~/.ssh/config' file:"
|
116
|
-
puts "
|
117
|
-
Host #{remoteHost}
|
118
|
-
ServerAliveInterval 120
|
119
|
-
|
120
|
-
"
|
121
|
-
puts "======================================================"
|
122
|
-
exec "ssh -nNT -g -R *:#{remotePort}:0.0.0.0:#{localPort} #{remoteUsername}@#{remoteHost}"
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
######################################################################################
|
128
|
-
######################################################################################
|
129
|
-
desc "Check if reverse tunnel is running"
|
130
|
-
task "status" => "environment" do
|
131
|
-
if `ssh #{FACEBOOK['tunnel']['username']}@#{FACEBOOK['tunnel']['host']} netstat -an |
|
132
|
-
egrep "tcp.*:#{FACEBOOK['tunnel']['port']}.*LISTEN" | wc`.to_i > 0
|
133
|
-
puts "Tunnel still running"
|
134
|
-
else
|
135
|
-
puts "Tunnel is down"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
end
|