/* 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 { ArchiveConfig, Cohort, CohortAnalysisMembership, CohortMergePatch, CohortPost, } from '../models'; export interface ArchiveCohortRequest { cohortId: string; archiveConfig: ArchiveConfig; } export interface CreateCohortRequest { cohortFields: CohortPost; } export interface DeleteCohortRequest { cohortId: string; } export interface ForceUpdateCohortRequest { cohortId: string; } export interface GetCohortRequest { cohortId: string; } export interface GetCohortAnalysisMembershipRequest { cohortId: string; } export interface GetCohortsRequest { ids?: Array; } export interface UnarchiveCohortRequest { cohortId: string; archiveConfig: ArchiveConfig; } export interface UpdateCohortRequest { cohortId: string; cohortFields: CohortMergePatch; } /** * */ export class CohortsApi extends runtime.BaseAPI { /** * Archive a cohort * Archive a cohort */ async archiveCohortRaw(requestParameters: ArchiveCohortRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling archiveCohort.'); } if (requestParameters.archiveConfig === null || requestParameters.archiveConfig === undefined) { throw new runtime.RequiredError('archiveConfig','Required parameter requestParameters.archiveConfig was null or undefined when calling archiveCohort.'); } 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: `/cohorts/{cohort_id}/archive`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.archiveConfig, }); return new runtime.VoidApiResponse(response); } /** * Archive a cohort * Archive a cohort */ async archiveCohort(cohortId: string, archiveConfig: ArchiveConfig, ): Promise { await this.archiveCohortRaw({ cohortId: cohortId, archiveConfig: archiveConfig }, ); } /** * Add a new cohort (defined as people who have made qualifying emissions of certain events) * Create cohort */ async createCohortRaw(requestParameters: CreateCohortRequest, ): Promise> { if (requestParameters.cohortFields === null || requestParameters.cohortFields === undefined) { throw new runtime.RequiredError('cohortFields','Required parameter requestParameters.cohortFields was null or undefined when calling createCohort.'); } 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: `/cohorts`, method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.cohortFields, }); return new runtime.JSONApiResponse(response); } /** * Add a new cohort (defined as people who have made qualifying emissions of certain events) * Create cohort */ async createCohort(cohortFields: CohortPost, ): Promise { const response = await this.createCohortRaw({ cohortFields: cohortFields }, ); return await response.value(); } /** * Delete a cohort */ async deleteCohortRaw(requestParameters: DeleteCohortRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling deleteCohort.'); } 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: `/cohorts/{cohort_id}`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'DELETE', headers: headerParameters, query: queryParameters, }); return new runtime.VoidApiResponse(response); } /** * Delete a cohort */ async deleteCohort(cohortId: string, ): Promise { await this.deleteCohortRaw({ cohortId: cohortId }, ); } /** * Trigger a rerun for this resource. Faraday automatically updates resources when their config changes, but this option is available in case of transient errors. * Trigger a rerun for this resource. */ async forceUpdateCohortRaw(requestParameters: ForceUpdateCohortRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling forceUpdateCohort.'); } 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: `/cohorts/{cohort_id}/force_update`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'POST', headers: headerParameters, query: queryParameters, }); return new runtime.VoidApiResponse(response); } /** * Trigger a rerun for this resource. Faraday automatically updates resources when their config changes, but this option is available in case of transient errors. * Trigger a rerun for this resource. */ async forceUpdateCohort(cohortId: string, ): Promise { await this.forceUpdateCohortRaw({ cohortId: cohortId }, ); } /** * Get details on a specific cohort * Retrieve a cohort */ async getCohortRaw(requestParameters: GetCohortRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling getCohort.'); } 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: `/cohorts/{cohort_id}`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get details on a specific cohort * Retrieve a cohort */ async getCohort(cohortId: string, ): Promise { const response = await this.getCohortRaw({ cohortId: cohortId }, ); return await response.value(); } /** * Get the cohort membership counts over time. */ async getCohortAnalysisMembershipRaw(requestParameters: GetCohortAnalysisMembershipRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling getCohortAnalysisMembership.'); } 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: `/cohorts/{cohort_id}/analysis/membership`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get the cohort membership counts over time. */ async getCohortAnalysisMembership(cohortId: string, ): Promise { const response = await this.getCohortAnalysisMembershipRaw({ cohortId: cohortId }, ); return await response.value(); } /** * Get a list of cohorts defined on the account * List cohorts */ async getCohortsRaw(requestParameters: GetCohortsRequest, ): 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: `/cohorts`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get a list of cohorts defined on the account * List cohorts */ async getCohorts(ids?: Array, ): Promise> { const response = await this.getCohortsRaw({ ids: ids }, ); return await response.value(); } /** * Unarchive a cohort * Unarchive a cohort */ async unarchiveCohortRaw(requestParameters: UnarchiveCohortRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling unarchiveCohort.'); } if (requestParameters.archiveConfig === null || requestParameters.archiveConfig === undefined) { throw new runtime.RequiredError('archiveConfig','Required parameter requestParameters.archiveConfig was null or undefined when calling unarchiveCohort.'); } 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: `/cohorts/{cohort_id}/unarchive`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.archiveConfig, }); return new runtime.VoidApiResponse(response); } /** * Unarchive a cohort * Unarchive a cohort */ async unarchiveCohort(cohortId: string, archiveConfig: ArchiveConfig, ): Promise { await this.unarchiveCohortRaw({ cohortId: cohortId, archiveConfig: archiveConfig }, ); } /** * Edit configuration of a cohort * Edit a cohort */ async updateCohortRaw(requestParameters: UpdateCohortRequest, ): Promise> { if (requestParameters.cohortId === null || requestParameters.cohortId === undefined) { throw new runtime.RequiredError('cohortId','Required parameter requestParameters.cohortId was null or undefined when calling updateCohort.'); } if (requestParameters.cohortFields === null || requestParameters.cohortFields === undefined) { throw new runtime.RequiredError('cohortFields','Required parameter requestParameters.cohortFields was null or undefined when calling updateCohort.'); } 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: `/cohorts/{cohort_id}`.replace(`{${"cohort_id"}}`, encodeURIComponent(String(requestParameters.cohortId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: requestParameters.cohortFields, }); return new runtime.JSONApiResponse(response); } /** * Edit configuration of a cohort * Edit a cohort */ async updateCohort(cohortId: string, cohortFields: CohortMergePatch, ): Promise { const response = await this.updateCohortRaw({ cohortId: cohortId, cohortFields: cohortFields }, ); return await response.value(); } }