terra.models.user

  1#  Copyright 2022 Terra Enabling Developers Limited
  2#
  3#  Licensed under the Apache License, Version 2.0 (the "License");
  4#  you may not use this file except in compliance with the License.
  5#  You may obtain a copy of the License at
  6#
  7#      http://www.apache.org/licenses/LICENSE-2.0
  8#
  9#  Unless required by applicable law or agreed to in writing, software
 10#  distributed under the License is distributed on an "AS IS" BASIS,
 11#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12#  See the License for the specific language governing permissions and
 13#  limitations under the License.
 14from __future__ import annotations
 15
 16__all__ = ["User"]
 17
 18import dataclasses
 19import datetime
 20import typing as t
 21
 22from terra import exceptions
 23from terra.models.base_model import TerraDataModel
 24
 25if t.TYPE_CHECKING:
 26    from terra import base_client
 27    from terra.api import api_responses
 28
 29
 30@dataclasses.dataclass
 31class User(TerraDataModel):
 32    def __init__(
 33        self,
 34        client: t.Optional[base_client.Terra] = None,
 35        user_id: t.Optional[str] = None,
 36        provider: t.Optional[str] = None,
 37        last_webhook_update: t.Optional[str] = None,
 38        scopes: t.Optional[str] = None,
 39    ) -> None:
 40        self.user_id = user_id
 41        self.provider = provider
 42        self.last_webhook_update = last_webhook_update
 43        self.scopes = scopes
 44        self._client = client
 45        self._resource = None
 46
 47    def _has_client(self) -> bool:
 48        return self._client is not None
 49
 50    def fill_in_user_info(self) -> None:
 51        """
 52        Internal method used to retrieve data for User
 53
 54        Args:
 55            dtype (:obj:`str`): datatype to be fetched
 56
 57
 58        """
 59        if self._client is None:
 60            raise exceptions.NoClientAvailable
 61
 62        if self._client:
 63            user_info = self._client.get_user_info(self)
 64            if not user_info.json:
 65                raise exceptions.NoUserInfoException
 66
 67            self.provider = user_info.json["user"]["provider"]
 68            self.last_webhook_update = user_info.json["user"]["last_webhook_update"]
 69            self.scopes = user_info.json["user"]["scopes"]
 70
 71    def _check_client(self) -> None:
 72        """
 73        Internal method used to check if user is connected to a client
 74
 75        Returns:
 76            None
 77        """
 78        if self._client is None:
 79            raise exceptions.NoClientAvailable
 80
 81    def get_activity(
 82        self,
 83        start_date: datetime.datetime,
 84        end_date: t.Optional[datetime.datetime] = None,
 85        to_webhook: bool = True,
 86    ) -> api_responses.TerraApiResponse:
 87        """
 88        Retrieves workouts/activity data for a given User object. By default, data will be asynchronously sent to registered
 89        webhook URL.
 90
 91        Args:
 92
 93            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
 94            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
 95            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
 96
 97        Returns:
 98            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
 99
100        """
101
102        if self._client is None:
103            raise exceptions.NoClientAvailable
104
105        return self._client._get_arbitrary_data(
106            dtype="activity",
107            user=self,
108            start_date=int(start_date.timestamp()),
109            end_date=int(end_date.timestamp()) if end_date is not None else None,
110            to_webhook=to_webhook,
111        )
112
113    def get_body(
114        self,
115        start_date: datetime.datetime,
116        end_date: t.Optional[datetime.datetime] = None,
117        to_webhook: bool = True,
118    ) -> api_responses.TerraApiResponse:
119        """
120        Retrieves body metrics data for a given User object. By default, data will be asynchronously sent to registered
121        webhook URL.
122
123        Args:
124            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
125            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
126            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
127
128        Returns:
129            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
130
131        """
132
133        if self._client is None:
134            raise exceptions.NoClientAvailable
135
136        return self._client._get_arbitrary_data(
137            dtype="body",
138            user=self,
139            start_date=int(start_date.timestamp()),
140            end_date=int(end_date.timestamp()) if end_date is not None else None,
141            to_webhook=to_webhook,
142        )
143
144    def get_nutrition(
145        self,
146        start_date: datetime.datetime,
147        end_date: t.Optional[datetime.datetime] = None,
148        to_webhook: bool = True,
149    ) -> api_responses.TerraApiResponse:
150        """
151        Retrieves nutrition data for a given User object. By default, data will be asynchronously sent to registered
152        webhook URL.
153
154        Args:
155            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
156            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
157            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
158
159        Returns:
160            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
161
162        """
163        if self._client is None:
164            raise exceptions.NoClientAvailable
165
166        return self._client._get_arbitrary_data(
167            dtype="nutrition",
168            user=self,
169            start_date=int(start_date.timestamp()),
170            end_date=int(end_date.timestamp()) if end_date is not None else None,
171            to_webhook=to_webhook,
172        )
173
174    def get_daily(
175        self,
176        start_date: datetime.datetime,
177        end_date: t.Optional[datetime.datetime] = None,
178        to_webhook: bool = True,
179    ) -> api_responses.TerraApiResponse:
180        """
181        Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered
182        webhook URL.
183
184        Args:
185            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
186            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
187            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
188
189        Returns:
190            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
191
192        """
193        if self._client is None:
194            raise exceptions.NoClientAvailable
195
196        return self._client._get_arbitrary_data(
197            dtype="daily",
198            user=self,
199            start_date=int(start_date.timestamp()),
200            end_date=int(end_date.timestamp()) if end_date is not None else None,
201            to_webhook=to_webhook,
202        )
203
204    def get_sleep(
205        self,
206        start_date: datetime.datetime,
207        end_date: t.Optional[datetime.datetime] = None,
208        to_webhook: bool = True,
209    ) -> api_responses.TerraApiResponse:
210        """
211        Retrieves sleep data for a given User object. By default, data will be asynchronously sent to registered
212        webhook URL.
213
214        Args:
215
216            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
217            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
218            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
219
220        Returns:
221            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
222
223        """
224        if self._client is None:
225            raise exceptions.NoClientAvailable
226
227        return self._client._get_arbitrary_data(
228            dtype="sleep",
229            user=self,
230            start_date=int(start_date.timestamp()),
231            end_date=int(end_date.timestamp()) if end_date is not None else None,
232            to_webhook=to_webhook,
233        )
234
235    def get_athlete(
236        self,
237        to_webhook: bool = True,
238    ) -> api_responses.TerraApiResponse:
239        """
240        Retrieves profile info/athlete data for a given User object. By default, data will be asynchronously sent to
241        registered webhook URL.
242
243        Args:
244            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
245        Returns:
246            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
247
248        """
249        if self._client is None:
250            raise exceptions.NoClientAvailable
251
252        return self._client._get_arbitrary_data(dtype="athlete", user=self, to_webhook=to_webhook)
253
254    def get_menstruation(
255        self,
256        start_date: datetime.datetime,
257        end_date: t.Optional[datetime.datetime] = None,
258        to_webhook: bool = True,
259    ) -> api_responses.TerraApiResponse:
260        """
261        Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered
262        webhook URL.
263
264        Args:
265            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
266            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
267            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
268
269        Returns:
270            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
271
272        """
273        if self._client is None:
274            raise exceptions.NoClientAvailable
275
276        return self._client._get_arbitrary_data(
277            dtype="menstruation",
278            user=self,
279            start_date=int(start_date.timestamp()),
280            end_date=int(end_date.timestamp()) if end_date is not None else None,
281            to_webhook=to_webhook,
282        )
@dataclasses.dataclass
class User(terra.models.base_model.TerraDataModel):
 31@dataclasses.dataclass
 32class User(TerraDataModel):
 33    def __init__(
 34        self,
 35        client: t.Optional[base_client.Terra] = None,
 36        user_id: t.Optional[str] = None,
 37        provider: t.Optional[str] = None,
 38        last_webhook_update: t.Optional[str] = None,
 39        scopes: t.Optional[str] = None,
 40    ) -> None:
 41        self.user_id = user_id
 42        self.provider = provider
 43        self.last_webhook_update = last_webhook_update
 44        self.scopes = scopes
 45        self._client = client
 46        self._resource = None
 47
 48    def _has_client(self) -> bool:
 49        return self._client is not None
 50
 51    def fill_in_user_info(self) -> None:
 52        """
 53        Internal method used to retrieve data for User
 54
 55        Args:
 56            dtype (:obj:`str`): datatype to be fetched
 57
 58
 59        """
 60        if self._client is None:
 61            raise exceptions.NoClientAvailable
 62
 63        if self._client:
 64            user_info = self._client.get_user_info(self)
 65            if not user_info.json:
 66                raise exceptions.NoUserInfoException
 67
 68            self.provider = user_info.json["user"]["provider"]
 69            self.last_webhook_update = user_info.json["user"]["last_webhook_update"]
 70            self.scopes = user_info.json["user"]["scopes"]
 71
 72    def _check_client(self) -> None:
 73        """
 74        Internal method used to check if user is connected to a client
 75
 76        Returns:
 77            None
 78        """
 79        if self._client is None:
 80            raise exceptions.NoClientAvailable
 81
 82    def get_activity(
 83        self,
 84        start_date: datetime.datetime,
 85        end_date: t.Optional[datetime.datetime] = None,
 86        to_webhook: bool = True,
 87    ) -> api_responses.TerraApiResponse:
 88        """
 89        Retrieves workouts/activity data for a given User object. By default, data will be asynchronously sent to registered
 90        webhook URL.
 91
 92        Args:
 93
 94            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
 95            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
 96            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
 97
 98        Returns:
 99            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
100
101        """
102
103        if self._client is None:
104            raise exceptions.NoClientAvailable
105
106        return self._client._get_arbitrary_data(
107            dtype="activity",
108            user=self,
109            start_date=int(start_date.timestamp()),
110            end_date=int(end_date.timestamp()) if end_date is not None else None,
111            to_webhook=to_webhook,
112        )
113
114    def get_body(
115        self,
116        start_date: datetime.datetime,
117        end_date: t.Optional[datetime.datetime] = None,
118        to_webhook: bool = True,
119    ) -> api_responses.TerraApiResponse:
120        """
121        Retrieves body metrics data for a given User object. By default, data will be asynchronously sent to registered
122        webhook URL.
123
124        Args:
125            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
126            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
127            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
128
129        Returns:
130            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
131
132        """
133
134        if self._client is None:
135            raise exceptions.NoClientAvailable
136
137        return self._client._get_arbitrary_data(
138            dtype="body",
139            user=self,
140            start_date=int(start_date.timestamp()),
141            end_date=int(end_date.timestamp()) if end_date is not None else None,
142            to_webhook=to_webhook,
143        )
144
145    def get_nutrition(
146        self,
147        start_date: datetime.datetime,
148        end_date: t.Optional[datetime.datetime] = None,
149        to_webhook: bool = True,
150    ) -> api_responses.TerraApiResponse:
151        """
152        Retrieves nutrition data for a given User object. By default, data will be asynchronously sent to registered
153        webhook URL.
154
155        Args:
156            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
157            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
158            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
159
160        Returns:
161            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
162
163        """
164        if self._client is None:
165            raise exceptions.NoClientAvailable
166
167        return self._client._get_arbitrary_data(
168            dtype="nutrition",
169            user=self,
170            start_date=int(start_date.timestamp()),
171            end_date=int(end_date.timestamp()) if end_date is not None else None,
172            to_webhook=to_webhook,
173        )
174
175    def get_daily(
176        self,
177        start_date: datetime.datetime,
178        end_date: t.Optional[datetime.datetime] = None,
179        to_webhook: bool = True,
180    ) -> api_responses.TerraApiResponse:
181        """
182        Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered
183        webhook URL.
184
185        Args:
186            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
187            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
188            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
189
190        Returns:
191            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
192
193        """
194        if self._client is None:
195            raise exceptions.NoClientAvailable
196
197        return self._client._get_arbitrary_data(
198            dtype="daily",
199            user=self,
200            start_date=int(start_date.timestamp()),
201            end_date=int(end_date.timestamp()) if end_date is not None else None,
202            to_webhook=to_webhook,
203        )
204
205    def get_sleep(
206        self,
207        start_date: datetime.datetime,
208        end_date: t.Optional[datetime.datetime] = None,
209        to_webhook: bool = True,
210    ) -> api_responses.TerraApiResponse:
211        """
212        Retrieves sleep data for a given User object. By default, data will be asynchronously sent to registered
213        webhook URL.
214
215        Args:
216
217            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
218            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
219            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
220
221        Returns:
222            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
223
224        """
225        if self._client is None:
226            raise exceptions.NoClientAvailable
227
228        return self._client._get_arbitrary_data(
229            dtype="sleep",
230            user=self,
231            start_date=int(start_date.timestamp()),
232            end_date=int(end_date.timestamp()) if end_date is not None else None,
233            to_webhook=to_webhook,
234        )
235
236    def get_athlete(
237        self,
238        to_webhook: bool = True,
239    ) -> api_responses.TerraApiResponse:
240        """
241        Retrieves profile info/athlete data for a given User object. By default, data will be asynchronously sent to
242        registered webhook URL.
243
244        Args:
245            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
246        Returns:
247            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
248
249        """
250        if self._client is None:
251            raise exceptions.NoClientAvailable
252
253        return self._client._get_arbitrary_data(dtype="athlete", user=self, to_webhook=to_webhook)
254
255    def get_menstruation(
256        self,
257        start_date: datetime.datetime,
258        end_date: t.Optional[datetime.datetime] = None,
259        to_webhook: bool = True,
260    ) -> api_responses.TerraApiResponse:
261        """
262        Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered
263        webhook URL.
264
265        Args:
266            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
267            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
268            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
269
270        Returns:
271            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
272
273        """
274        if self._client is None:
275            raise exceptions.NoClientAvailable
276
277        return self._client._get_arbitrary_data(
278            dtype="menstruation",
279            user=self,
280            start_date=int(start_date.timestamp()),
281            end_date=int(end_date.timestamp()) if end_date is not None else None,
282            to_webhook=to_webhook,
283        )

