class GiantBomb::Search

Wrapper for the Giant Bomb Search resource

@see api.giantbomb.com/documentation/#search

Attributes

query[R]

@private

resource[R]

@private

Public Class Methods

new(resource=nil) click to toggle source

Creates a new search

@example Initialize a Giant Bomb search

search = GiantBomb::Search.new
search = GiantBomb::Search.new('game')
# File lib/giantbomb/search.rb, line 16
def initialize(resource=nil)
  @params = {}
  @resource = resource.nil? ? '/search' : resource
  self
end

Public Instance Methods

fetch() click to toggle source

Fetch the results of the query

@return [Array] Items that match the specified query. @example

search = GiantBomb::Search.new.query("Duke Nukem").fetch
# File lib/giantbomb/search.rb, line 87
def fetch
  fetch_response['results']
end
fetch_response() click to toggle source

Fetch the full response of the query, including metadata Keys returned:

status_code
error
number_of_total_results
number_of_page_results
limit
offset
results

@return [Hash] Hash of the api response @example

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

@see api.giantbomb.com/documentation/#handling_responses

# File lib/giantbomb/search.rb, line 105
def fetch_response
  options = @params.merge(Api.config)
  response = Api.get(@resource, query: options)
  response.to_hash
end
fields(fields) click to toggle source

Only return the specified fields for the given resource

@param fields [String] A comma delimited list of fields to return. @return [GiantBomb::Search] self

# File lib/giantbomb/search.rb, line 28
def fields(fields)
  @params[:field_list] = "#{fields}"
  self
end
filter(conditions) click to toggle source

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.

# 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) click to toggle source

Only return a limited number of resources

@param limit [Integer] Nmber of items to limit by. @return [GiantBomb::Search] self

# File lib/giantbomb/search.rb, line 37
def limit(limit)
  @params[:limit] = "#{limit}"
  self
end
offset(offset) click to toggle source

Only include resources starting from a given offset

@param limit [Integer] Number of items to skip. @return [GiantBomb::Search] self

# File lib/giantbomb/search.rb, line 46
def offset(offset)
  @params[:offset] = "#{offset}"
  self
end
resources(resources) click to toggle source

Only include items of the specified resources

@param resources [String] A comma delimited list of resources to search. @return [GiantBomb::Search] self

# File lib/giantbomb/search.rb, line 64
def resources(resources)
  @params[:resources] = "#{resources}"
  self
end