class Cloverrb::Order

Public Class Methods

new(token) click to toggle source
# File lib/cloverrb/order.rb, line 3
def initialize(token)
  @token = token
end
total(line_items) click to toggle source
# File lib/cloverrb/order.rb, line 19
def self.total(line_items)
  items = line_items["elements"]
  items.inject(0) { |sum, item| sum + item["price"] }
end

Public Instance Methods

all(merchant_id, options = {}) click to toggle source
# File lib/cloverrb/order.rb, line 7
def all(merchant_id, options = {})
  url = "/merchants/#{merchant_id}/orders?"

  filters = []
  filters << "filter=createdTime>=#{options[:start_date]}" if has_start_date?(options)
  filters << "filter=createdTime<=#{options[:end_date]}" if has_end_date?(options)
  filters << "filter=state=#{options[:state]}" if has_state?(options)
  url += filters.join("&")

  get(@token, url)
end
has_end_date?(options) click to toggle source
# File lib/cloverrb/order.rb, line 28
def has_end_date?(options)
  options[:end_date]
end
has_start_date?(options) click to toggle source
# File lib/cloverrb/order.rb, line 24
def has_start_date?(options)
  options[:start_date]
end
has_state?(options) click to toggle source
# File lib/cloverrb/order.rb, line 32
def has_state?(options)
  options[:state]
end