facebooker 1.0.18 → 1.0.29
Sign up to get free protection for your applications and to get access to all the features.
- data/{History.txt → CHANGELOG.rdoc} +0 -0
- data/{COPYING → COPYING.rdoc} +0 -0
- data/{README.txt → README.rdoc} +11 -4
- data/Rakefile +18 -15
- data/{TODO.txt → TODO.rdoc} +0 -0
- data/generators/facebook/templates/config/facebooker.yml +3 -0
- data/init.rb +12 -61
- data/lib/facebooker.rb +22 -15
- data/lib/facebooker/adapters/adapter_base.rb +3 -0
- data/lib/facebooker/logging.rb +1 -1
- data/lib/facebooker/model.rb +6 -4
- data/lib/facebooker/models/user.rb +39 -4
- data/lib/facebooker/parser.rb +14 -0
- data/lib/facebooker/rails/controller.rb +34 -10
- data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
- data/lib/facebooker/rails/extensions/rack_setup.rb +2 -0
- data/lib/facebooker/rails/extensions/routing.rb +15 -0
- data/lib/facebooker/rails/facebook_url_helper.rb +3 -3
- data/lib/facebooker/rails/facebook_url_rewriting.rb +18 -5
- data/lib/facebooker/rails/helpers.rb +19 -2
- data/lib/facebooker/rails/helpers/fb_connect.rb +20 -10
- data/lib/facebooker/rails/publisher.rb +9 -5
- data/lib/facebooker/service.rb +1 -2
- data/lib/facebooker/session.rb +13 -1
- data/lib/facebooker/version.rb +1 -1
- data/lib/rack/facebook.rb +77 -0
- data/lib/tasks/tunnel.rake +3 -3
- data/test/facebooker/logging_test.rb +2 -2
- data/test/facebooker/models/user_test.rb +39 -3
- data/test/facebooker/rails/publisher_test.rb +19 -3
- data/test/facebooker/rails_integration_test.rb +52 -6
- data/test/rack/facebook_test.rb +62 -0
- data/test/rails_test_helper.rb +2 -0
- metadata +21 -27
- data/CHANGELOG.txt +0 -0
- data/Manifest.txt +0 -127
- data/README +0 -46
- data/lib/facebooker/models/user.rb.orig +0 -396
- data/lib/facebooker/models/user.rb.rej +0 -17
- data/lib/facebooker/session.rb.orig +0 -564
- data/lib/facebooker/session.rb.rej +0 -29
data/CHANGELOG.txt
DELETED
File without changes
|
data/Manifest.txt
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
CHANGELOG.txt
|
2
|
-
COPYING
|
3
|
-
History.txt
|
4
|
-
Manifest.txt
|
5
|
-
README
|
6
|
-
README.txt
|
7
|
-
Rakefile
|
8
|
-
TODO.txt
|
9
|
-
generators/publisher/publisher_generator.rb
|
10
|
-
generators/facebook/facebook_generator.rb
|
11
|
-
generators/facebook/templates/config/facebooker.yml
|
12
|
-
generators/facebook/templates/public/javascripts/facebooker.js
|
13
|
-
generators/facebook_controller/USAGE
|
14
|
-
generators/facebook_controller/facebook_controller_generator.rb
|
15
|
-
generators/facebook_controller/templates/controller.rb
|
16
|
-
generators/facebook_controller/templates/functional_test.rb
|
17
|
-
generators/facebook_controller/templates/helper.rb
|
18
|
-
generators/facebook_controller/templates/view.fbml.erb
|
19
|
-
generators/facebook_controller/templates/view.html.erb
|
20
|
-
generators/facebook_publisher/facebook_publisher_generator.rb
|
21
|
-
generators/facebook_publisher/templates/create_facebook_templates.rb
|
22
|
-
generators/facebook_publisher/templates/publisher.rb
|
23
|
-
generators/facebook_scaffold/USAGE
|
24
|
-
generators/facebook_scaffold/facebook_scaffold_generator.rb
|
25
|
-
generators/facebook_scaffold/templates/controller.rb
|
26
|
-
generators/facebook_scaffold/templates/facebook_style.css
|
27
|
-
generators/facebook_scaffold/templates/functional_test.rb
|
28
|
-
generators/facebook_scaffold/templates/helper.rb
|
29
|
-
generators/facebook_scaffold/templates/layout.fbml.erb
|
30
|
-
generators/facebook_scaffold/templates/layout.html.erb
|
31
|
-
generators/facebook_scaffold/templates/style.css
|
32
|
-
generators/facebook_scaffold/templates/view_edit.fbml.erb
|
33
|
-
generators/facebook_scaffold/templates/view_edit.html.erb
|
34
|
-
generators/facebook_scaffold/templates/view_index.fbml.erb
|
35
|
-
generators/facebook_scaffold/templates/view_index.html.erb
|
36
|
-
generators/facebook_scaffold/templates/view_new.fbml.erb
|
37
|
-
generators/facebook_scaffold/templates/view_new.html.erb
|
38
|
-
generators/facebook_scaffold/templates/view_show.fbml.erb
|
39
|
-
generators/facebook_scaffold/templates/view_show.html.erb
|
40
|
-
generators/xd_receiver/xd_receiver_generator.rb
|
41
|
-
generators/xd_receiver/templates/xd_receiver.html
|
42
|
-
init.rb
|
43
|
-
install.rb
|
44
|
-
lib/facebooker/adapters/adapter_base.rb
|
45
|
-
lib/facebooker/adapters/bebo_adapter.rb
|
46
|
-
lib/facebooker/adapters/facebook_adapter.rb
|
47
|
-
lib/facebooker/admin.rb
|
48
|
-
lib/facebooker/batch_request.rb
|
49
|
-
lib/facebooker/data.rb
|
50
|
-
lib/facebooker/feed.rb
|
51
|
-
lib/facebooker/logging.rb
|
52
|
-
lib/facebooker/mock/service.rb
|
53
|
-
lib/facebooker/mock/session.rb
|
54
|
-
lib/facebooker/mobile.rb
|
55
|
-
lib/facebooker/model.rb
|
56
|
-
lib/facebooker/models/affiliation.rb
|
57
|
-
lib/facebooker/models/album.rb
|
58
|
-
lib/facebooker/models/applicationproperties.rb
|
59
|
-
lib/facebooker/models/applicationrestrictions.rb
|
60
|
-
lib/facebooker/models/cookie.rb
|
61
|
-
lib/facebooker/models/education_info.rb
|
62
|
-
lib/facebooker/models/event.rb
|
63
|
-
lib/facebooker/models/friend_list.rb
|
64
|
-
lib/facebooker/models/group.rb
|
65
|
-
lib/facebooker/models/info_item.rb
|
66
|
-
lib/facebooker/models/info_section.rb
|
67
|
-
lib/facebooker/models/location.rb
|
68
|
-
lib/facebooker/models/notifications.rb
|
69
|
-
lib/facebooker/models/page.rb
|
70
|
-
lib/facebooker/models/photo.rb
|
71
|
-
lib/facebooker/models/tag.rb
|
72
|
-
lib/facebooker/models/user.rb
|
73
|
-
lib/facebooker/models/user.rb.orig
|
74
|
-
lib/facebooker/models/user.rb.rej
|
75
|
-
lib/facebooker/models/video.rb
|
76
|
-
lib/facebooker/models/work_info.rb
|
77
|
-
lib/facebooker/parser.rb
|
78
|
-
lib/facebooker/rails/controller.rb
|
79
|
-
lib/facebooker/rails/cucumber/world.rb
|
80
|
-
lib/facebooker/rails/cucumber.rb
|
81
|
-
lib/facebooker/rails/facebook_form_builder.rb
|
82
|
-
lib/facebooker/rails/facebook_pretty_errors.rb
|
83
|
-
lib/facebooker/rails/facebook_request_fix.rb
|
84
|
-
lib/facebooker/rails/facebook_session_handling.rb
|
85
|
-
lib/facebooker/rails/facebook_url_helper.rb
|
86
|
-
lib/facebooker/rails/facebook_url_rewriting.rb
|
87
|
-
lib/facebooker/rails/helpers/fb_connect.rb
|
88
|
-
lib/facebooker/rails/helpers.rb
|
89
|
-
lib/facebooker/rails/integration_session.rb
|
90
|
-
lib/facebooker/rails/profile_publisher_extensions.rb
|
91
|
-
lib/facebooker/rails/publisher.rb
|
92
|
-
lib/facebooker/rails/routing.rb
|
93
|
-
lib/facebooker/rails/test_helpers.rb
|
94
|
-
lib/facebooker/rails/utilities.rb
|
95
|
-
lib/facebooker/server_cache.rb
|
96
|
-
lib/facebooker/service.rb
|
97
|
-
lib/facebooker/session.rb
|
98
|
-
lib/facebooker/session.rb.orig
|
99
|
-
lib/facebooker/session.rb.rej
|
100
|
-
lib/facebooker/version.rb
|
101
|
-
lib/facebooker.rb
|
102
|
-
lib/net/http_multipart_post.rb
|
103
|
-
lib/tasks/facebooker.rake
|
104
|
-
lib/tasks/tunnel.rake
|
105
|
-
rails/init.rb
|
106
|
-
setup.rb
|
107
|
-
templates/layout.erb
|
108
|
-
test/facebooker/adapters_test.rb
|
109
|
-
test/facebooker/admin_test.rb
|
110
|
-
test/facebooker/batch_request_test.rb
|
111
|
-
test/facebooker/data_test.rb
|
112
|
-
test/facebooker/logging_test.rb
|
113
|
-
test/facebooker/model_test.rb
|
114
|
-
test/facebooker/models/event_test.rb
|
115
|
-
test/facebooker/models/user_test.rb
|
116
|
-
test/facebooker/rails/publisher_test.rb
|
117
|
-
test/facebooker/rails_integration_test.rb
|
118
|
-
test/facebooker/server_cache_test.rb
|
119
|
-
test/facebooker/session_test.rb
|
120
|
-
test/facebooker_test.rb
|
121
|
-
test/fixtures/multipart_post_body_with_only_parameters.txt
|
122
|
-
test/fixtures/multipart_post_body_with_single_file.txt
|
123
|
-
test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt
|
124
|
-
test/net/http_multipart_post_test.rb
|
125
|
-
test/rails_test_helper.rb
|
126
|
-
test/test_helper.rb
|
127
|
-
test/facebooker/mobile_test.rb
|
data/README
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
Copyright (c) 2007 Chad Fowler, Patrick Ewing
|
2
|
-
|
3
|
-
= Facebooker
|
4
|
-
|
5
|
-
Facebooker is a Ruby wrapper over the Facebook[http://facebook.com] {REST API}[http://developer.facebook.com]. Its goals are:
|
6
|
-
|
7
|
-
* Idiomatic Ruby
|
8
|
-
* No dependencies outside of the Ruby standard library (This is true with Rails 2.1. Previous Rails versions require the JSON gem)
|
9
|
-
* Concrete classes and methods modeling the Facebook data, so it's easy for a Rubyist to understand what's available
|
10
|
-
* Well tested
|
11
|
-
|
12
|
-
= Installing (Non Rails)
|
13
|
-
|
14
|
-
The best way is:
|
15
|
-
|
16
|
-
gem install facebooker
|
17
|
-
|
18
|
-
If, for some reason, you can't/won't use RubyGems, you can do:
|
19
|
-
|
20
|
-
(sudo) ruby setup.rb
|
21
|
-
|
22
|
-
= Installing (Rails)
|
23
|
-
|
24
|
-
Facebooker can be installed as a Rails plugin by:
|
25
|
-
|
26
|
-
script/plugin install git://github.com/mmangino/facebooker.git
|
27
|
-
|
28
|
-
If you don't have git, the plugin can be downloaded from http://github.com/mmangino/facebooker/tarball/master
|
29
|
-
|
30
|
-
Once the plugin is installed, you will need to configure your Facebook app in config/facebooker.yml.
|
31
|
-
|
32
|
-
Your application users will need to have added the application in facebook to access all of facebooker's features. You enforce this by adding
|
33
|
-
|
34
|
-
ensure_application_is_installed_by_facebook_user
|
35
|
-
|
36
|
-
to your application controller.
|
37
|
-
|
38
|
-
|
39
|
-
== Work in Progress
|
40
|
-
|
41
|
-
I'm not saying it meets its goals fully yet. Please help. I'm especially interested in feedback and criticism re: Ruby style and design and testing. RCov has the library (at the time of this writing) at 100% coverage. I take that with a grain of salt, but it's a good start.
|
42
|
-
|
43
|
-
== Contribute
|
44
|
-
|
45
|
-
Please visit the {RubyForge project page}[http://rubyforge.org/projects/facebooker] to get the latest source via svn, write some tests, add/fix features, and submit a patch via the tracker. If you submit a good patch, it's likely that I'll add you to the project for commit access if you want to be added.
|
46
|
-
|
@@ -1,396 +0,0 @@
|
|
1
|
-
require 'facebooker/model'
|
2
|
-
require 'facebooker/models/affiliation'
|
3
|
-
require 'facebooker/models/work_info'
|
4
|
-
module Facebooker
|
5
|
-
#
|
6
|
-
# Holds attributes and behavior for a Facebook User
|
7
|
-
class User
|
8
|
-
include Model
|
9
|
-
class Status
|
10
|
-
include Model
|
11
|
-
attr_accessor :message, :time, :status_id
|
12
|
-
end
|
13
|
-
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, :uid, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :first_name, :meeting_for, :last_name, :interests, :current_location, :pic, :books, :affiliations, :locale, :profile_url, :proxied_email]
|
14
|
-
STANDARD_FIELDS = [:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url]
|
15
|
-
attr_accessor :id, :session
|
16
|
-
populating_attr_accessor *FIELDS
|
17
|
-
attr_reader :affiliations
|
18
|
-
populating_hash_settable_accessor :current_location, Location
|
19
|
-
populating_hash_settable_accessor :hometown_location, Location
|
20
|
-
populating_hash_settable_accessor :hs_info, EducationInfo::HighschoolInfo
|
21
|
-
populating_hash_settable_accessor :status, Status
|
22
|
-
populating_hash_settable_list_accessor :affiliations, Affiliation
|
23
|
-
populating_hash_settable_list_accessor :education_history, EducationInfo
|
24
|
-
populating_hash_settable_list_accessor :work_history, WorkInfo
|
25
|
-
|
26
|
-
# Can pass in these two forms:
|
27
|
-
# id, session, (optional) attribute_hash
|
28
|
-
# attribute_hash
|
29
|
-
def initialize(*args)
|
30
|
-
if (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args.size==1
|
31
|
-
@id=Integer(args.shift)
|
32
|
-
@session = Session.current
|
33
|
-
elsif (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args[1].kind_of?(Session)
|
34
|
-
@id = Integer(args.shift)
|
35
|
-
@session = args.shift
|
36
|
-
end
|
37
|
-
if args.last.kind_of?(Hash)
|
38
|
-
populate_from_hash!(args.pop)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# Returns a user's events, params correspond to API call parameters (except UID):
|
43
|
-
# http://wiki.developers.facebook.com/index.php/Events.get
|
44
|
-
# E.g:
|
45
|
-
# @user.events(:start_time => Time.now, :end_time => 1.month.from_now)
|
46
|
-
# # => Returns events betwen now and a month from now
|
47
|
-
def events(params={})
|
48
|
-
@events ||= {}
|
49
|
-
[:start_time,:end_time].compact.each do |key|
|
50
|
-
params[key] = params[key].to_i
|
51
|
-
end
|
52
|
-
# puts @events[params.to_s].nil?
|
53
|
-
@events[params.to_s] ||= @session.post('facebook.events.get', {:uid => self.id}.merge(params)).map do |event|
|
54
|
-
Event.from_hash(event)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
#
|
59
|
-
# Set the list of friends, given an array of User objects. If the list has been retrieved previously, will not set
|
60
|
-
def friends=(list_of_friends,flid=nil)
|
61
|
-
@friends_hash ||= {}
|
62
|
-
flid=cast_to_friend_list_id(flid)
|
63
|
-
#use __blank instead of nil so that this is cached
|
64
|
-
cache_key = flid||"__blank"
|
65
|
-
|
66
|
-
@friends_hash[cache_key] ||= list_of_friends
|
67
|
-
end
|
68
|
-
|
69
|
-
def cast_to_friend_list_id(flid)
|
70
|
-
case flid
|
71
|
-
when String
|
72
|
-
list=friend_lists.detect {|f| f.name==flid}
|
73
|
-
raise Facebooker::Session::InvalidFriendList unless list
|
74
|
-
list.flid
|
75
|
-
when FriendList
|
76
|
-
flid.flid
|
77
|
-
else
|
78
|
-
flid
|
79
|
-
end
|
80
|
-
end
|
81
|
-
##
|
82
|
-
# Retrieve friends
|
83
|
-
def friends(flid = nil)
|
84
|
-
@friends_hash ||= {}
|
85
|
-
flid=cast_to_friend_list_id(flid)
|
86
|
-
|
87
|
-
#use __blank instead of nil so that this is cached
|
88
|
-
cache_key = flid||"__blank"
|
89
|
-
options = {:uid=>@id}
|
90
|
-
options[:flid] = flid unless flid.nil?
|
91
|
-
@friends_hash[cache_key] ||= @session.post('facebook.friends.get', options,false).map do |uid|
|
92
|
-
User.new(uid, @session)
|
93
|
-
end
|
94
|
-
@friends_hash[cache_key]
|
95
|
-
end
|
96
|
-
|
97
|
-
def friend_lists
|
98
|
-
@friend_lists ||= @session.post('facebook.friends.getLists').map do |hash|
|
99
|
-
friend_list = FriendList.from_hash(hash)
|
100
|
-
friend_list.session = session
|
101
|
-
friend_list
|
102
|
-
end
|
103
|
-
end
|
104
|
-
###
|
105
|
-
# Retrieve friends with user info populated
|
106
|
-
# Subsequent calls will be retrieved from memory.
|
107
|
-
# Optional: list of fields to retrieve as symbols
|
108
|
-
def friends!(*fields)
|
109
|
-
@friends ||= session.post('facebook.users.getInfo', :fields => collect(fields), :uids => friends.map{|f| f.id}.join(',')).map do |hash|
|
110
|
-
User.new(hash['uid'], session, hash)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
###
|
115
|
-
# Retrieve profile data for logged in user
|
116
|
-
# Optional: list of fields to retrieve as symbols
|
117
|
-
def populate(*fields)
|
118
|
-
session.post('facebook.users.getInfo', :fields => collect(fields), :uids => id) do |response|
|
119
|
-
populate_from_hash!(response.first)
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def friends_with?(user_or_id)
|
124
|
-
friends.map{|f| f.to_i}.include?(user_or_id.to_i)
|
125
|
-
end
|
126
|
-
|
127
|
-
def friends_with_this_app
|
128
|
-
@friends_with_this_app ||= session.post('facebook.friends.getAppUsers').map do |uid|
|
129
|
-
User.new(uid, session)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def groups(gids = [])
|
134
|
-
args = gids.empty? ? {} : {:gids => gids}
|
135
|
-
@groups ||= session.post('facebook.groups.get', args).map do |hash|
|
136
|
-
group = Group.from_hash(hash)
|
137
|
-
group.session = session
|
138
|
-
group
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def notifications
|
143
|
-
@notifications ||= Notifications.from_hash(session.post('facebook.notifications.get'))
|
144
|
-
end
|
145
|
-
|
146
|
-
def publish_story(story)
|
147
|
-
publish(story)
|
148
|
-
end
|
149
|
-
|
150
|
-
def publish_action(action)
|
151
|
-
publish(action)
|
152
|
-
end
|
153
|
-
|
154
|
-
def publish_templatized_action(action)
|
155
|
-
publish(action)
|
156
|
-
end
|
157
|
-
|
158
|
-
def albums
|
159
|
-
@albums ||= session.post('facebook.photos.getAlbums', :uid => self.id) do |response|
|
160
|
-
response.map do |hash|
|
161
|
-
Album.from_hash(hash)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
def create_album(params)
|
167
|
-
@album = session.post('facebook.photos.createAlbum', params) {|response| Album.from_hash(response)}
|
168
|
-
end
|
169
|
-
|
170
|
-
def profile_photos
|
171
|
-
session.get_photos(nil, nil, profile_pic_album_id)
|
172
|
-
end
|
173
|
-
|
174
|
-
# Upload a photo to the user's profile.
|
175
|
-
#
|
176
|
-
# In your view, create a multipart form that posts directly to your application (not through canvas):
|
177
|
-
#
|
178
|
-
# <% form_tag photos_url(:canvas => false), :html => {:multipart => true, :promptpermission => 'photo_upload'} do %>
|
179
|
-
# Photo: <%= file_field_tag 'photo' %>
|
180
|
-
# Caption: <%= text_area_tag 'caption' %>
|
181
|
-
# <%= submit_tag 'Upload Photo', :class => 'inputsubmit' %>
|
182
|
-
# <% end %>
|
183
|
-
#
|
184
|
-
# And in your controller:
|
185
|
-
#
|
186
|
-
# class PhotosController < ApplicationController
|
187
|
-
# def create
|
188
|
-
# file = Net::HTTP::MultipartPostFile.new(
|
189
|
-
# params[:photo].original_filename,
|
190
|
-
# params[:photo].content_type,
|
191
|
-
# params[:photo].read
|
192
|
-
# )
|
193
|
-
#
|
194
|
-
# @photo = facebook_session.user.upload_photo(file, :caption => params[:caption])
|
195
|
-
# redirect_to photos_url(:canvas => true)
|
196
|
-
# end
|
197
|
-
# end
|
198
|
-
#
|
199
|
-
# Options correspond to http://wiki.developers.facebook.com/index.php/Photos.upload
|
200
|
-
def upload_photo(multipart_post_file, options = {})
|
201
|
-
Photo.from_hash(session.post_file('facebook.photos.upload',
|
202
|
-
options.merge(nil => multipart_post_file)))
|
203
|
-
end
|
204
|
-
|
205
|
-
def profile_fbml
|
206
|
-
session.post('facebook.profile.getFBML', :uid => @id)
|
207
|
-
end
|
208
|
-
|
209
|
-
##
|
210
|
-
# Set the profile FBML for this user
|
211
|
-
#
|
212
|
-
# This does not set profile actions, that should be done with profile_action=
|
213
|
-
def profile_fbml=(markup)
|
214
|
-
set_profile_fbml(markup, nil, nil)
|
215
|
-
end
|
216
|
-
|
217
|
-
##
|
218
|
-
# Set the mobile profile FBML
|
219
|
-
def mobile_fbml=(markup)
|
220
|
-
set_profile_fbml(nil, markup, nil)
|
221
|
-
end
|
222
|
-
|
223
|
-
def profile_action=(markup)
|
224
|
-
set_profile_fbml(nil, nil, markup)
|
225
|
-
end
|
226
|
-
|
227
|
-
def profile_main=(markup)
|
228
|
-
set_profile_fbml(nil,nil,nil,markup)
|
229
|
-
end
|
230
|
-
|
231
|
-
def set_profile_fbml(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil)
|
232
|
-
parameters = {:uid => @id}
|
233
|
-
parameters[:profile] = profile_fbml if profile_fbml
|
234
|
-
parameters[:profile_action] = profile_action_fbml if profile_action_fbml
|
235
|
-
parameters[:mobile_profile] = mobile_fbml if mobile_fbml
|
236
|
-
parameters[:profile_main] = profile_main if profile_main
|
237
|
-
session.post('facebook.profile.setFBML', parameters,false)
|
238
|
-
end
|
239
|
-
|
240
|
-
## ** NEW PROFILE DESIGN ***
|
241
|
-
# Set a info section for this user
|
242
|
-
#
|
243
|
-
# Note: using set_profile_info as I feel using user.set_info could be confused with the user.getInfo facebook method.
|
244
|
-
# Also, I feel it fits in line with user.set_profile_fbml.
|
245
|
-
def set_profile_info(title, info_fields, format = :text)
|
246
|
-
session.post('facebook.profile.setInfo', :title => title, :uid => @id,
|
247
|
-
:type => format.to_s == "text" ? 1 : 5, :info_fields => info_fields.to_json)
|
248
|
-
end
|
249
|
-
|
250
|
-
def get_profile_info
|
251
|
-
session.post('facebook.profile.getInfo', :uid => @id)
|
252
|
-
end
|
253
|
-
|
254
|
-
##
|
255
|
-
# This DOES NOT set the status of a user on Facebook
|
256
|
-
# Use the set_status method instead
|
257
|
-
def status=(message)
|
258
|
-
case message
|
259
|
-
when String,Status
|
260
|
-
@status = message
|
261
|
-
when Hash
|
262
|
-
@status = Status.from_hash(message)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
##
|
267
|
-
# Set the status for a user
|
268
|
-
# DOES NOT prepend "is" to the message
|
269
|
-
#
|
270
|
-
# requires extended permission.
|
271
|
-
def set_status(message)
|
272
|
-
self.status=message
|
273
|
-
session.post('facebook.users.setStatus',:status=>message,:status_includes_verb=>1) do |ret|
|
274
|
-
ret
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
##
|
279
|
-
# Checks to see if the user has enabled the given extended permission
|
280
|
-
def has_permission?(ext_perm) # ext_perm = email, offline_access, status_update, photo_upload, create_listing, create_event, rsvp_event, sms
|
281
|
-
session.post('facebook.users.hasAppPermission',:ext_perm=>ext_perm) == "1"
|
282
|
-
end
|
283
|
-
|
284
|
-
##
|
285
|
-
# Convenience method to send email to the current user
|
286
|
-
def send_email(subject, text=nil, fbml=nil)
|
287
|
-
session.send_email([@id], subject, text, fbml)
|
288
|
-
end
|
289
|
-
|
290
|
-
##
|
291
|
-
# Convenience method to set cookie for the current user
|
292
|
-
def set_cookie(name, value, expires=nil, path=nil)
|
293
|
-
session.data.set_cookie(@id, name, value, expires, path)
|
294
|
-
end
|
295
|
-
|
296
|
-
##
|
297
|
-
# Convenience method to get cookies for the current user
|
298
|
-
def get_cookies(name=nil)
|
299
|
-
session.data.get_cookies(@id, name)
|
300
|
-
end
|
301
|
-
|
302
|
-
##
|
303
|
-
# Returns the user's id as an integer
|
304
|
-
def to_i
|
305
|
-
id
|
306
|
-
end
|
307
|
-
|
308
|
-
def to_s
|
309
|
-
id.to_s
|
310
|
-
end
|
311
|
-
|
312
|
-
##
|
313
|
-
# Two Facebooker::User objects should be considered equal if their Facebook ids are equal
|
314
|
-
def ==(other_user)
|
315
|
-
id == other_user.id
|
316
|
-
end
|
317
|
-
|
318
|
-
|
319
|
-
# register a user with Facebook
|
320
|
-
# users should be a hast with at least an :email field
|
321
|
-
# you can optionally provide an :account_id field as well
|
322
|
-
|
323
|
-
def self.register(users)
|
324
|
-
user_map={}
|
325
|
-
users=users.map do |h|
|
326
|
-
returning h.dup do |d|
|
327
|
-
if email=d.delete(:email)
|
328
|
-
hash = hash_email(email)
|
329
|
-
user_map[hash]=h
|
330
|
-
d[:email_hash]=hash
|
331
|
-
end
|
332
|
-
end
|
333
|
-
end
|
334
|
-
Facebooker::Session.create.post("facebook.connect.registerUsers",:accounts=>users.to_json) do |ret|
|
335
|
-
ret.each do |hash|
|
336
|
-
user_map.delete(hash)
|
337
|
-
end
|
338
|
-
unless user_map.empty?
|
339
|
-
e=Facebooker::Session::UserRegistrationFailed.new
|
340
|
-
e.failed_users = user_map.values
|
341
|
-
raise e
|
342
|
-
end
|
343
|
-
ret
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
def self.hash_email(email)
|
348
|
-
email = email.downcase.strip
|
349
|
-
crc=Zlib.crc32(email)
|
350
|
-
md5=Digest::MD5.hexdigest(email)
|
351
|
-
"#{crc}_#{md5}"
|
352
|
-
end
|
353
|
-
|
354
|
-
def self.cast_to_facebook_id(object)
|
355
|
-
if object.respond_to?(:facebook_id)
|
356
|
-
object.facebook_id
|
357
|
-
else
|
358
|
-
object
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
def facebook_id
|
363
|
-
@id
|
364
|
-
end
|
365
|
-
|
366
|
-
def self.user_fields(fields = [])
|
367
|
-
valid_fields(fields)
|
368
|
-
end
|
369
|
-
|
370
|
-
def self.standard_fields(fields = [])
|
371
|
-
valid_fields(fields,STANDARD_FIELDS)
|
372
|
-
end
|
373
|
-
|
374
|
-
private
|
375
|
-
def publish(feed_story_or_action)
|
376
|
-
session.post(Facebooker::Feed::METHODS[feed_story_or_action.class.name.split(/::/).last], feed_story_or_action.to_params) == "1" ? true : false
|
377
|
-
end
|
378
|
-
|
379
|
-
def self.valid_fields(fields, allowable=FIELDS)
|
380
|
-
allowable.reject{|field_name| !fields.empty? && !fields.include?(field_name)}.join(',')
|
381
|
-
end
|
382
|
-
|
383
|
-
def collect(fields, allowable=FIELDS)
|
384
|
-
allowable.reject{|field_name| !fields.empty? && !fields.include?(field_name)}.join(',')
|
385
|
-
end
|
386
|
-
|
387
|
-
def profile_pic_album_id
|
388
|
-
merge_aid(-3, @id)
|
389
|
-
end
|
390
|
-
|
391
|
-
def merge_aid(aid, uid)
|
392
|
-
(uid << 32) + (aid & 0xFFFFFFFF)
|
393
|
-
end
|
394
|
-
|
395
|
-
end
|
396
|
-
end
|