Skip to content

Commit

Permalink
Added several new api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky committed Oct 28, 2023
1 parent fe7582b commit b1bf777
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"K": f"Get all day stress data for '{today.isoformat()}'",
"L": f"Add body composition for '{today.isoformat()}'",
"M": "Set blood pressure '120,80,80,notes='Testing with example.py'",
"N": "Get user profile/settings",
"Z": "Remove stored login tokens (logout)",
"q": "Exit",
}
Expand Down Expand Up @@ -670,6 +671,12 @@ def switch(api, i):
f"api.set_blood_pressure(120,80,80,notes=`Testing with example.py`)",
api.set_blood_pressure(120,80,80,notes="Testing with example.py")
)
elif i == "N":
# Get user profile
display_json(
"api.get_user_profile()",
api.get_user_profile()
)
elif i == "Z":
# Remove stored login tokens for Garmin Connect portal
tokendir = os.path.expanduser(tokenstore)
Expand Down
21 changes: 20 additions & 1 deletion garminconnect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ def __init__(self, email=None, password=None, is_cn=False):
self.password = password
self.is_cn = is_cn

self.garmin_connect_user_settings_url = (
"/userprofile-service/userprofile/user-settings"
)
self.garmin_connect_devices_url = (
"/device-service/deviceregistration/devices"
)
Expand Down Expand Up @@ -175,7 +178,7 @@ def login(self, /, tokenstore: Optional[str] = None):
self.full_name = self.garth.profile["fullName"]

settings = self.garth.connectapi(
"/userprofile-service/userprofile/user-settings"
self.garmin_connect_user_settings_url
)
self.unit_system = settings["userData"]["measurementSystem"]

Expand Down Expand Up @@ -754,6 +757,14 @@ def get_activities_fordate(self, fordate: str):

return self.connectapi(url)

def set_activity_name(self, activity_id, title):
"""Set name for activity with id."""

url = f"{self.garmin_connect_activity}/{activity_id}"
payload = {"activityId": activity_id, "activityName": title}

return self.garth.put("connectapi", url, json=payload, api=True)

def get_last_activity(self):
"""Return last activity."""

Expand Down Expand Up @@ -1052,6 +1063,14 @@ def get_activity_gear(self, activity_id):

return self.connectapi(url, params=params)

def get_user_profile(self):
"""Get all users settings."""

url = self.garmin_connect_user_settings_url
logger.debug("Requesting user profile.")

return self.connectapi(url)

def logout(self):
"""Log user out of session."""

Expand Down

0 comments on commit b1bf777

Please sign in to comment.