User(client: 't.Optional[base_client.Terra]' = None, user_id: 't.Optional[str]' = None, provider: 't.Optional[str]' = None, last_webhook_update: 't.Optional[str]' = None, scopes: 't.Optional[str]' = None) -> 'None'

User( client: Optional[terra.base_client.Terra] = None, user_id: Optional[str] = None, provider: Optional[str] = None, last_webhook_update: Optional[str] = None, scopes: Optional[str] = None)
33    def __init__(
34        self,
35        client: t.Optional[base_client.Terra] = None,
36        user_id: t.Optional[str] = None,
37        provider: t.Optional[str] = None,
38        last_webhook_update: t.Optional[str] = None,
39        scopes: t.Optional[str] = None,
40    ) -> None:
41        self.user_id = user_id
42        self.provider = provider
43        self.last_webhook_update = last_webhook_update
44        self.scopes = scopes
45        self._client = client
46        self._resource = None
def fill_in_user_info(self) -> None:
51    def fill_in_user_info(self) -> None:
52        """
53        Internal method used to retrieve data for User
54
55        Args:
56            dtype (:obj:`str`): datatype to be fetched
57
58
59        """
60        if self._client is None:
61            raise exceptions.NoClientAvailable
62
63        if self._client:
64            user_info = self._client.get_user_info(self)
65            if not user_info.json:
66                raise exceptions.NoUserInfoException
67
68            self.provider = user_info.json["user"]["provider"]
69            self.last_webhook_update = user_info.json["user"]["last_webhook_update"]
70            self.scopes = user_info.json["user"]["scopes"]

