Class: Tankard::Api::Search

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Utils::PageFinders
Defined in:
lib/tankard/api/search.rb

Overview

Access for the /search route on brewerydb

Instance Method Summary collapse

Constructor Details

#initialize(request, options = {}) ⇒ Tankard::Api::Search

Initializes a new object

Parameters:



20
21
22
23
# File 'lib/tankard/api/search.rb', line 20

def initialize(request, options = {})
  @http_client = request
  @http_request_parameters = Hashie::Mash.new(options)
end

Instance Method Details

#each {|hash| ... } ⇒ Object

Calls the given block once for each result

Yield Parameters:

  • hash (Hash)

    containing individual beer information

Raises:



33
34
35
36
# File 'lib/tankard/api/search.rb', line 33

def each(&block)
  raise_if_required_options_not_set
  super(&block)
end

#geo_point(latitude, longitude) ⇒ self

search for berweries around a specific point. sets the endpoint to geo/point and passes lat/lng as parameters

Parameters:

  • latitude (Float)
  • longitude (Float)

Returns:

  • (self)

    returns itself



93
94
95
96
97
98
# File 'lib/tankard/api/search.rb', line 93

def geo_point(latitude, longitude)
  @http_request_parameters.lat = latitude
  @http_request_parameters.lng = longitude
  @http_request_parameters.endpoint = 'geo/point'
  self
end

#page(number) ⇒ self

Page number to request

Parameters:

  • number (Integer)

Returns:

  • (self)

    returns itself



51
52
53
54
# File 'lib/tankard/api/search.rb', line 51

def page(number)
  @http_request_parameters.p = number
  self
end

#params(options = {}) ⇒ self

Additional parameters to send with the request

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (self)

    returns itself



60
61
62
63
64
65
# File 'lib/tankard/api/search.rb', line 60

def params(options = {})
  options.each_pair do |key, value|
    @http_request_parameters[key] = value
  end
  self
end

#query(search_query) ⇒ self

Query to search for

Parameters:

  • search_query (String)

Returns:

  • (self)

    returns itself



42
43
44
45
# File 'lib/tankard/api/search.rb', line 42

def query(search_query)
  @http_request_parameters.q = search_query
  self
end

#type(search_type) ⇒ self

Type of search to perform

Parameters:

  • search_type (String)

Returns:

  • (self)

    returns itself



71
72
73
74
# File 'lib/tankard/api/search.rb', line 71

def type(search_type)
  @http_request_parameters.type = search_type
  self
end

#upc(upc_code) ⇒ self

search for a specific upc. sets the endpoint to upc and passes upc_code as a parameter

Parameters:

  • upc_code (Integer)

Returns:

  • (self)

    returns itself



81
82
83
84
85
# File 'lib/tankard/api/search.rb', line 81

def upc(upc_code)
  @http_request_parameters.code = upc_code
  @http_request_parameters.endpoint = 'upc'
  self
end