Sha256: deb7fb36af54ca29bab70d815dfd37adbae7a91c57dd28c9ecabc1dad94f034d
Contents?: true
Size: 810 Bytes
Versions: 10
Compression:
Stored size: 810 Bytes
Contents
module FbGraph class Collection < Array attr_reader :previous, :next def initialize(collection) # allow nil input collection ||= {:data => []} result = replace(collection[:data]) @previous, @next = {}, {} if (paging = collection[:paging]) if paging[:previous] @previous = fetch_params(paging[:previous]) end if paging[:next] @next = fetch_params(paging[:next]) end end end private def fetch_params(url) query = URI.parse(url).query params = {} query.split('&').each do |q| key, value = q.split('=') params[key] = URI.unescape(value) end params.delete_if do |k, v| !['limit', 'offset', 'until', 'since'].include?(k) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems