Class: Facebooker::User

Inherits:
Object
  • Object
show all
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

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)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Model

#anon=, included, #populate_from_hash!, #populated?, #session

Constructor Details

- (User) initialize(*args)

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

- (Object) affiliations (readonly)

Returns the value of attribute affiliations



17
18
19
# File 'lib/facebooker/models/user.rb', line 17

def affiliations
  @affiliations
end

- (Object) request_locale

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

+ (Object) cast_to_facebook_id(object)



710
711
712
713
714
715
716
# File 'lib/facebooker/models/user.rb', line 710

def self.cast_to_facebook_id(object)
  if object.respond_to?(:facebook_id)
    object.facebook_id
  else
    object
  end
end

+ (Object) dashboard_multi_decrement_count(*uids)

Facebooker::User.dashboard_multi_decrement_count ['1234', '5678']



565
566
567
# File 'lib/facebooker/models/user.rb', line 565

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

+ (Object) dashboard_multi_get_count(*uids)

Facebooker::User.dashboard_multi_get_count ['1234', '5678']



550
551
552
# File 'lib/facebooker/models/user.rb', line 550

def self.dashboard_multi_get_count(*uids)
 Facebooker::Session.create.post("facebook.dashboard.multiGetCount", :uids => uids.flatten)
end

+ (Object) dashboard_multi_increment_count(*uids)

Facebooker::User.dashboard_multi_increment_count ['1234', '5678']



560
561
562
# File 'lib/facebooker/models/user.rb', line 560

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

+ (Object) dashboard_multi_set_count(ids)

Facebooker::User.dashboard_multi_set_count({ '1234' => '11', '5678' => '22' })



555
556
557
# File 'lib/facebooker/models/user.rb', line 555

def self.dashboard_multi_set_count(ids)
  Facebooker::Session.create.post("facebook.dashboard.multiSetCount", :ids => ids.to_json)
end

+ (Object) hash_email(email)



703
704
705
706
707
708
# File 'lib/facebooker/models/user.rb', line 703

def self.hash_email(email)
  email = email.downcase.strip
  crc=Zlib.crc32(email)
  md5=Digest::MD5.hexdigest(email)
  "#{crc}_#{md5}"
end

+ (Object) multi_add_news(uids, news, image = nil)

Facebooker::User.multi_add_news(['1234', '4321'], [{ :message => 'Hi users', :action_link => { :text => “Uh hey there app”, :href => 'facebook.er/' }}], '')



597
598
599
600
601
602
# File 'lib/facebooker/models/user.rb', line 597

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

+ (Object) multi_clear_news(ids)



605
606
607
# File 'lib/facebooker/models/user.rb', line 605

def self.multi_clear_news(ids)
  Facebooker::Session.create.post("facebook.dashboard.multiClearNews", :ids => ids.to_json)
end

+ (Object) multi_get_news(ids)



610
611
612
# File 'lib/facebooker/models/user.rb', line 610

def self.multi_get_news(ids)
  Facebooker::Session.create.post('facebook.dashboard.multiGetNews', :ids => ids.to_json)
end

+ (Object) register(users)

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



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/facebooker/models/user.rb', line 644

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

+ (Object) standard_fields(fields = [])



722
723
724
# File 'lib/facebooker/models/user.rb', line 722

def self.standard_fields(fields = [])
  valid_fields(fields,STANDARD_FIELDS)
end

+ (Object) unregister(email_hashes)

Unregister an array of email hashes



675
676
677
678
679
680
681
682
683
684
685
686
687
# File 'lib/facebooker/models/user.rb', line 675

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

+ (Object) unregister_emails(emails)

unregister an array of email addresses



690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/facebooker/models/user.rb', line 690

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

+ (Object) user_fields(fields = [])



718
719
720
# File 'lib/facebooker/models/user.rb', line 718

def self.user_fields(fields = [])
  valid_fields(fields)
end

Instance Method Details

- (Object) ==(other_user)

Two Facebooker::User objects should be considered equal if their Facebook ids are equal



