dominosjp 0.1.0 β†’ 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a8eff1dcad6edc6236af5a90239ecd2afd0cdc3
4
- data.tar.gz: 3ca1d4888bb591523b1dbe3921e71ff6c3ec811f
3
+ metadata.gz: 48263e3873fe7c5919eda8b81495fd6027d2786b
4
+ data.tar.gz: 2427fb282cb3de6bd79f4fbfe5bd97f0b403ae59
5
5
  SHA512:
6
- metadata.gz: 8c63d14703893d31846c4d2691b8c73ea49b5cda9ca69fa937cb40beff10e99a42820d562c8d0f7c50d15a47ff2e76f7796b73a9741f557e3c861dd913596793
7
- data.tar.gz: 53dae35002494984757b89e65dbfda652ed6dfb26e0f9132741ee6948560076b33d5e7e8c84c297b80ec557e8c391678274b3ba307b09604984ea41e95e9149b
6
+ metadata.gz: b89c326f9245107463a209f9f739cdee49210519ab2f5226a79cf8204ff0f56d917d1c5468a6bdfac05789dd22ad1b61c9a02249ceded93deca25e78eec887b6
7
+ data.tar.gz: 2f835187568f3dbc1e1075f637d3dce5aaa7d6e39e2300aea0207f90dbd3af0c0fff3f66d4a59fd693c6a9c833895783f4478d3a2bf7109a580f8b0657c821fa
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # DominosJP πŸ•πŸ›΅πŸ‡―πŸ‡΅
2
2
  πŸ•Domino's Pizza Japan CLI πŸ•
3
3
 
