Skip to content
Browse files

Merge pull request #58 from utahstreetlabs/master

add test user support
  • Loading branch information...
2 parents 9ff5cbf + 6e8913b commit 4ecc1910fb41251b024190e08643f3c7b91202a2 @mmangino mmangino committed Jul 13, 2011
Showing with 67 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. +1 −0 spec/model_spec.rb
  5. +0 −6 spec/test_spec.rb
  6. +24 −0 spec/test_user_spec.rb
View
1 lib/mogli.rb
@@ -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"
View
15 lib/mogli/app_client.rb
@@ -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
View
27 lib/mogli/test_user.rb
@@ -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 spec/model_spec.rb
@@ -125,6 +125,7 @@ class TestModel < Mogli::Model
actions_data_array = [actions_data]
actions_data_array.stub!(:respond_to?).with(:to_json).and_return(false)
actions_data_array.stub!(:respond_to?).with(:code).and_return(false)
+ actions_data_array.stub!(:respond_to?).with(:parsed_response).and_return(false)
new_model = TestModel.new(:id=>1,:other_property=>2,:actions => actions_data_array)
new_model.post_params[:actions].should == "[{\"name\":\"Action Name\",\"link\":\"http://example.com\"}]"
View
6 spec/test_spec.rb
@@ -1,6 +0,0 @@
-require "spec_helper"
-describe "atest" do
- it "should run specs" do
- 1.should == 1
- end
-end
View
24 spec/test_user_spec.rb
@@ -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 4ecc191

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