Class: Tankard::Api::Beer

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Request::Get, 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:



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

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

Instance Method Details

#breweriesself

Sets the request to beer/:id/breweries

Returns:

  • (self)

    returns itself



59
60
61
62
# File 'lib/tankard/api/beer.rb', line 59

def breweries
  @options.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 37

#eventsself

Sets the request to beer/:id/events

Returns:

  • (self)

    returns itself



67
68
69
70
# File 'lib/tankard/api/beer.rb', line 67

def events
  @options.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 28

#id(beer_id) ⇒ self

BeerID to query

Parameters:

  • beer_id (String)

Returns:

  • (self)

    returns itself



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

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

#ingredientsself

Sets the request to beer/:id/ingredients

Returns:

  • (self)

    returns itself



75
76
77
78
# File 'lib/tankard/api/beer.rb', line 75

def ingredients
  @options.endpoint = "ingredients"
  self
end

#params(options = {}) ⇒ self

Additional parameters to send with the request

Parameters:

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

Returns:

  • (self)

    returns itself



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

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

#social_accountsself

Sets the request to beer/:id/socialaccounts

Returns:

  • (self)

    returns itself



83
84
85
86
# File 'lib/tankard/api/beer.rb', line 83

def social_accounts
  @options.endpoint = "socialaccounts"
  self
end

#variationsself

Sets the request to beer/:id/variations

Returns:

  • (self)

    returns itself



91
92
93
94
# File 'lib/tankard/api/beer.rb', line 91

def variations
  @options.endpoint = "variations"
  self
end