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.



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

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



50
51
52
# File 'lib/fbrails/graph.rb', line 50

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)



39
40
41
42
43
44
45
46
# File 'lib/fbrails/graph.rb', line 39

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



54
55
56
# File 'lib/fbrails/graph.rb', line 54

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

#call(method) ⇒ Object



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

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

#friendsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fbrails/graph.rb', line 12

def friends
  result = []
  friends = Fbrails.get(URL+"me"+"/"+"friends"+access_token)
  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