refacebook 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +1 -2
- data/VERSION.yml +1 -1
- data/lib/refacebook/sinatra.rb +23 -1
- data/lib/refacebook.rb +32 -7
- metadata +1 -1
data/README.txt
CHANGED
@@ -8,8 +8,7 @@ ReFacebook is a facebook library and Sinatra extension.
|
|
8
8
|
|
9
9
|
== TODO:
|
10
10
|
|
11
|
-
* Need to
|
12
|
-
* Need helpers to make life easier.
|
11
|
+
* Need more helpers to make life easier.
|
13
12
|
* Have a better example application with fbml, api, and all that good stuff.
|
14
13
|
* Test with ruby 1.9, remove json dep if 1.9 since json is included.
|
15
14
|
|
data/VERSION.yml
CHANGED
data/lib/refacebook/sinatra.rb
CHANGED
@@ -3,22 +3,44 @@ require 'refacebook'
|
|
3
3
|
|
4
4
|
module Sinatra
|
5
5
|
module ReFacebookHelper
|
6
|
+
# If in the facebook canvas returns true
|
6
7
|
def in_canvas?
|
7
8
|
params["fb_sig_in_canvas"].eql? "1"
|
8
9
|
end
|
9
10
|
|
10
|
-
# Return a url
|
11
|
+
# Return a concatenated url with the canvas url and the path
|
11
12
|
def link_from_canvas(path="")
|
12
13
|
path = (path.empty? || path.eql?("/")) ? "" : "/#{path}"
|
13
14
|
"#{options.canvas_url}#{path}"
|
14
15
|
end
|
15
16
|
|
17
|
+
# Since redirect doesn't work in the canvas since it relies
|
18
|
+
# on JavaScript Location field. This is a replacement which
|
19
|
+
# uses fbml as a means to redirect to the given url.
|
16
20
|
def fbml_redirect(url)
|
17
21
|
halt "<fb:redirect url=\"#{url}\" />"
|
18
22
|
end
|
19
23
|
end
|
20
24
|
|
21
25
|
module ReFacebookRegister
|
26
|
+
# ReFacebook configuration done at the beginning of a Sinatra file.
|
27
|
+
#
|
28
|
+
# An exaple:
|
29
|
+
# <pre><code>
|
30
|
+
# require_facebook(:api_key =>'MY_API_KEY',
|
31
|
+
# :secret_key => 'MY_SECRET_KEY',
|
32
|
+
# :canvas_url => 'http://apps.facebook.com/canvas-page',
|
33
|
+
# :require_login => true,
|
34
|
+
# :store => store)
|
35
|
+
# </code></pre>
|
36
|
+
#
|
37
|
+
# :api_key - Your application's Facebook API key.
|
38
|
+
# :secret_key - Your application's Facebook Secret key.
|
39
|
+
# :canvas_url - The full path to your canvas page.
|
40
|
+
# :require_login - If this is set to true then the user is redirected to
|
41
|
+
# the login page where she needs to authenticate.
|
42
|
+
# :store - This currently uses memcache-client as the session store since
|
43
|
+
# Rack doesn't currently have non cookie based session stores.
|
22
44
|
def require_facebook *args
|
23
45
|
settings = args[0]
|
24
46
|
|
data/lib/refacebook.rb
CHANGED
@@ -3,17 +3,19 @@ require 'uri'
|
|
3
3
|
require 'md5'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
# ReFacebook the main store for a facebook session.
|
7
6
|
module ReFacebook
|
8
7
|
APIRestServer = "http://api.facebook.com/restserver.php"
|
9
8
|
LoginUrl = "http://www.facebook.com/login.php"
|
10
9
|
|
10
|
+
# ReFacebook::Session is the main store for a facebook session.
|
11
11
|
class Session
|
12
12
|
attr_reader :api_key, :secret, :api
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
attr_reader :user, :friends, :session_key,
|
15
|
+
:expires, :time, :profile_update_time
|
16
16
|
|
17
|
+
# Create a new session.
|
18
|
+
# api_key and secret are the Facebook API and Secret keys.
|
17
19
|
def initialize api_key, secret
|
18
20
|
@api_key = api_key
|
19
21
|
@secret = secret
|
@@ -24,6 +26,8 @@ module ReFacebook
|
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
29
|
+
# Update the session variables based on the values that
|
30
|
+
# are sent in from the facebook parameters.
|
27
31
|
def update_session_params params
|
28
32
|
@user = params['fb_sig_user']
|
29
33
|
@friends = params['fb_sig_friends'].split(',')
|
@@ -36,6 +40,10 @@ module ReFacebook
|
|
36
40
|
@profile_update_time = params['fb_sig_profile_update_time']
|
37
41
|
end
|
38
42
|
|
43
|
+
# Generate a redirect path to the default login page.
|
44
|
+
# :next - The page to redirect to after login.
|
45
|
+
# Optional:
|
46
|
+
# :canvas - If this is true redirects to the canvas page.
|
39
47
|
def get_login_url *args
|
40
48
|
params = {}
|
41
49
|
params['v'] = '1.0'
|
@@ -49,21 +57,38 @@ module ReFacebook
|
|
49
57
|
LoginUrl + '?' + params.collect {|k,v| "#{k}=#{v}"}.join('&')
|
50
58
|
end
|
51
59
|
|
52
|
-
|
53
|
-
|
54
|
-
|
60
|
+
protected
|
61
|
+
# If the session_key changes update the API's session key as well.
|
62
|
+
def session_key=(session_key)
|
63
|
+
@session_key = @api.session_key = session_key
|
64
|
+
end
|
55
65
|
end
|
56
66
|
|
67
|
+
# All <a href="http://wiki.developers.facebook.com/index.php/API">API</a> calls go
|
68
|
+
# through this class. To request a method just modify the call such that . become _.
|
69
|
+
# If you create a session update the session_key with the session value so that
|
70
|
+
# all the calls become authenticated.
|
71
|
+
#
|
72
|
+
# Example calls:
|
73
|
+
# <pre><code>
|
74
|
+
# # This is without a parameter
|
75
|
+
# @api = API.new 'MY_API_KEY, 'MY_SECRET_KEY'
|
76
|
+
# token = @api.auth_createToken
|
77
|
+
# # This is with a parameter
|
78
|
+
# app_properties = @api.admin_getAppProperties :properties => ['application_name','callback_url']
|
79
|
+
# </pre></code>
|
57
80
|
class API
|
58
81
|
attr_accessor :session_key
|
59
82
|
|
83
|
+
# Create a new API.
|
84
|
+
# api_key and secret are the Facebook API and Secret keys.
|
60
85
|
def initialize api_key, secret
|
61
86
|
@api_key = api_key
|
62
87
|
@secret = secret
|
63
88
|
@session_key = nil
|
64
89
|
end
|
65
90
|
|
66
|
-
# FIXME:
|
91
|
+
# FIXME: This is not implemented yet. It is just a placeholder.
|
67
92
|
def batch_run *args
|
68
93
|
raise
|
69
94
|
end
|