Internal method used to retrieve data for User

Args: dtype (str): datatype to be fetched

def get_activity( self, start_date: datetime.datetime, end_date: Optional[datetime.datetime] = None, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
 82    def get_activity(
 83        self,
 84        start_date: datetime.datetime,
 85        end_date: t.Optional[datetime.datetime] = None,
 86        to_webhook: bool = True,
 87    ) -> api_responses.TerraApiResponse:
 88        """
 89        Retrieves workouts/activity data for a given User object. By default, data will be asynchronously sent to registered
 90        webhook URL.
 91
 92        Args:
 93
 94            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
 95            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
 96            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
 97
 98        Returns:
 99            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
100
101        """
102
103        if self._client is None:
104            raise exceptions.NoClientAvailable
105
106        return self._client._get_arbitrary_data(
107            dtype="activity",
108            user=self,
109            start_date=int(start_date.timestamp()),
110            end_date=int(end_date.timestamp()) if end_date is not None else None,
111            to_webhook=to_webhook,
112        )

Retrieves workouts/activity data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args:

start_date (`datetime.datetime`): Datetime object for which to fetch data
end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
to_webhook (`bool`): Whether to send data to registered webhook URL or return as a response body

Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured

def get_body( self, start_date: datetime.datetime, end_date: Optional[datetime.datetime] = None, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
114    def get_body(
115        self,
116        start_date: datetime.datetime,
117        end_date: t.Optional[datetime.datetime] = None,
118        to_webhook: bool = True,
119    ) -> api_responses.TerraApiResponse:
120        """
121        Retrieves body metrics data for a given User object. By default, data will be asynchronously sent to registered
122        webhook URL.
123
124        Args:
125            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
126            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
127            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
128
129        Returns:
130            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
131
132        """
133
134        if self._client is None:
135            raise exceptions.NoClientAvailable
136
137        return self._client._get_arbitrary_data(
138            dtype="body",
139            user=self,
140            start_date=int(start_date.timestamp()),
141            end_date=int(end_date.timestamp()) if end_date is not None else None,
142            to_webhook=to_webhook,
143        )

Retrieves body metrics data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args: start_date (datetime.datetime): Datetime object for which to fetch data end_date:obj (:datetime.datetime): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications to_webhook (bool): Whether to send data to registered webhook URL or return as a response body

Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured

def get_nutrition( self, start_date: datetime.datetime, end_date: Optional[datetime.datetime] = None, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
145    def get_nutrition(
146        self,
147        start_date: datetime.datetime,
148        end_date: t.Optional[datetime.datetime] = None,
149        to_webhook: bool = True,
150    ) -> api_responses.TerraApiResponse:
151        """
152        Retrieves nutrition data for a given User object. By default, data will be asynchronously sent to registered
153        webhook URL.
154
155        Args:
156            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
157            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
158            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
159
160        Returns:
161            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
162
163        """
164        if self._client is None:
165            raise exceptions.NoClientAvailable
166
167        return self._client._get_arbitrary_data(
168            dtype="nutrition",
169            user=self,
170            start_date=int(start_date.timestamp()),
171            end_date=int(end_date.timestamp()) if end_date is not None else None,
172            to_webhook=to_webhook,
173        )

Retrieves nutrition data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args: start_date (datetime.datetime): Datetime object for which to fetch data end_date:obj (:datetime.datetime): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications to_webhook (bool): Whether to send data to registered webhook URL or return as a response body

Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured

def get_daily( self, start_date: datetime.datetime, end_date: Optional[datetime.datetime] = None, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
175    def get_daily(
176        self,
177        start_date: datetime.datetime,
178        end_date: t.Optional[datetime.datetime] = None,
179        to_webhook: bool = True,
180    ) -> api_responses.TerraApiResponse:
181        """
182        Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered
183        webhook URL.
184
185        Args:
186            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
187            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
188            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
189
190        Returns:
191            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
192
193        """
194        if self._client is None:
195            raise exceptions.NoClientAvailable
196
197        return self._client._get_arbitrary_data(
198            dtype="daily",
199            user=self,
200            start_date=int(start_date.timestamp()),
201            end_date=int(end_date.timestamp()) if end_date is not None else None,
202            to_webhook=to_webhook,
203        )

Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args: start_date (datetime.datetime): Datetime object for which to fetch data end_date:obj (:datetime.datetime): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications to_webhook (bool): Whether to send data to registered webhook URL or return as a response body

Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured

def get_sleep( self, start_date: datetime.datetime, end_date: Optional[datetime.datetime] = None, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
205    def get_sleep(
206        self,
207        start_date: datetime.datetime,
208        end_date: t.Optional[datetime.datetime] = None,
209        to_webhook: bool = True,
210    ) -> api_responses.TerraApiResponse:
211        """
212        Retrieves sleep data for a given User object. By default, data will be asynchronously sent to registered
213        webhook URL.
214
215        Args:
216
217            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
218            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
219            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
220
221        Returns:
222            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
223
224        """
225        if self._client is None:
226            raise exceptions.NoClientAvailable
227
228        return self._client._get_arbitrary_data(
229            dtype="sleep",
230            user=self,
231            start_date=int(start_date.timestamp()),
232            end_date=int(end_date.timestamp()) if end_date is not None else None,
233            to_webhook=to_webhook,
234        )

Retrieves sleep data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args:

start_date (`datetime.datetime`): Datetime object for which to fetch data
end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
to_webhook (`bool`): Whether to send data to registered webhook URL or return as a response body

Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured

def get_athlete( self, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
236    def get_athlete(
237        self,
238        to_webhook: bool = True,
239    ) -> api_responses.TerraApiResponse:
240        """
241        Retrieves profile info/athlete data for a given User object. By default, data will be asynchronously sent to
242        registered webhook URL.
243
244        Args:
245            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
246        Returns:
247            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
248
249        """
250        if self._client is None:
251            raise exceptions.NoClientAvailable
252
253        return self._client._get_arbitrary_data(dtype="athlete", user=self, to_webhook=to_webhook)

Retrieves profile info/athlete data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args: to_webhook (bool): Whether to send data to registered webhook URL or return as a response body Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured

def get_menstruation( self, start_date: datetime.datetime, end_date: Optional[datetime.datetime] = None, to_webhook: bool = True) -> terra.api.api_responses.TerraApiResponse:
255    def get_menstruation(
256        self,
257        start_date: datetime.datetime,
258        end_date: t.Optional[datetime.datetime] = None,
259        to_webhook: bool = True,
260    ) -> api_responses.TerraApiResponse:
261        """
262        Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered
263        webhook URL.
264
265        Args:
266            start_date (:obj:`datetime.datetime`): Datetime object for which to fetch data
267            end_date:obj (:`datetime.datetime`): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications
268            to_webhook (:obj:`bool`): Whether to send data to registered webhook URL or return as a response body
269
270        Returns:
271            :obj:`models.api_responses.TerraApiResponse`: API response object containing DataReturned parsed response object if no error has occured
272
273        """
274        if self._client is None:
275            raise exceptions.NoClientAvailable
276
277        return self._client._get_arbitrary_data(
278            dtype="menstruation",
279            user=self,
280            start_date=int(start_date.timestamp()),
281            end_date=int(end_date.timestamp()) if end_date is not None else None,
282            to_webhook=to_webhook,
283        )

Retrieves daily summary data for a given User object. By default, data will be asynchronously sent to registered webhook URL.

Args: start_date (datetime.datetime): Datetime object for which to fetch data end_date:obj (:datetime.datetime): Optional end_date for which to fetch data - if not set, will default to start_date + 24h according to current API specifications to_webhook (bool): Whether to send data to registered webhook URL or return as a response body

Returns: models.api_responses.TerraApiResponse: API response object containing DataReturned parsed response object if no error has occured