You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,7 +12,7 @@ The KinesteX Content API allows you to fetch workout plans, workouts, and exerci
12
12
13
13
-**API Key**: You must have a valid API key provided by KinesteX.
14
14
-**Company Name**: Your company's name as registered with KinesteX.
15
-
-**Dependencies**: Ensure you have Kotlin Coroutines in your project and latest version of KinesteXSDK. Check latest version [here](https://jitpack.io/#KinesteX/KinesteX-SDK-Kotlin)
15
+
-**Dependencies**: Ensure you have Kotlin Coroutines in your project and the latest version of KinesteXSDK. Check the latest version [here](https://jitpack.io/#KinesteX/KinesteX-SDK-Kotlin).
16
16
17
17
### Fetching Content
18
18
@@ -22,6 +22,8 @@ You can fetch different types of content by specifying the `ContentType`. The av
22
22
-`ContentType.PLAN`
23
23
-`ContentType.EXERCISE`
24
24
25
+
Additionally, you can fetch lists of content by providing optional parameters such as `category`, `bodyParts`, `limit`, and `lastDocId` for pagination.
-**Button Click Listener**: When the button is clicked, a coroutine is launched in the lifecycle scope.
70
111
-**Switch to IO Dispatcher**: The `withContext(Dispatchers.IO)` block ensures that the network request is performed on an IO thread, preventing UI blocking.
71
-
-**Fetch Content**: The `fetchContent` function is called with the necessary parameters to fetch the desired content.
112
+
-**Fetch Content**: The `fetchContent` function is called with the necessary parameters to fetch the desired content. You can uncomment the relevant lines to fetch lists or specific items based on your needs.
72
113
-**Handle Result**: After fetching, the result is passed to `handleAPIResult` to process the response.
73
114
74
115
### Fetch Content Function
@@ -79,14 +120,24 @@ private suspend fun fetchContent(
79
120
companyName:String,
80
121
contentType:ContentType,
81
122
id:String? = null,
82
-
title:String? = null
123
+
title:String? = null,
124
+
lang:String = "en",
125
+
category:String? = null,
126
+
lastDocId:String? = null,
127
+
limit:Int? = null,
128
+
bodyParts:List<BodyPart>? = null
83
129
): APIContentResult {
84
130
returnKinesteXAPI.fetchAPIContentData(
85
131
apiKey = apiKey,
86
132
companyName = companyName,
87
133
contentType = contentType,
134
+
id = id,
88
135
title = title,
89
-
id = id
136
+
lang = lang,
137
+
category = category,
138
+
lastDocId = lastDocId,
139
+
limit = limit,
140
+
bodyParts = bodyParts
90
141
)
91
142
}
92
143
```
@@ -99,6 +150,10 @@ private suspend fun fetchContent(
99
150
-`contentType`: The type of content to fetch (`WORKOUT`, `PLAN`, `EXERCISE`).
100
151
-`id`*(optional)*: Specific ID of the content.
101
152
-`title`*(optional)*: Title of the content to search for.
153
+
-`category`*(optional)*: Filter content by category.
154
+
-`lastDocId`*(optional)*: Identifier for pagination to fetch the next set of results.
155
+
-`limit`*(optional)*: Limit the number of results returned.
156
+
-`bodyParts`*(optional)*: Filter workouts or exercises by targeted body parts using the `BodyPart` enum.
102
157
-**Return Value**: An `APIContentResult` object containing the fetched data or an error message.
103
158
104
159
### Handling the API Result
@@ -124,6 +179,30 @@ private fun handleAPIResult(result: APIContentResult) {
@@ -139,56 +218,80 @@ private fun handleAPIResult(result: APIContentResult) {
139
218
140
219
-**APIContentResult**: A sealed class representing the result of the API request.
141
220
-**Success Cases**:
142
-
-`Workout`: Contains a `WorkoutModel`.
143
-
-`Plan`: Contains a `PlanModel`.
144
-
-`Exercise`: Contains an `ExerciseModel`.
221
+
-`Workout`: Contains a single `WorkoutModel`.
222
+
-`Plan`: Contains a single `PlanModel`.
223
+
-`Exercise`: Contains a single `ExerciseModel`.
224
+
-`Workouts`: Contains a list of `WorkoutModel` along with `lastDocId` for pagination.
225
+
-`Plans`: Contains a list of `PlanModel` along with `lastDocId` for pagination.
226
+
-`Exercises`: Contains a list of `ExerciseModel` along with `lastDocId` for pagination.
145
227
-**Error Case**:
146
228
-`Error`: Contains an error message.
147
229
-**Handling Data**:
148
-
- Use `Gson` with pretty printing to convert the result into a readable JSON format.
149
-
- Print the data to the console or handle it as needed in your application.
230
+
- Use `Gson` with pretty printing to convert single item results into a readable JSON format.
231
+
- Iterate through lists (`Workouts`, `Plans`, `Exercises`) and handle each item as needed.
232
+
-**Pagination**: After handling the current set of results, use the provided `lastDocId` to fetch the next set of data.
150
233
-**Handling Errors**:
151
234
- Display a toast message or handle the error appropriately.
152
235
153
-
---
154
-
155
-
## Implementation Overview
156
-
157
-
The core of the Content API lies in the `KinesteXAPI` class and related data models. Here's a brief overview:
236
+
### Pagination with `lastDocId`
158
237
159
-
### KinesteXAPI Class
238
+
To implement pagination, utilize the `lastDocId` provided in the response of your initial request. This ID allows you to fetch the next set of results in subsequent API calls.
160
239
161
-
Responsible for making network requests to the KinesteX server to fetch content data.
1.**Initial Fetch**: Fetch the first set of workouts with a specified `limit`.
280
+
2.**Handle Initial Result**: Process and display the fetched workouts.
281
+
3.**Retrieve `lastDocId`**: Extract the `lastDocId` from the initial response to use for the next request.
282
+
4.**Fetch Next Page**: Use the retrieved `lastDocId` to fetch the subsequent set of workouts.
283
+
5.**Handle Next Page Result**: Process and display the next set of workouts.
284
+
285
+
---
286
+
186
287
#### Key Points
187
288
188
289
-**Endpoints**: Constructs the appropriate endpoint based on `ContentType`.
189
290
-**Headers**: Adds `x-api-key` and `x-company-name` to authenticate requests.
190
291
-**Network Call**: Uses `OkHttpClient` to perform synchronous network calls.
191
292
-**Error Handling**: Returns an `APIContentResult.Error` in case of failures.
293
+
-**BodyPart Filtering**: Supports filtering by `BodyPart` enum to fetch targeted content lists.
294
+
-**Pagination**: Utilizes `lastDocId` to implement pagination, allowing you to fetch subsequent pages of content.
192
295
193
296
### Data Models
194
297
@@ -198,7 +301,7 @@ Data classes representing the structure of the content:
198
301
-**ExerciseModel**
199
302
-**PlanModel**
200
303
201
-
These models represent the data received from the API and are used throughout your application.
304
+
These models represent the data received from the API and are used throughout your application. They now include `body_parts` as a list of `BodyPart` enums to ensure type safety and consistency.
202
305
203
306
---
204
307
@@ -228,13 +331,15 @@ val result = withContext(Dispatchers.IO) {
228
331
-**Error Handling**: Always handle possible exceptions, especially when dealing with network requests.
229
332
-**Thread Safety**: UI updates must occur on the main thread. Ensure that after fetching data on `Dispatchers.IO`, any UI operations are performed on the main thread.
230
333
-**Asynchronous Programming**: Utilizing coroutines and proper dispatchers helps in writing asynchronous code that is easy to read and maintain.
334
+
-**BodyPart Enum**: Utilize the `BodyPart` enum to specify targeted muscle groups when fetching workouts or exercises, ensuring consistency and type safety.
335
+
-**Pagination**: Use the `lastDocId` from your API responses to fetch subsequent pages of content, enabling smooth and efficient data loading.
231
336
232
337
---
233
338
234
339
## Conclusion
235
340
236
-
The KinesteX Content API provides a straightforward way to access workout content within your Android application. By following the usage examples and understanding the importance of coroutine dispatchers, you can efficiently integrate and handle content data.
341
+
The KinesteX Content API provides a straightforward way to access workout content within your Android application. By following the usage examples and understanding the importance of coroutine dispatchers and pagination, you can efficiently integrate and handle content data.
237
342
238
-
For any issues or further assistance, please contact KinesteX support at [support@kinestex.com](mailto:support@kinestex.com).
343
+
With the added capability to fetch lists of workouts, plans, and exercises with filters like `category`, `bodyParts`, `limit`, and `lastDocId`, you have greater flexibility in customizing the content retrieval to suit your application's needs.
239
344
240
-
---
345
+
For any issues or further assistance, please contact KinesteX support at [support@kinestex.com](mailto:support@kinestex.com).
0 commit comments