cwninja-facebooker 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. data/CHANGELOG.txt +0 -0
  2. data/COPYING +19 -0
  3. data/History.txt +16 -0
  4. data/Manifest.txt +114 -0
  5. data/README +46 -0
  6. data/README.txt +81 -0
  7. data/Rakefile +76 -0
  8. data/TODO.txt +10 -0
  9. data/generators/facebook/facebook_generator.rb +14 -0
  10. data/generators/facebook/templates/config/facebooker.yml +46 -0
  11. data/generators/facebook/templates/public/javascripts/facebooker.js +106 -0
  12. data/generators/facebook_controller/USAGE +33 -0
  13. data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
  14. data/generators/facebook_controller/templates/controller.rb +7 -0
  15. data/generators/facebook_controller/templates/functional_test.rb +11 -0
  16. data/generators/facebook_controller/templates/helper.rb +2 -0
  17. data/generators/facebook_controller/templates/view.fbml.erb +2 -0
  18. data/generators/facebook_controller/templates/view.html.erb +2 -0
  19. data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
  20. data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
  21. data/generators/facebook_publisher/templates/publisher.rb +3 -0
  22. data/generators/facebook_scaffold/USAGE +27 -0
  23. data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
  24. data/generators/facebook_scaffold/templates/controller.rb +93 -0
  25. data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
  26. data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
  27. data/generators/facebook_scaffold/templates/helper.rb +2 -0
  28. data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
  29. data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
  30. data/generators/facebook_scaffold/templates/style.css +74 -0
  31. data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
  32. data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
  33. data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
  34. data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
  35. data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
  36. data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
  37. data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
  38. data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
  39. data/generators/publisher/publisher_generator.rb +14 -0
  40. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  41. data/generators/xd_receiver/xd_receiver_generator.rb +9 -0
  42. data/init.rb +70 -0
  43. data/install.rb +12 -0
  44. data/lib/facebooker.rb +160 -0
  45. data/lib/facebooker/adapters/adapter_base.rb +87 -0
  46. data/lib/facebooker/adapters/bebo_adapter.rb +75 -0
  47. data/lib/facebooker/adapters/facebook_adapter.rb +48 -0
  48. data/lib/facebooker/admin.rb +28 -0
  49. data/lib/facebooker/batch_request.rb +44 -0
  50. data/lib/facebooker/data.rb +57 -0
  51. data/lib/facebooker/feed.rb +78 -0
  52. data/lib/facebooker/logging.rb +51 -0
  53. data/lib/facebooker/model.rb +123 -0
  54. data/lib/facebooker/models/affiliation.rb +10 -0
  55. data/lib/facebooker/models/album.rb +11 -0
  56. data/lib/facebooker/models/applicationproperties.rb +39 -0
  57. data/lib/facebooker/models/cookie.rb +10 -0
  58. data/lib/facebooker/models/education_info.rb +11 -0
  59. data/lib/facebooker/models/event.rb +26 -0
  60. data/lib/facebooker/models/friend_list.rb +14 -0
  61. data/lib/facebooker/models/group.rb +35 -0
  62. data/lib/facebooker/models/info_item.rb +10 -0
  63. data/lib/facebooker/models/info_section.rb +10 -0
  64. data/lib/facebooker/models/location.rb +8 -0
  65. data/lib/facebooker/models/notifications.rb +17 -0
  66. data/lib/facebooker/models/page.rb +27 -0
  67. data/lib/facebooker/models/photo.rb +10 -0
  68. data/lib/facebooker/models/tag.rb +12 -0
  69. data/lib/facebooker/models/user.rb +369 -0
  70. data/lib/facebooker/models/work_info.rb +9 -0
  71. data/lib/facebooker/parser.rb +547 -0
  72. data/lib/facebooker/rails/controller.rb +280 -0
  73. data/lib/facebooker/rails/facebook_asset_path.rb +18 -0
  74. data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
  75. data/lib/facebooker/rails/facebook_pretty_errors.rb +14 -0
  76. data/lib/facebooker/rails/facebook_request_fix.rb +24 -0
  77. data/lib/facebooker/rails/facebook_session_handling.rb +69 -0
  78. data/lib/facebooker/rails/facebook_url_helper.rb +191 -0
  79. data/lib/facebooker/rails/facebook_url_rewriting.rb +39 -0
  80. data/lib/facebooker/rails/helpers.rb +642 -0
  81. data/lib/facebooker/rails/helpers/fb_connect.rb +34 -0
  82. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  83. data/lib/facebooker/rails/publisher.rb +511 -0
  84. data/lib/facebooker/rails/routing.rb +49 -0
  85. data/lib/facebooker/rails/test_helpers.rb +88 -0
  86. data/lib/facebooker/rails/utilities.rb +22 -0
  87. data/lib/facebooker/server_cache.rb +24 -0
  88. data/lib/facebooker/service.rb +83 -0
  89. data/lib/facebooker/session.rb +564 -0
  90. data/lib/facebooker/version.rb +9 -0
  91. data/lib/net/http_multipart_post.rb +123 -0
  92. data/lib/tasks/facebooker.rake +18 -0
  93. data/lib/tasks/tunnel.rake +46 -0
  94. data/rails/init.rb +1 -0
  95. data/setup.rb +1585 -0
  96. data/templates/layout.erb +24 -0
  97. data/test/adapters_test.rb +98 -0
  98. data/test/batch_request_test.rb +82 -0
  99. data/test/event_test.rb +15 -0
  100. data/test/facebook_admin_test.rb +76 -0
  101. data/test/facebook_cache_test.rb +44 -0
  102. data/test/facebook_data_test.rb +86 -0
  103. data/test/facebooker_test.rb +855 -0
  104. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  105. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  106. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  107. data/test/http_multipart_post_test.rb +54 -0
  108. data/test/logging_test.rb +43 -0
  109. data/test/model_test.rb +91 -0
  110. data/test/publisher_test.rb +458 -0
  111. data/test/rails_integration_test.rb +1221 -0
  112. data/test/session_test.rb +613 -0
  113. data/test/test_helper.rb +60 -0
  114. data/test/user_test.rb +270 -0
  115. metadata +185 -0
