Class: Fbrails::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/fbrails/graph.rb

Constant Summary collapse

URL =
"https://graph.facebook.com/"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Graph

Returns a new instance of Graph.



7
8
9
# File 'lib/fbrails/graph.rb', line 7

def initialize(token)
  @token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object

Fbrails::Graph.me_books



59
60
61
# File 'lib/fbrails/graph.rb', line 59

def method_missing (method)  
  call(method)  
end

Class Method Details

.get_picture(id, type = nil) ⇒ Object

graph.get_picture(ID,TYPE) TYPE can be square (50x50), small (50 pixels wide, variable height), normal (100 pixels wide, variable height), large (about 200 pixels wide, variable height)



48
49
50
51
52
53
54
55
# File 'lib/fbrails/graph.rb', line 48

def self.get_picture(id,type=nil)
first = "http://graph.facebook.com/#{id}/picture"
  if type.blank?
    return first 
  elsif type == 'square' || type == 'small' || type == 'normal' || type == 'large'
    return first + "?type=#{type}"
  end
end

Instance Method Details

#access_tokenObject



63
64
65
# File 'lib/fbrails/graph.rb', line 63

def access_token
  "?access_token=#{@token}"
end

#call(method) ⇒ Object



67
68
69
70
# File 'lib/fbrails/graph.rb', line 67

def call (method)
  url = method.to_s.split("_").join("/")
  Fbrails.get(URL+url+access_token)
end

#friends(fields = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fbrails/graph.rb', line 12

def friends(fields = false)
  result = []
  if fields && fields.class == Array
    params = "&fields=" + fields.join(",")
  else
    params = ""
  end

  friends = Fbrails.get(URL+"me"+"/"+"friends"+access_token+params)



  loop do
    if friends.has_key?("paging") && friends["paging"].has_key?("next")
      unless friends["data"].blank?
        friends["data"].each do |fr|
          fr["id"] = fr["id"].to_i
          result << fr
        end
      end
    else
      return result
    end
  friends = Fbrails.get(friends["paging"]["next"])
  end
end