Skip to content

Commit a4fd8e0

Browse files
COilstoufa06
authored andcommitted
feat: add daily summary (#21)
close #21
1 parent 662800f commit a4fd8e0

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/GarminApi.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,39 @@ public function getActivitySummary(TokenCredentials $tokenCredentials, array $pa
201201
return $response->getBody()->getContents();
202202
}
203203

204+
/**
205+
* Get daily summary (/rest/dailies).
206+
*
207+
* @param TokenCredentials $tokenCredentials
208+
* @param array $params
209+
*
210+
* @see https://apis.garmin.com/tools/apiDocs#/Summary%20Endpoints/GET_DAILIES
211+
*
212+
* @return string json response
213+
* @throws Exception
214+
*/
215+
public function getDailySummary(TokenCredentials $tokenCredentials, array $params)
216+
{
217+
$client = $this->createHttpClient();
218+
$query = http_build_query($params);
219+
$query = 'dailies?'.$query;
220+
$headers = $this->getHeaders($tokenCredentials, 'GET', self::USER_API_URL . $query);
221+
222+
try {
223+
$response = $client->get(self::USER_API_URL . $query, [
224+
'headers' => $headers,
225+
]);
226+
} catch (BadResponseException $e) {
227+
$response = $e->getResponse();
228+
$body = $response->getBody();
229+
$statusCode = $response->getStatusCode();
230+
throw new \Exception(
231+
"Received error [$body] with status code [$statusCode] when retrieving daily summary."
232+
);
233+
}
234+
return $response->getBody()->getContents();
235+
}
236+
204237
/**
205238
* get manually activity summary
206239
*

0 commit comments

Comments
 (0)