Class: OpenGraph::FBOpenGraph

Inherits:
Struct
  • Object
show all
Defined in:
lib/open_graph/fb_open_graph.rb,
lib/open_graph/test/facebook_stub.rb

Constant Summary collapse

GRAPH_GET_METHODS =

creates .news_feed(options) options for pagable_method :limit, :offset, :until, :since options for picture :type => (square|small|large) begin get methods

{
  :info           => nil,
  :friends        => :friends,
  :news_feed      => :home,
  :profile_feed   => :feed,
  :likes          => :likes,
  :movies         => :movies,
  :music          => :music,
  :books          => :books,
  :notes          => :notes,
  :photo_tags     => :photos,
  :photo_albums   => :albums,
  :video_tags     => :videos,
  :video_uploads  => :'videos/uploaded',
  :events         => :events,
  :groups         => :groups,
  :checkins       => :checkins,
  :picture        => :picture
}
GRAPH_PUBLISH_METHODS =

end get methods

{
  # profiles
  :publish! => :feed,
  :note!    => :notes,
  :link!    => :links,
  :event!   => :events,
  :album!   => :albums,
  :checkin! => :checkins,
}
BASE_INFO =
{
  "name"          => "Gandalf The Grey",
  "location"      => {
    "name"        => "San Francisco, California",
    "city"        => "San Francisco",
    "zip"         => "",
    "country"     => "United States",
    "id"          => 114952118516947,
    "state"       => "California"
  },
  "timezone"      =>  -8,
  "gender"        => "male",
  "id"            => "6013893",
  "birthday"      => "01/12/1987",
  "last_name"     => "Shafer",
  "updated_time"  => "2011-02-10T00:40:26+0000",
  "verified"      => true,
  "locale"        => "en_US",
  "religion"      => "Wikipedia",
  "bio"           => "The greatest thing you'll ever learn is just to love and be loved in return.\r\n\r\nIf hearing the name Sharon Salinger causes you physical pain and emotional trauma then we are friends.\r\n\r\nMy life has a great cast but I can't figure out the plot.",
  "hometown"      => { "name" => nil, "id" => "" },
  "link"          => "http://www.facebook.com/thomas.shafer",
  "political"     => "Liberal",
  "email"         => "[email protected]",
  "middle_name"   => "'Growly Pants'",
  "first_name"    => "Thomas"
}
@@request_options =
{:timeout => 5}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#all_cookiesObject

Returns the value of attribute all_cookies

Returns:

  • (Object)

    the current value of all_cookies



2
3
4
# File 'lib/open_graph/fb_open_graph.rb', line 2

def all_cookies
  @all_cookies
end

Class Method Details

.access_token=(token) ⇒ Object



57
58
59
# File 'lib/open_graph/test/facebook_stub.rb', line 57

def access_token=(token)
  @@access_token = token
end

.info_override!(key, value) ⇒ Object



41
42
43
# File 'lib/open_graph/test/facebook_stub.rb', line 41

def info_override!(key, value)
  BASE_INFO[key.to_s] = value
end

.invalid!Object



45
46
47
# File 'lib/open_graph/test/facebook_stub.rb', line 45

def invalid!
  @@access_token = ''
end

.reset!Object

you must run this before each test



36
37
38
39
# File 'lib/open_graph/test/facebook_stub.rb', line 36

def reset!
  @@access_token = nil
  @@uid = nil
end

.uid=(uid) ⇒ Object



53
54
55
# File 'lib/open_graph/test/facebook_stub.rb', line 53

def uid=(uid)
  @@uid = uid
end

.valid!Object



49
50
51
# File 'lib/open_graph/test/facebook_stub.rb', line 49

def valid!
  @@access_token = 'fb_token'
end

Instance Method Details

#access_tokenObject



23
24
25
26
# File 'lib/open_graph/fb_open_graph.rb', line 23

def access_token
  @access_token ||= facebook_cookie['access_token'] unless @manual
  @access_token || ''
end

#access_token_with_testingObject



69
70
71
# File 'lib/open_graph/test/facebook_stub.rb', line 69

def access_token_with_testing
  @@access_token || access_token_without_testing
end


6
7
8
9
10
11
# File 'lib/open_graph/fb_open_graph.rb', line 6

def facebook_cookie
  @facebook_cookie ||= begin
    cookie = all_cookies["fbs_#{OpenGraph.config[:appid]}"]
    validated_cookie(cookie)
  end
end

#fql_query(table, field_names, new_uid = uid) ⇒ Object



87
88
89
90
91
# File 'lib/open_graph/fb_open_graph.rb', line 87

def fql_query(table, field_names, new_uid = uid)
  field_names = field_names.join(', ') if field_names.is_a?(Array)
  query = "SELECT #{field_names} FROM #{table} WHERE uid = #{new_uid}"
  fql_get(query)
end

#friends(*args) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/open_graph/test/facebook_stub.rb', line 84

def friends(*args)
  return false unless valid?
  {"data"=>
   [{"name"=>"Michael Levin-Gesundheit", "id"=>"11160"},
    {"name"=>"Eleanor Birrell", "id"=>"21139"},
    {"name"=>"Clotilde Dedecker", "id"=>"24021"},
    {"name"=>"Nancy Elizabeth Townsend", "id"=>"100001899260534"},
    {"name"=>"Allba Zackson", "id"=>"100001938274584"}]}
end

#has_permissions?(permission_names) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
97
98
99
100
101
102
103
# File 'lib/open_graph/fb_open_graph.rb', line 93

def has_permissions?(permission_names)
  response = fql_query('permissions', permission_names)
  permission_hash = response.first
  return false unless permission_hash.is_a?(Hash)

  permission_names = permission_names.split(',').collect(&:strip) if permission_names.is_a?(String)
  permission_names.each do |perm|
    return false if permission_hash[perm] != 1
  end
  return true
end

#info(*args) ⇒ Object



94
95
96
97
# File 'lib/open_graph/test/facebook_stub.rb', line 94

def info(*args)
  return false unless valid?
  BASE_INFO
end

#picture(*args) ⇒ Object



99
100
101
# File 'lib/open_graph/test/facebook_stub.rb', line 99

def picture(*args)
  @picture_data ||= {:content_type => 'image/png', :image => File.read(File.dirname(__FILE__)+'/facebook_stub/picture.png')}
end

#uidObject



28
29
30
31
# File 'lib/open_graph/fb_open_graph.rb', line 28

def uid
  @uid ||= facebook_cookie['uid'] unless @manual
  @uid.blank? ? nil : @uid.to_i
end

#uid_with_testingObject



64
65
66
# File 'lib/open_graph/test/facebook_stub.rb', line 64

def uid_with_testing
  @@uid || uid_without_testing
end

#use_manual_session!(uid, access_token) ⇒ Object



17
18
19
20
21
# File 'lib/open_graph/fb_open_graph.rb', line 17

def use_manual_session!(uid, access_token)
  @uid = uid
  @access_token = access_token
  @manual = true
end

#valid?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/open_graph/fb_open_graph.rb', line 13

def valid?
  access_token.present?
end