Skip to content

Commit cebacf1

Browse files
authored
Remove documentation redundancies following split (#19)
1 parent 4df6aa9 commit cebacf1

File tree

4 files changed

+53
-215
lines changed

4 files changed

+53
-215
lines changed

docs/DEVELOPMENT.md

Lines changed: 26 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,10 @@
11
# Conventions, Patterns, and Development Guide
22

3-
## Contents
4-
5-
- [Development Environment Setup](#development-environment-setup)
6-
- [Prerequisites](#prerequisites)
7-
- [Initial Setup](#initial-setup)
8-
- [Project Structure](#project-structure)
9-
- [Goals, Notes, and TODOs](#goals-notes-and-todos)
10-
- [Development Tools and Standards](#development-tools-and-standards)
11-
- [Code Formatting and Style](#code-formatting-and-style)
12-
- [Import Style](#import-style)
13-
- [Resource Implementation Guidelines](#resource-implementation-guidelines)
14-
- [Error Handling](#error-handling)
15-
- [Enum Usage](#enum-usage)
16-
- [Logging System](#logging-system)
17-
- [Application Logger](#application-logger)
18-
- [Data Logger](#data-logger)
19-
- [API Design](#api-design)
20-
- [Resource-Based API](#resource-based-api)
21-
- [Method Aliases](#method-aliases)
22-
- [Testing](#testing)
23-
- [Test Organization](#test-organization)
24-
- [Standard Test Fixtures](#standard-test-fixtures)
25-
- [Error Handling Tests](#error-handling-tests)
26-
- [Response Mocking](#response-mocking)
27-
- [OAuth Callback Implementation](#oauth-callback-implementation)
28-
- [Implementation Flow](#implementation-flow)
29-
- [Git Workflow](#git-workflow)
30-
- [Release Process](#release-process)
31-
- [Getting Help](#getting-help)
32-
- [Scope and Limitations - Intraday Data Support](#scope-and-limitations---intraday-data-support)
33-
343
## Development Environment Setup
354

365
### Prerequisites
376

38-
- Python 3.12+
7+
- Python 3.13+
398
- PDM
409
- Git
4110

@@ -53,9 +22,9 @@ cd fitbit-client-python
5322
```bash
5423
asdf plugin add python
5524
asdf plugin add pdm
56-
asdf install python 3.12.0
25+
asdf install python 3.13.0
5726
asdf install pdm latest
58-
asdf local python 3.12.0
27+
asdf local python 3.13.0
5928
asdf local pdm latest
6029
```
6130

@@ -79,7 +48,8 @@ fitbit-client/
7948
│ ├── client.py
8049
│ ├── resources/
8150
│ │ ├── __init__.py
82-
│ │ ├── [resource files]
51+
│ │ ├── [resource modules]
52+
│ │ ├── base.py
8353
│ │ └── constants.py
8454
│ ├── utils/
8555
│ │ ├── __init__.py
@@ -186,84 +156,29 @@ The codebase implements a comprehensive error handling system through
186156

187157
## Logging System
188158

189-
The project implements dual logging through the BaseResource class: application
190-
logging for API interactions and data logging for tracking important response
191-
fields.
192-
193-
### Application Logger
194-
195-
Each resource class inherits logging functionality from BaseResource, which
196-
initializes a logger with the resource's class name:
197-
198-
```python
199-
self.logger = getLogger(f"fitbit_client.{self.__class__.__name__}")
200-
```
201-
202-
The application logger handles:
203-
204-
- Success responses at INFO level
205-
- Error responses at ERROR level
206-
- Debug information about requests and responses
207-
- Internal server logging
208-
209-
The BaseResource.\_log_response method standardizes log message formats:
210-
211-
- For errors: "[error_type] field_name: message" (if field name available)
212-
- For success: "method succeeded for endpoint (status code)"
213-
214-
### Data Logger
215-
216-
The data logger specifically tracks important fields from API responses.
217-
BaseResource defines these fields in IMPORTANT_RESPONSE_FIELDS:
218-
219-
```python
220-
IMPORTANT_RESPONSE_FIELDS: Set[str] = {
221-
"access", # PUBLIC/PRIVATE/SHARED
222-
"date", # Dates
223-
"dateTime", # Timestamps
224-
"deviceId", # Device IDs
225-
"foodId", # Food resource IDs
226-
"logId", # Log entry IDs
227-
"name", # Resource names
228-
"subscriptionId" # Subscription IDs
229-
}
230-
```
231-
232-
The BaseResource.\_log_data method extracts and logs these fields when present
233-
in API responses.
234-
235-
Data log entries contain:
236-
237-
- Timestamp (ISO format)
238-
- Method name
239-
- Important fields found in the response
240-
241-
This logging system provides both operational visibility through the application
242-
logger and structured data capture through the data logger.
159+
The project implements two different logs in through the
160+
[`BaseResource`](fitbit_client/resources/base.py) class: application logging for
161+
API interactions and data logging for tracking important response fields. See
162+
[LOGGING](docs/LOGGING.md) for details.
243163

244164
## API Design
245165

246-
The client implements a dual-level API design pattern that balances both
247-
organization and ease-of-use.
248-
249166
### Resource-Based API
250167

251168
The primary API structure is resource-based, organizing related endpoints into
252-
dedicated resource classes:
169+
dedicated resource classes based on the structure and organzation of the
170+
[Fibit Web API](https://dev.fitbit.com/build/reference/web-api/) itself, e.g.
253171

254172
- `client.user` - User profile and badges endpoints
255173
- `client.activity` - Activity tracking, goals, and summaries
256174
- `client.sleep` - Sleep logs and goals
257175
- etc.
258176

259-
This organization provides a clean separation of concerns and makes the code
260-
more maintainable by grouping related functionality.
261-
262177
### Method Aliases
263178

264-
To improve developer experience, all resource methods are also available
265-
directly from the client instance through aliases. This means developers can
266-
choose between two equivalent approaches:
179+
All resource methods are also available directly from the client instance
180+
through aliases. This means developers can choose between two equivalent
181+
approaches:
267182

268183
```python
269184
# Standard resource-based access
@@ -275,8 +190,6 @@ client.get_profile()
275190
client.get_daily_activity_summary(date="2025-03-06")
276191
```
277192

278-
#### Rationale for Method Aliases
279-
280193
Method aliases were implemented for several important reasons:
281194

282195
1. **Reduced Verbosity**: Typing `client.resource_name.method_name(...)` with
@@ -294,9 +207,9 @@ Method aliases were implemented for several important reasons:
294207
\- organization or conciseness.
295208

296209
All method aliases are set up in the `_setup_method_aliases()` method in the
297-
`FitbitClient` class, which is called during initialization. Each alias is a
298-
direct reference to the corresponding resource method, ensuring consistent
299-
behavior regardless of how the method is accessed.
210+
[`FitbitClient`](fitbit_client/client.py) class, which is called during
211+
initialization. Each alias is a direct reference to the corresponding resource
212+
method, ensuring consistent behavior regardless of how the method is accessed.
300213

301214
## Testing
302215

@@ -305,8 +218,9 @@ across all components.
305218

306219
### Test Organization
307220

308-
The test directory mirrors the main package structure, with corresponding test
309-
modules for each component:
221+
The test directory mirrors the main package structure (except that the root is
222+
named "test" rather than "fitbit_client"), with corresponding test modules for
223+
each component:
310224

311225
- auth/: Tests for authentication and OAuth functionality
312226
- client/: Tests for the main client implementation
@@ -384,46 +298,19 @@ The OAuth callback mechanism is implemented using two main classes:
384298
## Git Workflow
385299

386300
1. Create a new branch for your feature/fix
387-
2. Make your changes, following the style guidelines
388-
3. Run formatting checks (`pdm format`)
301+
2. Make your changes, following the style guidelines (see also:
302+
[LINTING](docs/LINTING.md))
303+
3. Run formatting checks (`pdm format`) and tests (`pdm run pytest`)
389304
4. Submit a pull request with a clear description of changes
390305

391306
## Release Process
392307

393308
This section will be documented as we near our first release.
394309

395-
## Getting Help
396-
397-
- Check existing issues before creating new ones
398-
- Use issue templates when reporting bugs
399-
- Include Python version and environment details in bug reports
400-
401310
## Intraday Data Support
402311

403312
This client implements intraday data endpoints (detailed heart rate, steps, etc)
404-
through the `IntradayResource` class. These endpoints:
405-
406-
- Require special access from Fitbit (typically limited to research
407-
applications)
408-
- Have different rate limits than standard endpoints
409-
- Need additional OAuth2 scopes (specifically the 'activity' and 'heartrate'
410-
scopes)
411-
- Often require institutional review board (IRB) approval for research
412-
applications
413-
414-
To use intraday data:
415-
416-
1. Apply for intraday access through the
417-
[Fitbit developer portal](https://dev.fitbit.com/)
418-
2. Ensure your application requests the appropriate scopes
419-
3. Use the intraday methods with appropriate detail level parameters:
420-
```python
421-
client.intraday.get_heartrate_intraday_by_date(
422-
date="today",
423-
detail_level="1min" # or "1sec" depending on your access level
424-
)
425-
```
426-
427-
See the
313+
through the `IntradayResource` class. These endpoints have some special
314+
requirements if you're using them for anyone other that yourself. See the
428315
[Intraday API documentation](https://dev.fitbit.com/build/reference/web-api/intraday/)
429-
for more details on available endpoints and access requirements.
316+
for more details.

docs/LINTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Linting and formatting are handled by [Black](https://github.com/psf/black),
88

99
## Running the Linters
1010

11-
You can run all formatters using:
11+
Run all formatters using:
1212

1313
```bash
1414
pdm run format
@@ -61,6 +61,7 @@ from fitbit_client.resources.base import BaseResource
6161
The test suite verifies that all public methods have comprehensive docstrings
6262
that follow the Google style format with specific sections:
6363

64+
- API Reference
6465
- Args
6566
- Returns
6667
- Raises

docs/NAMING.md

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,75 +4,42 @@
44

55
The method names in this library are designed to align with the official Fitbit
66
Web API Documentation. When there are inconsistencies in the official
7-
documentation, we follow these principles:
8-
9-
1. The URL slug in the documentation is the primary reference
10-
2. Method names always use underscores (snake_case), not camelCase
11-
3. The HTTP verb is reflected in the method name prefix:
12-
- `get_`: For HTTP GET operations
13-
- `create_`: For HTTP POST operations that create new resources
14-
- `update_`: For HTTP PUT operations
15-
- `delete_`: For HTTP DELETE operations
16-
- `add_`: Only used in specific contexts where "add" is more intuitive than
17-
"create"
18-
19-
## API Documentation Alignment
20-
21-
For any discrepancies between different parts of the official documentation, we
22-
prioritize the URL slug. For example, if the documentation page title says "Get
23-
Time Series by Date" but the URL is ".../get-azm-timeseries-by-date/", our
24-
method will be named `get_azm_timeseries_by_date()`.
7+
documentation, we prioritize the URL slug. For example, if the documentation
8+
page title says "Get **Time Series** by Date" but the URL is
9+
".../get-azm-timeseries-by-date/", our method will be named
10+
`get_azm_timeseries_by_date()`. (not `get_azm_time_series_by_date()`).
2511

2612
This approach ensures consistent naming throughout the library and makes methods
2713
easier to find based on the official documentation.
2814

2915
## Inconsistencies in the API
3016

3117
The Fitbit API contains several inconsistencies, which our method names and
32-
implementation necessarily reflect. Understanding these inconsistencies can help
18+
implementation dutifully reflect. Understanding these inconsistencies can help
3319
you navigate the API more effectively:
3420

3521
### Method Name vs. Functionality Inconsistencies
3622

3723
- `create_activity_goals` creates only one goal at a time, despite the plural
3824
name
3925
- `add_favorite_foods` adds one food at a time, while all other creation methods
40-
use "create" prefix
26+
start with "create".
4127
- `get_sleep_goals` returns a single goal, not multiple goals
42-
- Some pluralized methods return lists, while others return dictionaries
43-
containing lists
28+
- Additionally, some pluralized methods return lists, while others return
29+
dictionaries containing lists
4430

45-
### Parameter and Response Format Inconsistencies
31+
For user convenience, these inconsistencies have aliases:
4632

47-
```python
48-
# Sleep endpoint uses a different API version than most other endpoints
49-
client.sleep.get_sleep_log_by_date(date="2025-01-01") # Uses API v1.2
50-
client.activity.get_daily_activity_summary(date="2025-01-01") # Uses API v1
51-
52-
# Sleep date parameters have inconsistent response behavior
53-
# The request uses "2025-01-01" but response might contain data from "2025-01-02"
54-
sleep_data = client.get_sleep_log_by_date(date="2025-01-01")
55-
# A sleep log started on 2025-01-01 at 23:00 and ended on 2025-01-02 at 07:00
56-
# will be included in the response, but with dateOfSleep="2025-01-02"
57-
58-
# Pagination parameters vary across endpoints
59-
# Some endpoints require offset=0
60-
food_log = client.get_food_log(date="2025-01-01", offset=0) # Valid
61-
# Others support arbitrary offsets
62-
badges = client.get_badges(offset=20) # Also valid
63-
64-
# Date range validations vary by endpoint
65-
# Sleep endpoints allow up to 100 days
66-
sleep_logs = client.get_sleep_log_by_date_range(
67-
start_date="2025-01-01",
68-
end_date="2025-04-10" # 100 days later, valid for sleep endpoint
69-
)
70-
# Activity endpoints allow only 31 days
71-
activity_logs = client.get_activity_log_list(
72-
before_date="2025-02-01",
73-
after_date="2025-01-01" # 31 days earlier, valid for activity endpoint
74-
)
75-
```
33+
- (`alias` -> `target`)
34+
- `create_activity_goal` -> `create_activity_goals`
35+
- `add_favorite_food` -> `add_favorite_foods`
36+
- `create_favorite_food` -> `add_favorite_foods`
37+
- `delete_favorite_food` -> `delete_favorite_foods`
38+
- `create_sleep_goal` -> `create_sleep_goals`
39+
- `get_sleep_goal` -> `get_sleep_goals`
40+
41+
These aliases help accommodate different expectations and ensure backward
42+
compatibility.
7643

7744
### Response Structure Inconsistencies
7845

@@ -118,20 +85,6 @@ Our library handles these inconsistencies internally to provide a unified
11885
experience, but it's helpful to be aware of them when working with the raw API
11986
responses.
12087

121-
## Method Aliases
122-
123-
For user convenience, some methods have aliases:
124-
125-
- `create_activity_goal` -> `create_activity_goals`
126-
- `add_favorite_food` -> `add_favorite_foods`
127-
- `create_favorite_food` -> `add_favorite_foods`
128-
- `delete_favorite_food` -> `delete_favorite_foods`
129-
- `create_sleep_goal` -> `create_sleep_goals`
130-
- `get_sleep_goal` -> `get_sleep_goals`
131-
132-
These aliases help accommodate different expectations and ensure backward
133-
compatibility.
134-
13588
## Resource Structure
13689

13790
The client organizes API endpoints into logical resource classes, each

0 commit comments

Comments
 (0)