Class: Cloverrb::Order

Inherits:
Client
  • Object
show all
Defined in:
lib/cloverrb/order.rb

Constant Summary

Constants inherited from Client

Client::AUTH_URL, Client::BASE_URL

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

generate_access_token, #get, #post, #put

Constructor Details

#initialize(token) ⇒ Order

Returns a new instance of Order.



3
4
5
# File 'lib/cloverrb/order.rb', line 3

def initialize(token)
  @token = token
end

Class Method Details

.total(line_items) ⇒ Object



19
20
21
22
# 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

Instance Method Details

#all(merchant_id, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# 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) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cloverrb/order.rb', line 28

def has_end_date?(options)
  options[:end_date]
end

#has_start_date?(options) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/cloverrb/order.rb', line 24

def has_start_date?(options)
  options[:start_date]
end

#has_state?(options) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/cloverrb/order.rb', line 32

def has_state?(options)
  options[:state]
end