Class: GiantBomb::Search
- Inherits:
-
Object
- Object
- GiantBomb::Search
- Includes:
- Api
- Defined in:
- lib/giantbomb/search.rb
Overview
Wrapper for the Giant Bomb Search resource
Generic filters collapse
-
#query(query) ⇒ GiantBomb::Search
readonly
Search query.
Instance Attribute Summary collapse
- #resource ⇒ Object readonly
Generic filters collapse
-
#fetch ⇒ Array
Fetch the results of the query.
-
#fetch_response ⇒ Hash
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.
-
#fields(fields) ⇒ GiantBomb::Search
Only return the specified fields for the given resource.
-
#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.
-
#limit(limit) ⇒ GiantBomb::Search
Only return a limited number of resources.
-
#offset(offset) ⇒ GiantBomb::Search
Only include resources starting from a given offset.
-
#resources(resources) ⇒ GiantBomb::Search
Only include items of the specified resources.
Instance Method Summary collapse
-
#initialize(resource = nil) ⇒ Search
constructor
Creates a new search.
Methods included from Api
Constructor Details
#initialize(resource = nil) ⇒ Search
Creates a new search
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
9 10 11 |
# File 'lib/giantbomb/search.rb', line 9 def query @query end |
#resource ⇒ Object (readonly)
9 10 11 |
# File 'lib/giantbomb/search.rb', line 9 def resource @resource end |
Instance Method Details
#fetch ⇒ Array
Fetch the results of the query
87 88 89 |
# File 'lib/giantbomb/search.rb', line 87 def fetch fetch_response['results'] end |
#fetch_response ⇒ Hash
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
105 106 107 108 109 |
# File 'lib/giantbomb/search.rb', line 105 def fetch_response = @params.merge(Api.config) response = Api.get(@resource, :query => ) response.to_hash end |
#fields(fields) ⇒ GiantBomb::Search
Only return the specified fields for the given resource
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
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
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
64 65 66 67 |
# File 'lib/giantbomb/search.rb', line 64 def resources(resources) @params[:resources] = "#{resources}" self end |