Class: Facebooker::User
- Inherits:
-
Object
- Object
- Facebooker::User
- Includes:
- Model
- Defined in:
- lib/facebooker/models/user.rb,
lib/facebooker/adapters/bebo_adapter.rb
Overview
Holds attributes and behavior for a Facebook User
Defined Under Namespace
Classes: Status
Constant Summary collapse
- FIELDS =
[:status, :political, :pic_small, :name, :quotes, :is_app_user, :tv, :profile_update_time, :meeting_sex, :hs_info, :timezone, :relationship_status, :hometown_location, :about_me, :wall_count, :significant_other_id, :pic_big, :music, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :birthday_date, :first_name, :meeting_for, :last_name, :interests, :current_location, :pic, :books, :affiliations, :locale, :profile_url, :proxied_email, :email_hashes, :allowed_restrictions, :pic_with_logo, :pic_big_with_logo, :pic_small_with_logo, :pic_square_with_logo, :online_presence, :verified, :profile_blurb, :username, :website, :is_blocked, :family, :email]
- STANDARD_FIELDS =
[:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url, :proxied_email, :email]
Instance Attribute Summary collapse
-
#affiliations ⇒ Object
readonly
Returns the value of attribute affiliations.
-
#request_locale ⇒ Object
Returns the value of attribute request_locale.
Class Method Summary collapse
- .cast_to_facebook_id(object) ⇒ Object
-
.dashboard_multi_decrement_count(*uids) ⇒ Object
Facebooker::User.dashboard_multi_decrement_count [‘1234’, ‘5678’].
-
.dashboard_multi_get_count(*uids) ⇒ Object
Facebooker::User.dashboard_multi_get_count [‘1234’, ‘5678’].
-
.dashboard_multi_increment_count(*uids) ⇒ Object
Facebooker::User.dashboard_multi_increment_count [‘1234’, ‘5678’].
-
.dashboard_multi_set_count(ids) ⇒ Object
Facebooker::User.dashboard_multi_set_count({ ‘1234’ => ‘11’, ‘5678’ => ‘22’ }).
- .hash_email(email) ⇒ Object
-
.multi_add_news(uids, news, image = nil) ⇒ Object
Facebooker::User.multi_add_news([‘1234’, ‘4321’], [{ :message => ‘Hi users’, :action_link => { :text => “Uh hey there app”, :href => ‘facebook.er/’ }}], ‘’).
-
.multi_clear_news(ids) ⇒ Object
Facebooker::User.multi_clear_news(href=""319103117527"">1234”=>, “4321”=>).
-
.multi_get_news(ids) ⇒ Object
Facebooker::User.multi_get_news(href=""319103117527"">1234”=>, “4321”=>).
-
.register(users) ⇒ Object
register a user with Facebook users should be a hast with at least an :email field you can optionally provide an :account_id field as well.
- .standard_fields(fields = []) ⇒ Object
-
.unregister(email_hashes) ⇒ Object
Unregister an array of email hashes.
-
.unregister_emails(emails) ⇒ Object
unregister an array of email addresses.
- .user_fields(fields = []) ⇒ Object
Instance Method Summary collapse
-
#==(other_user) ⇒ Object
Two Facebooker::User objects should be considered equal if their Facebook ids are equal.
-
#add_comment(xid, text, title = nil, url = nil, publish_to_stream = false) ⇒ Object
Publish a comment to a specific comment set by xid.
-
#add_like_on(post_id) ⇒ Object
Add a like on a post.
-
#add_news(news, image = nil) ⇒ Object
facebook_session.user.add_news [{ :message => ‘Hey, who are you?’, :action_link => { :text => “I-I’m a test user”, :href => ‘facebook.er/’ }}], ‘’.
- #albums ⇒ Object
-
#app_user? ⇒ Boolean
Returns whether the user (either the session user or user specified by uid) has authorized the calling application.
- #cast_to_friend_list_id(flid) ⇒ Object
-
#clear_news(*news_ids) ⇒ Object
facebook_session.user.clear_news [‘111111’].
-
#comment_on(post_id, comment) ⇒ Object
Publish a comment on a post.
- #convert_attachment_to_json(attachment) ⇒ Object
- #create_album(params) ⇒ Object
-
#dashboard_count ⇒ Object
facebook_session.user.dashboard_count.
-
#dashboard_count=(new_count) ⇒ Object
facebook_session.user.dashboard_count = 5.
-
#dashboard_decrement_count ⇒ Object
facebook_session.user.dashboard_decrement_count.
-
#dashboard_increment_count ⇒ Object
facebook_session.user.dashboard_increment_count.
-
#events(params = {}) ⇒ Object
Returns a user’s events, params correspond to API call parameters (except UID): wiki.developers.facebook.com/index.php/Events.get E.g: @user.events(:start_time => Time.now, :end_time => 1.month.from_now) # => Returns events betwen now and a month from now.
- #friend_ids ⇒ Object
- #friend_ids_with_this_app ⇒ Object
- #friend_lists ⇒ Object
-
#friends(flid = nil) ⇒ Object
Retrieve friends.
-
#friends!(*fields) ⇒ Object
Retrieve friends with user info populated Subsequent calls will be retrieved from memory.
-
#friends=(list_of_friends, flid = nil) ⇒ Object
Set the list of friends, given an array of User objects.
- #friends_with?(user_or_id) ⇒ Boolean
- #friends_with_this_app ⇒ Object
-
#get_activity(*activity_ids) ⇒ Object
facebook_session.user.get_activity ‘123’.
-
#get_cookies(name = nil) ⇒ Object
Convenience method to get cookies for the current user.
- #get_news(*news_ids) ⇒ Object
- #get_profile_info ⇒ Object
-
#getUnconnectedFriendsCount ⇒ Object
Get a count of unconnected friends.
- #groups(gids = []) ⇒ Object
-
#has_permission?(ext_perm) ⇒ Boolean
Checks to see if the user has enabled the given extended permission.
-
#has_permissions?(ext_perms) ⇒ Boolean
Convenience method to check multiple permissions at once.
-
#initialize(*args) ⇒ User
constructor
Can pass in these two forms: id, session, (optional) attribute_hash attribute_hash.
-
#mobile_fbml=(markup) ⇒ Object
Set the mobile profile FBML.
- #notifications ⇒ Object
-
#populate(*fields) ⇒ Object
Retrieve profile data for logged in user Optional: list of fields to retrieve as symbols.
-
#prepare_publish_to_options(target, options) ⇒ Object
Prepares options for the stream.publish.
- #profile_action=(markup) ⇒ Object
- #profile_fbml ⇒ Object
-
#profile_fbml=(markup) ⇒ Object
Set the profile FBML for this user.
- #profile_main=(markup) ⇒ Object
- #profile_photos ⇒ Object
- #publish_action(action) ⇒ Object
-
#publish_activity(activity) ⇒ Object
facebook_session.user.publish_activity({ :message => ‘<strong>actor</strong> rolled around’, :action_link => { :text => ‘Roll around too’, :href => ‘facebook.er/’ }}).
- #publish_story(story) ⇒ Object
- #publish_templatized_action(action) ⇒ Object
-
#publish_to(target, options = {}) ⇒ Object
Publish a post into the stream on the user’s Wall and News Feed.
-
#remove_activity(*activity_ids) ⇒ Object
facebook_session.user.remove_activity [‘123’].
-
#rsvp_event(eid, rsvp_status, options = {}) ⇒ Object
Rsvp to an event with the eid and rsvp_status which can be ‘attending’, ‘unsure’, or ‘declined’.
-
#send_email(subject, text = nil, fbml = nil) ⇒ Object
Convenience method to send email to the current user.
-
#set_cookie(name, value, expires = nil, path = nil) ⇒ Object
Convenience method to set cookie for the current user.
- #set_profile_fbml_with_bebo_adapter(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil) ⇒ Object (also: #set_profile_fbml)
-
#set_profile_info(title, info_fields, format = :text) ⇒ Object
** NEW PROFILE DESIGN *** Set a info section for this user.
-
#set_status(message) ⇒ Object
Set the status for a user DOES NOT prepend “is” to the message.
-
#status=(message) ⇒ Object
This DOES NOT set the status of a user on Facebook Use the set_status method instead.
-
#statuses(limit = 50) ⇒ Object
Return
limit
statuses from the user. -
#threads(options = {}) ⇒ Object
Get threads in a folder.
-
#to_i ⇒ Object
Returns the user’s id as an integer.
- #to_s ⇒ Object
-
#upload_photo(multipart_post_file, options = {}) ⇒ Object
Upload a photo to the user’s profile.
-
#upload_video(multipart_post_file, options = {}) ⇒ Object
Upload a video to the user’s profile.
Methods included from Model
#anon=, included, #populate_from_hash!, #populated?, #session
Constructor Details
#initialize(*args) ⇒ User
Can pass in these two forms: id, session, (optional) attribute_hash attribute_hash
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/facebooker/models/user.rb', line 33 def initialize(*args) @friends = nil @current_location = nil @pic = nil @hometown_location = nil @populated = false @session = nil @id = nil if (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args.size==1 self.uid = args.shift @session = Session.current elsif (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args[1].kind_of?(Session) self.uid = args.shift @session = args.shift end if args.last.kind_of?(Hash) populate_from_hash!(args.pop) end end |
Instance Attribute Details
#affiliations ⇒ Object (readonly)
Returns the value of attribute affiliations.
17 18 19 |
# File 'lib/facebooker/models/user.rb', line 17 def affiliations @affiliations end |
#request_locale ⇒ Object
Returns the value of attribute request_locale.
28 29 30 |
# File 'lib/facebooker/models/user.rb', line 28 def request_locale @request_locale end |
Class Method Details
.cast_to_facebook_id(object) ⇒ Object
684 685 686 687 688 689 690 |
# File 'lib/facebooker/models/user.rb', line 684 def self.cast_to_facebook_id(object) if object.respond_to?(:facebook_id) object.facebook_id else object end end |
.dashboard_multi_decrement_count(*uids) ⇒ Object
Facebooker::User.dashboard_multi_decrement_count [‘1234’, ‘5678’]
539 540 541 |
# File 'lib/facebooker/models/user.rb', line 539 def self.dashboard_multi_decrement_count(*uids) Facebooker::Session.create.post("facebook.dashboard.multiDecrementCount", :uids => uids.flatten.collect{ |uid| uid.to_s }.to_json) end |
.dashboard_multi_get_count(*uids) ⇒ Object
Facebooker::User.dashboard_multi_get_count [‘1234’, ‘5678’]
524 525 526 |
# File 'lib/facebooker/models/user.rb', line 524 def self.dashboard_multi_get_count(*uids) Facebooker::Session.create.post("facebook.dashboard.multiGetCount", :uids => uids.flatten) end |
.dashboard_multi_increment_count(*uids) ⇒ Object
Facebooker::User.dashboard_multi_increment_count [‘1234’, ‘5678’]
534 535 536 |
# File 'lib/facebooker/models/user.rb', line 534 def self.dashboard_multi_increment_count(*uids) Facebooker::Session.create.post("facebook.dashboard.multiIncrementCount", :uids => uids.flatten.collect{ |uid| uid.to_s }.to_json) end |
.dashboard_multi_set_count(ids) ⇒ Object
Facebooker::User.dashboard_multi_set_count({ ‘1234’ => ‘11’, ‘5678’ => ‘22’ })
529 530 531 |
# File 'lib/facebooker/models/user.rb', line 529 def self.dashboard_multi_set_count(ids) Facebooker::Session.create.post("facebook.dashboard.multiSetCount", :ids => ids.to_json) end |
.hash_email(email) ⇒ Object
677 678 679 680 681 682 |
# File 'lib/facebooker/models/user.rb', line 677 def self.hash_email(email) email = email.downcase.strip crc=Zlib.crc32(email) md5=Digest::MD5.hexdigest(email) "#{crc}_#{md5}" end |
.multi_add_news(uids, news, image = nil) ⇒ Object
Facebooker::User.multi_add_news([‘1234’, ‘4321’], [{ :message => ‘Hi users’, :action_link => { :text => “Uh hey there app”, :href => ‘facebook.er/’ }}], ‘’)
571 572 573 574 575 576 |
# File 'lib/facebooker/models/user.rb', line 571 def self.multi_add_news(uids, news, image=nil) params = { :uids => uids, :news => news } params[:image] = image if image Facebooker::Session.create.post("facebook.dashboard.multiAddNews", params) end |
.multi_clear_news(ids) ⇒ Object
Facebooker::User.multi_clear_news(href=""319103117527"">1234”=>, “4321”=>)
579 580 581 |
# File 'lib/facebooker/models/user.rb', line 579 def self.multi_clear_news(ids) Facebooker::Session.create.post("facebook.dashboard.multiClearNews", :ids => ids.to_json) end |
.multi_get_news(ids) ⇒ Object
Facebooker::User.multi_get_news(href=""319103117527"">1234”=>, “4321”=>)
584 585 586 |
# File 'lib/facebooker/models/user.rb', line 584 def self.multi_get_news(ids) Facebooker::Session.create.post('facebook.dashboard.multiGetNews', :ids => ids.to_json) end |
.register(users) ⇒ Object
register a user with Facebook users should be a hast with at least an :email field you can optionally provide an :account_id field as well
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/facebooker/models/user.rb', line 618 def self.register(users) user_map={} users=users.map do |h| returning h.dup do |d| if email=d.delete(:email) hash = hash_email(email) user_map[hash]=h d[:email_hash]=hash end end end Facebooker::Session.create.post("facebook.connect.registerUsers",:accounts=>users.to_json) do |ret| ret.each do |hash| user_map.delete(hash) end unless user_map.empty? e=Facebooker::Session::UserRegistrationFailed.new e.failed_users = user_map.values raise e end ret end end |
.standard_fields(fields = []) ⇒ Object
696 697 698 |
# File 'lib/facebooker/models/user.rb', line 696 def self.standard_fields(fields = []) valid_fields(fields,STANDARD_FIELDS) end |
.unregister(email_hashes) ⇒ Object
Unregister an array of email hashes
649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/facebooker/models/user.rb', line 649 def self.unregister(email_hashes) Facebooker::Session.create.post("facebook.connect.unregisterUsers",:email_hashes=>email_hashes.to_json) do |ret| ret.each do |hash| email_hashes.delete(hash) end unless email_hashes.empty? e=Facebooker::Session::UserUnRegistrationFailed.new e.failed_users = email_hashes raise e end ret end end |
.unregister_emails(emails) ⇒ Object
unregister an array of email addresses
664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/facebooker/models/user.rb', line 664 def self.unregister_emails(emails) emails_hash = {} emails.each {|e| emails_hash[hash_email(e)] = e} begin unregister(emails_hash.keys).collect {|r| emails_hash[r]} rescue # re-raise with emails instead of hashes. e = Facebooker::Session::UserUnRegistrationFailed.new e.failed_users = $!.failed_users.collect { |f| emails_hash[f] } raise e end end |
.user_fields(fields = []) ⇒ Object
692 693 694 |
# File 'lib/facebooker/models/user.rb', line 692 def self.user_fields(fields = []) valid_fields(fields) end |
Instance Method Details
#==(other_user) ⇒ Object
Two Facebooker::User objects should be considered equal if their Facebook ids are equal
609 610 611 |
# File 'lib/facebooker/models/user.rb', line 609 def ==(other_user) other_user.is_a?(User) && id == other_user.id end |
#add_comment(xid, text, title = nil, url = nil, publish_to_stream = false) ⇒ Object
Publish a comment to a specific comment set by xid
See: wiki.developers.facebook.com/index.php/Comments.add
xid
the xid for the set of comments text
the text of the comment
196 197 198 |
# File 'lib/facebooker/models/user.rb', line 196 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_like_on(post_id) ⇒ Object
Add a like on a post
See: wiki.developers.facebook.com/index.php/Stream.addLike
post_id
the post_id for the post that is being commented on
206 207 208 |
# File 'lib/facebooker/models/user.rb', line 206 def add_like_on(post_id) @session.post('facebook.stream.addLike', {:post_id=>post_id}) end |
#add_news(news, image = nil) ⇒ Object
facebook_session.user.add_news [{ :message => ‘Hey, who are you?’, :action_link => { :text => “I-I’m a test user”, :href => ‘facebook.er/’ }}], ‘’
554 555 556 557 558 559 560 |
# File 'lib/facebooker/models/user.rb', line 554 def add_news(news, image=nil) params = { :uid => uid } params[:news] = news params[:image] = image if image session.post('facebook.dashboard.addNews', params) end |
#albums ⇒ Object
292 293 294 295 296 297 298 |
# File 'lib/facebooker/models/user.rb', line 292 def albums @albums ||= session.post('facebook.photos.getAlbums', :uid => self.id) do |response| response.map do |hash| Album.from_hash(hash) end end end |
#app_user? ⇒ Boolean
Returns whether the user (either the session user or user specified by uid) has authorized the calling application
459 460 461 |
# File 'lib/facebooker/models/user.rb', line 459 def app_user? session.post('facebook.users.isAppUser', {:uid => self.id}, use_session_key = true) end |
#cast_to_friend_list_id(flid) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/facebooker/models/user.rb', line 93 def cast_to_friend_list_id(flid) case flid when String list=friend_lists.detect {|f| f.name==flid} raise Facebooker::Session::InvalidFriendList unless list list.flid when FriendList flid.flid else flid end end |
#clear_news(*news_ids) ⇒ Object
facebook_session.user.clear_news [‘111111’]
563 564 565 566 567 568 |
# File 'lib/facebooker/models/user.rb', line 563 def clear_news(*news_ids) params = { :uid => uid } params[:news_ids] = news_ids.flatten if news_ids session.post('facebook.dashboard.clearNews', params) end |
#comment_on(post_id, comment) ⇒ Object
Publish a comment on a post
See: wiki.developers.facebook.com/index.php/Stream.addComment
post_id
the post_id for the post that is being commented on comment
the text of the comment
184 185 186 |
# File 'lib/facebooker/models/user.rb', line 184 def comment_on(post_id, comment) @session.post('facebook.stream.addComment', {:post_id=>post_id, :comment=>comment}) end |
#convert_attachment_to_json(attachment) ⇒ Object
172 173 174 175 |
# File 'lib/facebooker/models/user.rb', line 172 def () a = .respond_to?(:to_hash) ? .to_hash : Facebooker.json_encode(a) end |
#create_album(params) ⇒ Object
300 301 302 |
# File 'lib/facebooker/models/user.rb', line 300 def create_album(params) @album = session.post('facebook.photos.createAlbum', params) {|response| Album.from_hash(response)} end |
#dashboard_count ⇒ Object
facebook_session.user.dashboard_count
501 502 503 |
# File 'lib/facebooker/models/user.rb', line 501 def dashboard_count session.post('facebook.dashboard.getCount', :uid => uid) end |
#dashboard_count=(new_count) ⇒ Object
facebook_session.user.dashboard_count = 5
506 507 508 |
# File 'lib/facebooker/models/user.rb', line 506 def dashboard_count=(new_count) session.post('facebook.dashboard.setCount', :uid => uid, :count => new_count) end |
#dashboard_decrement_count ⇒ Object
facebook_session.user.dashboard_decrement_count
516 517 518 |
# File 'lib/facebooker/models/user.rb', line 516 def dashboard_decrement_count session.post('facebook.dashboard.decrementCount', :uid => uid) end |
#dashboard_increment_count ⇒ Object
facebook_session.user.dashboard_increment_count
511 512 513 |
# File 'lib/facebooker/models/user.rb', line 511 def dashboard_increment_count session.post('facebook.dashboard.incrementCount', :uid => uid) end |
#events(params = {}) ⇒ Object
Returns a user’s events, params correspond to API call parameters (except UID): wiki.developers.facebook.com/index.php/Events.get E.g:
@user.events(:start_time => Time.now, :end_time => 1.month.from_now)
# => Returns events betwen now and a month from now
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/facebooker/models/user.rb', line 61 def events(params={}) @events ||= {} [:start_time,:end_time].compact.each do |key| params[key] = params[key].to_i end # puts @events[params.to_s].nil? @events[params.to_s] ||= @session.post('facebook.events.get', {:uid => self.id}.merge(params)).map do |event| Event.from_hash(event) end end |
#friend_ids ⇒ Object
121 122 123 124 |
# File 'lib/facebooker/models/user.rb', line 121 def friend_ids = {:uid => self.id} @session.post('facebook.friends.get', , false) end |
#friend_ids_with_this_app ⇒ Object
248 249 250 |
# File 'lib/facebooker/models/user.rb', line 248 def friend_ids_with_this_app @friend_ids_with_this_app ||= session.post('facebook.friends.getAppUsers') end |
#friend_lists ⇒ Object
210 211 212 213 214 215 216 |
# File 'lib/facebooker/models/user.rb', line 210 def friend_lists @friend_lists ||= @session.post('facebook.friends.getLists').map do |hash| friend_list = FriendList.from_hash(hash) friend_list.session = session friend_list end end |
#friends(flid = nil) ⇒ Object
Retrieve friends
107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/facebooker/models/user.rb', line 107 def friends(flid = nil) @friends_hash ||= {} flid=cast_to_friend_list_id(flid) #use __blank instead of nil so that this is cached cache_key = flid||"__blank" = {:uid=>self.id} [:flid] = flid unless flid.nil? @friends_hash[cache_key] ||= @session.post('facebook.friends.get', ,false).map do |uid| User.new(uid, @session) end @friends_hash[cache_key] end |
#friends!(*fields) ⇒ Object
Retrieve friends with user info populated Subsequent calls will be retrieved from memory. Optional: list of fields to retrieve as symbols
221 222 223 224 225 |
# File 'lib/facebooker/models/user.rb', line 221 def friends!(*fields) @friends ||= session.post('facebook.users.getInfo', :fields => collect(fields), :uids => friends.map{|f| f.id}.join(',')).map do |hash| User.new(hash['uid'], session, hash) end end |
#friends=(list_of_friends, flid = nil) ⇒ Object
Set the list of friends, given an array of User objects. If the list has been retrieved previously, will not set
84 85 86 87 88 89 90 91 |
# File 'lib/facebooker/models/user.rb', line 84 def friends=(list_of_friends,flid=nil) @friends_hash ||= {} flid=cast_to_friend_list_id(flid) #use __blank instead of nil so that this is cached cache_key = flid||"__blank" @friends_hash[cache_key] ||= list_of_friends end |
#friends_with?(user_or_id) ⇒ Boolean
238 239 240 |
# File 'lib/facebooker/models/user.rb', line 238 def friends_with?(user_or_id) friends.map{|f| f.to_i}.include?(user_or_id.to_i) end |
#friends_with_this_app ⇒ Object
242 243 244 245 246 |
# File 'lib/facebooker/models/user.rb', line 242 def friends_with_this_app @friends_with_this_app ||= friend_ids_with_this_app.map do |uid| User.new(uid, session) end end |
#get_activity(*activity_ids) ⇒ Object
facebook_session.user.get_activity ‘123’
589 590 591 592 593 594 |
# File 'lib/facebooker/models/user.rb', line 589 def get_activity(*activity_ids) params = {} params[:activity_ids] = activity_ids.flatten if activity_ids session.post('facebook.dashboard.getActivity', params) end |
#get_cookies(name = nil) ⇒ Object
Convenience method to get cookies for the current user
483 484 485 |
# File 'lib/facebooker/models/user.rb', line 483 def (name=nil) session.data.(id, name) end |
#get_news(*news_ids) ⇒ Object
546 547 548 549 550 551 |
# File 'lib/facebooker/models/user.rb', line 546 def get_news(*news_ids) params = { :uid => uid } params[:news_ids] = news_ids.flatten if news_ids session.post('facebook.dashboard.getNews', params) end |
#get_profile_info ⇒ Object
416 417 418 |
# File 'lib/facebooker/models/user.rb', line 416 def get_profile_info session.post('facebook.profile.getInfo', :uid => id) end |
#getUnconnectedFriendsCount ⇒ Object
Get a count of unconnected friends
643 644 645 |
# File 'lib/facebooker/models/user.rb', line 643 def getUnconnectedFriendsCount session.post("facebook.connect.getUnconnectedFriendsCount") end |
#groups(gids = []) ⇒ Object
252 253 254 255 256 257 258 259 |
# File 'lib/facebooker/models/user.rb', line 252 def groups(gids = []) args = gids.empty? ? {} : {:gids => gids} @groups ||= session.post('facebook.groups.get', args).map do |hash| group = Group.from_hash(hash) group.session = session group end end |
#has_permission?(ext_perm) ⇒ Boolean
Checks to see if the user has enabled the given extended permission
453 454 455 |
# File 'lib/facebooker/models/user.rb', line 453 def (ext_perm) # ext_perm = email, offline_access, status_update, photo_upload, create_listing, create_event, rsvp_event, sms session.post('facebook.users.hasAppPermission', {:ext_perm=>ext_perm, :uid => uid}, false) == "1" end |
#has_permissions?(ext_perms) ⇒ Boolean
Convenience method to check multiple permissions at once
465 466 467 |
# File 'lib/facebooker/models/user.rb', line 465 def (ext_perms) ext_perms.all?{|p| (p)} end |
#mobile_fbml=(markup) ⇒ Object
Set the mobile profile FBML
385 386 387 |
# File 'lib/facebooker/models/user.rb', line 385 def mobile_fbml=(markup) set_profile_fbml(nil, markup, nil,nil) end |
#notifications ⇒ Object
276 277 278 |
# File 'lib/facebooker/models/user.rb', line 276 def notifications @notifications ||= Notifications.from_hash(session.post('facebook.notifications.get')) end |
#populate(*fields) ⇒ Object
Retrieve profile data for logged in user Optional: list of fields to retrieve as symbols
230 231 232 233 234 235 236 |
# File 'lib/facebooker/models/user.rb', line 230 def populate(*fields) arguments = {:fields => collect(fields), :uids => id} arguments[:locale]=request_locale unless request_locale.nil? session.post('facebook.users.getInfo', arguments) do |response| populate_from_hash!(response.first) end end |
#prepare_publish_to_options(target, options) ⇒ Object
Prepares options for the stream.publish
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/facebooker/models/user.rb', line 152 def (target, ) opts = {:uid => self.id, :target_id => target.id, :message => [:message]} if a = [:attachment] opts[:attachment] = (a) end if (links = [:action_links] && Facebooker.json_encode([:action_links])) opts[:action_links] = links end unless [:uid].nil? opts[:uid] = [:uid] end if [:post_as_page] opts.delete(:target_id) end opts end |
#profile_action=(markup) ⇒ Object
389 390 391 |
# File 'lib/facebooker/models/user.rb', line 389 def profile_action=(markup) set_profile_fbml(nil, nil, markup,nil) end |
#profile_fbml ⇒ Object
371 372 373 |
# File 'lib/facebooker/models/user.rb', line 371 def profile_fbml session.post('facebook.profile.getFBML', :uid => id) end |
#profile_fbml=(markup) ⇒ Object
Set the profile FBML for this user
This does not set profile actions, that should be done with profile_action=
379 380 381 |
# File 'lib/facebooker/models/user.rb', line 379 def profile_fbml=(markup) set_profile_fbml(markup, nil, nil, nil) end |
#profile_main=(markup) ⇒ Object
393 394 395 |
# File 'lib/facebooker/models/user.rb', line 393 def profile_main=(markup) set_profile_fbml(nil,nil,nil,markup) end |
#profile_photos ⇒ Object
304 305 306 |
# File 'lib/facebooker/models/user.rb', line 304 def profile_photos session.get_photos(nil, nil, profile_pic_album_id) end |
#publish_action(action) ⇒ Object
284 285 286 |
# File 'lib/facebooker/models/user.rb', line 284 def publish_action(action) publish(action) end |
#publish_activity(activity) ⇒ Object
facebook_session.user.publish_activity({ :message => ‘<strong>actor</strong> rolled around’, :action_link => { :text => ‘Roll around too’, :href => ‘facebook.er/’ }})
597 598 599 |
# File 'lib/facebooker/models/user.rb', line 597 def publish_activity(activity) session.post('facebook.dashboard.publishActivity', { :activity => activity.to_json }) end |
#publish_story(story) ⇒ Object
280 281 282 |
# File 'lib/facebooker/models/user.rb', line 280 def publish_story(story) publish(story) end |
#publish_templatized_action(action) ⇒ Object
288 289 290 |
# File 'lib/facebooker/models/user.rb', line 288 def publish_templatized_action(action) publish(action) end |
#publish_to(target, options = {}) ⇒ Object
Publish a post into the stream on the user’s Wall and News Feed. This post also appears in the user’s friend’s streams. The publish_stream
extended permission must be granted in order to use this method.
See: wiki.developers.facebook.com/index.php/Stream.publish
target
can be the current user or some other user.
To publish to a Page on the Page’s behave, specify the page id as :uid and set :post_as_page to ‘true’, use the current user as target
Example:
# Publish a message to my own wall:
me.publish_to(me, :message => 'hello world')
# Publish to a friend's wall with an action link:
me.publish_to(my_friend, :message => 'how are you?', :action_links => [
:text => 'my website',
:href => 'http://tenderlovemaking.com/'
])
147 148 149 |
# File 'lib/facebooker/models/user.rb', line 147 def publish_to(target, = {}) @session.post('facebook.stream.publish', (target, ), false) end |
#remove_activity(*activity_ids) ⇒ Object
facebook_session.user.remove_activity [‘123’]
602 603 604 |
# File 'lib/facebooker/models/user.rb', line 602 def remove_activity(*activity_ids) session.post('facebook.dashboard.removeActivity', { :activity_ids => activity_ids.flatten }) end |
#rsvp_event(eid, rsvp_status, options = {}) ⇒ Object
Rsvp to an event with the eid and rsvp_status which can be ‘attending’, ‘unsure’, or ‘declined’. wiki.developers.facebook.com/index.php/Events.rsvp E.g:
@user.rsvp_event('100321123', 'attending')
# => Returns true if all went well
77 78 79 80 |
# File 'lib/facebooker/models/user.rb', line 77 def rsvp_event(eid, rsvp_status, = {}) result = @session.post('facebook.events.rsvp', .merge(:eid => eid, :rsvp_status => rsvp_status)) result == '1' ? true : false end |
#send_email(subject, text = nil, fbml = nil) ⇒ Object
Convenience method to send email to the current user
471 472 473 |
# File 'lib/facebooker/models/user.rb', line 471 def send_email(subject, text=nil, fbml=nil) session.send_email([id], subject, text, fbml) end |
#set_cookie(name, value, expires = nil, path = nil) ⇒ Object
Convenience method to set cookie for the current user
477 478 479 |
# File 'lib/facebooker/models/user.rb', line 477 def (name, value, expires=nil, path=nil) session.data.(id, name, value, expires, path) end |
#set_profile_fbml_with_bebo_adapter(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil) ⇒ Object Also known as: set_profile_fbml
38 39 40 41 42 43 44 |
# File 'lib/facebooker/adapters/bebo_adapter.rb', line 38 def set_profile_fbml_with_bebo_adapter(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil) if(Facebooker.is_for?(:bebo)) self.session.post('facebook.profile.setFBML', :uid => @id, :markup => profile_fbml) else set_profile_fbml_without_bebo_adapter(profile_fbml,mobile_fbml, profile_action_fbml, profile_main) end end |
#set_profile_info(title, info_fields, format = :text) ⇒ Object
** NEW PROFILE DESIGN *** Set a info section for this user
Note: using set_profile_info as I feel using user.set_info could be confused with the user.getInfo facebook method.
Also, I feel it fits in line with user.set_profile_fbml.
411 412 413 414 |
# File 'lib/facebooker/models/user.rb', line 411 def set_profile_info(title, info_fields, format = :text) session.post('facebook.profile.setInfo', :title => title, :uid => id, :type => format.to_s == "text" ? 1 : 5, :info_fields => info_fields.to_json) end |
#set_status(message) ⇒ Object
Set the status for a user DOES NOT prepend “is” to the message
requires extended permission.
444 445 446 447 448 449 |
# File 'lib/facebooker/models/user.rb', line 444 def set_status() self.status= session.post('facebook.users.setStatus',{:status=>,:status_includes_verb=>1,:uid => uid}, false) do |ret| ret end end |
#status=(message) ⇒ Object
This DOES NOT set the status of a user on Facebook Use the set_status method instead
423 424 425 426 427 428 429 430 |
# File 'lib/facebooker/models/user.rb', line 423 def status=() case when String,Status @status = when Hash @status = Status.from_hash() end end |
#statuses(limit = 50) ⇒ Object
Return limit
statuses from the user
435 436 437 |
# File 'lib/facebooker/models/user.rb', line 435 def statuses( limit = 50 ) session.post('facebook.status.get', {:uid => uid, :limit => limit}).collect { |ret| Status.from_hash(ret) } end |
#threads(options = {}) ⇒ Object
Get threads in a folder
See: wiki.developers.facebook.com/index.php/Message.getThreadsInFolder
options
possible options are :folder_id, :limit and :offset
267 268 269 270 271 272 273 274 |
# File 'lib/facebooker/models/user.rb', line 267 def threads( = {}) ||= {} @threads = session.post('facebook.message.getThreadsInFolder', ) do |response| response.map do |hash| MessageThread.from_hash(hash) end end end |
#to_i ⇒ Object
Returns the user’s id as an integer
489 490 491 |
# File 'lib/facebooker/models/user.rb', line 489 def to_i id end |
#to_s ⇒ Object
493 494 495 |
# File 'lib/facebooker/models/user.rb', line 493 def to_s id.to_s end |
#upload_photo(multipart_post_file, options = {}) ⇒ Object
Upload a photo to the user’s profile.
In your view, create a multipart form that posts directly to your application (not through canvas):
<% form_tag photos_url(:canvas => false), :html => {:multipart => true, :promptpermission => 'photo_upload'} do %>
Photo: <%= file_field_tag 'photo' %>
Caption: <%= text_area_tag 'caption' %>
<%= submit_tag 'Upload Photo', :class => 'inputsubmit' %>
<% end %>
And in your controller:
class PhotosController < ApplicationController
def create
file = Net::HTTP::MultipartPostFile.new(
params[:photo].original_filename,
params[:photo].content_type,
params[:photo].read
)
@photo = facebook_session.user.upload_photo(file, :caption => params[:caption])
redirect_to photos_url(:canvas => true)
end
end
Options correspond to wiki.developers.facebook.com/index.php/Photos.upload
334 335 336 337 |
# File 'lib/facebooker/models/user.rb', line 334 def upload_photo(multipart_post_file, = {}) Photo.from_hash(session.post_file('facebook.photos.upload', .merge(nil => multipart_post_file))) end |
#upload_video(multipart_post_file, options = {}) ⇒ Object
Upload a video to the user’s profile.
In your view, create a multipart form that posts directly to your application (not through canvas):
<% form_tag videos_url(:canvas => false), :html => {:multipart => true, :promptpermission => 'video_upload'} do %>
Video: <%= file_field_tag 'video' %>
Title: <%= text_area_tag 'title' %>
Description: <%= text_area_tag 'description' %>
<%= submit_tag 'Upload Video', :class => 'inputsubmit' %>
<% end %>
And in your controller:
class VideosController < ApplicationController
def create
file = Net::HTTP::MultipartPostFile.new(
params[:photo].original_filename,
params[:photo].content_type,
params[:photo].read
)
@video = facebook_session.user.upload_video(file, :description => params[:description])
redirect_to videos_url(:canvas => true)
end
end
Options correspond to wiki.developers.facebook.com/index.php/Video.upload
366 367 368 369 |
# File 'lib/facebooker/models/user.rb', line 366 def upload_video(multipart_post_file, = {}) Video.from_hash(session.post_file('facebook.video.upload', .merge(nil => multipart_post_file, :base => Facebooker.video_server_base))) end |