Skip to content

Commit

Permalink
Add getListMetricsV2 function
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovelinux committed Sep 11, 2023
1 parent c125261 commit cd82e9f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
49 changes: 44 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
createUserAgent,
ApiResponse,
} from "ask-sdk-model-runtime";
import { MetricsV2RequestOptions, MetricsV2Response } from "./models";
import {
ListMetricsV2RequestOptions,
ListMetricsV2Response,
MetricsV2RequestOptions,
MetricsV2Response,
} from "./models";
import { RefreshTokenConfig } from "ask-smapi-sdk";

const DEFAULT_API_ENDPOINT = "https://api.amazonalexa.com";
Expand Down Expand Up @@ -100,10 +105,44 @@ export class CustomSkillManagementServiceClient extends BaseServiceClient {
skillId: string,
options: MetricsV2RequestOptions
): Promise<MetricsV2Response> {
const apiResponse: ApiResponse = await this.callGetSkillMetricsV2(
skillId,
options
);
const apiResponse = await this.callGetSkillMetricsV2(skillId, options);
return apiResponse.body as MetricsV2Response;
}

protected async callGetListMetricsV2(
options: ListMetricsV2RequestOptions
): Promise<ApiResponse> {
const accessToken: string = await this.lwaServiceClient.getAccessToken();
const authorizationValue = "Bearer " + accessToken;

const headerParams: Array<{ key: string; value: string }> = [
{ key: "Authorization", value: authorizationValue },
{ key: "User-Agent", value: this.userAgent },
];

const queryParams = Object.entries(options).map(([key, value]) => ({
key,
value,
}));

const resourcePath: string = "/v2/skills/metrics";

return this.invoke(
"GET",
this.apiConfiguration.apiEndpoint,
resourcePath,
null,
queryParams,
headerParams,
null,
errorDefinitions
);
}

async getListMetricsV2(
options: ListMetricsV2RequestOptions
): Promise<ListMetricsV2Response> {
const apiResponse = await this.callGetListMetricsV2(options);
return apiResponse.body as ListMetricsV2Response;
}
}
20 changes: 19 additions & 1 deletion src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,22 @@ export class Data {
export class GroupedBy {
groupedByField: string;
groupedByValue: string;
}
}

export class ListMetricsV2RequestOptions {
metricNamespace: Metrics.AnyNamespace;
maxResults?: number;
nextToken?: string;
}

export class ListMetricsV2Response {
paginationContext?: {nextToken: string};
metrics: Array<Metric>;
}

export class Metric {
name: string;
supportedDimensions: Array<string>;
supportedGroupByOptions: Array<string>;
supportedStats: Array<Stat>;
}

0 comments on commit cd82e9f

Please sign in to comment.