Sha256: e102c8309e2b7b2eb74781c9b5baaafafdfc580fb4c3da0ead66c06eb3a2fcc9

Contents?: true

Size: 1009 Bytes

Versions: 13

Compression:

Stored size: 1009 Bytes

Contents

module FbGraph
  module Searchable
    def self.search(query, options = {})
      klass = options.delete(:class) || Searchable
      query_param = klass.search_query_param
      collection = Collection.new(
        Node.new(:search).send(:get, options.merge(query_param.to_sym => query))
      )
      yield collection if block_given?
      Searchable::Result.new(query, klass, options.merge(:collection => collection))
    end

    def search(query, options = {})
      type = self.to_s.underscore.split('/').last.gsub("_", "")
      Searchable.search(query, options.merge(:type => type, :class => self)) do |collection|
        collection.map! do |obj|
          self.new(obj[:id], obj.merge(
            :access_token => options[:access_token]
          ))
        end
      end
    end

    # The majority of Graph API searches use 'q' but some, like AdKeywordSuggestion
    # use an alternate search query param
    def search_query_param
      :q
    end
  end
end

require 'fb_graph/searchable/result'

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
fb_graph-2.2.2 lib/fb_graph/searchable.rb
fb_graph-2.2.1 lib/fb_graph/searchable.rb
fb_graph-2.2.0 lib/fb_graph/searchable.rb
fb_graph-2.2.0.beta lib/fb_graph/searchable.rb
fb_graph-2.2.0.alpha2 lib/fb_graph/searchable.rb
fb_graph-2.2.0.alpha lib/fb_graph/searchable.rb
fb_graph-2.1.13 lib/fb_graph/searchable.rb
fb_graph-2.1.12 lib/fb_graph/searchable.rb
fb_graph-2.1.11 lib/fb_graph/searchable.rb
fb_graph-2.1.10 lib/fb_graph/searchable.rb
fb_graph-2.1.9 lib/fb_graph/searchable.rb
fb_graph-2.1.8 lib/fb_graph/searchable.rb
fb_graph-2.1.7 lib/fb_graph/searchable.rb