Sha256: 5a1a893cd69a83c8e3a462a08c346cf6878a0b684adb420467a87f222bd18e60

Contents?: true

Size: 848 Bytes

Versions: 11

Compression:

Stored size: 848 Bytes

Contents

require 'hashie/mash'

module FBGraph
  class Result

    attr_accessor :params, :unparsed, :data

    def initialize(result, params = {}, &block)
      result = result.respond_to?(:body) ? result.body : result.to_s
      @data = Hashie::Mash.new(JSON.parse(result)) rescue result
      @unparsed = result
      @params = params.symbolize_keys      
      self
    end

    def paging
      data.paging
    end

    def metadata
      data.metadata
    end

    # Implement enumerable
    def each(&block)
      return nil if data.blank?
      data.each(&block)
    end
    include Enumerable

    # Implement Comparable
    def <=>(other)
      (data <=> other.data) rescue 0
    end
    include Comparable

    def method_missing(method, *args, &block)
      data.send(method, *args, &block) rescue super(method, *args, &block)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
fbgraph-1.10.1 lib/fbgraph/result.rb
fbgraph-1.10.0 lib/fbgraph/result.rb
fbgraph-1.9.0 lib/fbgraph/result.rb
fbgraph-1.8.4 lib/fbgraph/result.rb
fbgraph-1.8.3 lib/fbgraph/result.rb
fbgraph-1.8.0 lib/fbgraph/result.rb
fbgraph-1.7.1 lib/fbgraph/result.rb
fbgraph-1.7.0 lib/fbgraph/result.rb
fbgraph-1.6.0 lib/fbgraph/result.rb
fbgraph-1.5.4 lib/fbgraph/result.rb
fbgraph-1.5.2 lib/fbgraph/result.rb