Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate new cmd for credit usage and project info api #468

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"/oclif.manifest.json"
],
"dependencies": {
"@autifyhq/autify-sdk": "^0.18.0",
"@autifyhq/autify-sdk": "^0.19.0",
"@oclif/core": "^2.15.0",
"@oclif/errors": "^1.3.6",
"@oclif/plugin-help": "^5.2.20",
Expand Down
54 changes: 54 additions & 0 deletions src/commands/web/api/get-credit-usage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Command, Flags } from "@oclif/core";
import { getWebClient } from "../../../autify/web/getWebClient";

export default class WebApiGetCreditUsage extends Command {
static description =
"Get the number of credits used in the project\\ \\ Notes:\\ This endpoint works only for organizations on credit-based plans. It always returns 0 for `credits_consumed` and `credit_consumption_event_count` if your organization is on a run-based plan.";

static examples = ["<%= config.bin %> <%= command.id %>"];

static flags = {
"project-id": Flags.integer({
description:
"For example, 1 for the following URL: https://app.autify.com/projects/1/credits",
required: true,
}),
"date-from": Flags.string({
description:
"The date to start counting used credits from.\\ If not specified, the date will be set to 1 week ago.\\ Up to 90 days in advance can be specified. If the specified date is more than 90 days in the past, the date will be set to 90 days ago.\\ Date must follow the format YYYY-MM-DD (example: &quot;2023-09-21&quot;).",
required: false,
}),
"date-to": Flags.string({
description:
"The date to end counting used credits from.\\ If not specified, the date will be set to today.\\ Date must follow the format YYYY-MM-DD (example: &quot;2023-09-28&quot;).",
required: false,
}),
"scenario-id": Flags.integer({
description: "The scenario ID to filter used credits by.",
required: false,
}),
"test-plan-id": Flags.integer({
description: "The test plan ID to filter used credits by.",
required: false,
}),
"user-id": Flags.integer({
description: "The user ID that executed tests to filter used credits by.",
required: false,
}),
};

public async run(): Promise<void> {
const { flags } = await this.parse(WebApiGetCreditUsage);
const { configDir, userAgent } = this.config;
const client = getWebClient(configDir, userAgent);
const res = await client.getCreditUsage(
flags["project-id"],
flags["date-from"],
flags["date-to"],
flags["scenario-id"],
flags["test-plan-id"],
flags["user-id"]
);
console.log(JSON.stringify(res.data, null, 2));
}
}
24 changes: 24 additions & 0 deletions src/commands/web/api/get-project-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Command, Flags } from "@oclif/core";
import { getWebClient } from "../../../autify/web/getWebClient";

export default class WebApiGetProjectInfo extends Command {
static description = "Get project information.";

static examples = ["<%= config.bin %> <%= command.id %>"];

static flags = {
"project-id": Flags.integer({
description:
"For example, 1 for the following URL: https://app.autify.com/projects/1/project_info",
required: true,
}),
};

public async run(): Promise<void> {
const { flags } = await this.parse(WebApiGetProjectInfo);
const { configDir, userAgent } = this.config;
const client = getWebClient(configDir, userAgent);
const res = await client.getProjectInfo(flags["project-id"]);
console.log(JSON.stringify(res.data, null, 2));
}
}