/* 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 { AnalysisDimensionsTrait, ArchiveConfig, Trait, TraitMergePatch, TraitPost, } from '../models'; export interface ArchiveTraitRequest { traitId: string; archiveConfig: ArchiveConfig; } export interface CreateTraitRequest { traitFields: TraitPost; } export interface DeleteTraitRequest { traitId: string; } export interface ForceUpdateTraitRequest { traitId: string; } export interface GetTraitRequest { traitId: string; } export interface GetTraitAnalysisDimensionsRequest { traitId: string; } export interface GetTraitsRequest { ids?: Array; } export interface UnarchiveTraitRequest { traitId: string; archiveConfig: ArchiveConfig; } export interface UpdateTraitRequest { traitId: string; traitMergePatch: TraitMergePatch; } /** * */ export class TraitsApi extends runtime.BaseAPI { /** * Archive a trait * Archive a trait */ async archiveTraitRaw(requestParameters: ArchiveTraitRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling archiveTrait.'); } if (requestParameters.archiveConfig === null || requestParameters.archiveConfig === undefined) { throw new runtime.RequiredError('archiveConfig','Required parameter requestParameters.archiveConfig was null or undefined when calling archiveTrait.'); } 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: `/traits/{trait_id}/archive`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.archiveConfig, }); return new runtime.VoidApiResponse(response); } /** * Archive a trait * Archive a trait */ async archiveTrait(traitId: string, archiveConfig: ArchiveConfig, ): Promise { await this.archiveTraitRaw({ traitId: traitId, archiveConfig: archiveConfig }, ); } /** * Create a new user-defined Trait. You can connect your uploaded data to this trait by sending a PATCH to the relevant dataset with `output_to_traits` defined. * Create a Trait */ async createTraitRaw(requestParameters: CreateTraitRequest, ): Promise> { if (requestParameters.traitFields === null || requestParameters.traitFields === undefined) { throw new runtime.RequiredError('traitFields','Required parameter requestParameters.traitFields was null or undefined when calling createTrait.'); } 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: `/traits`, method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.traitFields, }); return new runtime.JSONApiResponse(response); } /** * Create a new user-defined Trait. You can connect your uploaded data to this trait by sending a PATCH to the relevant dataset with `output_to_traits` defined. * Create a Trait */ async createTrait(traitFields: TraitPost, ): Promise { const response = await this.createTraitRaw({ traitFields: traitFields }, ); return await response.value(); } /** * Delete all traits without a source dataset. * Delete all orphaned traits */ async deleteAllOrphanedTraitsRaw(): 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: `/traits`, method: 'DELETE', headers: headerParameters, query: queryParameters, }); return new runtime.VoidApiResponse(response); } /** * Delete all traits without a source dataset. * Delete all orphaned traits */ async deleteAllOrphanedTraits(): Promise { await this.deleteAllOrphanedTraitsRaw(); } /** * Delete a trait * Delete a trait */ async deleteTraitRaw(requestParameters: DeleteTraitRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling deleteTrait.'); } 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: `/traits/{trait_id}`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), method: 'DELETE', headers: headerParameters, query: queryParameters, }); return new runtime.VoidApiResponse(response); } /** * Delete a trait * Delete a trait */ async deleteTrait(traitId: string, ): Promise { await this.deleteTraitRaw({ traitId: traitId }, ); } /** * 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 forceUpdateTraitRaw(requestParameters: ForceUpdateTraitRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling forceUpdateTrait.'); } 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: `/traits/{trait_id}/force_update`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), 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 forceUpdateTrait(traitId: string, ): Promise { await this.forceUpdateTraitRaw({ traitId: traitId }, ); } /** * Get a specific trait by ID. * Get a specific trait */ async getTraitRaw(requestParameters: GetTraitRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling getTrait.'); } 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: `/traits/{trait_id}`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get a specific trait by ID. * Get a specific trait */ async getTrait(traitId: string, ): Promise { const response = await this.getTraitRaw({ traitId: traitId }, ); return await response.value(); } /** * The percentage of the US population that falls into each category of this trait. */ async getTraitAnalysisDimensionsRaw(requestParameters: GetTraitAnalysisDimensionsRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling getTraitAnalysisDimensions.'); } 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: `/traits/{trait_id}/analysis/dimensions`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * The percentage of the US population that falls into each category of this trait. */ async getTraitAnalysisDimensions(traitId: string, ): Promise { const response = await this.getTraitAnalysisDimensionsRaw({ traitId: traitId }, ); return await response.value(); } /** * Get a list of all available traits, including those provided by Faraday and those defined by the user. * List all user-defined and Faraday-provided traits */ async getTraitsRaw(requestParameters: GetTraitsRequest, ): 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: `/traits`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.JSONApiResponse(response); } /** * Get a list of all available traits, including those provided by Faraday and those defined by the user. * List all user-defined and Faraday-provided traits */ async getTraits(ids?: Array, ): Promise> { const response = await this.getTraitsRaw({ ids: ids }, ); return await response.value(); } /** * Get a csv of all available traits, including those provided by Faraday and those defined by the user. * List all user-defined and Faraday-provided traits, in csv form */ async getTraitsCsvRaw(): 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: `/traits.csv`, method: 'GET', headers: headerParameters, query: queryParameters, }); return new runtime.TextApiResponse(response) as any; } /** * Get a csv of all available traits, including those provided by Faraday and those defined by the user. * List all user-defined and Faraday-provided traits, in csv form */ async getTraitsCsv(): Promise { const response = await this.getTraitsCsvRaw(); return await response.value(); } /** * Unarchive a trait * Unarchive a trait */ async unarchiveTraitRaw(requestParameters: UnarchiveTraitRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling unarchiveTrait.'); } if (requestParameters.archiveConfig === null || requestParameters.archiveConfig === undefined) { throw new runtime.RequiredError('archiveConfig','Required parameter requestParameters.archiveConfig was null or undefined when calling unarchiveTrait.'); } 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: `/traits/{trait_id}/unarchive`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), method: 'POST', headers: headerParameters, query: queryParameters, body: requestParameters.archiveConfig, }); return new runtime.VoidApiResponse(response); } /** * Unarchive a trait * Unarchive a trait */ async unarchiveTrait(traitId: string, archiveConfig: ArchiveConfig, ): Promise { await this.unarchiveTraitRaw({ traitId: traitId, archiveConfig: archiveConfig }, ); } /** * Update the configuration of a trait * Update a trait */ async updateTraitRaw(requestParameters: UpdateTraitRequest, ): Promise> { if (requestParameters.traitId === null || requestParameters.traitId === undefined) { throw new runtime.RequiredError('traitId','Required parameter requestParameters.traitId was null or undefined when calling updateTrait.'); } if (requestParameters.traitMergePatch === null || requestParameters.traitMergePatch === undefined) { throw new runtime.RequiredError('traitMergePatch','Required parameter requestParameters.traitMergePatch was null or undefined when calling updateTrait.'); } 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: `/traits/{trait_id}`.replace(`{${"trait_id"}}`, encodeURIComponent(String(requestParameters.traitId))), method: 'PATCH', headers: headerParameters, query: queryParameters, body: requestParameters.traitMergePatch, }); return new runtime.JSONApiResponse(response); } /** * Update the configuration of a trait * Update a trait */ async updateTrait(traitId: string, traitMergePatch: TraitMergePatch, ): Promise { const response = await this.updateTraitRaw({ traitId: traitId, traitMergePatch: traitMergePatch }, ); return await response.value(); } }