Class: Tankard::Api::Beer

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

Overview

Access for the /beer route on brewerydb

Instance Method Summary collapse

Constructor Details

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

Initialize a new object

Parameters:



21
22
23
24
# File 'lib/tankard/api/beer.rb', line 21

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

Instance Method Details

#breweriesself

Sets the request to beer/:id/breweries

Returns:

  • (self)

    returns itself



57
58
59
60
# File 'lib/tankard/api/beer.rb', line 57

def breweries
  @http_request_parameters.endpoint = 'breweries'
  self
end

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

Calls the given block once for each beer

Yield Parameters:

  • hash (Hash)

    containing individual beer information

Raises:



# File 'lib/tankard/api/beer.rb', line 35

#eventsself

Sets the request to beer/:id/events

Returns:

  • (self)

    returns itself



65
66
67
68
# File 'lib/tankard/api/beer.rb', line 65

def events
  @http_request_parameters.endpoint = 'events'
  self
end

#find(id_or_array, options = {}) ⇒ Hash, Array

Find a single or multiple beers by their id

Parameters:

  • id_or_array (String, Array)
  • options (Hash) (defaults to: {})

Returns:

  • (Hash, Array)

    if a string with a beer id is passed to find then the hash of the beer is returned. if an array is passed to find an array containing hashes with each beer is returned. if a beer is not found nothing for that beer is returned.



# File 'lib/tankard/api/beer.rb', line 26

#id(beer_id) ⇒ self

BeerID to query

Parameters:

  • beer_id (String)

Returns:

  • (self)

    returns itself



49
50
51
52
# File 'lib/tankard/api/beer.rb', line 49

def id(beer_id)
  @http_request_parameters.id = beer_id
  self
end

#ingredientsself

Sets the request to beer/:id/ingredients

Returns:

  • (self)

    returns itself



73
74
75
76
# File 'lib/tankard/api/beer.rb', line 73

def ingredients
  @http_request_parameters.endpoint = 'ingredients'
  self
end

#params(options = {}) ⇒ self

Additional parameters to send with the request

Parameters:

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

Returns:

  • (self)

    returns itself



98
99
100
101
102
103
# File 'lib/tankard/api/beer.rb', line 98

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

#social_accountsself

Sets the request to beer/:id/socialaccounts

Returns:

  • (self)

    returns itself



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

def social_accounts
  @http_request_parameters.endpoint = 'socialaccounts'
  self
end

#variationsself

Sets the request to beer/:id/variations

Returns:

  • (self)

    returns itself



89
90
91
92
# File 'lib/tankard/api/beer.rb', line 89

def variations
  @http_request_parameters.endpoint = 'variations'
  self
end