Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support for methods 'facebook.comments.add','facebook.comments.remove…

…', and 'facebook.comments.get'.

This is usefull for a Facebook Connect site that wants to render FB comments on the server so that they can be seen by search engines and/or non-javascript enabled browsers.
  • Loading branch information...
commit 4b8b3b145914d04f58b5569d84e1de1b708f5126 1 parent b7c7400
@jagthedrummer jagthedrummer authored committed
View
1  Manifest.txt
@@ -63,6 +63,7 @@ lib/facebooker/models/album.rb
lib/facebooker/models/applicationproperties.rb
lib/facebooker/models/applicationrestrictions.rb
lib/facebooker/models/cookie.rb
+lib/facebooker/models/comment.rb
lib/facebooker/models/education_info.rb
lib/facebooker/models/event.rb
lib/facebooker/models/family_relative_info.rb
View
2  facebooker.gemspec
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
* Well tested}
s.email = ["chad@chadfowlwer.com", "", "", "", "", "mmangino@elevatedrails.com"]
s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "COPYING.rdoc", "README.rdoc", "TODO.rdoc"]
- s.files = [".autotest", "CHANGELOG.rdoc", "COPYING.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "TODO.rdoc", "examples/desktop_login.rb", "facebooker.gemspec", "generators/facebook/facebook_generator.rb", "generators/facebook/templates/config/facebooker.yml", "generators/facebook/templates/public/javascripts/facebooker.js", "generators/facebook_controller/USAGE", "generators/facebook_controller/facebook_controller_generator.rb", "generators/facebook_controller/templates/controller.rb", "generators/facebook_controller/templates/functional_test.rb", "generators/facebook_controller/templates/helper.rb", "generators/facebook_controller/templates/view.fbml.erb", "generators/facebook_controller/templates/view.html.erb", "generators/facebook_publisher/facebook_publisher_generator.rb", "generators/facebook_publisher/templates/create_facebook_templates.rb", "generators/facebook_publisher/templates/publisher.rb", "generators/facebook_scaffold/USAGE", "generators/facebook_scaffold/facebook_scaffold_generator.rb", "generators/facebook_scaffold/templates/controller.rb", "generators/facebook_scaffold/templates/facebook_style.css", "generators/facebook_scaffold/templates/functional_test.rb", "generators/facebook_scaffold/templates/helper.rb", "generators/facebook_scaffold/templates/layout.fbml.erb", "generators/facebook_scaffold/templates/layout.html.erb", "generators/facebook_scaffold/templates/style.css", "generators/facebook_scaffold/templates/view_edit.fbml.erb", "generators/facebook_scaffold/templates/view_edit.html.erb", "generators/facebook_scaffold/templates/view_index.fbml.erb", "generators/facebook_scaffold/templates/view_index.html.erb", "generators/facebook_scaffold/templates/view_new.fbml.erb", "generators/facebook_scaffold/templates/view_new.html.erb", "generators/facebook_scaffold/templates/view_show.fbml.erb", "generators/facebook_scaffold/templates/view_show.html.erb", "generators/publisher/publisher_generator.rb", "generators/xd_receiver/templates/xd_receiver_ssl.html", "generators/xd_receiver/templates/xd_receiver.html", "generators/xd_receiver/xd_receiver_generator.rb", "init.rb", "install.rb", "lib/facebooker.rb", "lib/facebooker/adapters/adapter_base.rb", "lib/facebooker/adapters/bebo_adapter.rb", "lib/facebooker/adapters/facebook_adapter.rb", "lib/facebooker/attachment.rb", "lib/facebooker/admin.rb", "lib/facebooker/application.rb", "lib/facebooker/batch_request.rb", "lib/facebooker/data.rb", "lib/facebooker/feed.rb", "lib/facebooker/logging.rb", "lib/facebooker/mobile.rb", "lib/facebooker/mock/service.rb", "lib/facebooker/mock/session.rb", "lib/facebooker/model.rb", "lib/facebooker/models/affiliation.rb", "lib/facebooker/models/album.rb", "lib/facebooker/models/applicationproperties.rb", "lib/facebooker/models/applicationrestrictions.rb", "lib/facebooker/models/cookie.rb", "lib/facebooker/models/education_info.rb", "lib/facebooker/models/event.rb", "lib/facebooker/models/family_relative_info.rb", "lib/facebooker/models/friend_list.rb", "lib/facebooker/models/group.rb", "lib/facebooker/models/info_item.rb", "lib/facebooker/models/info_section.rb", "lib/facebooker/models/location.rb", "lib/facebooker/models/notifications.rb", "lib/facebooker/models/page.rb", "lib/facebooker/models/photo.rb", "lib/facebooker/models/tag.rb", "lib/facebooker/models/user.rb", "lib/facebooker/models/video.rb", "lib/facebooker/models/work_info.rb", "lib/facebooker/models/message_thread.rb", "lib/facebooker/parser.rb", "lib/facebooker/rails/backwards_compatible_param_checks.rb", "lib/facebooker/rails/controller.rb", "lib/facebooker/rails/cucumber.rb", "lib/facebooker/rails/cucumber/world.rb", "lib/facebooker/rails/extensions/action_controller.rb", "lib/facebooker/rails/extensions/rack_setup.rb", "lib/facebooker/rails/extensions/routing.rb", "lib/facebooker/rails/facebook_form_builder.rb", "lib/facebooker/rails/facebook_pretty_errors.rb", "lib/facebooker/rails/facebook_request_fix.rb", "lib/facebooker/rails/facebook_request_fix_2-3.rb", "lib/facebooker/rails/facebook_session_handling.rb", "lib/facebooker/rails/facebook_url_helper.rb", "lib/facebooker/rails/facebook_url_rewriting.rb", "lib/facebooker/rails/helpers.rb", "lib/facebooker/rails/helpers/fb_connect.rb", "lib/facebooker/rails/helpers/stream_publish.rb", "lib/facebooker/rails/integration_session.rb", "lib/facebooker/rails/profile_publisher_extensions.rb", "lib/facebooker/rails/publisher.rb", "lib/facebooker/rails/routing.rb", "lib/facebooker/rails/test_helpers.rb", "lib/facebooker/rails/utilities.rb", "lib/facebooker/server_cache.rb", "lib/facebooker/service.rb", "lib/facebooker/service/base_service.rb", "lib/facebooker/service/curl_service.rb", "lib/facebooker/service/net_http_service.rb", "lib/facebooker/service/typhoeus_service.rb", "lib/facebooker/service/typhoeus_multi_service.rb", "lib/facebooker/session.rb", "lib/facebooker/stream_post.rb", "lib/facebooker/version.rb", "lib/net/http_multipart_post.rb", "lib/rack/facebook.rb", "lib/rack/facebook_session.rb", "lib/tasks/facebooker.rake", "lib/tasks/facebooker.rb", "lib/tasks/tunnel.rake", "rails/init.rb", "setup.rb", "templates/layout.erb", "test/facebooker/adapters_test.rb", "test/facebooker/admin_test.rb", "test/facebooker/application_test.rb", "test/facebooker/attachment_test.rb", "test/facebooker/batch_request_test.rb", "test/facebooker/data_test.rb", "test/facebooker/logging_test.rb", "test/facebooker/mobile_test.rb", "test/facebooker/model_test.rb", "test/facebooker/models/event_test.rb", "test/facebooker/models/page_test.rb", "test/facebooker/models/photo_test.rb", "test/facebooker/models/user_test.rb", "test/facebooker/rails/publisher_test.rb", "test/facebooker/rails_integration_test.rb", "test/facebooker/rails/facebook_request_fix_2-3_test.rb", "test/facebooker/server_cache_test.rb", "test/facebooker/session_test.rb", "test/facebooker_test.rb", "test/fixtures/multipart_post_body_with_only_parameters.txt", "test/fixtures/multipart_post_body_with_single_file.txt", "test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt", "test/net/http_multipart_post_test.rb", "test/rack/facebook_test.rb", "test/rack/facebook_session_test.rb", "test/rails_test_helper.rb", "test/test_helper.rb", "test/facebooker/rails/facebook_url_rewriting_test.rb", "test/facebooker/rails/integration_session_test.rb", "test/facebooker/service_test.rb"]
+ s.files = [".autotest", "CHANGELOG.rdoc", "COPYING.rdoc", "Manifest.txt", "README.rdoc", "Rakefile", "TODO.rdoc", "examples/desktop_login.rb", "facebooker.gemspec", "generators/facebook/facebook_generator.rb", "generators/facebook/templates/config/facebooker.yml", "generators/facebook/templates/public/javascripts/facebooker.js", "generators/facebook_controller/USAGE", "generators/facebook_controller/facebook_controller_generator.rb", "generators/facebook_controller/templates/controller.rb", "generators/facebook_controller/templates/functional_test.rb", "generators/facebook_controller/templates/helper.rb", "generators/facebook_controller/templates/view.fbml.erb", "generators/facebook_controller/templates/view.html.erb", "generators/facebook_publisher/facebook_publisher_generator.rb", "generators/facebook_publisher/templates/create_facebook_templates.rb", "generators/facebook_publisher/templates/publisher.rb", "generators/facebook_scaffold/USAGE", "generators/facebook_scaffold/facebook_scaffold_generator.rb", "generators/facebook_scaffold/templates/controller.rb", "generators/facebook_scaffold/templates/facebook_style.css", "generators/facebook_scaffold/templates/functional_test.rb", "generators/facebook_scaffold/templates/helper.rb", "generators/facebook_scaffold/templates/layout.fbml.erb", "generators/facebook_scaffold/templates/layout.html.erb", "generators/facebook_scaffold/templates/style.css", "generators/facebook_scaffold/templates/view_edit.fbml.erb", "generators/facebook_scaffold/templates/view_edit.html.erb", "generators/facebook_scaffold/templates/view_index.fbml.erb", "generators/facebook_scaffold/templates/view_index.html.erb", "generators/facebook_scaffold/templates/view_new.fbml.erb", "generators/facebook_scaffold/templates/view_new.html.erb", "generators/facebook_scaffold/templates/view_show.fbml.erb", "generators/facebook_scaffold/templates/view_show.html.erb", "generators/publisher/publisher_generator.rb", "generators/xd_receiver/templates/xd_receiver_ssl.html", "generators/xd_receiver/templates/xd_receiver.html", "generators/xd_receiver/xd_receiver_generator.rb", "init.rb", "install.rb", "lib/facebooker.rb", "lib/facebooker/adapters/adapter_base.rb", "lib/facebooker/adapters/bebo_adapter.rb", "lib/facebooker/adapters/facebook_adapter.rb", "lib/facebooker/attachment.rb", "lib/facebooker/admin.rb", "lib/facebooker/application.rb", "lib/facebooker/batch_request.rb", "lib/facebooker/data.rb", "lib/facebooker/feed.rb", "lib/facebooker/logging.rb", "lib/facebooker/mobile.rb", "lib/facebooker/mock/service.rb", "lib/facebooker/mock/session.rb", "lib/facebooker/model.rb", "lib/facebooker/models/affiliation.rb", "lib/facebooker/models/album.rb","lib/facebooker/models/comment.rb", "lib/facebooker/models/applicationproperties.rb", "lib/facebooker/models/applicationrestrictions.rb", "lib/facebooker/models/cookie.rb", "lib/facebooker/models/education_info.rb", "lib/facebooker/models/event.rb", "lib/facebooker/models/family_relative_info.rb", "lib/facebooker/models/friend_list.rb", "lib/facebooker/models/group.rb", "lib/facebooker/models/info_item.rb", "lib/facebooker/models/info_section.rb", "lib/facebooker/models/location.rb", "lib/facebooker/models/notifications.rb", "lib/facebooker/models/page.rb", "lib/facebooker/models/photo.rb", "lib/facebooker/models/tag.rb", "lib/facebooker/models/user.rb", "lib/facebooker/models/video.rb", "lib/facebooker/models/work_info.rb", "lib/facebooker/models/message_thread.rb", "lib/facebooker/parser.rb", "lib/facebooker/rails/backwards_compatible_param_checks.rb", "lib/facebooker/rails/controller.rb", "lib/facebooker/rails/cucumber.rb", "lib/facebooker/rails/cucumber/world.rb", "lib/facebooker/rails/extensions/action_controller.rb", "lib/facebooker/rails/extensions/rack_setup.rb", "lib/facebooker/rails/extensions/routing.rb", "lib/facebooker/rails/facebook_form_builder.rb", "lib/facebooker/rails/facebook_pretty_errors.rb", "lib/facebooker/rails/facebook_request_fix.rb", "lib/facebooker/rails/facebook_request_fix_2-3.rb", "lib/facebooker/rails/facebook_session_handling.rb", "lib/facebooker/rails/facebook_url_helper.rb", "lib/facebooker/rails/facebook_url_rewriting.rb", "lib/facebooker/rails/helpers.rb", "lib/facebooker/rails/helpers/fb_connect.rb", "lib/facebooker/rails/helpers/stream_publish.rb", "lib/facebooker/rails/integration_session.rb", "lib/facebooker/rails/profile_publisher_extensions.rb", "lib/facebooker/rails/publisher.rb", "lib/facebooker/rails/routing.rb", "lib/facebooker/rails/test_helpers.rb", "lib/facebooker/rails/utilities.rb", "lib/facebooker/server_cache.rb", "lib/facebooker/service.rb", "lib/facebooker/service/base_service.rb", "lib/facebooker/service/curl_service.rb", "lib/facebooker/service/net_http_service.rb", "lib/facebooker/service/typhoeus_service.rb", "lib/facebooker/service/typhoeus_multi_service.rb", "lib/facebooker/session.rb", "lib/facebooker/stream_post.rb", "lib/facebooker/version.rb", "lib/net/http_multipart_post.rb", "lib/rack/facebook.rb", "lib/rack/facebook_session.rb", "lib/tasks/facebooker.rake", "lib/tasks/facebooker.rb", "lib/tasks/tunnel.rake", "rails/init.rb", "setup.rb", "templates/layout.erb", "test/facebooker/adapters_test.rb", "test/facebooker/admin_test.rb", "test/facebooker/application_test.rb", "test/facebooker/attachment_test.rb", "test/facebooker/batch_request_test.rb", "test/facebooker/data_test.rb", "test/facebooker/logging_test.rb", "test/facebooker/mobile_test.rb", "test/facebooker/model_test.rb", "test/facebooker/models/event_test.rb", "test/facebooker/models/page_test.rb", "test/facebooker/models/photo_test.rb", "test/facebooker/models/user_test.rb", "test/facebooker/rails/publisher_test.rb", "test/facebooker/rails_integration_test.rb", "test/facebooker/rails/facebook_request_fix_2-3_test.rb", "test/facebooker/server_cache_test.rb", "test/facebooker/session_test.rb", "test/facebooker_test.rb", "test/fixtures/multipart_post_body_with_only_parameters.txt", "test/fixtures/multipart_post_body_with_single_file.txt", "test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt", "test/net/http_multipart_post_test.rb", "test/rack/facebook_test.rb", "test/rack/facebook_session_test.rb", "test/rails_test_helper.rb", "test/test_helper.rb", "test/facebooker/rails/facebook_url_rewriting_test.rb", "test/facebooker/rails/integration_session_test.rb", "test/facebooker/service_test.rb"]
s.homepage = %q{http://facebooker.rubyforge.org}
s.rdoc_options = ["--main", "README.rdoc"]
s.require_paths = ["lib"]
View
1  lib/facebooker.rb
@@ -238,6 +238,7 @@ def request_for_canvas(is_canvas_request)
require 'facebooker/models/location'
require 'facebooker/models/affiliation'
require 'facebooker/models/album'
+require 'facebooker/models/comment'
require 'facebooker/models/education_info'
require 'facebooker/models/work_info'
require 'facebooker/models/event'
View
9 lib/facebooker/models/comment.rb
@@ -0,0 +1,9 @@
+require 'facebooker/model'
+module Facebooker
+ ##
+ # A simple representation of a comment
+ class Comment
+ include Model
+ attr_accessor :xid, :fromid, :time, :text, :id
+ end
+end
View
12 lib/facebooker/models/user.rb
@@ -185,6 +185,18 @@ def comment_on(post_id, comment)
@session.post('facebook.stream.addComment', {:post_id=>post_id, :comment=>comment})
end
+
+ ###
+ # Publish a comment to a specific comment set by xid
+ #
+ # See: http://wiki.developers.facebook.com/index.php/Comments.add
+ #
+ # +xid+ the xid for the set of comments
+ # +text+ the text of the comment
+ def add_comment(xid, text,title=nil,url=nil,publish_to_stream=false)
+ @session.post('facebook.comments.add',{:xid=>xid,:text=>text,:title=>title,:url=>url,:publish_to_stream=>publish_to_stream})
+ end
+
###
# Add a like on a post
#
View
23 lib/facebooker/parser.rb
@@ -301,6 +301,24 @@ def self.process(data)
end
end
+ class CommentsAdd < Parser#:nodoc:
+ def self.process(data)
+ element('comments_add_response', data).content.strip
+ end
+ end
+
+ class CommentsRemove < Parser#:nodoc:
+ def self.process(data)
+ booleanize(data)
+ end
+ end
+
+ class CommentsGet < Parser#:nodoc:
+ def self.process(data)
+ array_of_hashes(element('comments_get_response', data), 'comment')
+ end
+ end
+
class BatchRun < Parser #:nodoc:
class << self
def current_batch=(current_batch)
@@ -726,7 +744,10 @@ class Parser
'facebook.data.setUserPreference' => SetPreference,
'facebook.video.upload' => UploadVideo,
'facebook.sms.send' => SmsSend,
- 'facebook.sms.canSend' => SmsCanSend
+ 'facebook.sms.canSend' => SmsCanSend,
+ 'facebook.comments.add' => CommentsAdd,
+ 'facebook.comments.remove' => CommentsRemove,
+ 'facebook.comments.get' => CommentsGet
}
end
end
View
14 lib/facebooker/session.rb
@@ -424,6 +424,20 @@ def get_photos(pids = nil, subj_id = nil, aid = nil)
end
end
+ #remove a comment from a given xid stream with comment_id
+ def remove_comment(xid,comment_id)
+ post('facebook.comments.remove', :xid=>xid, :comment_id =>comment_id)
+ end
+
+ #pulls comment list for a given XID
+ def get_comments(xid)
+ @comments = post('facebook.comments.get', :xid => xid) do |response|
+ response.map do |hash|
+ Comment.from_hash(hash)
+ end
+ end
+ end
+
def get_albums(aids)
@albums = post('facebook.photos.getAlbums', :aids => aids) do |response|
response.map do |hash|
View
13 test/facebooker/models/user_test.rb
@@ -201,6 +201,12 @@ def test_comment_on
expect_http_posts_with_responses(example_comment_on_response)
assert_equal('703826862_78463536863', @user.comment_on('703826862_78463536862', :message => 'that was hilarious!'))
end
+
+ def test_add_comment
+ @user = Facebooker::User.new(548871286, @session)
+ expect_http_posts_with_responses(example_add_comment_response)
+ assert_equal('403917', @user.add_comment('test_xid','that was realy hilarious!') )
+ end
def test_add_like_on
@user = Facebooker::User.new(548871286, @session)
@@ -471,6 +477,13 @@ def example_comment_on_response
eoxml
end
+ def example_add_comment_response
+ <<-eoxml
+<?xml version="1.0" encoding="UTF-8"?>
+<comments_add_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">403917</comments_add_response>
+ eoxml
+ end
+
def example_add_like_on_response
<<-eoxml
<?xml version="1.0" encoding="UTF-8"?>
View
53 test/facebooker_test.rb
@@ -246,6 +246,13 @@ def test_getting_photos_requires_arguments
assert_raise(ArgumentError) { @session.get_photos() }
end
+ def test_can_get_comments_by_xid
+ expect_http_posts_with_responses(example_comments_xml)
+ comments = @session.get_comments('pete_comments')
+ assert_equal('Hola', comments[0].text)
+ assert_equal(2, comments.size)
+ end
+
def test_can_get_albums_for_user
expect_http_posts_with_responses(example_user_albums_xml)
assert_equal('Summertime is Best', @session.user.albums.first.name)
@@ -377,6 +384,20 @@ def test_revoke_authorization_false
assert_equal false, @session.post('facebook.auth.revokeAuthorization', :uid => 123)
end
+
+
+ def test_remove_comment_true
+ expect_http_posts_with_responses(example_remove_comment_true)
+ assert_equal true, @session.remove_comment('pete_comments',123)
+ end
+
+ def test_remove_comment_false
+ expect_http_posts_with_responses(example_remove_comment_false)
+ assert_equal false, @session.remove_comment('pete_comments',123)
+ end
+
+
+
private
def populate_user_info
mock_http = establish_session
@@ -812,6 +833,28 @@ def example_app_users_xml
XML
end
+ def example_comments_xml
+ <<-XML
+ <?xml version="1.0" encoding="UTF-8"?>
+ <comments_get_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" list="true">
+ <comment>
+ <xid>pete_comments</xid>
+ <fromid>563683308</fromid>
+ <time>1234227529</time>
+ <text>Hola</text>
+ <id>65020</id>
+ </comment>
+ <comment>
+ <xid>pete_comments</xid>
+ <fromid>563683308</fromid>
+ <time>1234227542</time>
+ <text>holla</text>
+ <id>65021</id>
+ </comment>
+ </comments_get_response>
+ XML
+ end
+
def example_user_albums_xml
<<-XML
<?xml version="1.0" encoding="UTF-8"?>
@@ -948,4 +991,14 @@ def example_revoke_authorization_true
def example_revoke_authorization_false
"0"
end
+
+
+ def example_remove_comment_true
+ "1"
+ end
+
+ def example_remove_comment_false
+ "0"
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.