class ShakenNotStirred
Constants
- BASE_URL
testing purposes
BASE_URL
= “localhost:3000/api/v1”.freeze
Attributes
configuration[RW]
filters[RW]
resource[RW]
Public Class Methods
configure() { |configuration| ... }
click to toggle source
# File lib/shaken_not_stirred.rb, line 17 def self.configure self.configuration ||= Configuration.new yield(configuration) end
new()
click to toggle source
# File lib/shaken_not_stirred.rb, line 23 def initialize @filters = {} @resource = "cocktails" end
Public Instance Methods
by_categories(query)
click to toggle source
“classic” | [“classic”, “new_era”]
# File lib/shaken_not_stirred.rb, line 49 def by_categories(query) # "OR" behavior by default apply_filter_list "categories", query self end
by_description(query)
click to toggle source
# File lib/shaken_not_stirred.rb, line 34 def by_description(query) apply_filter "description", query self end
by_iba(query)
click to toggle source
# File lib/shaken_not_stirred.rb, line 62 def by_iba(query) apply_filter "iba", query self end
by_ingredients(query)
click to toggle source
“rum” | [“orange”, “rum”]
# File lib/shaken_not_stirred.rb, line 41 def by_ingredients(query) # "OR" behavior by default apply_filter_list "ingredients", query self end
by_multiple(query)
click to toggle source
# File lib/shaken_not_stirred.rb, line 74 def by_multiple(query) apply_filter "multiple", query self end
by_name(query)
click to toggle source
# File lib/shaken_not_stirred.rb, line 28 def by_name(query) apply_filter "name", query self end
by_page(page)
click to toggle source
# File lib/shaken_not_stirred.rb, line 80 def by_page(page) apply_filter "page", page self end
by_random(count=1)
click to toggle source
# File lib/shaken_not_stirred.rb, line 86 def by_random(count=1) apply_filter "random", count self end
by_rating(query)
click to toggle source
# File lib/shaken_not_stirred.rb, line 68 def by_rating(query) apply_filter "rating", query self end
by_timing(query)
click to toggle source
# File lib/shaken_not_stirred.rb, line 56 def by_timing(query) apply_filter "timing", query self end
categories()
click to toggle source
# File lib/shaken_not_stirred.rb, line 92 def categories @resource = "categories" @results = [] self end
ingredients()
click to toggle source
# File lib/shaken_not_stirred.rb, line 99 def ingredients @resource = "ingredients" @results = [] self end
results()
click to toggle source
# File lib/shaken_not_stirred.rb, line 106 def results @results = HTTParty.get(url, headers: headers) end
url()
click to toggle source
# File lib/shaken_not_stirred.rb, line 110 def url "#{BASE_URL}/#{@resource}?#{get_filters}" end
Private Instance Methods
api_key()
click to toggle source
# File lib/shaken_not_stirred.rb, line 116 def api_key @api_key ||= ShakenNotStirred.configuration.api_key end
apply_filter(filter_name, value)
click to toggle source
# File lib/shaken_not_stirred.rb, line 120 def apply_filter(filter_name, value) filters[filter_name] = value end
apply_filter_list(filter_name, value)
click to toggle source
# File lib/shaken_not_stirred.rb, line 124 def apply_filter_list(filter_name, value) # categories[]=classic,new_era filters["#{filter_name}[]"] = [value].flatten.join(",") end
get_filters()
click to toggle source
# File lib/shaken_not_stirred.rb, line 129 def get_filters filters.map { |k,v| "#{k}=#{v}" }.join("&") end
headers()
click to toggle source
# File lib/shaken_not_stirred.rb, line 133 def headers { "Authorization"=>"Token token=\"#{api_key}\"" } end