Skip to content

Commit 52cf444

Browse files
authored
Also fetch rating counts with app details (#15)
1 parent bebf0f5 commit 52cf444

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

docs/README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ The result of a fetch app details request.
105105

106106
#### Defined in
107107

108-
[endpoints/app-details.ts:58](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L58)
108+
[endpoints/app-details.ts:59](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L59)
109109

110110
___
111111

@@ -123,7 +123,7 @@ The metadata for a single app. The available properties depend on which endpoint
123123

124124
#### Defined in
125125

126-
[common/data-format.ts:112](https://github.com/baltpeter/parse-play/blob/main/src/common/data-format.ts#L112)
126+
[common/data-format.ts:127](https://github.com/baltpeter/parse-play/blob/main/src/common/data-format.ts#L127)
127127

128128
___
129129

@@ -165,6 +165,13 @@ this, see [AppMetadata](README.md#appmetadata).
165165
| `price` | `string` \| `undefined` | The app's price. Can be undefined for pre-release apps. |
166166
| `privacy_policy_url` | `string` \| `undefined` | The URL to the app's privacy policy. |
167167
| `rating` | `number` \| `undefined` | The app's review rating. |
168+
| `rating_counts` | { `1`: `number` ; `2`: `number` ; `3`: `number` ; `4`: `number` ; `5`: `number` ; `total`: `number` } | The number of each rating the app has received. |
169+
| `rating_counts.1` | `number` | The number of 1-star ratings. |
170+
| `rating_counts.2` | `number` | The number of 2-star ratings. |
171+
| `rating_counts.3` | `number` | The number of 3-star ratings. |
172+
| `rating_counts.4` | `number` | The number of 4-star ratings. |
173+
| `rating_counts.5` | `number` | The number of 5-star ratings. |
174+
| `rating_counts.total` | `number` | The total number of ratings. |
168175
| `released_on?` | `Date` | The date when the app was first published. |
169176
| `requires_android?` | {} | The app's required version of Android. |
170177
| `screenshot_urls` | `string`[] | URLs to screenshots of the app. |
@@ -195,7 +202,7 @@ A property that can be present in the metadata of an app.
195202

196203
#### Defined in
197204

198-
[common/data-format.ts:110](https://github.com/baltpeter/parse-play/blob/main/src/common/data-format.ts#L110)
205+
[common/data-format.ts:125](https://github.com/baltpeter/parse-play/blob/main/src/common/data-format.ts#L125)
199206

200207
___
201208

@@ -207,7 +214,7 @@ A property present when fetching app details.
207214

208215
#### Defined in
209216

210-
[endpoints/app-details.ts:56](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L56)
217+
[endpoints/app-details.ts:57](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L57)
211218

212219
___
213220

@@ -600,7 +607,7 @@ ___
600607

601608
### fetchAppDetailsMetadataProperties
602609

603-
`Const` **fetchAppDetailsMetadataProperties**: readonly [``"app_id"``, ``"name"``, ``"content_rating"``, ``"released_on"``, ``"downloads"``, ``"downloads_exact"``, ``"in_app_purchases"``, ``"offered_by"``, ``"rating"``, ``"price"``, ``"buy_url"``, ``"top_chart_placement"``, ``"developer"``, ``"developer_path"``, ``"developer_website_url"``, ``"developer_email"``, ``"developer_address"``, ``"description"``, ``"permissions"``, ``"screenshot_urls"``, ``"category"``, ``"icon_url"``, ``"cover_image_url"``, ``"privacy_policy_url"``, ``"trailer_url"``, ``"tags"``, ``"data_shared"``, ``"data_collected"``, ``"security_practices"``, ``"version"``, ``"requires_android"``, ``"updated_on"``]
610+
`Const` **fetchAppDetailsMetadataProperties**: readonly [``"app_id"``, ``"name"``, ``"content_rating"``, ``"released_on"``, ``"downloads"``, ``"downloads_exact"``, ``"in_app_purchases"``, ``"offered_by"``, ``"rating"``, ``"rating_counts"``, ``"price"``, ``"buy_url"``, ``"top_chart_placement"``, ``"developer"``, ``"developer_path"``, ``"developer_website_url"``, ``"developer_email"``, ``"developer_address"``, ``"description"``, ``"permissions"``, ``"screenshot_urls"``, ``"category"``, ``"icon_url"``, ``"cover_image_url"``, ``"privacy_policy_url"``, ``"trailer_url"``, ``"tags"``, ``"data_shared"``, ``"data_collected"``, ``"security_practices"``, ``"version"``, ``"requires_android"``, ``"updated_on"``]
604611

605612
The properties present when fetching app details.
606613

@@ -657,7 +664,7 @@ The app details.
657664

658665
#### Defined in
659666

660-
[endpoints/app-details.ts:243](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L243)
667+
[endpoints/app-details.ts:252](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L252)
661668

662669
**fetchAppDetails**(`requests`, `options`): `Promise`<[`AppDetailsResult`](README.md#appdetailsresult)[]\>
663670

@@ -681,7 +688,7 @@ An array of the app details, in the same order as the requests.
681688

682689
#### Defined in
683690

684-
[endpoints/app-details.ts:257](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L257)
691+
[endpoints/app-details.ts:266](https://github.com/baltpeter/parse-play/blob/main/src/endpoints/app-details.ts#L266)
685692

686693
___
687694

@@ -821,7 +828,7 @@ Parse an app entry in a search or top chart response.
821828

822829
#### Defined in
823830

824-
[common/data-format.ts:139](https://github.com/baltpeter/parse-play/blob/main/src/common/data-format.ts#L139)
831+
[common/data-format.ts:154](https://github.com/baltpeter/parse-play/blob/main/src/common/data-format.ts#L154)
825832

826833
___
827834

src/common/data-format.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ export type AppMetadataFull = {
3030
name: string;
3131
/** The app's review rating. */
3232
rating: number | undefined;
33+
/** The number of each rating the app has received. */
34+
rating_counts: {
35+
/** The number of 1-star ratings. */
36+
1: number;
37+
/** The number of 2-star ratings. */
38+
2: number;
39+
/** The number of 3-star ratings. */
40+
3: number;
41+
/** The number of 4-star ratings. */
42+
4: number;
43+
/** The number of 5-star ratings. */
44+
5: number;
45+
/** The total number of ratings. */
46+
total: number;
47+
};
3348
/** The app's main category. */
3449
category: string;
3550
/** The app's price. Can be undefined for pre-release apps. */

src/endpoints/app-details.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const fetchAppDetailsMetadataProperties = [
2828
'in_app_purchases',
2929
'offered_by',
3030
'rating',
31+
'rating_counts',
3132
'price',
3233
'buy_url',
3334
'top_chart_placement',
@@ -186,6 +187,14 @@ export const parseAppDetailsPayload = (payload: any, options: AppDetailsOptions)
186187
in_app_purchases: data[19]?.[0],
187188
offered_by: data[37][0],
188189
rating: data[51][0][1],
190+
rating_counts: {
191+
1: data[51][1][1][1],
192+
2: data[51][1][2][1],
193+
3: data[51][1][3][1],
194+
4: data[51][1][4][1],
195+
5: data[51][1][5][1],
196+
total: data[51][2][1],
197+
},
189198
price: data[57][0][0][0][0]
190199
? formatCurrency(data[57][0][0][0][0]?.[1][0][0] / 1e6, data[57][0][0][0][0]?.[1][0][1], options)
191200
: undefined,

0 commit comments

Comments
 (0)