Class: Facebooker::Session
- Inherits:
-
Object
- Object
- Facebooker::Session
- Defined in:
- lib/facebooker/session.rb
Direct Known Subclasses
Defined Under Namespace
Classes: AlbumIsFull, AppPermissionError, BlankFeedTitle, CallOutOfOrder, ConfigurationMissing, Desktop, EventNameLocked, ExtendedPermissionRequired, FQLFieldDoesNotExist, FQLFunctionDoesNotExist, FQLParseError, FQLStatementNotIndexable, FQLTableDoesNotExist, FQLWrongNumberArgumentsPassedToFunction, FeedBodyDataInvalid, FeedBodyLengthTooLong, FeedBodyTemplateInvalid, FeedMarkupInvalid, FeedPhotosNotRetrieved, FeedTargetIdsInvalid, FeedTitleDataInvalid, FeedTitleTemplateInvalid, HostNotAllowed, IncorrectSignature, InvalidAPIKey, InvalidAlbumId, InvalidFeedPhotoLink, InvalidFeedPhotoSource, InvalidFeedTitleLength, InvalidFeedTitleLink, InvalidFeedTitleName, InvalidFriendList, MaxRequestsDepleted, MissingOrInvalidImageFile, MissingOrInvalidParameter, PermissionError, ReadMailboxExtendedPermissionRequired, ServiceUnavailable, SessionExpired, SignatureTooOld, TemplateBundleInvalid, TemplateDataMissingRequiredTokens, TooManyUnapprovedPhotosPending, TooManyUserActionCalls, TooManyUserCalls, UnknownError, UserRegistrationFailed, UserUnRegistrationFailed
Constant Summary collapse
- API_SERVER_BASE_URL =
ENV["FACEBOOKER_API"] == "new" ? "api.new.facebook.com" : "api.facebook.com"
- API_PATH_REST =
"/restserver.php"
- WWW_SERVER_BASE_URL =
ENV["FACEBOOKER_API"] == "new" ? "www.new.facebook.com" : "www.facebook.com"
- WWW_PATH_LOGIN =
"/login.php"
- WWW_PATH_ADD =
"/add.php"
- WWW_PATH_INSTALL =
"/install.php"
Instance Attribute Summary collapse
- #auth_token ⇒ Object
-
#secret_from_session ⇒ Object
readonly
Returns the value of attribute secret_from_session.
-
#session_key ⇒ Object
readonly
Returns the value of attribute session_key.
Class Method Summary collapse
- .api_key ⇒ Object
- .configuration_file_path ⇒ Object
- .configuration_file_path=(path) ⇒ Object
- .create(api_key = nil, secret_key = nil) ⇒ Object
- .current ⇒ Object
- .current=(session) ⇒ Object
- .secret_key ⇒ Object
Instance Method Summary collapse
- #active_template_bundles ⇒ Object
- #add_next_parameters(options) ⇒ Object
- #add_tags(pid, x, y, tag_uid = nil, tag_text = nil) ⇒ Object
- #add_to_batch(req, &proc) ⇒ Object
- #admin ⇒ Object
- #application ⇒ Object
-
#batch(serial_only = false) ⇒ Object
Submit the enclosed requests for this session inside a batch.
- #batch_request? ⇒ Boolean
-
#cancel_event(eid, options = {}) ⇒ Object
Cancel an event wiki.developers.facebook.com/index.php/Events.cancel E.g: @session.cancel_event(‘100321123’, :cancel_message => “It’s raining…”) # => Returns true if all went well.
-
#check_friendship(array_of_pairs_of_users) ⇒ Object
Given an array like: [[userid, otheruserid], [yetanotherid, andanotherid]] returns a Hash indicating friendship of those pairs: otheruserid] => true, [yetanotherid, andanotherid] => false if one of the Hash values is nil, it means the facebook platform’s answer is “I don’t know”.
- #connect_permission_url(permission, options = {}) ⇒ Object
-
#create_event(event_info, multipart_post_file = nil) ⇒ Object
Creates an event with the event_info hash and an optional Net::HTTP::MultipartPostFile for the event picture.
-
#data ⇒ Object
Returns a proxy object for handling calls to the Facebook Data API.
-
#deactivate_template_bundle_by_id(template_bundle_id) ⇒ Object
Deactivate a template bundle with Facebook.
- #default_login_url_options ⇒ Object
- #edit_event(eid, event_info, options = {}) ⇒ Object
-
#event_invite(eid, uids, options = {}) ⇒ Object
Invite users to an event wiki.developers.facebook.com/index.php/Events.invite E.g: @session.event_invite(‘1000321123’, %w4567 1000123321, :personal_message => “Please come!”).
- #event_members(eid) ⇒ Object
-
#event_rsvp(eid, rsvp_status, options = {}) ⇒ Object
RSVP to an event wiki.developers.facebook.com/index.php/Events.rsvp E.g: @session.event_rsvp(‘1000321123’, ‘attending’).
-
#events(options = {}) ⇒ Object
This one has so many parameters, a Hash seemed cleaner than a long param list.
- #expired? ⇒ Boolean
- #fields_to_serialize ⇒ Object
- #fql_build_object(type, hash) ⇒ Object
- #fql_multiquery(queries, format = 'XML') ⇒ Object
- #fql_query(query, format = 'XML') ⇒ Object
- #get_albums(aids) ⇒ Object
-
#get_comments(xid) ⇒ Object
pulls comment list for a given XID.
- #get_photos(pids = nil, subj_id = nil, aid = nil) ⇒ Object
-
#get_stream(viewer_id, options = {}) ⇒ Object
Retrieve a viewer’s facebook stream See wiki.developers.facebook.com/index.php/Stream.get for options.
- #get_tags(pids) ⇒ Object
- #infinite? ⇒ Boolean
-
#initialize(api_key, secret_key) ⇒ Session
constructor
A new instance of Session.
- #install_url(options = {}) ⇒ Object
- #install_url_optional_parameters(options) ⇒ Object
- #instance_variable_set_value(field, value) ⇒ Object
- #instance_variable_value(field) ⇒ Object
-
#is_fan(page_id, uid) ⇒ Object
Takes page_id and uid, returns true if uid is a fan of the page_id.
- #login_url(options = {}) ⇒ Object
- #login_url_optional_parameters(options) ⇒ Object
-
#marshal_dump ⇒ Object
Only serialize the bare minimum to recreate the session.
-
#marshal_load(variables) ⇒ Object
Only serialize the bare minimum to recreate the session.
- #mobile ⇒ Object
- #pages(options = {}) ⇒ Object
-
#permission_url(permission, options = {}) ⇒ Object
The url to get user to approve extended permissions wiki.developers.facebook.com/index.php/Extended_permission.
- #post(method, params = {}, use_session_key = true, &proc) ⇒ Object
- #post_file(method, params = {}) ⇒ Object
- #post_without_logging(method, params = {}, use_session_key = true, &proc) ⇒ Object
-
#publish_user_action(bundle_id, data = {}, target_ids = nil, body_general = nil, story_size = nil) ⇒ Object
publish a previously rendered template bundle see wiki.developers.facebook.com/index.php/Feed.publishUserAction.
-
#register_template_bundle(one_line_story_templates, short_story_templates = nil, full_story_template = nil, action_links = nil) ⇒ Object
Register a template bundle with Facebook.
-
#remove_comment(xid, comment_id) ⇒ Object
remove a comment from a given xid stream with comment_id.
- #secret_for_method(method_name) ⇒ Object
- #secure!(args = {}) ⇒ Object
- #secure_with!(session_key, uid = nil, expires = nil, secret_from_session = nil) ⇒ Object
- #secure_with_session_secret! ⇒ Object
- #secured? ⇒ Boolean
-
#send_email(user_ids, subject, text, fbml = nil) ⇒ Object
Send email to as many as 100 users at a time.
- #send_notification(user_ids, fbml, email_fbml = nil) ⇒ Object
-
#server_cache ⇒ Object
Returns a proxy object for handling calls to Facebook cached items such as images and FBML ref handles.
-
#to_yaml(opts = {}) ⇒ Object
Only serialize the bare minimum to recreate the session.
-
#upload_native_strings(native_strings) ⇒ Object
Upload strings in native locale to facebook for translations.
- #user ⇒ Object
- #users(user_ids, fields = []) ⇒ Object
- #users_standard(user_ids, fields = []) ⇒ Object
Constructor Details
#initialize(api_key, secret_key) ⇒ Session
Returns a new instance of Session.
173 174 175 176 177 178 179 180 181 182 |
# File 'lib/facebooker/session.rb', line 173 def initialize(api_key, secret_key) @api_key = api_key @secret_key = secret_key @batch_request = nil @session_key = nil @uid = nil @auth_token = nil @secret_from_session = nil @expires = nil end |
Instance Attribute Details
#auth_token ⇒ Object
188 189 190 |
# File 'lib/facebooker/session.rb', line 188 def auth_token @auth_token ||= post 'facebook.auth.createToken' end |
#secret_from_session ⇒ Object (readonly)
Returns the value of attribute secret_from_session.
80 81 82 |
# File 'lib/facebooker/session.rb', line 80 def secret_from_session @secret_from_session end |
#session_key ⇒ Object (readonly)
Returns the value of attribute session_key.
79 80 81 |
# File 'lib/facebooker/session.rb', line 79 def session_key @session_key end |
Class Method Details
.api_key ⇒ Object
89 90 91 |
# File 'lib/facebooker/session.rb', line 89 def self.api_key extract_key_from_environment(:api) || extract_key_from_configuration_file(:api) rescue report_inability_to_find_key(:api) end |
.configuration_file_path ⇒ Object
731 732 733 |
# File 'lib/facebooker/session.rb', line 731 def self.configuration_file_path @configuration_file_path || File.("~/.facebookerrc") end |
.configuration_file_path=(path) ⇒ Object
735 736 737 |
# File 'lib/facebooker/session.rb', line 735 def self.configuration_file_path=(path) @configuration_file_path = path end |
.create(api_key = nil, secret_key = nil) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/facebooker/session.rb', line 82 def self.create(api_key=nil, secret_key=nil) api_key ||= self.api_key secret_key ||= self.secret_key raise ArgumentError unless !api_key.nil? && !secret_key.nil? new(api_key, secret_key) end |
.current ⇒ Object
97 98 99 |
# File 'lib/facebooker/session.rb', line 97 def self.current Thread.current['facebook_session'] end |
.current=(session) ⇒ Object
101 102 103 |
# File 'lib/facebooker/session.rb', line 101 def self.current=(session) Thread.current['facebook_session'] = session end |
.secret_key ⇒ Object
93 94 95 |
# File 'lib/facebooker/session.rb', line 93 def self.secret_key extract_key_from_environment(:secret) || extract_key_from_configuration_file(:secret) rescue report_inability_to_find_key(:secret) end |
Instance Method Details
#active_template_bundles ⇒ Object
543 544 545 |
# File 'lib/facebooker/session.rb', line 543 def active_template_bundles post("facebook.feed.getRegisteredTemplateBundles",{},false) end |
#add_next_parameters(options) ⇒ Object
148 149 150 151 152 153 |
# File 'lib/facebooker/session.rb', line 148 def add_next_parameters() opts = [] opts << "&next=#{CGI.escape([:next])}" if [:next] opts << "&next_cancel=#{CGI.escape([:next_cancel])}" if [:next_cancel] opts end |
#add_tags(pid, x, y, tag_uid = nil, tag_text = nil) ⇒ Object
491 492 493 494 495 496 |
# File 'lib/facebooker/session.rb', line 491 def (pid, x, y, tag_uid = nil, tag_text = nil ) if [tag_uid, tag_text].all? {|arg| arg.nil?} raise ArgumentError, "Must enter a name or string for this tag" end @tags = post('facebook.photos.addTag', :pid => pid, :tag_uid => tag_uid, :tag_text => tag_text, :x => x, :y => y ) end |
#add_to_batch(req, &proc) ⇒ Object
642 643 644 645 646 |
# File 'lib/facebooker/session.rb', line 642 def add_to_batch(req,&proc) batch_request = BatchRequest.new(req,proc) Thread.current[:facebooker_current_batch_queue]<<batch_request batch_request end |
#admin ⇒ Object
409 410 411 |
# File 'lib/facebooker/session.rb', line 409 def admin Facebooker::Admin.new(self) end |
#application ⇒ Object
413 414 415 |
# File 'lib/facebooker/session.rb', line 413 def application Facebooker::Application.new(self) end |
#batch(serial_only = false) ⇒ Object
Submit the enclosed requests for this session inside a batch
All requests will be sent to Facebook at the end of the block each method inside the block will return a proxy object attempting to access the proxy before the end of the block will yield an exception
For Example:
facebook_session.batch do
@send_result = facebook_session.send_notification([12451752],"Woohoo")
@albums = facebook_session.user.albums
end
puts @albums.first.inspect
is valid, however
facebook_session.batch do
@send_result = facebook_session.send_notification([12451752],"Woohoo")
@albums = facebook_session.user.albums
puts @albums.first.inspect
end
will raise Facebooker::BatchRequest::UnexecutedRequest
If an exception is raised while processing the result, that exception will be re-raised on the next access to that object or when exception_raised? is called
for example, if the send_notification resulted in TooManyUserCalls being raised, calling
@send_result.exception_raised?
would re-raise that exception if there was an error retrieving the albums, it would be re-raised when
@albums.first
is called
683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/facebooker/session.rb', line 683 def batch(serial_only=false) @batch_request=true Thread.current[:facebooker_current_batch_queue]=[] yield # Set the batch request to false so that post will execute the batch job @batch_request=false BatchRun.current_batch=Thread.current[:facebooker_current_batch_queue] post("facebook.batch.run",:method_feed=>BatchRun.current_batch.map{|q| q.uri}.to_json,:serial_only=>serial_only.to_s) ensure @batch_request=false BatchRun.current_batch=nil end |
#batch_request? ⇒ Boolean
638 639 640 |
# File 'lib/facebooker/session.rb', line 638 def batch_request? @batch_request end |
#cancel_event(eid, options = {}) ⇒ Object
Cancel an event wiki.developers.facebook.com/index.php/Events.cancel E.g:
@session.cancel_event('100321123', :cancel_message => "It's raining...")
# => Returns true if all went well
337 338 339 340 |
# File 'lib/facebooker/session.rb', line 337 def cancel_event(eid, = {}) result = post('facebook.events.cancel', .merge(:eid => eid)) result == '1' ? true : false end |
#check_friendship(array_of_pairs_of_users) ⇒ Object
Given an array like:
- [userid, otheruserid], [yetanotherid, andanotherid]
-
returns a Hash indicating friendship of those pairs: otheruserid] => true, [yetanotherid, andanotherid] => false if one of the Hash values is nil, it means the facebook platform’s answer is “I don’t know”
427 428 429 430 431 432 433 434 435 |
# File 'lib/facebooker/session.rb', line 427 def check_friendship(array_of_pairs_of_users) uids1 = [] uids2 = [] array_of_pairs_of_users.each do |pair| uids1 << pair.first uids2 << pair.last end post('facebook.friends.areFriends', :uids1 => uids1.join(','), :uids2 => uids2.join(',')) end |
#connect_permission_url(permission, options = {}) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/facebooker/session.rb', line 135 def (,={}) = .merge() = add_next_parameters() << "&ext_perm=#{}" "#{Facebooker.}#{.join}" end |
#create_event(event_info, multipart_post_file = nil) ⇒ Object
Creates an event with the event_info hash and an optional Net::HTTP::MultipartPostFile for the event picture. If ActiveSupport::TimeWithZone is installed (it’s in Rails > 2.1), and start_time or end_time are given as ActiveSupport::TimeWithZone, then they will be assumed to represent local time for the event. They will automatically be converted to the expected timezone for Facebook, which is PST or PDT depending on when the event occurs. Returns the eid of the newly created event wiki.developers.facebook.com/index.php/Events.create
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/facebooker/session.rb', line 304 def create_event(event_info, multipart_post_file = nil) if defined?(ActiveSupport::TimeWithZone) && defined?(ActiveSupport::TimeZone) # Facebook expects all event local times to be in Pacific Time, so we need to take the actual local time and # send it to Facebook as if it were Pacific Time converted to Unix epoch timestamp. Very confusing... facebook_time = ActiveSupport::TimeZone["Pacific Time (US & Canada)"] start_time = event_info.delete(:start_time) || event_info.delete('start_time') if start_time && start_time.is_a?(ActiveSupport::TimeWithZone) event_info['start_time'] = facebook_time.parse(start_time.strftime("%Y-%m-%d %H:%M:%S")).to_i else event_info['start_time'] = start_time end end_time = event_info.delete(:end_time) || event_info.delete('end_time') if end_time && end_time.is_a?(ActiveSupport::TimeWithZone) event_info['end_time'] = facebook_time.parse(end_time.strftime("%Y-%m-%d %H:%M:%S")).to_i else event_info['end_time'] = end_time end end post_file('facebook.events.create', :event_info => event_info.to_json, nil => multipart_post_file) end |
#data ⇒ Object
Returns a proxy object for handling calls to the Facebook Data API
405 406 407 |
# File 'lib/facebooker/session.rb', line 405 def data Facebooker::Data.new(self) end |
#deactivate_template_bundle_by_id(template_bundle_id) ⇒ Object
Deactivate a template bundle with Facebook. Returns true if a bundle with the specified id is active and owned by this app. Useful to avoid exceeding the 100 templates/app limit.
539 540 541 |
# File 'lib/facebooker/session.rb', line 539 def deactivate_template_bundle_by_id(template_bundle_id) post("facebook.feed.deactivateTemplateBundleByID", {:template_bundle_id => template_bundle_id.to_s}, false) end |
#default_login_url_options ⇒ Object
169 170 171 |
# File 'lib/facebooker/session.rb', line 169 def {} end |
#edit_event(eid, event_info, options = {}) ⇒ Object
328 329 330 |
# File 'lib/facebooker/session.rb', line 328 def edit_event(eid, event_info, = {}) post('facebook.events.edit', .merge(:eid => eid, :event_info => event_info.to_json)) end |
#event_invite(eid, uids, options = {}) ⇒ Object
Invite users to an event wiki.developers.facebook.com/index.php/Events.invite E.g: @session.event_invite(‘1000321123’, %w4567 1000123321, :personal_message => “Please come!”)
346 347 348 |
# File 'lib/facebooker/session.rb', line 346 def event_invite(eid, uids, = {}) post('facebook.events.invite', .merge(:eid => eid, :uids => uids.to_json)) end |
#event_members(eid) ⇒ Object
358 359 360 361 362 363 364 365 |
# File 'lib/facebooker/session.rb', line 358 def event_members(eid) @members ||= {} @members[eid] ||= post('facebook.events.getMembers', :eid => eid) do |response| response.map do |attendee_hash| Event::Attendance.from_hash(attendee_hash) end end end |
#event_rsvp(eid, rsvp_status, options = {}) ⇒ Object
RSVP to an event wiki.developers.facebook.com/index.php/Events.rsvp E.g: @session.event_rsvp(‘1000321123’, ‘attending’)
354 355 356 |
# File 'lib/facebooker/session.rb', line 354 def event_rsvp(eid,rsvp_status, = {}) post('facebook.events.rsvp', .merge(:eid => eid, :rsvp_status => rsvp_status)) end |
#events(options = {}) ⇒ Object
This one has so many parameters, a Hash seemed cleaner than a long param list. Options can be: :uid => Filter by events associated with a user with this uid :eids => Filter by this list of event ids. This is a comma-separated list of eids. :start_time => Filter with this UTC as lower bound. A missing or zero parameter indicates no lower bound. (Time or Integer) :end_time => Filter with this UTC as upper bound. A missing or zero parameter indicates no upper bound. (Time or Integer) :rsvp_status => Filter by this RSVP status.
289 290 291 292 293 294 295 296 |
# File 'lib/facebooker/session.rb', line 289 def events( = {}) @events ||= {} @events[.to_s] ||= post('facebook.events.get', ) do |response| response.map do |hash| Event.from_hash(hash) end end end |
#expired? ⇒ Boolean
196 197 198 |
# File 'lib/facebooker/session.rb', line 196 def expired? @expires.nil? || (!infinite? && Time.at(@expires) <= Time.now) end |
#fields_to_serialize ⇒ Object
612 613 614 |
# File 'lib/facebooker/session.rb', line 612 def fields_to_serialize %w(session_key uid expires secret_from_session auth_token api_key secret_key) end |
#fql_build_object(type, hash) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/facebooker/session.rb', line 220 def fql_build_object(type, hash) case type when 'user' user = User.new user.session = self user.populate_from_hash!(hash) user when 'photo' Photo.from_hash(hash) when 'album' Album.from_hash(hash) when 'page' Page.from_hash(hash) when 'page_admin' Page.from_hash(hash) when 'group' Group.from_hash(hash) when 'event' Event.from_hash(hash) when 'event_member' Event::Attendance.from_hash(hash) else hash end end |
#fql_multiquery(queries, format = 'XML') ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/facebooker/session.rb', line 259 def fql_multiquery(queries, format = 'XML') results = {} post('facebook.fql.multiquery', :queries => queries.to_json, :format => format) do |responses| responses.each do |response| name = response.shift response = response.shift type = response.shift value = [] unless type.nil? value = response.shift.map do |hash| fql_build_object(type, hash) end end results[name] = value end end results end |
#fql_query(query, format = 'XML') ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/facebooker/session.rb', line 246 def fql_query(query, format = 'XML') post('facebook.fql.query', :query => query, :format => format) do |response| type = response.shift if type.nil? [] else response.shift.map do |hash| fql_build_object(type, hash) end end end end |
#get_albums(aids) ⇒ Object
464 465 466 467 468 469 470 |
# File 'lib/facebooker/session.rb', line 464 def get_albums(aids) @albums = post('facebook.photos.getAlbums', :aids => aids) do |response| response.map do |hash| Album.from_hash(hash) end end end |
#get_comments(xid) ⇒ Object
pulls comment list for a given XID
456 457 458 459 460 461 462 |
# File 'lib/facebooker/session.rb', line 456 def get_comments(xid) @comments = post('facebook.comments.get', :xid => xid) do |response| response.map do |hash| Comment.from_hash(hash) end end end |
#get_photos(pids = nil, subj_id = nil, aid = nil) ⇒ Object
437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/facebooker/session.rb', line 437 def get_photos(pids = nil, subj_id = nil, aid = nil) if [subj_id, pids, aid].all? {|arg| arg.nil?} raise ArgumentError, "Can't get a photo without a picture, album or subject ID" end # We have to normalize params orherwise FB complain about signature params = {:pids => pids, :subj_id => subj_id, :aid => aid}.delete_if { |k,v| v.nil? } @photos = post('facebook.photos.get', params ) do |response| response.map do |hash| Photo.from_hash(hash) end end end |
#get_stream(viewer_id, options = {}) ⇒ Object
Retrieve a viewer’s facebook stream See wiki.developers.facebook.com/index.php/Stream.get for options
476 477 478 479 480 481 |
# File 'lib/facebooker/session.rb', line 476 def get_stream(viewer_id, = {}) @stream = post('facebook.stream.get', (viewer_id, ), true) do |response| response end end |
#get_tags(pids) ⇒ Object
483 484 485 486 487 488 489 |
# File 'lib/facebooker/session.rb', line 483 def (pids) @tags = post('facebook.photos.getTags', :pids => pids) do |response| response.map do |hash| Tag.from_hash(hash) end end end |
#infinite? ⇒ Boolean
192 193 194 |
# File 'lib/facebooker/session.rb', line 192 def infinite? @expires == 0 end |
#install_url(options = {}) ⇒ Object
110 111 112 |
# File 'lib/facebooker/session.rb', line 110 def install_url(={}) "#{Facebooker.install_url_base}#{install_url_optional_parameters()}" end |
#install_url_optional_parameters(options) ⇒ Object
142 143 144 145 146 |
# File 'lib/facebooker/session.rb', line 142 def install_url_optional_parameters() optional_parameters = [] optional_parameters += add_next_parameters() optional_parameters.join end |
#instance_variable_set_value(field, value) ⇒ Object
604 605 606 |
# File 'lib/facebooker/session.rb', line 604 def instance_variable_set_value(field, value) self.instance_variable_set("@#{field}", value) end |
#instance_variable_value(field) ⇒ Object
608 609 610 |
# File 'lib/facebooker/session.rb', line 608 def instance_variable_value(field) self.instance_variable_get("@#{field}") end |
#is_fan(page_id, uid) ⇒ Object
Takes page_id and uid, returns true if uid is a fan of the page_id
390 391 392 393 |
# File 'lib/facebooker/session.rb', line 390 def is_fan(page_id, uid) puts "Deprecated. Use Page#user_is_fan? instead" Page.new(page_id).user_is_fan?(uid) end |
#login_url(options = {}) ⇒ Object
105 106 107 108 |
# File 'lib/facebooker/session.rb', line 105 def login_url(={}) = .merge() "#{Facebooker.login_url_base}#{login_url_optional_parameters()}" end |
#login_url_optional_parameters(options) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/facebooker/session.rb', line 155 def login_url_optional_parameters() # It is important that unused options are omitted as stuff like &canvas=false will still display the canvas. optional_parameters = [] optional_parameters += add_next_parameters() optional_parameters << "&skipcookie=true" if [:skip_cookie] optional_parameters << "&hide_checkbox=true" if [:hide_checkbox] optional_parameters << "&canvas=true" if [:canvas] optional_parameters << "&fbconnect=true" if [:fbconnect] optional_parameters << "&return_session=true" if [:return_session] optional_parameters << "&session_key_only=true" if [:session_key_only] optional_parameters << "&req_perms=#{[:req_perms]}" if [:req_perms] optional_parameters.join end |
#marshal_dump ⇒ Object
Only serialize the bare minimum to recreate the session.
589 590 591 |
# File 'lib/facebooker/session.rb', line 589 def marshal_dump#:nodoc: fields_to_serialize.map{|field| instance_variable_value(field)} end |
#marshal_load(variables) ⇒ Object
Only serialize the bare minimum to recreate the session.
584 585 586 |
# File 'lib/facebooker/session.rb', line 584 def marshal_load(variables)#:nodoc: fields_to_serialize.each_with_index{|field, index| instance_variable_set_value(field, variables[index])} end |
#mobile ⇒ Object
417 418 419 |
# File 'lib/facebooker/session.rb', line 417 def mobile Facebooker::Mobile.new(self) end |
#pages(options = {}) ⇒ Object
379 380 381 382 383 384 385 386 387 |
# File 'lib/facebooker/session.rb', line 379 def pages( = {}) raise ArgumentError, 'fields option is mandatory' unless .has_key?(:fields) @pages ||= {} @pages[] ||= post('facebook.pages.getInfo', ) do |response| response.map do |hash| Page.from_hash(hash) end end end |
#permission_url(permission, options = {}) ⇒ Object
The url to get user to approve extended permissions wiki.developers.facebook.com/index.php/Extended_permission
permissions:
-
email
-
offline_access
-
status_update
-
photo_upload
-
video_upload
-
create_listing
-
create_event
-
rsvp_event
-
sms
-
read_mailbox
128 129 130 131 132 133 |
# File 'lib/facebooker/session.rb', line 128 def (,={}) = .merge() = add_next_parameters() << "&ext_perm=#{}" "#{Facebooker.}#{.join}" end |
#post(method, params = {}, use_session_key = true, &proc) ⇒ Object
709 710 711 712 713 714 715 716 717 |
# File 'lib/facebooker/session.rb', line 709 def post(method, params = {}, use_session_key = true, &proc) if batch_request? or Facebooker::Logging.skip_api_logging post_without_logging(method, params, use_session_key, &proc) else Logging.log_fb_api(method, params) do post_without_logging(method, params, use_session_key, &proc) end end end |
#post_file(method, params = {}) ⇒ Object
719 720 721 722 723 724 725 726 |
# File 'lib/facebooker/session.rb', line 719 def post_file(method, params = {}) base = params.delete(:base) Logging.log_fb_api(method, params) do add_facebook_params(params, method) @session_key && params[:session_key] ||= @session_key unless params[:uid] service.post_file(params.merge(:base => base, :sig => signature_for(params.reject{|key, value| key.nil?}))) end end |
#post_without_logging(method, params = {}, use_session_key = true, &proc) ⇒ Object
696 697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/facebooker/session.rb', line 696 def post_without_logging(method, params = {}, use_session_key = true, &proc) add_facebook_params(params, method) use_session_key && @session_key && params[:session_key] ||= @session_key final_params=params.merge(:sig => signature_for(params)) if batch_request? add_to_batch(final_params,&proc) else result = service.post(final_params) result = yield result if block_given? result end end |
#publish_user_action(bundle_id, data = {}, target_ids = nil, body_general = nil, story_size = nil) ⇒ Object
publish a previously rendered template bundle see wiki.developers.facebook.com/index.php/Feed.publishUserAction
551 552 553 554 555 556 557 |
# File 'lib/facebooker/session.rb', line 551 def publish_user_action(bundle_id,data={},target_ids=nil,body_general=nil,story_size=nil) parameters={:template_bundle_id=>bundle_id,:template_data=>data.to_json} parameters[:target_ids] = target_ids unless target_ids.blank? parameters[:body_general] = body_general unless body_general.blank? parameters[:story_size] = story_size unless story_size.nil? post("facebook.feed.publishUserAction", parameters) end |
#register_template_bundle(one_line_story_templates, short_story_templates = nil, full_story_template = nil, action_links = nil) ⇒ Object
Register a template bundle with Facebook. returns the template id to use to send using this template
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/facebooker/session.rb', line 515 def register_template_bundle(one_line_story_templates,short_story_templates=nil,full_story_template=nil, action_links=nil) templates = ensure_array(one_line_story_templates) parameters = {:one_line_story_templates => templates.to_json} unless action_links.blank? parameters[:action_links] = action_links.to_json end unless short_story_templates.blank? templates = ensure_array(short_story_templates) parameters[:short_story_templates] = templates.to_json end unless full_story_template.blank? parameters[:full_story_template] = full_story_template.to_json end post("facebook.feed.registerTemplateBundle", parameters, false) end |
#remove_comment(xid, comment_id) ⇒ Object
remove a comment from a given xid stream with comment_id
451 452 453 |
# File 'lib/facebooker/session.rb', line 451 def remove_comment(xid,comment_id) post('facebook.comments.remove', :xid=>xid, :comment_id =>comment_id) end |
#secret_for_method(method_name) ⇒ Object
184 185 186 |
# File 'lib/facebooker/session.rb', line 184 def secret_for_method(method_name) @secret_key end |
#secure!(args = {}) ⇒ Object
204 205 206 207 |
# File 'lib/facebooker/session.rb', line 204 def secure!(args = {}) response = post 'facebook.auth.getSession', :auth_token => auth_token, :generate_session_secret => args[:generate_session_secret] ? "1" : "0" secure_with!(response['session_key'], response['uid'], response['expires'], response['secret']) end |
#secure_with!(session_key, uid = nil, expires = nil, secret_from_session = nil) ⇒ Object
213 214 215 216 217 218 |
# File 'lib/facebooker/session.rb', line 213 def secure_with!(session_key, uid = nil, expires = nil, secret_from_session = nil) @session_key = session_key @uid = uid ? Integer(uid) : post('facebook.users.getLoggedInUser', :session_key => session_key) @expires = expires ? Integer(expires) : 0 @secret_from_session = secret_from_session end |
#secure_with_session_secret! ⇒ Object
209 210 211 |
# File 'lib/facebooker/session.rb', line 209 def secure_with_session_secret! self.secure!(:generate_session_secret => true) end |
#secured? ⇒ Boolean
200 201 202 |
# File 'lib/facebooker/session.rb', line 200 def secured? !@session_key.nil? && !expired? end |
#send_email(user_ids, subject, text, fbml = nil) ⇒ Object
Send email to as many as 100 users at a time
577 578 579 580 581 |
# File 'lib/facebooker/session.rb', line 577 def send_email(user_ids, subject, text, fbml = nil) user_ids = Array(user_ids) params = {:fbml => fbml, :recipients => user_ids.map{ |id| User.cast_to_facebook_id(id)}.join(','), :text => text, :subject => subject} post 'facebook.notifications.sendEmail', params, false end |
#send_notification(user_ids, fbml, email_fbml = nil) ⇒ Object
498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/facebooker/session.rb', line 498 def send_notification(user_ids, fbml, email_fbml = nil) params = {:notification => fbml, :to_ids => user_ids.map{ |id| User.cast_to_facebook_id(id)}.join(',')} if email_fbml params[:email] = email_fbml end params[:type]="user_to_user" # if there is no uid, this is an announcement unless uid? params[:type]="app_to_user" end post 'facebook.notifications.send', params,uid? end |
#server_cache ⇒ Object
Returns a proxy object for handling calls to Facebook cached items such as images and FBML ref handles
399 400 401 |
# File 'lib/facebooker/session.rb', line 399 def server_cache Facebooker::ServerCache.new(self) end |
#to_yaml(opts = {}) ⇒ Object
Only serialize the bare minimum to recreate the session.
594 595 596 597 598 599 600 601 602 |
# File 'lib/facebooker/session.rb', line 594 def to_yaml( opts = {} ) YAML::quick_emit(self.object_id, opts) do |out| out.map(taguri) do |map| fields_to_serialize.each do |field| map.add(field, instance_variable_value(field)) end end end end |
#upload_native_strings(native_strings) ⇒ Object
Upload strings in native locale to facebook for translations.
e.g. facebook_session.upload_native_strings([:text => “Welcome #user”, :description => “Welcome message to currently logged in user.”]) returns the number of strings uploaded
See wiki.developers.facebook.com/index.php/Intl.uploadNativeStrings for method options
567 568 569 570 571 572 573 |
# File 'lib/facebooker/session.rb', line 567 def upload_native_strings(native_strings) raise ArgumentError, "You must provide strings to upload" if native_strings.nil? post('facebook.intl.uploadNativeStrings', :native_strings => Facebooker.json_encode(native_strings)) do |response| response end end |
#user ⇒ Object
278 279 280 |
# File 'lib/facebooker/session.rb', line 278 def user @user ||= User.new(uid, self) end |
#users(user_ids, fields = []) ⇒ Object
373 374 375 376 377 |
# File 'lib/facebooker/session.rb', line 373 def users(user_ids, fields=[]) post("facebook.users.getInfo",:uids=>user_ids.join(","),:fields=>User.user_fields(fields)) do |users| users.map { |u| User.new(u)} end end |
#users_standard(user_ids, fields = []) ⇒ Object
367 368 369 370 371 |
# File 'lib/facebooker/session.rb', line 367 def users_standard(user_ids, fields=[]) post("facebook.users.getStandardInfo",:uids=>user_ids.join(","),:fields=>User.standard_fields(fields)) do |users| users.map { |u| User.new(u)} end end |