class OmnivoreIO::API

Constants

HEADERS
OPTIONS
VERSION

Public Class Methods

new(options={}) click to toggle source
# File lib/omnivore-io/api.rb, line 69
def initialize(options={})
  options = OPTIONS.merge(options)

  @api_key = options.delete(:api_key) || ENV['OMNIVORE_IO_API_KEY']
end

Public Instance Methods

add_menu_item_to_ticket(location_id, ticket_id, payload_json) click to toggle source
# File lib/omnivore-io/api/ticket.rb, line 90
def add_menu_item_to_ticket(location_id, ticket_id, payload_json)
  response = request(:post, "/locations/#{location_id}/tickets/#{ticket_id}/items", payload_json)
  OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
end
add_payment_to_ticket(location_id, ticket_id, payload_json) click to toggle source
# File lib/omnivore-io/api/ticket.rb, line 95
def add_payment_to_ticket(location_id, ticket_id, payload_json)
  response = request(:post, "/locations/#{location_id}/tickets/#{ticket_id}/payments", payload_json)
  response
end
api_key() click to toggle source
# File lib/omnivore-io/api.rb, line 75
def api_key
  @api_key
end
get_location(location_id) click to toggle source
# File lib/omnivore-io/api/location.rb, line 48
def get_location(location_id)
  response = request(
    :get,
    "/locations/#{location_id}"
  )
  OmnivoreIO::Location.new self, response
end
get_locations(options={}) click to toggle source
# File lib/omnivore-io/api/location.rb, line 37
def get_locations(options={})
  response = request(
    :get,
    '/locations',
    options
  )
  (response['_embedded']['locations'] || []).map do |location_hash|
    OmnivoreIO::Location.new self, location_hash
  end
end
get_menu_item(location_id, menu_item_id) click to toggle source
# File lib/omnivore-io/api/menu_item.rb, line 29
def get_menu_item(location_id, menu_item_id)
  response = request(:get, "/locations/#{location_id}/menu/items/#{menu_item_id}")
  OmnivoreIO::MenuItem.new self, response.merge(location_id: location_id)
end
get_menu_items(location_id, options={}) click to toggle source
# File lib/omnivore-io/api/menu_item.rb, line 22
def get_menu_items(location_id, options={})
  response = request(:get, "/locations/#{location_id}/menu/items", options)
  (response['_embedded']['menu_items'] || []).map do |menu_item_hash|
    OmnivoreIO::MenuItem.new self, menu_item_hash.merge(location_id: location_id)
  end
end
get_modifier(location_id, modifier_id) click to toggle source
# File lib/omnivore-io/api/modifier.rb, line 29
def get_modifier(location_id, modifier_id)
  response = request(:get, "/locations/#{location_id}/menu/modifiers/#{modifier_id}")
  OmnivoreIO::Modifier.new self, response.merge(location_id: location_id)
end
get_modifiers(location_id, options={}) click to toggle source
# File lib/omnivore-io/api/modifier.rb, line 22
def get_modifiers(location_id, options={})
  response = request(:get, "/locations/#{location_id}/menu/modifiers", options)
  (response['_embedded']['modifiers'] || []).map do |modifier_hash|
    OmnivoreIO::Modifier.new self, modifier_hash.merge(location_id: location_id)
  end
end
get_order_types(location_id, options={}) click to toggle source
# File lib/omnivore-io/api/order_type.rb, line 21
def get_order_types(location_id, options={})
  response = request(:get, "/locations/#{location_id}/order_types", options)
  (response['_embedded']['order_types'] || []).map do |order_type_hash|
    OmnivoreIO::OrderType.new self, order_type_hash.merge(location_id: location_id)
  end
end
get_ticket(location_id, ticket_id) click to toggle source
# File lib/omnivore-io/api/ticket.rb, line 75
def get_ticket(location_id, ticket_id)
  response = request(:get, "/locations/#{location_id}/tickets/#{ticket_id}")
  OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
end
get_tickets(location_id, options={}) click to toggle source
# File lib/omnivore-io/api/ticket.rb, line 68
def get_tickets(location_id, options={})
  response = request(:get, "/locations/#{location_id}/tickets", options)
  (response['_embedded']['tickets'] || []).map do |ticket_hash|
    OmnivoreIO::Ticket.new self, ticket_hash.merge(location_id: location_id)
  end
end
open_ticket(location_id, ticket_json) click to toggle source
# File lib/omnivore-io/api/ticket.rb, line 80
def open_ticket(location_id, ticket_json)
  response = request(:post, "/locations/#{location_id}/tickets", ticket_json)
  OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
end
request(method, endpoint, query={}, headers={}) click to toggle source
# File lib/omnivore-io/api.rb, line 79
def request(method, endpoint, query={}, headers={})
  headers.merge!({ 'content_type' => :json, 'Api-Key' => self.api_key })
  response = case method
  when :get
    url = "#{OPTIONS[:host]}#{OPTIONS[:api_version]}#{endpoint}"
    if query.keys.length
      url << "?"
      url << URI.encode_www_form(query)
    end
    RestClient.get url, headers
  when :post
    url = "#{OPTIONS[:host]}#{OPTIONS[:api_version]}#{endpoint}"
    payload = query.as_json.to_json
    RestClient::Request.execute(method: :post, url: url, payload: payload, headers: headers)
  end
  # TODO: handle errors
  JSON.parse(response.to_str)
end
void_ticket(location_id, ticket_id) click to toggle source
# File lib/omnivore-io/api/ticket.rb, line 85
def void_ticket(location_id, ticket_id)
  response = request(:post, "/locations/#{location_id}/tickets/#{ticket_id}", {"void": true})
  OmnivoreIO::Ticket.new self, response.merge(location_id: location_id)
end