Class: Kitely::Order

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(customer:) {|jobs| ... } ⇒ Order

Returns a new instance of Order.

Yields:



7
8
9
10
11
# File 'lib/kitely/order.rb', line 7

def initialize(customer:)
  self.customer = customer
  self.jobs = []
  yield jobs if block_given?
end

Instance Attribute Details

#customerObject

Returns the value of attribute customer.



5
6
7
# File 'lib/kitely/order.rb', line 5

def customer
  @customer
end

#jobsObject

Returns the value of attribute jobs.



5
6
7
# File 'lib/kitely/order.rb', line 5

def jobs
  @jobs
end

Instance Method Details

#add(job) ⇒ Object



13
14
15
# File 'lib/kitely/order.rb', line 13

def add(job)
  self.jobs.push(job)
end

#attributesObject



17
18
19
20
21
22
23
24
# File 'lib/kitely/order.rb', line 17

def attributes
  {
    shipping_address: self.customer.shipping_address,
    customer_phone: self.customer.phone,
    customer_email: self.customer.email,
    jobs: self.jobs.map(&:attributes)
  }
end

#httpObject



30
31
32
# File 'lib/kitely/order.rb', line 30

def http
  @http ||= HTTP.auth("ApiKey #{Kitely.public_key}:#{Kitely.secret_key}")
end

#order!Object



26
27
28
# File 'lib/kitely/order.rb', line 26

def order!
  self.http.post(Kitely.url('print'), json: self.attributes)
end