Module: FbGraph::Searchable

Included in:
AdKeyword, AdKeywordValid, Checkin, Event, Group, Offer, Page, Post, User
Defined in:
lib/fb_graph/searchable.rb,
lib/fb_graph/searchable/result.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.search(query, options = {}) {|collection| ... } ⇒ Object

Yields:

  • (collection)


3
4
5
6
7
8
9
10
11
# File 'lib/fb_graph/searchable.rb', line 3

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

.search_query_paramObject

The majority of Graph API searches use ‘q’ but some, like AdKeywordSuggestion use an alternate search query param



26
27
28
# File 'lib/fb_graph/searchable.rb', line 26

def self.search_query_param
  :q
end

Instance Method Details

#search(query, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/fb_graph/searchable.rb', line 13

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