Sha256: 57c83f6d5b096076a7fab421496dbe942cdb84614f6a00c4481e0d342a1b1109

Contents?: true

Size: 719 Bytes

Versions: 4

Compression:

Stored size: 719 Bytes

Contents

module FbGraph
  class Collection < Array
    attr_reader :previous, :next

    def initialize(collection)
      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|
        k == 'access_token'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fb_graph-0.0.7 lib/fb_graph/collection.rb
fb_graph-0.0.6 lib/fb_graph/collection.rb
fb_graph-0.0.5 lib/fb_graph/collection.rb
fb_graph-0.0.4 lib/fb_graph/collection.rb