Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote branch 'jagthedrummer/master' into integration

  • Loading branch information...
commit c832cd0175717e7a34931d6262117939120fd4bb 2 parents 2017c6a + 350c6e9
cbaclig authored
Showing with 53 additions and 1 deletion.
  1. +53 −1 lib/koala/graph_api.rb
54 lib/koala/graph_api.rb
View
@@ -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.
#
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.