Skip to content
Browse files

Got the JS Graph API call working again.

I added helper methods `versioned_*` to add a modification timestamp to static
assets such that the most up-to-date version of the static asset will get
served.
  • Loading branch information...
1 parent f9c3f88 commit 16e2f10d89b2799eae8c62e3b808c46dce3be5bd @agibralter agibralter committed Feb 10, 2011
Showing with 32 additions and 8 deletions.
  1. +1 −0 config/redis-development.conf
  2. +21 −0 lib/lovers/application.rb
  3. +8 −6 public/javascripts/lovers.js
  4. +1 −1 views/canvas.erb
  5. +1 −1 views/layout.erb
View
1 config/redis-development.conf
@@ -7,3 +7,4 @@ dir .
loglevel debug
logfile stdout
databases 16
+save 60 1
View
21 lib/lovers/application.rb
@@ -49,6 +49,20 @@ def rel_code(rtype)
@code_hash_for_user ||= Lovers::Relationship.code_hash_for_user(@user.facebook.user_id)
@code_hash_for_user[rtype]
end
+
+ def user_access_token
+ @user && @user.facebook && @user.facebook.access_token
+ end
+
+ # Make sure the browser only caches the latest version of static files.
+ # Taken from: http://agib.me/edwfXX
+ def versioned_stylesheet(stylesheet)
+ ts_path('stylesheets', "#{stylesheet}.css")
+ end
+
+ def versioned_javascript(js)
+ ts_path('javascripts', "#{js}.js")
+ end
end
@@ -182,6 +196,13 @@ def validate_uid(uid)
Integer(uid) rescue raise Lovers::TargetIdInvalid
end
+ def ts_path(dir, file)
+ "/#{dir}/#{file}?" + ts_file(dir, file).to_i.to_s
+ end
+
+ def ts_file(dir, file)
+ File.mtime(File.join(Lovers.root, 'public', dir, file))
+ end
# @staticmethod
# def base64_url_encode(data):
# return base64.urlsafe_b64encode(data).rstrip("=")
View
14 public/javascripts/lovers.js
@@ -7,7 +7,7 @@ var Lovers = {};
// Document ready...
$(function () {
- access_token = $("body").data("access_token");
+ access_token = $("*[data-access_token]").data("access_token");
$ul_req_pending = $("#requests-pending");
@@ -18,15 +18,13 @@ var Lovers = {};
message: "Choose from your friends.",
data: {rtype: $("#lover-type").val()}
}, function (response) {
- //console.log(response);
});
return false;
});
// Accept lovers behavior.
$("a.request-accept").live("click", function () {
var req_data = $(this).closest("li").data("req-data");
- console.log(req_data);
});
// Ignore lovers behavior.
});
@@ -35,16 +33,20 @@ var Lovers = {};
FBInit: function () {
- FB.api("/me/apprequests/?access_token=" + access_token, function (response) {
+ var url_with_token = "/me/apprequests/?access_token=" + access_token;
+
+ FB.api(url_with_token, function (response) {
var $li_sample = $ul_req_pending.find("li:hidden");
if (response.data) {
$.each(response.data, function (i, req) {
- var $new_li = $li_sample.clone();
+ var $new_li = $li_sample.clone(),
+ data = $.parseJSON(req.data);
$new_li.find("span.request-name").text(req.from.name);
- $new_li.data("req-data", $.parseJSON(req.data));
+ $new_li.data("req-data", data);
$ul_req_pending.append($new_li.show());
+ //console.log(data);
});
}
});
View
2 views/canvas.erb
@@ -1,4 +1,4 @@
-<h1>Welcome, Lover!</h1>
+<h1 data-access_token="<%= user_access_token %>">Welcome, Lover!</h1>
<ul id="tabs">
<li><a href="#home">Home</a></li>
View
2 views/layout.erb
@@ -6,7 +6,7 @@
<link rel="stylesheet" href="/stylesheets/screen.css" media="screen, projection">
<script src="/javascripts/create-html5-elements.js"></script>
<script src="/javascripts/jquery.min.js"></script>
- <script src="/javascripts/lovers.js"></script>
+ <script src="<%= versioned_javascript('lovers') %>"></script>
</head>
<body>
<div id="fb-root"></div>

0 comments on commit 16e2f10

Please sign in to comment.
Something went wrong with that request. Please try again.