635
636
637
# File 'lib/facebooker/models/user.rb', line 635

def ==(other_user)
  other_user.is_a?(User) && id == other_user.id
end

- (Object) add_comment(xid, text, title = nil, url = nil, publish_to_stream = false)

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



195
196
197
# File 'lib/facebooker/models/user.rb', line 195

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

- (Object) add_like_on(post_id)

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



205
206
207
# File 'lib/facebooker/models/user.rb', line 205

def add_like_on(post_id)
  @session.post('facebook.stream.addLike', {:post_id=>post_id})
end

- (Object) add_news(news, image = nil)

facebook_session.user.add_news [{ :message => 'Hey, who are you?', :action_link => { :text => “I-I'm a test user”, :href => 'facebook.er/' }}], ''



580
581
582
583
584
585
586
# File 'lib/facebooker/models/user.rb', line 580

def add_news(news, image=nil)
  params = { :uid => uid }
  params[:news] = news
  params[:image] = image if image
  
  session.post('facebook.dashboard.addNews', params)
end

- (Object) albums



301
302
303
304
305
306
307
# File 'lib/facebooker/models/user.rb', line 301

def albums
  @albums ||= session.post('facebook.photos.getAlbums', :uid => self.id) do |response|
    response.map do |hash|
      Album.from_hash(hash)
    end
  end
end

- (Boolean) app_user?

Returns whether the user (either the session user or user specified by uid) has authorized the calling application



479
480
481
# File 'lib/facebooker/models/user.rb', line 479

def app_user?
  session.post('facebook.users.isAppUser', {:uid => self.id}, use_session_key = true)
end

- (Object) cast_to_friend_list_id(flid)



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/facebooker/models/user.rb', line 92

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

- (Object) clear_news(*news_ids)

facebook_session.user.clear_news ['111111']



589
590
591
592
593
594
# File 'lib/facebooker/models/user.rb', line 589

def clear_news(*news_ids)
  params = { :uid => uid }
  params[:news_ids] = news_ids.flatten if news_ids
  
  session.post('facebook.dashboard.clearNews', params)
end

- (Object) comment_on(post_id, comment)

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



183
184
185
# File 'lib/facebooker/models/user.rb', line 183

def comment_on(post_id, comment)
  @session.post('facebook.stream.addComment', {:post_id=>post_id, :comment=>comment})
end

- (Object) convert_attachment_to_json(attachment)



171
172
173
174
# File 'lib/facebooker/models/user.rb', line 171

def convert_attachment_to_json(attachment)
  a = attachment.respond_to?(:to_hash) ? attachment.to_hash : attachment
  Facebooker.json_encode(a)
end

- (Object) create_album(params)



320
321
322
# File 'lib/facebooker/models/user.rb', line 320

def create_album(params)
  @album = session.post('facebook.photos.createAlbum', params) {|response| Album.from_hash(response)}
end

- (Object) dashboard_count

facebook_session.user.dashboard_count



527
528
529
# File 'lib/facebooker/models/user.rb', line 527

def dashboard_count
  session.post('facebook.dashboard.getCount', :uid => uid)
end

- (Object) dashboard_count=(new_count)

facebook_session.user.dashboard_count = 5



532
533
534
# File 'lib/facebooker/models/user.rb', line 532

def dashboard_count=(new_count)
  session.post('facebook.dashboard.setCount', :uid => uid, :count => new_count)
end

- (Object) dashboard_decrement_count

facebook_session.user.dashboard_decrement_count



542
543
544
# File 'lib/facebooker/models/user.rb', line 542

def dashboard_decrement_count
  session.post('facebook.dashboard.decrementCount', :uid => uid)
end

- (Object) dashboard_increment_count

facebook_session.user.dashboard_increment_count



537
538
539
# File 'lib/facebooker/models/user.rb', line 537

def dashboard_increment_count
  session.post('facebook.dashboard.incrementCount', :uid => uid)
end

- (Object) events(params = {})

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

- (Object) friend_ids



120
121
122
123
# File 'lib/facebooker/models/user.rb', line 120

def friend_ids
  options = {:uid => self.id}
  @session.post('facebook.friends.get', options, false)
end

- (Object) friend_ids_with_this_app



257
258
259
# File 'lib/facebooker/models/user.rb', line 257

def friend_ids_with_this_app
  @friend_ids_with_this_app ||= session.post('facebook.friends.getAppUsers')
end

- (Object) friend_lists



219
220
221
222
223
224
225
# File 'lib/facebooker/models/user.rb', line 219

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

- (Object) friends(flid = nil)

Retrieve friends



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/facebooker/models/user.rb', line 106

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"
   options = {:uid=>self.id}
   options[:flid] = flid unless flid.nil?
   @friends_hash[cache_key] ||= @session.post('facebook.friends.get', options,false).map do |uid|
      User.new(uid, @session)
  end
  @friends_hash[cache_key]
end

- (Object) friends!(*fields)

Retrieve friends with user info populated Subsequent calls will be retrieved from memory. Optional: list of fields to retrieve as symbols



230
231
232
233
234
# File 'lib/facebooker/models/user.rb', line 230

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

- (Object) friends=(list_of_friends, flid = nil)

Set the list of friends, given an array of User objects. If the list has been retrieved previously, will not set



83
84
85
86
87
88
89
90
# File 'lib/facebooker/models/user.rb', line 83

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

- (Boolean) friends_with?(user_or_id)



247
248
249
# File 'lib/facebooker/models/user.rb', line 247

def friends_with?(user_or_id)
  friends.map{|f| f.to_i}.include?(user_or_id.to_i)
end

- (Object) friends_with_this_app



251
252
253
254
255
# File 'lib/facebooker/models/user.rb', line 251

def friends_with_this_app
  @friends_with_this_app ||= friend_ids_with_this_app.map do |uid|
    User.new(uid, session)
  end
end

- (Object) get_activity(*activity_ids)

facebook_session.user.get_activity '123'



615
616
617
618
619
620
# File 'lib/facebooker/models/user.rb', line 615

def get_activity(*activity_ids)
  params = {}
  params[:activity_ids] = activity_ids.flatten if activity_ids
  
  session.post('facebook.dashboard.getActivity', params)
end

- (Object) get_cookies(name = nil)

Convenience method to get cookies for the current user



509
510
511
# File 'lib/facebooker/models/user.rb', line 509

def get_cookies(name=nil)
  session.data.get_cookies(id, name)
end

- (Object) get_news(*news_ids)



572
573
574
575
576
577
# File 'lib/facebooker/models/user.rb', line 572

def get_news(*news_ids)
  params = { :uid => uid }
  params[:news_ids] = news_ids.flatten if news_ids
  
  session.post('facebook.dashboard.getNews', params)
end

- (Object) get_profile_info



436
437
438
# File 'lib/facebooker/models/user.rb', line 436

def get_profile_info
  session.post('facebook.profile.getInfo', :uid => id)
end

- (Object) getUnconnectedFriendsCount

Get a count of unconnected friends



669
670
671
# File 'lib/facebooker/models/user.rb', line 669

def getUnconnectedFriendsCount
  session.post("facebook.connect.getUnconnectedFriendsCount")
end

- (Object) groups(gids = [])



261
262
263
264
265
266
267
268
# File 'lib/facebooker/models/user.rb', line 261

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

- (Boolean) has_permission?(ext_perm)

Checks to see if the user has enabled the given extended permission



473
474
475
# File 'lib/facebooker/models/user.rb', line 473

def has_permission?(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

- (Boolean) has_permissions?(ext_perms)

Convenience method to check multiple permissions at once



485
486
487
# File 'lib/facebooker/models/user.rb', line 485

def has_permissions?(ext_perms)
  ext_perms.all?{|p| has_permission?(p)}
end

- (Object) mobile_fbml=(markup)

Set the mobile profile FBML



405
406
407
# File 'lib/facebooker/models/user.rb', line 405

def mobile_fbml=(markup)
  set_profile_fbml(nil, markup, nil,nil)
end

- (Object) notifications



285
286
287
# File 'lib/facebooker/models/user.rb', line 285

def notifications
  @notifications ||= Notifications.from_hash(session.post('facebook.notifications.get'))
end

- (Object) populate(*fields)

Retrieve profile data for logged in user Optional: list of fields to retrieve as symbols



239
240
241
242
243
244
245
# File 'lib/facebooker/models/user.rb', line 239

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

- (Object) prepare_publish_to_options(target, options)

Prepares options for the stream.publish



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/facebooker/models/user.rb', line 151

def prepare_publish_to_options(target, options)
  opts = {:uid          => self.id,
          :target_id    => target.id,
          :message      => options[:message]}

  if a = options[:attachment]
    opts[:attachment] = convert_attachment_to_json(a)
  end
  if (links = options[:action_links] && Facebooker.json_encode(options[:action_links]))
    opts[:action_links] = links
  end
  unless options[:uid].nil?
    opts[:uid] = options[:uid]
  end
  if options[:post_as_page]
    opts.delete(:target_id)
  end
  opts
end

- (Object) profile_action=(markup)



409
410
411
# File 'lib/facebooker/models/user.rb', line 409

def profile_action=(markup)
  set_profile_fbml(nil, nil, markup,nil)
end

- (Object) profile_fbml



391
392
393
# File 'lib/facebooker/models/user.rb', line 391

def profile_fbml
  session.post('facebook.profile.getFBML', :uid => id)
end

- (Object) profile_fbml=(markup)

Set the profile FBML for this user

This does not set profile actions, that should be done with profile_action=



399
400
401
# File 'lib/facebooker/models/user.rb', line 399

def profile_fbml=(markup)
  set_profile_fbml(markup, nil, nil, nil)
end

- (Object) profile_main=(markup)



413
414
415
# File 'lib/facebooker/models/user.rb', line 413

def profile_main=(markup)
 set_profile_fbml(nil,nil,nil,markup)
end

- (Object) profile_photos



324
325
326
# File 'lib/facebooker/models/user.rb', line 324

def profile_photos
  session.get_photos(nil, nil, profile_pic_album_id)
end

- (Object) publish_action(action)



293
294
295
# File 'lib/facebooker/models/user.rb', line 293

def publish_action(action)
  publish(action)
end

- (Object) publish_activity(activity)

facebook_session.user.publish_activity({ :message => '<b>actor</b> rolled around', :action_link => { :text => 'Roll around too', :href => 'facebook.er/' }})



623
624
625
# File 'lib/facebooker/models/user.rb', line 623

def publish_activity(activity)
  session.post('facebook.dashboard.publishActivity', { :activity => activity.to_json })
end

- (Object) publish_story(story)



289
290
291
# File 'lib/facebooker/models/user.rb', line 289

def publish_story(story)
  publish(story)
end

- (Object) publish_templatized_action(action)



297
298
299
# File 'lib/facebooker/models/user.rb', line 297

def publish_templatized_action(action)
  publish(action)
end

- (Object) publish_to(target, options = {})

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/'
])


146
147
148
# File 'lib/facebooker/models/user.rb', line 146

def publish_to(target, options = {})
  @session.post('facebook.stream.publish', prepare_publish_to_options(target, options), false)
end

- (Object) remove_activity(*activity_ids)

facebook_session.user.remove_activity ['123']



628
629
630
# File 'lib/facebooker/models/user.rb', line 628

def remove_activity(*activity_ids)
  session.post('facebook.dashboard.removeActivity', { :activity_ids => activity_ids.flatten })
end

- (Object) remove_like_on(post_id)

Remove a like on a post

See: wiki.developers.facebook.com/index.php/Stream.removeLike

post_id the post_id for the post that is being commented on



215
216
217
# File 'lib/facebooker/models/user.rb', line 215

def remove_like_on(post_id)
  @session.post('facebook.stream.removeLike', {:post_id=>post_id})
end

- (Object) revoke_permission(ext_perm)

Revoke any extended permission given by a user



491
492
493
# File 'lib/facebooker/models/user.rb', line 491

def revoke_permission(ext_perm)
  session.post('facebook.auth.revokeExtendedPermission', { :perm => ext_perm, :uid => uid }, false)
end

- (Object) rsvp_event(eid, rsvp_status, options = {})

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
# File 'lib/facebooker/models/user.rb', line 77

def rsvp_event(eid, rsvp_status, options = {})
  result = @session.post('facebook.events.rsvp', options.merge(:eid => eid, :rsvp_status => rsvp_status))
end

- (Object) send_email(subject, text = nil, fbml = nil)

Convenience method to send email to the current user



497
498
499
# File 'lib/facebooker/models/user.rb', line 497

def send_email(subject, text=nil, fbml=nil)
  session.send_email([id], subject, text, fbml)
end

Convenience method to set cookie for the current user



503
504
505
# File 'lib/facebooker/models/user.rb', line 503

def set_cookie(name, value, expires=nil, path=nil)
  session.data.set_cookie(id, name, value, expires, path)
end

- (Object) set_profile_fbml_with_bebo_adapter(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil) 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

- (Object) set_profile_info(title, info_fields, format = :text)

** 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.


431
432
433
434
# File 'lib/facebooker/models/user.rb', line 431

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

- (Object) set_status(message)

Set the status for a user DOES NOT prepend “is” to the message

requires extended permission.



464
465
466
467
468
469
# File 'lib/facebooker/models/user.rb', line 464

def set_status(message)
  self.status=message
  session.post('facebook.users.setStatus',{:status=>message,:status_includes_verb=>1,:uid => uid}, false) do |ret|
    ret
  end
end

- (Object) status=(message)

This DOES NOT set the status of a user on Facebook Use the set_status method instead



443
444
445
446
447
448
449
450
# File 'lib/facebooker/models/user.rb', line 443

def status=(message)
  case message
  when String,Status
    @status = message
  when Hash
    @status = Status.from_hash(message)
  end
end

- (Object) statuses(limit = 50)

Return limit statuses from the user



455
456
457
# File 'lib/facebooker/models/user.rb', line 455

def statuses( limit = 50 )
  session.post('facebook.status.get', {:uid => uid, :limit => limit}).collect { |ret| Status.from_hash(ret) }
end

- (Object) stream(options = {})

Retrieve user's facebook stream See wiki.developers.facebook.com/index.php/Stream.get for options



314
315
316
317
318
# File 'lib/facebooker/models/user.rb', line 314

def stream(options = {})
  @stream = session.post('facebook.stream.get', prepare_get_stream_options(options)) do |response|
    response
  end
end

- (Object) threads(options = {})

Get threads in a folder

See: wiki.developers.facebook.com/index.php/Message.getThreadsInFolder

options possible options are :folder_id, :limit and :offset



276
277
278
279
280
281
282
283
# File 'lib/facebooker/models/user.rb', line 276

def threads(options = {})
  options ||= {}
  @threads = session.post('facebook.message.getThreadsInFolder', options) do |response|
    response.map do |hash|
      MessageThread.from_hash(hash)
    end
  end
end

- (Object) to_i

Returns the user's id as an integer



515
516
517
# File 'lib/facebooker/models/user.rb', line 515

def to_i
  id
end

- (Object) to_s



519
520
521
# File 'lib/facebooker/models/user.rb', line 519

def to_s
  id.to_s
end

- (Object) upload_photo(multipart_post_file, options = {})

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



354
355
356
357
# File 'lib/facebooker/models/user.rb', line 354

def upload_photo(multipart_post_file, options = {})
  Photo.from_hash(session.post_file('facebook.photos.upload',
    options.merge(nil => multipart_post_file)))
end

- (Object) upload_video(multipart_post_file, options = {})

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



386
387
388
389
# File 'lib/facebooker/models/user.rb', line 386

def upload_video(multipart_post_file, options = {})
  Video.from_hash(session.post_file('facebook.video.upload',
    options.merge(nil => multipart_post_file, :base => Facebooker.video_server_base)))
end