PluginProbe
Parse.ly / 3.14.1
Parse.ly v3.14.1
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / content-helper / common / utils / api.ts

api.ts in Parse.ly 3.14.1, at src/content-helper/common/utils/api.ts

50 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Period } from './constants';
2 import { removeDaysFromDate } from './date';
3
4 export interface AnalyticsApiQueryParams extends AnalyticsApiOptionalQueryParams {
5 type: string,
6 }
7
8 export interface AnalyticsApiOptionalQueryParams extends ApiPeriodRange {
9 pub_date_start?: string;
10 pub_date_end?: string;
11 sort?: string;
12 limit?: number;
13 page?: number;
14 author?: string;
15 tag?: string;
16 section?: string;
17 segment?: string;
18 }
19
20 export interface ApiPeriodRange {
21 period_start?: string; // Defaults to 3 days ago.
22 period_end?: string; // Defaults to current date and time.
23 }
24
25 /**
26 * Gets `period_start` and `period_end` params for API.
27 *
28 * @param {Period} period Number of days for which to calculate the period range.
29 *
30 * @return {ApiPeriodRange} API query params.
31 */
32 export function getApiPeriodParams( period: Period ): ApiPeriodRange {
33 return {
34 period_start: period,
35 period_end: '',
36 };
37 }
38
39 /**
40 * Gets period start date for API.
41 *
42 * @param {number} days Number of days for which to calculate the period start
43 * date.
44 *
45 * @return {string} period start date.
46 */
47 export function getApiPeriodStartDate( days: number ): string {
48 return removeDaysFromDate( new Date(), days - 1 ) + 'T00:00';
49 }
50