Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Endpoint tester #309

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
117 changes: 117 additions & 0 deletions all_get.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#directions/v5/{user}/{profile}/{coordinates}
#getKeyInfo/{keyInfoId}
#guid/{guid}/vins
#listKeyInfo/{deviceId}
#mileage-verification/vin/{vin}
#/oa21mm/v1/ota/update/check
#oa21mm/v1/svc/guid/{guid}/vins
#/oa21mm/v1/svc/musicpreference
#/oa21mm/v1/svc/subscriptions
#/oa21mm/v1/svc/sync/vapreference
#onetrust/consent/dataSubject/{id}
#onetrust/consent/purposes/{id}
#/orders
#/osb/slider
#/self-service/asset-device/mop/unlock-status
#tou/product/mapping
#translations/xKQ1i33s9htHVN9fi994WJZUE/feed/{locale}
#/v1/account/emailsearch
#/v1/campaigns
/v1/canbus/trip/events
/#v1/collisiondata
#/v1/customer/eligibility
#/v1/dashboardlights
#/v1/deeplink
/v1/destinations
#/v1/eligibility
/v1/external/vehicle-subscriptions
/v1/feedback/metadata
/v1/global/remote/ac-reservation
/v1/global/remote/climate-settings
/v1/global/remote/climate-status
/v1/global/remote/electric/status
/v1/global/remote/profile-settings
/v1/global/remote/status
/v1/home-charging/charge-boxes
#/v1/home-charging/charge-boxes/energy-contract/country/{countryIso}/tariff-configuration
/v1/home-charging/charge-boxes/invitations
#/v1/home-charging/charge-boxes/{serialNumber}
#/v1/home-charging/charge-boxes/{serialNumber}/charging-sessions-history
/v1/home-charging/charge-boxes/smart-charging/details
/v1/immobiliser
# WORK /v1/insurance/contracts
# WORK /v1/insurance/fhi
# WORK /v1/insurance/ubi
# WORK /v1/insurance/ubi/trips
# WORK /v1/irf/list
# WORK /v1/irf/search
#/v1/legacy/remote/profile-settings
#/v1/license
/v1/location
#/v1/marketing/banner
#/v1/mobile-utilites/app-details/android
#/v1/mp/parking
#v1/mp/parking/booking/{bookingId}
#/v1/mp/parking/booking/confirmation/{confirmationId}/
#/v1/mp/parking/booking/user/{userId}
#/v1/mp/parking/dashboard/{userId}
#/v1/mp/parking/help
#/v1/mp/parking/{locationId}
#/v1/mp/payment/wallet/{userId}
#/v1/mp/profile/{userId}
#/v1/navigation
# WORK /v1/one/dealers
/v1/one/vehicle
#/v1/ota/update
#/v1/ota/update/history/all
#/v1/ota/update/versions
#/v1/poi-service/commands/vin/{vin}
#/v1/poi-service/pois/contract/state
#/v1/poi-service/pois/{id}
#/1/poi-service/pois/{id}/rating
# WORK /v1/preferred-dealer
#/v1/radio
/v1/servicehistory/vehicle/summary
#/v1/sms/consent
#/v1/subscriptions
/v1/token
/v1/trips
/v1/trips/preferences
/v1/vdr/history
# WORK /v1/vehicle-alerts
#/v1/vehicle/guidvins
#/v1/vehiclehealth/report
/v1/vehiclehealth/status
/v1/vehicle/maintenance-schedule
#/v1/vehicle-subscriptions
#/v1/vehicle/vehicle-spec
#/v1/vgi/eligibility
/v1/vhr/history
/v1/videos
/v1/wifistatus
#/v1/zuora/payments
#/v1/zuora/rsa-signature
#/v2/dealer-service/appointments
#/v2/dealer-service/{dealerId}/advisors
#/v2/dealer-service/{dealerId}/appointment/calendar/slots
#/v2/dealer-service/{dealerId}/appointment/slots
#/v2/dealer-service/{dealerId}/appointment/timeslot
#/v2/dealer-service/{dealerId}/services
#/v2/dealer-service/{dealerId}/transportoptions
#/v2/download/ssa
#/v2/manual/pdf/{documentURI}
#WORK /v2/manuals
#/v2/marketing/cards
/v2/notification/history
/v2/notification-preferences
#/v2/rsa/contacts
/v2/telemetry
/v2/vehicle/guid
/v3/account/secondaryUserName
#WORK /v3/canbus/score
#WORK /v3/canbus/trip
/v3/telemetry
/v4/account
#/v4/dealers/{dealerCode}
#/vehicleassociation/additionalInfo
#vehicles/{vin}/privacy-mode
80 changes: 80 additions & 0 deletions endpoint_tester.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import asyncio
import json
import sys
from pprint import PrettyPrinter

from mytoyota import MyT
from mytoyota.models.vehicle import Vehicle


async def test_endpoint(myt: MyT, vehicle: Vehicle, method: str, endpoint: str) -> None:
print(f"+++++ Endpoint: {endpoint}")
try:
response = await myt._api.controller.request_raw(method, endpoint, vin=vehicle.vin)
except Exception as e:
print(f"----- EXCEPTION: {e}")
return
if response:
print(f"----- Status:\n({response.status_code},{response.reason_phrase})\n")
print(f"----- Headers:\n{response.headers}\n")
print("----- Content:\n")
try:
j = json.loads(response.content.decode("utf-8"))
pp = PrettyPrinter(indent=4)
pp.pprint(j)
except Exception:
print(f"{response.content.decode('utf-8')}")

else:
print(f"FAILED: {sys.argv[2]} => {response.reason_phrase}({response.status_code})")


def load_credentials():
"""Load credentials from 'credentials.json'."""
try:
with open("credentials.json", encoding="utf-8") as f:
return json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError):
return None


async def main():
print(sys.argv)

credentials = load_credentials()
if not credentials:
raise ValueError(
"Did you forget to set your username and password? Or supply the credentials file"
)

USERNAME = credentials["username"]
PASSWORD = credentials["password"]

client = MyT(username=USERNAME, password=PASSWORD)
vehicles = await client.get_vehicles()
assert len(vehicles) > 0

# If an endpoint URL has been provided on the command line then we just test it
if len(sys.argv) == 3:
await test_endpoint(client, vehicles[0], sys.argv[1], sys.argv[2])

elif len(sys.argv) == 2:
with open(sys.argv[1], "r") as f:
while True:
url = f.readline()
if len(url) == 0:
break

if url[0] != "#":
print(f"-> {url.strip()} <-")
await test_endpoint(client, vehicles[0], "GET", url.strip())

pass
else:
print('Expects 1 argument to file containing METHOD,"URL" pair on each line')
print("Expects 2 arguments(METHOD, ENDPOINT to test a single endpoint")


loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
12 changes: 1 addition & 11 deletions mytoyota/models/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import copy
import json
import logging
from datetime import date, timedelta
from datetime import date
from functools import partial
from itertools import groupby
from operator import attrgetter
Expand Down Expand Up @@ -75,16 +75,6 @@ def __init__(self, api: Api, vehicle_info: VehicleGuidModel, metric: bool = True
"capable": vehicle_info.extended_capabilities.vehicle_status,
"function": partial(self._api.get_remote_status_endpoint, vin=vehicle_info.vin),
},
{
"name": "trips",
"capable": True, # TODO Unsure of the required capability
"function": partial(
self._api.get_trips_endpoint,
vin=vehicle_info.vin,
from_date=date.today() - timedelta(days=1),
to_date=date.today(),
),
},
]
self._endpoint_collect = [
(endpoint["name"], endpoint["function"])
Expand Down