Class: OrderCoupon

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#add_couponObject

Returns the value of attribute add_coupon.



4
5
6
# File 'lib/order_coupon.rb', line 4

def add_coupon
  @add_coupon
end

#couponObject

Returns the value of attribute coupon.



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

def coupon
  @coupon
end

#total_price_without_taxObject

Returns the value of attribute total_price_without_tax.



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

def total_price_without_tax
  @total_price_without_tax
end

Instance Method Details

#inputObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/order_coupon.rb', line 7

def input
  self.add_coupon = Ask.confirm "Add a coupon?"
  return unless add_coupon

  response = Request.get("https://order.dominos.jp/eng/coupon/use/",
                         expect: :ok, failure: "Couldn't get coupons list")

  coupons = Coupons.from(response.body, total_price_without_tax)
  selected_coupon_index = Ask.list "Choose a coupon", coupons.selection_list
  self.coupon = coupons[selected_coupon_index]
end

#validateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/order_coupon.rb', line 19

def validate
  return unless add_coupon

  unless coupon.usable?
    puts "This coupon cannot be used."
    return
  end

  Request.post("https://order.dominos.jp/eng/webapi/sides/setUserCoupon/", coupon.params,
               expect: :ok, failure: "Couldn't add coupon")
end