/* tslint:disable */ /* eslint-disable */ /** * Faraday REST API * The [Faraday](https://faraday.ai) API makes it easy to predict customer behavior programmatically. See our [API change policy](https://faraday.ai/legal). * * The version of the OpenAPI document: 1.0.0 * Contact: support@faraday.ai * * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). * https://openapi-generator.tech * Do not edit the class manually. */ import * as runtime from '../runtime'; import { Account, AccountMergePatch, AccountPost, AccountUsageSummary, } from '../models'; export interface CreateAccountRequest { accountFields: AccountPost; } export interface DeleteAccountRequest { accountId: string; } export interface GetAccountRequest { accountId: string; } export interface GetAccountUsageRequest { accountId: string; } export interface GetAccountsRequest { ids?: Array; } export interface UpdateAccountRequest { accountId: string; accountMergePatch: AccountMergePatch; } /** * */ export class AccountsApi extends runtime.BaseAPI { /** * Create a subaccount. * Create account */ async createAccountRaw(requestParameters: CreateAccountRequest, ): Promise> { if (requestParameters.accountFields === null || requestParameters.accountFields === undefined) { throw new runtime.RequiredError('accountFields','Required parameter requestParameters.accountFields was null or undefined when calling createAccount.'); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; headerParameters['Content-Type'] = 'application/json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts`, method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.accountFields, }); return new runtime.JSONApiResponse(response); } /** * Create a subaccount. * Create account */ async createAccount(accountFields: AccountPost, ): Promise { const response = await this.createAccountRaw({ accountFields: accountFields }, ); return await response.value(); } /** * Request an account deletion. In 24 hours, the account and all resources associated with it will be deleted. Contact support within the 24 hour window if you wish to reverse this. * Delete an account */ async deleteAccountRaw(requestParameters: DeleteAccountRequest, ): Promise> { if (requestParameters.accountId === null || requestParameters.accountId === undefined) { throw new runtime.RequiredError('accountId','Required parameter requestParameters.accountId was null or undefined when calling deleteAccount.'); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/{account_id}`.replace(`{${"account_id"}}`, encodeURIComponent(String(requestParameters.accountId))), method: 'DELETE', headers: headerParameters, query: queryParameters, }); return new runtime.VoidApiResponse(response); } /** * Request an account deletion. In 24 hours, the account and all resources associated with it will be deleted. Contact support within the 24 hour window if you wish to reverse this. * Delete an account */ async deleteAccount(accountId: string, ): Promise { await this.deleteAccountRaw({ accountId: accountId }, ); } /** * Get details on a specific account. This must be an account controlled by your API key. * Retrieve an account */ async getAccountRaw(requestParameters: GetAccountRequest, ): Promise> { if (requestParameters.accountId === null || requestParameters.accountId === undefined) { throw new runtime.RequiredError('accountId','Required parameter requestParameters.accountId was null or undefined when calling getAccount.'); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/{account_id}`.replace(`{${"account_id"}}`, encodeURIComponent(String(requestParameters.accountId))), method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get details on a specific account. This must be an account controlled by your API key. * Retrieve an account */ async getAccount(accountId: string, ): Promise { const response = await this.getAccountRaw({ accountId: accountId }, ); return await response.value(); } /** * Get historical usage metrics for the current account from the most recent metrics dashboard event. * Get usage metrics for current account */ async getAccountCurrentUsageRaw(): Promise> { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/current/usage`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get historical usage metrics for the current account from the most recent metrics dashboard event. * Get usage metrics for current account */ async getAccountCurrentUsage(): Promise { const response = await this.getAccountCurrentUsageRaw(); return await response.value(); } /** * Get aggregated historical usage metrics for the current account and all of its sub-accounts. * Get usage metrics for current and sub accounts */ async getAccountCurrentUsageAllRaw(): Promise> { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/current/usage/all`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get aggregated historical usage metrics for the current account and all of its sub-accounts. * Get usage metrics for current and sub accounts */ async getAccountCurrentUsageAll(): Promise { const response = await this.getAccountCurrentUsageAllRaw(); return await response.value(); } /** * Get usage metrics for a specific account */ async getAccountUsageRaw(requestParameters: GetAccountUsageRequest, ): Promise> { if (requestParameters.accountId === null || requestParameters.accountId === undefined) { throw new runtime.RequiredError('accountId','Required parameter requestParameters.accountId was null or undefined when calling getAccountUsage.'); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/{account_id}/usage`.replace(`{${"account_id"}}`, encodeURIComponent(String(requestParameters.accountId))), method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get usage metrics for a specific account */ async getAccountUsage(accountId: string, ): Promise { const response = await this.getAccountUsageRaw({ accountId: accountId }, ); return await response.value(); } /** * Get a list of accounts defined on the account * List accounts */ async getAccountsRaw(requestParameters: GetAccountsRequest, ): Promise>> { const queryParameters: any = {}; if (requestParameters.ids) { queryParameters['ids'] = requestParameters.ids; } const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get a list of accounts defined on the account * List accounts */ async getAccounts(ids?: Array, ): Promise> { const response = await this.getAccountsRaw({ ids: ids }, ); return await response.value(); } /** * Get details on the current account, as identified by the API key * Retrieve current account */ async getCurrentAccountRaw(): Promise> { const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/current`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get details on the current account, as identified by the API key * Retrieve current account */ async getCurrentAccount(): Promise { const response = await this.getCurrentAccountRaw(); return await response.value(); } /** * Update the configuration of an account. * Update an account */ async updateAccountRaw(requestParameters: UpdateAccountRequest, ): Promise> { if (requestParameters.accountId === null || requestParameters.accountId === undefined) { throw new runtime.RequiredError('accountId','Required parameter requestParameters.accountId was null or undefined when calling updateAccount.'); } if (requestParameters.accountMergePatch === null || requestParameters.accountMergePatch === undefined) { throw new runtime.RequiredError('accountMergePatch','Required parameter requestParameters.accountMergePatch was null or undefined when calling updateAccount.'); } const queryParameters: any = {}; const headerParameters: runtime.HTTPHeaders = {}; headerParameters['Content-Type'] = 'application/merge-patch+json'; if (this.configuration && this.configuration.accessToken) { const token = this.configuration.accessToken; const tokenString = await token("bearer", []); if (tokenString) { headerParameters["Authorization"] = `Bearer ${tokenString}`; } } const response = await this.request({ path: `/accounts/{account_id}`.replace(`{${"account_id"}}`, encodeURIComponent(String(requestParameters.accountId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: requestParameters.accountMergePatch, }); return new runtime.JSONApiResponse(response); } /** * Update the configuration of an account. * Update an account */ async updateAccount(accountId: string, accountMergePatch: AccountMergePatch, ): Promise { const response = await this.updateAccountRaw({ accountId: accountId, accountMergePatch: accountMergePatch }, ); return await response.value(); } }