Skip to content

Commit

Permalink
added daily stress endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Pinta365 committed Feb 29, 2024
1 parent e906307 commit 26a584d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
31 changes: 8 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,14 @@ Library and method documentation can be found at the [Deno Land documentation](h

### Included data scopes for v2 of the API.

| Endpoint/Scope | Status |
| :------------------------------------------------------------------------ | :---------- |
| **[Oura Base](https://deno.land/x/oura_api/mod.ts?s=Oura)** | |
| Daily Activity | Implemented |
| Daily Readiness | Implemented |
| Daily Sleep | Implemented |
| Daily Spo2 | Implemented |
| Enhanced Tag | Implemented |
| Heart Rate | Implemented |
| Personal Info | Implemented |
| Rest Mode Period | Implemented |
| Ring Configuration | Implemented |
| Session | Implemented |
| Sleep | Implemented |
| Sleep Time | Implemented |
| Tag | DEPRICATED |
| Workout | Implemented |
| **[Webhook Subscription](https://deno.land/x/oura_api/mod.ts?s=Webhook)** | |
| List subscription | Implemented |
| Create subscription | Implemented |
| Update subscription | Implemented |
| Delete subscription | Implemented |
| Renew subscription | Implemented |
| Endpoint/Scope | Status | | :------------------------------------------------------------------------ | :---------- |"
| **[Oura Base](https://deno.land/x/oura_api/mod.ts?s=Oura)** | | | Daily Activity | Implemented | | Daily Readiness |
Implemented | | Daily Sleep | Implemented | | Daily Spo2 | Implemented | | Daily Stress | Implemented | | Enhanced Tag |
Implemented | | Heart Rate | Implemented | | Personal Info | Implemented | | Rest Mode Period | Implemented | | Ring
Configuration | Implemented | | Session | Implemented | | Sleep | Implemented | | Sleep Time | Implemented | | Tag |
DEPRICATED | | Workout | Implemented | | **[Webhook Subscription](https://deno.land/x/oura_api/mod.ts?s=Webhook)** | | |
List subscription | Implemented | | Create subscription | Implemented | | Update subscription | Implemented | | Delete
subscription | Implemented | | Renew subscription | Implemented |

### Additional info concerning the webhook API

Expand Down
25 changes: 25 additions & 0 deletions src/Oura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
DailySleepDocuments,
DailySpo2,
DailySpo2Documents,
DailyStress,
DailyStressDocuments,
DateFormat,
EnhancedTag,
EnhancedTagDocuments,
Expand All @@ -39,6 +41,7 @@ import { APIError, isValidDate, MissingTokenError, ValidationError } from "./uti

/**
* Base class for the Oura API.
* Class containing all the methods to access the Oura API with an access token.
*/
class Oura {
#accessToken: string;
Expand Down Expand Up @@ -205,6 +208,28 @@ class Oura {
return this.#get("daily_spo2/" + documentId) as Promise<DailySpo2>;
}

/**
* Retrieves daily stress summary for a specified date range.
*
* @param {string} startDate - Start date of the period in string format (e.g., 'YYYY-MM-DD').
* @param {string} endDate - End date of the period in string format (e.g., 'YYYY-MM-DD').
* @returns {Promise<DailyStressDocuments>} A DailyStressDocuments typed object.
*/
getDailyStressDocuments(startDate: DateFormat, endDate: DateFormat): Promise<DailyStressDocuments> {
const params = { start_date: startDate, end_date: endDate };
return this.#get("daily_stress", params) as Promise<DailyStressDocuments>;
}

/**
* Retrieves a single daily stress summary document by its ID.
*
* @param {string} documentId - The document ID in string format.
* @returns {Promise<DailyStress>} A DailyStress typed object.
*/
getDailyStress(documentId: string): Promise<DailyStress> {
return this.#get("daily_stress/" + documentId) as Promise<DailyStress>;
}

/**
* Retrieves heart rate data for a specified date and time period.
*
Expand Down
1 change: 1 addition & 0 deletions src/Webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { APIError, MissingClientIdError, MissingClientSecretError } from "./util

/**
* Base class for the Oura Webhook Subscription API
* Class containing all the methods to access the Oura Webhook Subscription API with a client id and client secret.
*/
class Webhook {
#clientId: string;
Expand Down
26 changes: 26 additions & 0 deletions src/types/oura.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,29 @@ export interface EnhancedTagDocuments {
/** Next Token */
next_token: string | null;
}

/**
* Represents daily strees summary
*/
export interface DailyStress {
/** Unique identifier */
id: string;
/** Day that the daily stress belongs to */
day: string;
/** Time spent in a high stress zone (top quartile of data) */
stress_high: number;
/** Time spend in a high recovery zone (bottom quartile data) */
recovery_high: number;
/** Stress summary of full day */
day_summary: string;
}

/**
* Represents a response object containing multiple daily strees summaries.
*/
export interface DailyStressDocuments {
/** Array of Workout documents */
data: Workout[];
/** Next Token */
next_token: string | null;
}

0 comments on commit 26a584d

Please sign in to comment.