Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for app properties calls
git-svn-id: svn+ssh://rubyforge.org/var/svn/facebooker/trunk/facebooker@175 06148572-b36b-44fe-9aa8-f68b04d8b080
  • Loading branch information
drummr77 committed Feb 14, 2008
1 parent 8a3c5fd commit 8a449ef
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 3 deletions.
5 changes: 5 additions & 0 deletions History.txt
@@ -1,3 +1,8 @@
=== x.x.x / 2008-xx-xx

* Added support for data.getCookies and data.setCookies [shane]
* Added support for admin.getAppProperties and admin.setAppProperties [shane]

=== 0.9.5 / 2008-02-13

* Next release of documentation
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -14,6 +14,7 @@ Hoe.new('facebooker', Facebooker::VERSION) do |p|
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
p.remote_rdoc_dir = '' # Release to root
p.extra_deps << ['json', '>= 1.0.0']
end

# vim: syntax=Ruby
Expand Down
5 changes: 4 additions & 1 deletion lib/facebooker.rb
@@ -1,3 +1,4 @@
require 'json'

require 'facebooker/affiliation'
require 'facebooker/album'
Expand All @@ -12,6 +13,8 @@
require 'facebooker/service'
require 'facebooker/server_cache'
require 'facebooker/data'
require 'facebooker/admin'
require 'facebooker/applicationproperties'
require 'facebooker/session'
require 'facebooker/tag'
require 'facebooker/user'
Expand Down Expand Up @@ -60,4 +63,4 @@ def request_for_canvas(is_canvas_request)
end
end
end
end
end
22 changes: 22 additions & 0 deletions lib/facebooker/admin.rb
@@ -0,0 +1,22 @@
module Facebooker
class Admin
def initialize(session)
@session = session
end

# ** BETA ***
# +properties+: Hash of properties you want to set
def set_app_properties(properties)
properties.respond_to?(:to_json) ? properties.to_json : properties
(@session.post 'facebook.admin.setAppProperties', :properties => properties) == '1'
end

# ** BETA ***
def get_app_properties(properties)
properties = properties.to_json if properties.respond_to?(:to_json)
json = @session.post('facebook.admin.getAppProperties', :properties => properties)
array_of_hashes = JSON.parse(json)
@properties = ApplicationProperties.from_array_of_hashes(array_of_hashes)
end
end
end
57 changes: 57 additions & 0 deletions lib/facebooker/applicationproperties.rb
@@ -0,0 +1,57 @@
module Facebooker

# application_name string The name of your application.
# callback_url string Your application's callback URL. The callback URL cannot be longer than 100 characters.
# post_install_url string The URL where a user gets redirected after installing your application. The post-install URL cannot be longer than 100 characters.
# edit_url string
# dashboard_url string
# uninstall_url string The URL where a user gets redirected after removing your application.
# ip_list string For Web-based applications, these are the IP addresses of your servers that can access Facebook's servers and serve information to your application.
# email string The email address associated with the application; the email address Facebook uses to contact you about your application. (default value is your Facebook email address.)
# description string The description of your application.
# use_iframe bool Indicates whether you render your application with FBML (0) or in an iframe (1). (default value is 1)
# desktop bool Indicates whether your application is Web-based (0) or gets installed on a user's desktop (1). (default value is 1)
# is_mobile bool Indicates whether your application can run on a mobile device (1) or not (0). (default value is 1)
# default_fbml string The default FBML code that appears in the user's profile box when he or she adds your application.
# default_column bool Indicates whether your application appears in the wide (1) or narrow (0) column of a user's Facebook profile. (default value is 1)
# message_url string For applications that can create attachments, this is the URL where you store the attachment's content.
# message_action string For applications that can create attachments, this is the label for the action that creates the attachment. It cannot be more than 20 characters.
# about_url string This is the URL to your application's About page. About pages are now Facebook Pages.
# private_install bool Indicates whether you want to disable (1) or enable (0) News Feed and Mini-Feed stories when a user installs your application. (default value is 1)
# installable bool Indicates whether a user can (1) or cannot (0) install your application. (default value is 1)
# privacy_url string The URL to your application's privacy terms.
# help_url string The URL to your application's help page.
# see_all_url string
# tos_url string The URL to your application's Terms of Service.
# dev_mode bool Indicates whether developer mode is enabled (1) or disabled (0). Only developers can install applications in developer mode. (default value is 1)
# preload_fql string A preloaded FQL query.
class ApplicationProperties
attr_accessor :application_name, :callback_url, :post_install_url, :edit_url, :dashboard_url,
:uninstall_url, :ip_list, :email, :description, :use_iframe, :desktop, :is_mobile,
:default_fbml, :default_column, :message_url, :message_action, :about_url,
:private_install, :installable, :privacy_url, :help_url, :see_all_url, :tos_url,
:dev_mode, :preload_fql

