m
[playfm2.git] / vendor / plugins / facebooker / lib / facebooker / data.rb
blobd2acbf58be4314017dc0f2e2a517e7998720b32c
1 module Facebooker
2   class Data
3     def initialize(session)
4       @session = session
5     end
7     ##
8     # ** BETA ***
9     # Sets a cookie on Facebook
10     # +user+ The user for whom this cookie needs to be set.
11     # +name+ Name of the cookie
12     # +value+ Value of the cookie
13     # Optional:
14     # +expires+ Time when the cookie should expire. If not specified, the cookie never expires.
15     # +path+ Path relative to the application's callback URL, with which the cookie should be associated. (default value is /?
16     def set_cookie(user, name, value, expires=nil, path=nil)
17       @session.post('facebook.data.setCookie',
18         :uid => User.cast_to_facebook_id(user),
19         :name => name,
20         :value => value,
21         :expires => expires,
22         :path => path) {|response| response == '1'}
23     end
25     ##
26     # ** BETA ***
27     # Gets a cookie stored on Facebook
28     # +user+    The user from whom to get the cookies.
29     # Optional:
30     # +name+ The name of the cookie. If not specified, all the cookies for the given user get returned.
31     def get_cookies(user, name=nil)
32       @cookies = @session.post(
33         'facebook.data.getCookies', :uid => User.cast_to_facebook_id(user), :name => name) do |response|
34           response.map do |hash|
35             Cookie.from_hash(hash)
36           end
37       end
38     end
40     ##
41     # ** BETA ***
42     # Gets a preference stored on Facebook
43     # +pref_id+ The id of the preference to get
44     def get_preference(pref_id)
45       @session.post('facebook.data.getUserPreference', :pref_id=>pref_id)
46     end
48     ##
49     # ** BETA ***
50     # Sets a preference on Facebook
51     # +pref_id+ The id of the preference to set
52     # +value+ The value to set for this preference
53     def set_preference(pref_id, value)
54       @session.post('facebook.data.setUserPreference', :pref_id=>pref_id, :value=>value)
55     end
56   end
57 end