4
- ![](https://i.imgur.com/CRaTrSE.jpg)
4
+ <img src="https://i.imgur.com/CRaTrSE.jpg" width="500">
5
5
 
6
6
  ### Requirements
7
7
 
@@ -39,7 +39,7 @@ Note: All keys are optional. It even allows for partial credit card info.
39
39
  - (1) Allow for paying via cash (credit card-only now)
40
40
  - (5) Allow for selecting pizza toppings
41
41
  - (4) Allow for selecting pizza size/cut type/number of slices
42
- - (2) Allow for selecting sides (not only pizzas), (5) maybe even the special menu
42
+ - (4) Allow for selecting items from the special menu
43
43
  - (5) Extra: Pizza Tracking via the CLI, and hopefully automate the Mystery Deal
44
44
 
45
45
  ### Contact
@@ -13,6 +13,8 @@ require_relative "order_payment"
13
13
  require_relative "order_review"
14
14
  require_relative "pizza"
15
15
  require_relative "pizza_selector"
16
+ require_relative "side"
17
+ require_relative "side_selector"
16
18
 
17
19
  class DominosJP
18
20
  attr_accessor :order_address, :order_information
@@ -51,7 +53,7 @@ class DominosJP
51
53
  order_information.confirm
52
54
 
53
55
  PizzaSelector.select_pizzas
54
- # TODO: allow selecting sides
56
+ SideSelector.select_sides
55
57
 
56
58
  order_review.display
57
59
 
@@ -91,7 +91,7 @@ class OrderLastReview
91
91
 
92
92
  def to_s
93
93
  sections = doc.css(".l-section").map do |section|
94
- next unless section.css(".m-heading__caption").count.positive?
94
+ next unless section.css(".m-heading__caption").count > 0
95
95
 
96
96
  section_name = section.css(".m-heading__caption").text.strip.gsub(/\s+/, " ").colorize(:green)
97
97
  rows = section.css("tr").map do |row|
@@ -81,7 +81,7 @@ class CouponItems < Array
81
81
  end
82
82
 
83
83
  def to_s
84
- return unless count.positive?
84
+ return unless count > 0
85
85
  "\nCoupons".colorize(:green)
86
86
  end
87
87
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  class PizzaSelector
3
3
  def self.select_pizzas
4
+ return unless Ask.confirm "Add a pizza?"
5
+
4
6
  response = Request.get("https://order.dominos.jp/eng/pizza/search/",
5
7
  expect: :ok, failure: "Couldn't get pizza list page")
6
8
 
@@ -45,8 +47,7 @@ class PizzaSelector
45
47
  end
46
48
 
47
49
  def self.add_pizza(pizza)
48
- params = pizza.params
49
- params = params.merge(
50
+ params = pizza.params.merge(
50
51
  "pageId" => "PIZZA_DETAIL",
51
52
  # TODO: Allow cut type, number of slices and quantity selection
52
53
  "cutTypeC" => 1, # Type of cut: 1=Round Cut
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+ require "byebug"
3
+ class Sides < Array
4
+ def self.from(source)
5
+ doc = Nokogiri::HTML(source)
6
+
7
+ Sides.new(
8
+ doc.css(".jso-dataLayerProductClick").map { |el| Side.new(el) }.select(&:valid?)
9
+ )
10
+ end
11
+
12
+ def selection_list
13
+ map(&:list_item)
14
+ end
15
+ end
16
+
17
+ class Side
18
+ attr_accessor :id, :category_id, :url, :name, :description, :allergen_warning
19
+ attr_accessor :combo
20
+
21
+ def initialize(element)
22
+ return unless element["iname"]
23
+
24
+ link = element["href"]
25
+ parts = link.split("/")
26
+ side_id = parts.pop
27
+ category_id = parts.pop
28
+ # some_other_number = parts.pop # TODO: figure out what this is
29
+
30
+ description = element.css(".menu_itemList_item_text").first
31
+ description = description.text if description
32
+
33
+ allergen_warning = element.css(".js-menuSetHeight_allergen").first
34
+ allergen_warning = allergen_warning.text if allergen_warning
35
+
36
+ self.url = "https://order.dominos.jp#{link}"
37
+ self.id = side_id # shohinC
38
+ self.category_id = category_id # categoryC
39
+ self.name = element["iname"]
40
+ self.description = description
41
+ self.allergen_warning = allergen_warning
42
+ end
43
+
44
+ def valid?
45
+ url != nil
46
+ end
47
+
48
+ def customizable?
49
+ available_combos.count > 0
50
+ end
51
+
52
+ def available_combos
53
+ @available_combos ||=
54
+ detail_page_content.css(".m-section_item__changeSide .m-input__radio").map do |option|
55
+ Side::Combo.new(option)
56
+ end
57
+
58
+ @available_combos.sort_by! { |cmb| cmb.default ? 0 : 1 }
59
+ end
60
+
61
+ def params
62
+ {
63
+ "shohinC" => id,
64
+ "categoryC" => category_id,
65
+ "setRecommendYosoData" => combo.value
66
+ }
67
+ end
68
+
69
+ def list_item
70
+ allergen = allergen_warning || ""
71
+
72
+ "#{name.colorize(:blue)} "\
73
+ "#{allergen.strip.colorize(:yellow)}\n "\
74
+ "#{description.gsub(",", ", ").gsub(")", ") ")}\n".sub("\n \n", "")
75
+ end
76
+
77
+ private
78
+
79
+ def detail_page_content
80
+ @detail_page_content ||= Nokogiri::HTML(
81
+ Request.get(url, expect: :ok, failure: "Couldn't open side detail page").body
82
+ )
83
+ end
84
+ end
85
+
86
+ class Side
87
+ class Combo
88
+ attr_accessor :title, :price, :value, :setvalue, :default
89
+
90
+ def initialize(option)
91
+ self.title = option.css(".radio_side_title").text.strip
92
+ self.price = option.css(".radio_side_prise_set").text.strip
93
+ self.value = option.css("input[name=setRecommendYosoData]").first["value"]
94
+ self.default = (title == "No thanks")
95
+ end
96
+
97
+ def list_item
98
+ [title, price.colorize(:blue)].join(price == "" ? "" : ": ")
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+ class SideSelector
3
+ def self.select_sides
4
+ return unless Ask.confirm "Add sides?"
5
+
6
+ response = Request.get("https://order.dominos.jp/eng/side/search/",
7
+ expect: :ok, failure: "Couldn't get side list page")
8
+
9
+ sides = Sides.from(response.body)
10
+
11
+ cli = HighLine.new
12
+ choices = sides.selection_list
13
+
14
+ loop do
15
+ puts "-" * 42
16
+ cli.choose do |menu|
17
+ menu.prompt = "Add a side via number:"
18
+ menu.choices(*(choices + ["Cancel"])) do |choice|
19
+ index = choices.index(choice)
20
+
21
+ if index && index < choices.count
22
+ selected_side = sides[index]
23
+
24
+ puts "#{"β†’".colorize(:green)} #{selected_side.name.colorize(:blue)}"
25
+ add_side(customize_side(selected_side))
26
+ end
27
+ end
28
+ menu.default = "Cancel"
29
+ end
30
+
31
+ break unless Ask.confirm "Add another side?"
32
+ end
33
+ end
34
+
35
+ def self.customize_side(side)
36
+ return side unless side.customizable?
37
+
38
+ # Choosing the combo
39
+ selected_combo_index = Ask.list "Choose the combo", side.available_combos.map(&:list_item)
40
+ side.combo = side.available_combos[selected_combo_index]
41
+
42
+ side
43
+ end
44
+
45
+ def self.add_side(side)
46
+ params = side.params.merge(
47
+ "pageId" => "SIDE_DETAIL",
48
+ "shohinPretotypingCouponC" => "",
49
+ "figure" => "1" # Quantity
50
+ )
51
+
52
+ response = Request.post(
53
+ "https://order.dominos.jp/eng/cart/add/side/", params,
54
+ expect: :redirect, to: %r{\Ahttps?://order\.dominos\.jp/eng/cart/added/\z},
55
+ failure: "Couldn't add the side you selected"
56
+ )
57
+
58
+ # For some reason we need to GET this URL otherwise it doesn't count as added <_<
59
+ Request.get(response["Location"],
60
+ expect: :redirect, to: "https://order.dominos.jp/eng/cart/",
61
+ failure: "Couldn't add the side you selected")
62
+ end
63
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  class DominosJP
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0".freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dominosjp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mahdi Bchetnia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-17 00:00:00.000000000 Z
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -115,6 +115,8 @@ files:
115
115
  - lib/pizza_selector.rb
116
116
  - lib/preferences.rb
117
117
  - lib/request.rb
118
+ - lib/side.rb
119
+ - lib/side_selector.rb
118
120
  - lib/version.rb
119
121
  homepage: https://github.com/inket/dominosjp
120
122
  licenses: