Skip to content

Commit

Permalink
Merge pull request #85 from matin/profile
Browse files Browse the repository at this point in the history
undo a breaking change with Client.profile
  • Loading branch information
matin authored Dec 12, 2024
2 parents 4a22315 + 977d05f commit 922f3c3
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 16 deletions.
18 changes: 11 additions & 7 deletions garth/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Client:
backoff_factor: float = 0.5
pool_connections: int = 10
pool_maxsize: int = 10
_social_profile: Dict[str, Any] | None = None
_user_profile: Dict[str, Any] | None = None

def __init__(self, session: Session | None = None, **kwargs):
self.sess = session if session else Session()
Expand Down Expand Up @@ -92,19 +92,23 @@ def configure(
self.sess.mount("https://", adapter)

@property
def social_profile(self):
if not self._social_profile:
self._social_profile = self.connectapi(
def user_profile(self):
if not self._user_profile:
self._user_profile = self.connectapi(
"/userprofile-service/socialProfile"
)
assert isinstance(
self._social_profile, dict
self._user_profile, dict
), "No profile from connectapi"
return self._social_profile
return self._user_profile

@property
def profile(self):
return self.user_profile

@property
def username(self):
return self.social_profile["userName"]
return self.user_profile["userName"]

def request(
self,
Expand Down
2 changes: 1 addition & 1 deletion garth/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.1"
__version__ = "0.5.2"
82 changes: 82 additions & 0 deletions tests/cassettes/test_profile_alias.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
interactions:
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- Bearer SANITIZED
Connection:
- keep-alive
User-Agent:
- GCM-iOS-5.7.2.1
referer:
- https://sso.garmin.com/sso/verifyMFA/loginEnterMfaCode?id=gauth-widget&embedWidget=true&gauthHost=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&service=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&source=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&redirectAfterAccountLoginUrl=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed&redirectAfterAccountCreationUrl=https%3A%2F%2Fsso.garmin.com%2Fsso%2Fembed
method: GET
uri: https://connectapi.garmin.com/userprofile-service/socialProfile
response:
body:
string: '{"id": 3154645, "profileId": 2591602, "garminGUID": "0690cc1d-d23d-4412-b027-80fd4ed1c0f6",
"displayName": "mtamizi", "fullName": "Matin Tamizi", "userName": "mtamizi",
"profileImageType": "UPLOADED_PHOTO", "profileImageUrlLarge": "https://s3.amazonaws.com/garmin-connect-prod/profile_images/73240e81-6e4d-43fc-8af8-c8f6c51b3b8f-2591602.png",
"profileImageUrlMedium": "https://s3.amazonaws.com/garmin-connect-prod/profile_images/685a19e9-a7be-4a11-9bf9-faca0c5d1f1a-2591602.png",
"profileImageUrlSmall": "https://s3.amazonaws.com/garmin-connect-prod/profile_images/6302f021-0ec7-4dc9-b0c3-d5a19bc5a08c-2591602.png",
"location": "Ciudad de M\u00e9xico, CDMX", "facebookUrl": null, "twitterUrl":
null, "personalWebsite": null, "motivation": null, "bio": null, "primaryActivity":
null, "favoriteActivityTypes": [], "runningTrainingSpeed": 0.0, "cyclingTrainingSpeed":
0.0, "favoriteCyclingActivityTypes": [], "cyclingClassification": null, "cyclingMaxAvgPower":
0.0, "swimmingTrainingSpeed": 0.0, "profileVisibility": "private", "activityStartVisibility":
"private", "activityMapVisibility": "public", "courseVisibility": "public",
"activityHeartRateVisibility": "public", "activityPowerVisibility": "public",
"badgeVisibility": "private", "showAge": false, "showWeight": false, "showHeight":
false, "showWeightClass": false, "showAgeRange": false, "showGender": false,
"showActivityClass": false, "showVO2Max": false, "showPersonalRecords": false,
"showLast12Months": false, "showLifetimeTotals": false, "showUpcomingEvents":
false, "showRecentFavorites": false, "showRecentDevice": false, "showRecentGear":
false, "showBadges": true, "otherActivity": null, "otherPrimaryActivity":
null, "otherMotivation": null, "userRoles": ["SCOPE_ATP_READ", "SCOPE_ATP_WRITE",
"SCOPE_COMMUNITY_COURSE_READ", "SCOPE_COMMUNITY_COURSE_WRITE", "SCOPE_CONNECT_READ",
"SCOPE_CONNECT_WRITE", "SCOPE_DT_CLIENT_ANALYTICS_WRITE", "SCOPE_GARMINPAY_READ",
"SCOPE_GARMINPAY_WRITE", "SCOPE_GCOFFER_READ", "SCOPE_GCOFFER_WRITE", "SCOPE_GHS_SAMD",
"SCOPE_GHS_UPLOAD", "SCOPE_GOLF_API_READ", "SCOPE_GOLF_API_WRITE", "SCOPE_INSIGHTS_READ",
"SCOPE_INSIGHTS_WRITE", "SCOPE_OMT_CAMPAIGN_READ", "SCOPE_OMT_SUBSCRIPTION_READ",
"SCOPE_PRODUCT_SEARCH_READ", "ROLE_CONNECTUSER", "ROLE_FITNESS_USER", "ROLE_WELLNESS_USER",
"ROLE_OUTDOOR_USER", "ROLE_CONNECT_2_USER", "ROLE_TACX_APP_USER"], "nameApproved":
true, "userProfileFullName": "Matin Tamizi", "makeGolfScorecardsPrivate":
true, "allowGolfLiveScoring": false, "allowGolfScoringByConnections": true,
"userLevel": 4, "userPoint": 166, "levelUpdateDate": "2024-01-31T12:18:59.0",
"levelIsViewed": false, "levelPointThreshold": 300, "userPointOffset": 0,
"userPro": false}'
headers:
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 8f0d992ebcfb6c34-DFW
Cache-Control:
- no-cache, no-store, private
Connection:
- keep-alive
Content-Type:
- application/json;charset=UTF-8
Date:
- Thu, 12 Dec 2024 12:08:11 GMT
NEL:
- '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}'
Report-To:
- '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=niRDLu7E86gruuRnFLQL4RUQO9vMZyAA5NQ64mt7vW0Gmmsl2%2BCut6v2k9Pj6yXDDr42mqOH%2B%2BvYhVgRbnkLUTD3xXo3YREb7jiUYBGZhBKpRQafvfz0TvC63Co%2BVJCaehygZ%2B9HlA%3D%3D"}],"group":"cf-nel","max_age":604800}'
Server:
- cloudflare
Set-Cookie:
- _cfuvid=SANITIZED; path=SANITIZED; domain=SANITIZED; HttpOnly; Secure; SameSite=SANITIZED
Transfer-Encoding:
- chunked
alt-svc:
- h3=":443"; ma=86400
pragma:
- no-cache
status:
code: 200
message: OK
version: 1
12 changes: 10 additions & 2 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,17 @@ def mock_input(_):

@pytest.mark.vcr
def test_username(authed_client: Client):
assert authed_client._social_profile is None
assert authed_client._user_profile is None
assert authed_client.username
assert authed_client._social_profile
assert authed_client._user_profile


@pytest.mark.vcr
def test_profile_alias(authed_client: Client):
assert authed_client._user_profile is None
profile = authed_client.profile
assert profile == authed_client.user_profile
assert authed_client._user_profile is not None


@pytest.mark.vcr
Expand Down
28 changes: 22 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 922f3c3

Please sign in to comment.