1
0
mirror of https://github.com/pyro2927/SouthwestCheckin.git synced 2025-12-06 01:13:19 +00:00

Abstracting out json page loads

This commit is contained in:
pyro2927
2019-02-16 15:45:03 -08:00
parent d7722fa1ce
commit d9e0a360d4

View File

@@ -43,23 +43,28 @@ class Reservation():
# Ignore responses with no json data in body
pass
def load_json_page(self, url, body=None):
data = self.safe_request(url, body)
for k, v in list(data.items()):
if k.endswith("Page"):
return v
def with_suffix(self, uri):
return "{}{}{}?first-name={}&last-name={}".format(BASE_URL, uri, self.number, self.first, self.last)
def lookup_existing_reservation(self):
# Find our existing record
url = "{}mobile-misc/v1/mobile-misc/page/view-reservation/{}?first-name={}&last-name={}".format(BASE_URL, self.number, self.first, self.last)
data = self.safe_request(url)
return data['viewReservationViewPage']
return self.load_json_page(self.with_suffix("mobile-misc/v1/mobile-misc/page/view-reservation/"))
def get_checkin_data(self):
url = "{}mobile-air-operations/v1/mobile-air-operations/page/check-in/{}?first-name={}&last-name={}".format(BASE_URL, self.number, self.first, self.last)
data = self.safe_request(url)
return data['checkInViewReservationPage']
return self.load_json_page(self.with_suffix("mobile-air-operations/v1/mobile-air-operations/page/check-in/"))
def checkin(self):
data = self.get_checkin_data()
info_needed = data['_links']['checkIn']
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
print("Attempting check-in...")
confirmation = self.safe_request(url, info_needed['body'])['checkInConfirmationPage']
confirmation = self.load_json_page(url, info_needed['body'])
if len(self.notifications) > 0:
self.send_notification(confirmation)
return confirmation
@@ -67,8 +72,8 @@ class Reservation():
def send_notification(self, checkindata):
info_needed = checkindata['_links']['boardingPasses']
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
mbpdata = self.safe_request(url, info_needed['body'])
info_needed = mbpdata['checkInViewBoardingPassPage']['_links']
mbpdata = self.load_json_page(url, info_needed['body'])
info_needed = mbpdata['_links']
url = "{}mobile-air-operations{}".format(BASE_URL, info_needed['href'])
print("Attempting to send boarding pass...")
body = info_needed['body']