Permalink
Browse files

Add support to PHP SDK for graph-video.facebook.com endpoint to follow:

  • Loading branch information...
1 parent 14b0b9e commit 3c89a5a6116b552ddd3e516dc6d198c21b67dc8a @amachang committed Feb 2, 2012
Showing with 86 additions and 1 deletion.
  1. +19 −1 lib/basefacebook.js
  2. +67 −0 test/basefacebook.test.js
View
20 lib/basefacebook.js
@@ -603,6 +603,22 @@ BaseFacebook.prototype.restserver = function restserver(params, callback) {
BaseFacebook.prototype.restserver = cb.wrap(BaseFacebook.prototype.restserver);
/**
+ * Return true if this is video post.
+ *
+ * @param string $path The path
+ * @param string $method The http method (default 'GET')
+ *
+ * @return boolean true if this is video post
+ */
+BaseFacebook.prototype.isVideoPost = function isVideoPost(path, method) {
+ method = method || 'GET';
+ if (method == 'POST' && path.match(/^(\/)(.+)(\/)(videos)$/)) {
+ return true;
+ }
+ return false;
+}
+
+/**
* Invoke the Graph API.
*
* @param string $path The path (required)
@@ -632,8 +648,10 @@ BaseFacebook.prototype.graph = function graph(/* path, method, params, callback
params.method = method; // method override as we always do a POST
+ var domain = this.isVideoPost(path, method) ? 'graph-video.facebook.com' : 'graph.facebook.com';
+
var self = this;
- this.oauthRequest('graph.facebook.com', path, params, cb.returnToCallback(callback, false, function(response) {
+ this.oauthRequest(domain, path, params, cb.returnToCallback(callback, false, function(response) {
try {
result = JSON.parse(response);
}
View
67 test/basefacebook.test.js
@@ -639,6 +639,7 @@ module.exports = {
});
facebook.api('/amachang', 'DELETE', function(err, response) {
+ console.log(err, response);
assert.equal(response, null);
assert.notEqual(err, null);
assert.equal(err + '',
@@ -1449,6 +1450,72 @@ module.exports = {
});
},
+ isVideoPost: function(beforeExit, assert) {
+ var done = false;
+ beforeExit(function() { assert.ok(done) });
+
+ var facebook = new TransientFacebook({
+ appId: config.appId,
+ secret: config.secret
+ });
+
+ assert.equal(facebook.isVideoPost('/me/videos'), false);
+ assert.equal(facebook.isVideoPost('/foo/videos', 'GET'), false);
+ assert.equal(facebook.isVideoPost('/bar/videos', 'POST'), true);
+ assert.equal(facebook.isVideoPost('/me/videossss', 'POST'), false);
+ assert.equal(facebook.isVideoPost('/videos', 'POST'), false);
+ assert.equal(facebook.isVideoPost('/baz', 'POST'), false);
+
+ done = true;
+ },
+
+ requestToGraphVideoDomain: function(beforeExit, assert) {
+ var done = false;
+ beforeExit(function() { assert.ok(done) });
+
+ var facebook = new TransientFacebook({
+ appId: config.appId,
+ secret: config.secret
+ });
+
+ facebook.makeRequest = function(host, path, params, callback) {
+ assert.equal(host, 'graph-video.facebook.com');
+ callback(null, '{ "test": "ok" }');
+ };
+
+ facebook.graph('/amachang/videos', 'POST', function(err, data) {
+ assert.equal(err, null);
+ assert.equal(data.test, 'ok');
+ });
+
+ facebook.graph('/foo/videos', 'POST', function(err, data) {
+ assert.equal(err, null);
+ assert.equal(data.test, 'ok');
+ });
+
+ facebook.makeRequest = function(host, path, params, callback) {
+ assert.equal(host, 'graph.facebook.com');
+ callback(null, '{ "test": "ok" }');
+ };
+
+ facebook.graph('/bar/videossss', 'POST', function(err, data) {
+ assert.equal(err, null);
+ assert.equal(data.test, 'ok');
+ });
+
+ facebook.graph('/videos', 'POST', function(err, data) {
+ assert.equal(err, null);
+ assert.equal(data.test, 'ok');
+ });
+
+ facebook.graph('/baz/videos', 'GET', function(err, data) {
+ assert.equal(err, null);
+ assert.equal(data.test, 'ok');
+ });
+
+ done = true;
+ },
+
graph: function(beforeExit, assert) {
var done = false;
beforeExit(function() { assert.ok(done) });

0 comments on commit 3c89a5a

Please sign in to comment.