forked from mmangino/facebooker
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
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
Showing
9 changed files
with
158 additions
and
3 deletions.
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 |
---|---|---|
@@ -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 |
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
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,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 |
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,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 |
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
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,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 |