Skip to content

Commit

Permalink
Merge remote branch 'jagthedrummer/master' into integration
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaclig committed Sep 4, 2010
2 parents 2017c6a + 350c6e9 commit c832cd0
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion lib/koala/graph_api.rb
Expand Up @@ -2,6 +2,57 @@ module Koala
module Facebook
GRAPH_SERVER = "graph.facebook.com"

class GraphCollection < Array
#This class is a light wrapper for collections returned
#from the Graph API.
#
#It extends Array to allow direct access to the data colleciton
#which should allow it to drop in seamlessly.
#
#It also allows access to paging information and the
#ability to get the next/previous page in the collection
#by calling next_page or previous_page.
attr_reader :paging

def initialize(response)
super response["data"]
@paging = response["paging"]
end

def next_page(graph)
base,args = next_page_params
GraphCollection.new graph.graph_call(base, args)
end

def previous_page(graph)
base,args = previous_page_params
GraphCollection.new graph.graph_call(base, args)
end

def next_page_params
parse_page_url(@paging["next"])
end

def previous_page_params
parse_page_url(@paging["previous"])
end

def parse_page_url(url)
match = url.match(/.com\/(.*)\?(.*)/)
base = match[1]
args = match[2]
params = CGI.parse(args)
new_params = {}
params.each_pair do |key,value|
new_params[key] = value.join ","
end
[base,new_params]
end

end



module GraphAPIMethods
# A client for the Facebook Graph API.
#
Expand Down Expand Up @@ -44,8 +95,9 @@ def get_objects(ids, args = {})

def get_connections(id, connection_name, args = {})
# Fetchs the connections for given object.
graph_call("#{id}/#{connection_name}", args)["data"]
GraphCollection.new graph_call("#{id}/#{connection_name}", args)
end


def get_picture(object, args = {})
result = graph_call("#{object}/picture", args, "get", :http_component => :headers)
Expand Down

0 comments on commit c832cd0

Please sign in to comment.