Module: FbGraph2::Searchable

Included in:
Event, Group, Page, User
Defined in:
lib/fb_graph2/searchable.rb,
lib/fb_graph2/searchable/result.rb

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

Yields:

  • (collection)


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

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

Instance Method Details

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



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

def search(query, access_token, options = {})
  type = self.to_s.split('::').last.underscore
  Searchable.search(query, access_token, 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