Class: GiantBomb::Search

Inherits:
Object
  • Object
show all
Includes:
Api
Defined in:
lib/giantbomb/search.rb

Overview

Wrapper for the Giant Bomb Search resource

Generic filters collapse

Instance Attribute Summary collapse

Generic filters collapse

Instance Method Summary collapse

Methods included from Api

config, key

Constructor Details

#initialize(resource = nil) ⇒ Search

Creates a new search

Examples:

Initialize a Giant Bomb search

search = GiantBomb::Search.new
search = GiantBomb::Search.new('game')


16
17
18
19
20
# File 'lib/giantbomb/search.rb', line 16

def initialize(resource=nil)
  @params = {}
  @resource = resource.nil? ? '/search' : resource
  self
end

Instance Attribute Details

#query(query) ⇒ GiantBomb::Search (readonly)

Search query

Parameters:

  • query (String)

    The search query.

Returns:



9
10
11
# File 'lib/giantbomb/search.rb', line 9

def query
  @query
end

#resourceObject (readonly)



9
10
11
# File 'lib/giantbomb/search.rb', line 9

def resource
  @resource
end

Instance Method Details

#fetchArray

Fetch the results of the query

Examples:

search = GiantBomb::Search.new.query("Duke Nukem").fetch

Returns:

  • (Array)

    Items that match the specified query.



87
88
89
90
91
# File 'lib/giantbomb/search.rb', line 87

def fetch
  options = @params.merge(Api.config)
  response = Api.get(@resource, :query => options)
  response['results']
end

#fields(fields) ⇒ GiantBomb::Search

Only return the specified fields for the given resource

Parameters:

  • fields (String)

    A comma delimited list of fields to return.

Returns:



28
29
30
31
# File 'lib/giantbomb/search.rb', line 28

def fields(fields)
  @params[:field_list] = "#{fields}"
  self
end

#filter(conditions) ⇒ Object

A convenience method that takes a hash where each key is the symbol of a method, and each value is the parameters passed to that method.



72
73
74
75
76
77
78
79
80
# File 'lib/giantbomb/search.rb', line 72

def filter(conditions)
  if conditions
    conditions.each do |key, value|
      if self.respond_to?(key)
        self.send(key, value)
      end
    end
  end
end

#limit(limit) ⇒ GiantBomb::Search

Only return a limited number of resources

Parameters:

  • limit (Integer)

    Nmber of items to limit by.

Returns:



37
38
39
40
# File 'lib/giantbomb/search.rb', line 37

def limit(limit)
  @params[:limit] = "#{limit}"
  self
end

#offset(offset) ⇒ GiantBomb::Search

Only include resources starting from a given offset

Parameters:

  • limit (Integer)

    Number of items to skip.

Returns:



46
47
48
49
# File 'lib/giantbomb/search.rb', line 46

def offset(offset)
  @params[:offset] = "#{offset}"
  self
end

#resources(resources) ⇒ GiantBomb::Search

Only include items of the specified resources

Parameters:

  • resources (String)

    A comma delimited list of resources to search.

Returns:



64
65
66
67
# File 'lib/giantbomb/search.rb', line 64

def resources(resources)
  @params[:resources] = "#{resources}"
  self
end