forked from mmangino/mogli
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
First test of subscriptions
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,3 +35,4 @@ module Mogli | |
require "mogli/work" | ||
require "mogli/user" | ||
require "mogli/client" | ||
require "mogli/app_client" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "mogli/client/event" | ||
require "mogli/client/user" | ||
|
||
module Mogli | ||
class AppClient < Client | ||
attr_accessor :application_id | ||
|
||
def subscription_url | ||
"http://graph.facebook.com/#{application_id}/subscriptions" | ||
end | ||
|
||
def subscribe_to_model(model,options) | ||
options_to_send = options.dup | ||
options_to_send[:fields] = Array(options[:fields]).join(",") | ||
options_to_send[:object] = name_for_class(model) | ||
self.class.post(subscription_url,:body=>default_params.merge(options_to_send)) | ||
end | ||
|
||
def name_for_class(klass) | ||
klass.name.split("::").last.downcase | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "spec_helper" | ||
describe Mogli::AppClient do | ||
describe "subscribing" do | ||
let :client do | ||
a=Mogli::AppClient.new('key') | ||
a.application_id="123" | ||
a | ||
end | ||
|
||
it "should allow you to subscribe with callback url, fields and verify token" do | ||
Mogli::Client.should_receive(:post).with("http://graph.facebook.com/123/subscriptions",an_instance_of(Hash)) | ||
client.subscribe_to_model(Mogli::User,:callback_url=>"http://localhost:3000",:fields=>["username"]) | ||
end | ||
|
||
it "should pass the type as the object field" do | ||
Mogli::Client.should_receive(:post).with("http://graph.facebook.com/123/subscriptions",{:body=>hash_including(:object=>"user")}) | ||
client.subscribe_to_model(Mogli::User,:callback_url=>"http://localhost:3000",:fields=>["username"]) | ||
end | ||
|
||
it "sends the list of fields comma separated" do | ||
Mogli::Client.should_receive(:post).with("http://graph.facebook.com/123/subscriptions",{:body=>hash_including(:fields=>"username,friends")}) | ||
client.subscribe_to_model(Mogli::User,:callback_url=>"http://localhost:3000",:fields=>["username,friends"]) | ||
end | ||
it "sends the callback url" do | ||
Mogli::Client.should_receive(:post).with("http://graph.facebook.com/123/subscriptions",{:body=>hash_including(:callback_url=>"http://localhost:3000")}) | ||
client.subscribe_to_model(Mogli::User,:callback_url=>"http://localhost:3000",:fields=>["username"]) | ||
end | ||
|
||
it "should send the verify token if provided" do | ||
Mogli::Client.should_receive(:post).with("http://graph.facebook.com/123/subscriptions",{:body=>hash_including(:verify_token=>"TOKEN")}) | ||
client.subscribe_to_model(Mogli::User,:callback_url=>"http://localhost:3000",:fields=>["username"],:verify_token=>"TOKEN") | ||
|
||
end | ||
end | ||
|
||
end |