Skip to content

Commit 54c6ada

Browse files
update to include canada
1 parent a17a77c commit 54c6ada

File tree

8 files changed

+100
-39
lines changed

8 files changed

+100
-39
lines changed

pizzapi/address.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from .store import Store
22
from .utils import request_json
3-
from .urls import FIND_URL
3+
from .urls import Urls, COUNTRY_USA
44

55
class Address(object):
6-
def __init__(self, street, city, region='', zip='', *args):
6+
def __init__(self, street, city, region='', zip='', country=COUNTRY_USA, *args):
77
self.street = street.strip()
88
self.city = city.strip()
99
self.region = region.strip()
10-
self.zip = str(zip).strip()
10+
self.zip = str(zip).strip(),
11+
self.urls = Urls(country)
12+
self.country = country
1113

1214
@property
1315
def data(self):
@@ -23,8 +25,8 @@ def line2(self):
2325
return '{City}, {Region}, {PostalCode}'.format(**self.data)
2426

2527
def nearby_stores(self, service='Delivery'):
26-
data = request_json(FIND_URL, line1=self.line1, line2=self.line2, type=service)
27-
return [Store(x) for x in data['Stores']
28+
data = request_json(self.urls.find_url(), line1=self.line1, line2=self.line2, type=service)
29+
return [Store(x, self.country) for x in data['Stores']
2830
if x['IsOnlineNow'] and x['ServiceIsOpen'][service]]
2931

3032
def closest_store(self, service='Delivery'):

pizzapi/menu.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import print_function
2-
from .urls import MENU_URL
2+
from .urls import Urls, COUNTRY_USA
33
from .utils import request_json
44

55

@@ -28,10 +28,12 @@ def __init__(self, data={}):
2828

2929

3030
class Menu(object):
31-
def __init__(self, data={}):
31+
def __init__(self, data={}, country=COUNTRY_USA):
3232
self.variants = data.get('Variants', {})
3333
self.menu_by_code = {}
3434
self.root_categories = {}
35+
self.country = COUNTRY_USA
36+
3537
if self.variants:
3638
self.products = self.parse_items(data['Products'])
3739
self.coupons = self.parse_items(data['Coupons'])
@@ -40,8 +42,8 @@ def __init__(self, data={}):
4042
self.root_categories[key] = self.build_categories(value)
4143

4244
@classmethod
43-
def from_store(cls, store_id, lang='en'):
44-
response = request_json(MENU_URL, store_id=store_id, lang=lang)
45+
def from_store(self, cls, store_id, lang='en', country=COUNTRY_USA):
46+
response = request_json(Urls(country).menu_url(), store_id=store_id, lang=lang)
4547
menu = cls(response)
4648
return menu
4749

pizzapi/order.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import requests
22

33
from .menu import Menu
4-
from .urls import PRICE_URL, PLACE_URL, VALIDATE_URL
4+
from .urls import Urls, COUNTRY_USA
55

66

77
# TODO: Add add_coupon and remove_coupon methods
88
class Order(object):
9-
def __init__(self, store, customer, address):
9+
def __init__(self, store, customer, address, country=COUNTRY_USA):
1010
self.store = store
11-
self.menu = Menu.from_store(store_id=store.id)
11+
self.menu = Menu.from_store(store_id=store.id, country=country)
1212
self.customer = customer
1313
self.address = address
14+
self.urls = Urls(country)
1415
self.data = {
1516
'Address': {'Street': self.address.street,
1617
'City': self.address.city,
@@ -81,22 +82,22 @@ def _send(self, url, merge):
8182
self.data[key] = value
8283
return json_data
8384

84-
# TODO: Figure out if this validates anything that PRICE_URL does not
85+
# TODO: Figure out if this validates anything that self.urls.price_url() does not
8586
def validate(self):
86-
response = self._send(VALIDATE_URL, True)
87+
response = self._send(self.urls.validate_url(), True)
8788
return response['Status'] != -1
8889

8990
# TODO: Actually test this
9091
def place(self, card):
9192
self.pay_with(card)
92-
response = self._send(PLACE_URL, False)
93+
response = self._send(self.urls.place_url(), False)
9394
return response
9495

9596
# TODO: Add self.price() and update whenever called and items were changed
9697
def pay_with(self, card):
9798
"""Use this instead of self.place when testing"""
9899
# get the price to check that everything worked okay
99-
response = self._send(PRICE_URL, True)
100+
response = self._send(self.urls.price_url(), True)
100101

101102
if response['Status'] == -1:
102103
raise Exception('get price failed: %r' % response)

pizzapi/store.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
from .menu import Menu
2-
from .urls import INFO_URL, MENU_URL
2+
from .urls import Urls, COUNTRY_USA
33
from .utils import request_json
44

55

66
class Store(object):
7-
def __init__(self, data={}):
7+
def __init__(self, data={}, country=COUNTRY_USA):
88
self.id = str(data.get('StoreID', -1))
9+
self.country = country
10+
self.urls = Urls(country)
911
self.data = data
1012

1113
def get_details(self):
12-
details = request_json(INFO_URL, store_id=self.id)
14+
details = request_json(self.urls.info_url(), store_id=self.id)
1315
return details
1416

1517
def get_menu(self, lang='en'):
16-
response = request_json(MENU_URL, store_id=self.id, lang=lang)
17-
menu = Menu(response)
18+
response = request_json(self.urls.menu_url(), store_id=self.id, lang=lang)
19+
menu = Menu(response, self.country)
1820
return menu

pizzapi/track.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from .urls import TRACK_BY_PHONE, TRACK_BY_ORDER
1+
from .urls import Urls, COUNTRY_USA
22
from .utils import request_xml, request_json
33

44

5-
def track_by_phone(phone):
5+
def track_by_phone(phone, country=COUNTRY_USA):
66
phone = str(phone).strip()
7-
data = request_xml(TRACK_BY_PHONE, phone=phone)['soap:Envelope']['soap:Body']
7+
data = request_xml(Urls(country).track_by_phone(), phone=phone)['soap:Envelope']['soap:Body']
88
response = data['GetTrackerDataResponse']['OrderStatuses']['OrderStatus']
99
return response
1010

1111

12-
def track_by_order(store_id, order_key):
13-
return request_json(TRACK_BY_ORDER, store_id=store_id, order_key=order_key)
12+
def track_by_order(store_id, order_key, country=COUNTRY_USA):
13+
return request_json(Urls(country).track_by_order(), store_id=store_id, order_key=order_key)

pizzapi/urls.py

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,61 @@
1-
FIND_URL = 'https://order.dominos.com/power/store-locator?s={line1}&c={line2}&type={type}'
2-
INFO_URL = 'https://order.dominos.com/power/store/{store_id}/profile'
3-
MENU_URL = 'https://order.dominos.com/power/store/{store_id}/menu?lang={lang}&structured=true'
4-
PLACE_URL = 'https://order.dominos.com/power/place-order'
5-
PRICE_URL = 'https://order.dominos.com/power/price-order'
6-
TRACK_BY_ORDER = 'https://trkweb.dominos.com/orderstorage/GetTrackerData?StoreID={store_id}&OrderKey={order_key}'
7-
TRACK_BY_PHONE = 'https://trkweb.dominos.com/orderstorage/GetTrackerData?Phone={phone}'
8-
VALIDATE_URL = 'https://order.dominos.com/power/validate-order'
9-
COUPON_URL = 'https://order.dominos.com/power/store/{store_id}/coupon/{couponid}?lang={lang}'
1+
COUNTRY_USA = 'us'
2+
COUNTRY_CANADA = 'ca'
3+
4+
class Urls(object):
5+
def __init__(self, country=COUNTRY_USA):
6+
7+
self.country = country
8+
self.urls = {
9+
COUNTRY_USA: {
10+
'find_url' : 'https://order.dominos.com/power/store-locator?s={line1}&c={line2}&type={type}',
11+
'info_url' : 'https://order.dominos.com/power/store/{store_id}/profile',
12+
'menu_url' : 'https://order.dominos.com/power/store/{store_id}/menu?lang={lang}&structured=true',
13+
'place_url' : 'https://order.dominos.com/power/place-order',
14+
'price_url' : 'https://order.dominos.com/power/price-order',
15+
'track_by_order' : 'https://trkweb.dominos.com/orderstorage/GetTrackerData?StoreID={store_id}&OrderKey={order_key}',
16+
'track_by_phone' : 'https://trkweb.dominos.com/orderstorage/GetTrackerData?Phone={phone}',
17+
'validate_url' : 'https://order.dominos.com/power/validate-order',
18+
'coupon_url' : 'https://order.dominos.com/power/store/{store_id}/coupon/{couponid}?lang={lang}',
19+
},
20+
COUNTRY_CANADA: {
21+
'find_url' : 'https://order.dominos.ca/power/store-locator?s={line1}&c={line2}&type={type}',
22+
'info_url' : 'https://order.dominos.ca/power/store/{store_id}/profile',
23+
'menu_url' : 'https://order.dominos.ca/power/store/{store_id}/menu?lang={lang}&structured=true',
24+
'place_url' : 'https://order.dominos.ca/power/place-order',
25+
'price_url' : 'https://order.dominos.ca/power/price-order',
26+
'track_by_order' : 'https://trkweb.dominos.ca/orderstorage/GetTrackerData?StoreID={store_id}&OrderKey={order_key}',
27+
'track_by_phone' : 'https://trkweb.dominos.ca/orderstorage/GetTrackerData?Phone={phone}',
28+
'validate_url' : 'https://order.dominos.ca/power/validate-order',
29+
'coupon_url' : 'https://order.dominos.ca/power/store/{store_id}/coupon/{couponid}?lang={lang}',
30+
}
31+
}
32+
33+
def find_url(self):
34+
return self.urls[self.country]['find_url']
35+
36+
def info_url(self):
37+
return self.urls[self.country]['info_url']
38+
39+
def menu_url(self):
40+
return self.urls[self.country]['menu_url']
41+
42+
def place_url(self):
43+
return self.urls[self.country]['place_url']
44+
45+
def price_url(self):
46+
return self.urls[self.country]['price_url']
47+
48+
def track_by_order(self):
49+
return self.urls[self.country]['track_by_order']
50+
51+
def track_by_phone(self):
52+
return self.urls[self.country]['track_by_phone']
53+
54+
def validate_url(self):
55+
return self.urls[self.country]['validate_url']
56+
57+
def coupon_url(self):
58+
return self.urls[self.country]['coupon_url']
59+
60+
61+

tests/test_address.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pytest import mark
77

88
from pizzapi.address import Address
9-
from pizzapi.urls import FIND_URL
9+
from pizzapi.urls import Urls, COUNTRY_USA
1010

1111

1212
fixture_path = os.path.join('tests', 'fixtures', 'stores.json')
@@ -25,7 +25,8 @@
2525

2626

2727
def mocked_request_json(url, **kwargs):
28-
assert_that(url, equal_to(FIND_URL))
28+
29+
assert_that(url, equal_to(Urls(COUNTRY_USA).find_url()))
2930
assert_that(kwargs, has_entries(
3031
line1='700 Pennsylvania Avenue NW',
3132
line2='Washington, DC, 20408',

tests/test_menu.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pytest import mark
77

88
from pizzapi.menu import Menu
9-
from pizzapi.urls import MENU_URL
9+
from pizzapi.urls import Urls, COUNTRY_USA
1010

1111

1212
fixture_path = os.path.join('tests', 'fixtures', 'menu.json')
@@ -16,7 +16,8 @@
1616

1717

1818
def mocked_request_json(url, **kwargs):
19-
assert_that(url, equal_to(MENU_URL))
19+
20+
assert_that(url, equal_to(Urls(COUNTRY_USA).menu_url()))
2021
assert_that(kwargs, has_items('store_id', 'lang'))
2122
return menu_fixture
2223

0 commit comments

Comments
 (0)