@@ -0,0 +1,35 @@
1
+ require 'facebooker/model'
2
+ module Facebooker
3
+ class Group
4
+ ##
5
+ # The model of a user's relationship to a group. Users can occupy different positions within a group (e.g. 'owner')
6
+ class Membership
7
+ include Model
8
+ attr_accessor :position, :gid, :uid
9
+ end
10
+ include Model
11
+ attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :gid, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid
12
+
13
+
14
+ ##
15
+ # Get the full list of members as populated User objects. First time fetches group members via Facebook API call.
16
+ # Subsequent calls return cached values.
17
+ # This is a convenience method for getting all of the Membership instances and instantiating User instances for each Membership.
18
+ def members
19
+ @members ||= memberships.map do |membership|
20
+ User.new(membership.uid, session)
21
+ end
22
+ end
23
+
24
+ ##
25
+ # Get a list of Membership instances associated with this Group. First call retrieves the Membership instances via a Facebook
26
+ # API call. Subsequent calls are retrieved from in-memory cache.
27
+ def memberships
28
+ @memberships ||= session.post('facebook.groups.getMembers', :gid => gid).map do |hash|
29
+ Membership.from_hash(hash) do |membership|
30
+ membership.gid = gid
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ module Facebooker
2
+ class InfoItem
3
+ include Model
4
+ attr_accessor :label, :image, :description, :link, :sublabel
5
+
6
+ def to_json
7
+ {:label => label, :image => image, :description => description, :link => link, :sublabel => sublabel}.to_json
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Facebooker
2
+ class InfoSection
3
+ include Model
4
+ attr_accessor :field, :items
5
+
6
+ def to_json
7
+ {:field => field, :items => items}.to_json
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Facebooker
2
+ ##
3
+ # Representation of Location used in all places where a Location is specified.
4
+ class Location
5
+ include Model
6
+ attr_accessor :city, :zip, :country, :state
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module Facebooker
2
+ class Notifications
3
+ include Model
4
+ attr_accessor :messages, :group_invites, :pokes, :friend_requests, :event_invites, :shares
5
+
6
+ [:Messages, :Pokes, :Shares].each do |notification_type|
7
+ const_set(notification_type, Class.new do
8
+ include Model
9
+ attr_accessor :unread, :most_recent
10
+ end)
11
+ attribute_name = "#{notification_type.to_s.downcase}"
12
+ define_method("#{attribute_name}=") do |value|
13
+ instance_variable_set("@#{attribute_name}", value.kind_of?(Hash) ? Notifications.const_get(notification_type).from_hash(value) : value)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'facebooker/model'
2
+ module Facebooker
3
+ class Page
4
+
5
+ class Genre
6
+ include Model
7
+ FIELDS = [ :dance, :party, :relax, :talk, :think, :workout, :sing, :intimate, :raunchy, :headphones ]
8
+ attr_accessor *FIELDS
9
+
10
+ def initialize(*args)
11
+ super
12
+
13
+ # convert '1'/'0' to true/false
14
+ FIELDS.each do |field|
15
+ self.send("#{field}=", self.send(field) == '1')
16
+ end
17
+ end
18
+ end
19
+
20
+ include Model
21
+ attr_accessor :page_id, :name, :pic_small, :pic_big, :pic_square, :pic_large, :type, :type, :website, :location, :hours, :band_members, :bio, :hometown, :genre, :record_label, :influences, :has_added_app, :founded, :company_overview, :mission, :products, :release_date, :starring, :written_by, :directed_by, :produced_by, :studio, :awards, :plot_outline, :network, :season, :schedule
22
+
23
+ def genre=(value)
24
+ @genre = value.kind_of?(Hash) ? Genre.from_hash(value) : value
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ require 'facebooker/model'
2
+ module Facebooker
3
+ class Photo
4
+ include Model
5
+ attr_accessor :pid, :aid, :owner, :title,
6
+ :link, :caption, :created,
7
+ :src, :src_big, :src_small,
8
+ :story_fbid
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'facebooker/model'
2
+ module Facebooker
3
+ class Tag
4
+ include Model
5
+ attr_accessor :pid, :subject, :xcoord, :ycoord
6
+
7
+ def coordinates
8
+ [xcoord, ycoord]
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,369 @@
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
+ def upload_photo(multipart_post_file)
175
+ Photo.from_hash(session.post_file('facebook.photos.upload', {nil => multipart_post_file}))
176
+ end
177
+
178
+ def profile_fbml
179
+ session.post('facebook.profile.getFBML', :uid => @id)
180
+ end
181
+
182
+ ##
183
+ # Set the profile FBML for this user
184
+ #
185
+ # This does not set profile actions, that should be done with profile_action=
186
+ def profile_fbml=(markup)
187
+ set_profile_fbml(markup, nil, nil)
188
+ end
189
+
190
+ ##
191
+ # Set the mobile profile FBML
192
+ def mobile_fbml=(markup)
193
+ set_profile_fbml(nil, markup, nil)
194
+ end
195
+
196
+ def profile_action=(markup)
197
+ set_profile_fbml(nil, nil, markup)
198
+ end
199
+
200
+ def profile_main=(markup)
201
+ set_profile_fbml(nil,nil,nil,markup)
202
+ end
203
+
204
+ def set_profile_fbml(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil)
205
+ parameters = {:uid => @id}
206
+ parameters[:profile] = profile_fbml if profile_fbml
207
+ parameters[:profile_action] = profile_action_fbml if profile_action_fbml
208
+ parameters[:mobile_profile] = mobile_fbml if mobile_fbml
209
+ parameters[:profile_main] = profile_main if profile_main
210
+ session.post('facebook.profile.setFBML', parameters,false)
211
+ end
212
+
213
+ ## ** NEW PROFILE DESIGN ***
214
+ # Set a info section for this user
215
+ #
216
+ # Note: using set_profile_info as I feel using user.set_info could be confused with the user.getInfo facebook method.
217
+ # Also, I feel it fits in line with user.set_profile_fbml.
218
+ def set_profile_info(title, info_fields, format = :text)
219
+ session.post('facebook.profile.setInfo', :title => title, :uid => @id,
220
+ :type => format.to_s == "text" ? 1 : 5, :info_fields => info_fields.to_json)
221
+ end
222
+
223
+ def get_profile_info
224
+ session.post('facebook.profile.getInfo', :uid => @id)
225
+ end
226
+
227
+ ##
228
+ # This DOES NOT set the status of a user on Facebook
229
+ # Use the set_status method instead
230
+ def status=(message)
231
+ case message
232
+ when String,Status
233
+ @status = message
234
+ when Hash
235
+ @status = Status.from_hash(message)
236
+ end
237
+ end
238
+
239
+ ##
240
+ # Set the status for a user
241
+ # DOES NOT prepend "is" to the message
242
+ #
243
+ # requires extended permission.
244
+ def set_status(message)
245
+ self.status=message
246
+ session.post('facebook.users.setStatus',:status=>message,:status_includes_verb=>1) do |ret|
247
+ ret
248
+ end
249
+ end
250
+
251
+ ##
252
+ # Checks to see if the user has enabled the given extended permission
253
+ def has_permission?(ext_perm) # ext_perm = email, offline_access, status_update, photo_upload, create_listing, create_event, rsvp_event, sms
254
+ session.post('facebook.users.hasAppPermission',:ext_perm=>ext_perm) == "1"
255
+ end
256
+
257
+ ##
258
+ # Convenience method to send email to the current user
259
+ def send_email(subject, text=nil, fbml=nil)
260
+ session.send_email([@id], subject, text, fbml)
261
+ end
262
+
263
+ ##
264
+ # Convenience method to set cookie for the current user
265
+ def set_cookie(name, value, expires=nil, path=nil)
266
+ session.data.set_cookie(@id, name, value, expires, path)
267
+ end
268
+
269
+ ##
270
+ # Convenience method to get cookies for the current user
271
+ def get_cookies(name=nil)
272
+ session.data.get_cookies(@id, name)
273
+ end
274
+
275
+ ##
276
+ # Returns the user's id as an integer
277
+ def to_i
278
+ id
279
+ end
280
+
281
+ def to_s
282
+ id.to_s
283
+ end
284
+
285
+ ##
286
+ # Two Facebooker::User objects should be considered equal if their Facebook ids are equal
287
+ def ==(other_user)
288
+ id == other_user.id
289
+ end
290
+
291
+
292
+ # register a user with Facebook
293
+ # users should be a hast with at least an :email field
294
+ # you can optionally provide an :account_id field as well
295
+
296
+ def self.register(users)
297
+ user_map={}
298
+ users=users.map do |h|
299
+ returning h.dup do |d|
300
+ if email=d.delete(:email)
301
+ hash = hash_email(email)
302
+ user_map[hash]=h
303
+ d[:email_hash]=hash
304
+ end
305
+ end
306
+ end
307
+ Facebooker::Session.create.post("facebook.connect.registerUsers",:accounts=>users.to_json) do |ret|
308
+ ret.each do |hash|
309
+ user_map.delete(hash)
310
+ end
311
+ unless user_map.empty?
312
+ e=Facebooker::Session::UserRegistrationFailed.new
313
+ e.failed_users = user_map.values
314
+ raise e
315
+ end
316
+ ret
317
+ end
318
+ end
319
+
320
+ def self.hash_email(email)
321
+ email = email.downcase.strip
322
+ crc=Zlib.crc32(email)
323
+ md5=Digest::MD5.hexdigest(email)
324
+ "#{crc}_#{md5}"
325
+ end
326
+
327
+ def self.cast_to_facebook_id(object)
328
+ if object.respond_to?(:facebook_id)
329
+ object.facebook_id
330
+ else
331
+ object
332
+ end
333
+ end
334
+
335
+ def facebook_id
336
+ @id
337
+ end
338
+
339
+ def self.user_fields(fields = [])
340
+ valid_fields(fields)
341
+ end
342
+
343
+ def self.standard_fields(fields = [])
344
+ valid_fields(fields,STANDARD_FIELDS)
345
+ end
346
+
347
+ private
348
+ def publish(feed_story_or_action)
349
+ session.post(Facebooker::Feed::METHODS[feed_story_or_action.class.name.split(/::/).last], feed_story_or_action.to_params) == "1" ? true : false
350
+ end
351
+
352
+ def self.valid_fields(fields, allowable=FIELDS)
353
+ allowable.reject{|field_name| !fields.empty? && !fields.include?(field_name)}.join(',')
354
+ end
355
+
356
+ def collect(fields, allowable=FIELDS)
357
+ allowable.reject{|field_name| !fields.empty? && !fields.include?(field_name)}.join(',')
358
+ end
359
+
360
+ def profile_pic_album_id
361
+ merge_aid(-3, @id)
362
+ end
363
+
364
+ def merge_aid(aid, uid)
365
+ (uid << 32) + (aid & 0xFFFFFFFF)
366
+ end
367
+
368
+ end
369
+ end