dominosjp 0.1.0 β 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/dominosjp.rb +3 -1
- data/lib/order_payment.rb +1 -1
- data/lib/order_review.rb +1 -1
- data/lib/pizza_selector.rb +3 -2
- data/lib/side.rb +101 -0
- data/lib/side_selector.rb +63 -0
- data/lib/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48263e3873fe7c5919eda8b81495fd6027d2786b
|
4
|
+
data.tar.gz: 2427fb282cb3de6bd79f4fbfe5bd97f0b403ae59
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
- (
|
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
|
data/lib/dominosjp.rb
CHANGED
@@ -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
|
-
|
56
|
+
SideSelector.select_sides
|
55
57
|
|
56
58
|
order_review.display
|
57
59
|
|
data/lib/order_payment.rb
CHANGED
@@ -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
|
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|
|
data/lib/order_review.rb
CHANGED
data/lib/pizza_selector.rb
CHANGED
@@ -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
|
data/lib/side.rb
ADDED
@@ -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
|
data/lib/version.rb
CHANGED
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.
|
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-
|
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:
|