Permalink
Browse files

Merge pull request #2 from travis/test-user

Add test user creation/listing
  • Loading branch information...
2 parents f75b1b8 + c5341e3 commit 6e8913b7d1a2c3eae2a5ed5630d2ab1ee0fd8bac @bcm bcm committed Jul 13, 2011
Showing with 66 additions and 7 deletions.
  1. +1 −0 lib/mogli.rb
  2. +14 −1 lib/mogli/app_client.rb
  3. +27 −0 lib/mogli/test_user.rb
  4. +0 −6 spec/test_spec.rb
  5. +24 −0 spec/test_user_spec.rb
View
@@ -36,6 +36,7 @@ module Mogli
require "mogli/video"
require "mogli/work"
require "mogli/user"
+require "mogli/test_user"
require "mogli/client"
require "mogli/app_client"
require "mogli/fql_multiquery"
@@ -5,6 +5,11 @@ module Mogli
class AppClient < Client
attr_accessor :application_id
+ def initialize(app_token, application_id=nil)
+ super(app_token)
+ self.application_id = application_id
+ end
+
def subscription_url
"https://graph.facebook.com/#{application_id}/subscriptions"
end
@@ -23,5 +28,13 @@ def name_for_class(klass)
def subscriptions
get_and_map_url(subscription_url,"Subscription")
end
+
+ def post(path, klass, query)
+ super("#{application_id}/#{path}", klass, query)
+ end
+
+ def get_and_map(path, klass, query)
+ super("#{application_id}/#{path}", klass, query)
+ end
end
-end
+end
@@ -0,0 +1,27 @@
+module Mogli
+ # Support for Facebook test users, as described here:
+ #
+ # http://developers.facebook.com/docs/test_users/
+ #
+ # Test user creation/listing requires an app access token and an app
+ # id.
+ #
+ # Example usage:
+ #
+ # +Mogli::TestUser.all({}, Mogli::AppClient.new('access_token', 'app_id'))+
+ class TestUser < User
+ define_properties :access_token, :login_url, :password
+
+ def self.create(query, app_client)
+ app_client.post("accounts/test-users", self, query)
+ end
+
+ def self.all(query, app_client)
+ app_client.get_and_map("accounts/test-users", self, query)
+ end
+
+ def to_s
+ id
+ end
+ end
+end
View
@@ -1,6 +0,0 @@
-require "spec_helper"
-describe "atest" do
- it "should run specs" do
- 1.should == 1
- end
-end
@@ -0,0 +1,24 @@
+require "spec_helper"
+describe Mogli::User do
+
+ let(:app_id) { '12345' }
+ let(:access_token) { '678910' }
+
+ describe "#create" do
+ it "POSTs to the test user creation url" do
+ Mogli::Client.should_receive(:post).with("https://graph.facebook.com/#{app_id}/accounts/test-users",
+ :body => {:access_token => access_token}).and_return({:id=>1, :login_url => 'http://example.com/hamsocks' })
+ user = Mogli::TestUser.create({}, Mogli::AppClient.new(access_token, app_id))
+ user.login_url.should == 'http://example.com/hamsocks'
+ end
+ end
+
+ describe "#all" do
+ it "GETs the test user url" do
+ Mogli::Client.should_receive(:get).with("https://graph.facebook.com/#{app_id}/accounts/test-users",
+ :query => {:access_token => access_token}).and_return([{:id=>1, :login_url => 'http://example.com/hamsocks'}])
+ users = Mogli::TestUser.all({}, Mogli::AppClient.new(access_token, app_id))
+ users.first.login_url.should == 'http://example.com/hamsocks'
+ end
+ end
+end

0 comments on commit 6e8913b

Please sign in to comment.