Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
Add Facebook batch api call. Minimal infrastructure put in place for …
Browse files Browse the repository at this point in the history
…this since the interface is relatively opaque.
  • Loading branch information
Ali Faiz and Michael Arick authored and Change committed Jun 6, 2012
1 parent 7ff7321 commit ee7480d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
31 changes: 31 additions & 0 deletions bin/facebook-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,37 @@
} else if(/\/me\/.+:.+/.test(path) && method == 'post') {
FBWorld.posted({path: path, params: params});
callback({id: randomPostId()});
} else if (/\//.test(path) && method == 'post') { // / for batch api updates
var result = [];
for(var i=0; i<params.batch.length; i++) {
result.push(
{
"code":200,
"headers":[
{
"name":"Access-Control-Allow-Origin",
"value":"*"
},{
"name":"Cache-Control",
"value":"private, no-cache, no-store, must-revalidate"
},{
"name":"Connection",
"value":"close"
},{
"name":"Content-Type",
"value":"text\/javascript; charset=UTF-8"
},{
"name":"Expires",
"value":"Sat, 01 Jan 2000 00:00:00 GMT"
},{
"name":"Pragma",
"value":"no-cache"
}],
"body":"{\n \"id\": \""+randomPostId()+"\"\n}"
}
);
}
callback(result)
} else {
callback(apiFailMessage(path));
}
Expand Down
31 changes: 31 additions & 0 deletions lib/facebook_stub/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,37 @@
} else if(/\/me\/.+:.+/.test(path) && method == 'post') {
FBWorld.posted({path: path, params: params});
callback({id: randomPostId()});
} else if (/\//.test(path) && method == 'post') { // / for batch api updates
var result = [];
for(var i=0; i<params.batch.length; i++) {
result.push(
{
"code":200,
"headers":[
{
"name":"Access-Control-Allow-Origin",
"value":"*"
},{
"name":"Cache-Control",
"value":"private, no-cache, no-store, must-revalidate"
},{
"name":"Connection",
"value":"close"
},{
"name":"Content-Type",
"value":"text\/javascript; charset=UTF-8"
},{
"name":"Expires",
"value":"Sat, 01 Jan 2000 00:00:00 GMT"
},{
"name":"Pragma",
"value":"no-cache"
}],
"body":"{\n \"id\": \""+randomPostId()+"\"\n}"
}
);
}
callback(result)
} else {
callback(apiFailMessage(path));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/facebook_stub/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FacebookStub
VERSION = "0.0.1.15"
VERSION = "0.0.1.16"
end
28 changes: 28 additions & 0 deletions spec/javascripts/FBApiSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,34 @@ describe("FB.api", function() {
});
});

describe("when I call FB.api('/', 'post', params, callback)", function() {
it("should callback with 1 item when passed one item", function() {
FB.api('/', 'post', { batch: [{
method: "POST",
relative_url: "/me/feed",
body: "message=test"
}]
}, function (r) {
expect(r.length).toEqual(1);
});
});

it("should callback with 2 item when passed two items", function() {
FB.api('/', 'post', { batch: [{
method: "POST",
relative_url: "/me/feed",
body: "message=test"
},{
method: "POST",
relative_url: "/123/feed",
body: "message=test"
}]
}, function (r) {
expect(r.length).toEqual(2);
});
});
});

});

describe("when not connected", function () {
Expand Down

0 comments on commit ee7480d

Please sign in to comment.