Class: OrderInformation
- Inherits:
-
Object
- Object
- OrderInformation
- Defined in:
- lib/order_information.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#phone_number ⇒ Object
Returns the value of attribute phone_number.
Instance Method Summary collapse
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/order_information.rb', line 3 def name @name end |
#phone_number ⇒ Object
Returns the value of attribute phone_number.
3 4 5 |
# File 'lib/order_information.rb', line 3 def phone_number @phone_number end |
Instance Method Details
#confirm ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/order_information.rb', line 49 def confirm raise "Stopped by user" unless Ask.confirm "Continue?" Request.post("https://order.dominos.jp/eng/receipt/complete", @page_params, expect: :redirect, to: "https://order.dominos.jp/eng/menu/", failure: "Couldn't validate your information") end |
#display ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/order_information.rb', line 38 def display doc = Nokogiri::HTML(@second_response.body) info = doc.css(".m-input__heading").map(&:text). zip(doc.css(".section_content_table_td").map(&:text)).to_h @page_params = doc.css("input[type=hidden]").map do |input| [input["name"], input["value"]] end.to_h info.each { |title, value| puts "#{title.colorize(:blue)}: #{value}" } end |
#input ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/order_information.rb', line 5 def input response = Request.get("https://order.dominos.jp/eng/receipt/input/", expect: :ok, failure: "Couldn't get information input page") saved_name = Name.from(response.body) phone_numbers = PhoneNumbers.from(response.body) self.name = Preferences.instance.name || Ask.input("Name", default: saved_name) self.phone_number = phone_numbers.find_number(Preferences.instance.phone_number) unless phone_number phone_number_index = Ask.list "Phone Number", phone_numbers.selection_list self.phone_number = phone_numbers[phone_number_index] end @first_response = response end |
#validate ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/order_information.rb', line 23 def validate raise "Missing attributes" unless name && phone_number # Get the default parameters and add in the client name and phone number params = default_params.merge( "kokyakuNm" => name, "telSeq" => phone_number.value ) @second_response = Request.post("https://order.dominos.jp/eng/receipt/confirm", params, expect: :ok, failure: "Couldn't set your information") do |resp| resp.body.include?("Order Type, Day&Time and Your Store") end end |