class << self
def from_array_of_hashes(array_of_hashes)
new(array_of_hashes)
end
end

def initialize(array_of_hashes = [])
populate_from_array_of_hashes!(array_of_hashes)
end

# Set model's attributes via Array of hashes. Keys should map directly to the model's attribute names.
def populate_from_array_of_hashes!(array_of_hashes)
unless array_of_hashes.empty?
array_of_hashes.each do |hash|
hash.each do |key, value|
self.__send__("#{key}=", value)
end
end
end
end

end
end
14 changes: 14 additions & 0 deletions lib/facebooker/parser.rb
Expand Up @@ -124,8 +124,20 @@ class PublishTemplatizedAction < Parser#:nodoc:
def self.process(data)
element('feed_publishTemplatizedAction_response', data).children[1].text_value
end
end

class SetAppProperties < Parser#:nodoc:
def self.process(data)
element('data_setAppProperties_response', data).text_value
end
end

class GetAppProperties < Parser#:nodoc:
def self.process(data)
element('admin_getAppProperties_response', data).text_value
end
end

class GetAppUsers < Parser#:nodoc:
def self.process(data)
array_of_text_values(element('friends_getAppUsers_response', data), 'uid')
Expand Down Expand Up @@ -368,6 +380,8 @@ class Parser
'facebook.fbml.refreshImgSrc' => RefreshImgSrc,
'facebook.data.setCookie' => SetCookie,
'facebook.data.getCookies' => GetCookies,
'facebook.admin.setAppProperties' => SetAppProperties,
'facebook.admin.getAppProperties' => GetAppProperties,
'facebook.fql.query' => FqlQuery,
'facebook.photos.get' => GetPhotos,
'facebook.photos.getAlbums' => GetAlbums,
Expand Down
4 changes: 4 additions & 0 deletions lib/facebooker/session.rb
Expand Up @@ -200,6 +200,10 @@ def data
Facebooker::Data.new(self)
end

def admin
Facebooker::Admin.new(self)
end

#
# Given an array like:
# [[userid, otheruserid], [yetanotherid, andanotherid]]
Expand Down
4 changes: 2 additions & 2 deletions lib/facebooker/version.rb
@@ -1,8 +1,8 @@
module Facebooker #:nodoc:
module VERSION #:nodoc:
MAJOR = 0
MINOR = 5
TINY = 0
MINOR = 9
TINY = 5

STRING = [MAJOR, MINOR, TINY].join('.')
end
Expand Down
49 changes: 49 additions & 0 deletions test/facebook_admin_test.rb
@@ -0,0 +1,49 @@
require File.dirname(__FILE__) + '/test_helper.rb'

class FacebookAdminTest < Test::Unit::TestCase
def setup
@session = Facebooker::Session.create('apikey', 'secretkey')
end

def test_can_ask_facebook_to_set_app_properties
expect_http_posts_with_responses(example_set_properties_xml)
properties = { :application_name => "Video Jukebox", :dev_mode => 0 }
assert(@session.admin.set_app_properties(properties))
end

def test_can_ask_facebook_to_get_app_properties
expect_http_posts_with_responses(example_get_properties_xml)
properties = [ :application_name, :dev_mode ]
assert(@session.admin.get_app_properties(properties))
end

def test_can_get_properties
mock_http = establish_session
mock_http.should_receive(:post_form).and_return(example_get_properties_xml).once.ordered(:posts)
properties = [ :application_name, :dev_mode ]
p = @session.admin.get_app_properties(properties)
assert_equal 'Trunc', p.application_name
assert_equal 0, p.dev_mode
end

private
def example_set_properties_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<data_setAppProperties_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</data_setAppProperties_response>
XML
end

def example_get_properties_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
<admin_getAppProperties_response
xmlns="http://api.facebook.com/1.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
[{"application_name": "Trunc"}, {"dev_mode": 0}]
</admin_getAppProperties_response>
XML
end
end

0 comments on commit 8a449ef

Please sign in to comment.