From f9551b574ff9c4dca1668af87ab7db9083c63124 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Tue, 13 Aug 2024 00:51:26 +0530 Subject: [PATCH] chore: added static files for iam domain --- src/rest/Iam.ts | 32 ++++ src/rest/IamBase.ts | 33 ++++ src/rest/Twilio.ts | 11 ++ src/rest/iam/V1.ts | 56 ++++++ src/rest/iam/v1/apiKey.ts | 349 ++++++++++++++++++++++++++++++++++ src/rest/iam/v1/getApiKeys.ts | 283 +++++++++++++++++++++++++++ src/rest/iam/v1/key.ts | 203 ++++++++++++++++++++ 7 files changed, 967 insertions(+) create mode 100644 src/rest/Iam.ts create mode 100644 src/rest/IamBase.ts create mode 100644 src/rest/iam/V1.ts create mode 100644 src/rest/iam/v1/apiKey.ts create mode 100644 src/rest/iam/v1/getApiKeys.ts create mode 100644 src/rest/iam/v1/key.ts diff --git a/src/rest/Iam.ts b/src/rest/Iam.ts new file mode 100644 index 000000000..99b8099a9 --- /dev/null +++ b/src/rest/Iam.ts @@ -0,0 +1,32 @@ +import IamBase from "./IamBase"; +import {ApiKeyListInstance} from "./iam/v1/apiKey"; +import {GetApiKeysListInstance} from "./iam/v1/getApiKeys"; +import {KeyListInstance} from "./iam/v1/key"; + +class Iam extends IamBase { + /** + * @deprecated - Use v1.apiKey instead + */ + get apiKey(): ApiKeyListInstance { + console.warn("apiKey is deprecated. Use v1.apiKey instead."); + return this.v1.apiKey; + } + + /** + * @deprecated - Use v1.getApiKeys instead + */ + get getApiKeys(): GetApiKeysListInstance { + console.warn("getApiKeys is deprecated. Use v1.getApiKeys instead."); + return this.v1.getApiKeys; + } + + /** + * @deprecated - Use v1.keys instead + */ + get keys(): KeyListInstance { + console.warn("keys is deprecated. Use v1.keys instead."); + return this.v1.keys; + } +} + +export = Iam; diff --git a/src/rest/IamBase.ts b/src/rest/IamBase.ts new file mode 100644 index 000000000..575e678e5 --- /dev/null +++ b/src/rest/IamBase.ts @@ -0,0 +1,33 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import Domain from "../base/Domain"; +import V1 from "./iam/V1"; + +class IamBase extends Domain { + _v1?: V1; + + /** + * Initialize iam domain + * + * @param twilio - The twilio client + */ + constructor(twilio: any) { + super(twilio, "https://iam.twilio.com"); + } + + get v1(): V1 { + this._v1 = this._v1 || new V1(this); + return this._v1; + } +} + +export = IamBase; diff --git a/src/rest/Twilio.ts b/src/rest/Twilio.ts index 70d63a4ac..fdd2da84a 100644 --- a/src/rest/Twilio.ts +++ b/src/rest/Twilio.ts @@ -19,6 +19,7 @@ import Conversations from "./Conversations"; import Events from "./Events"; import FlexApi from "./FlexApi"; import FrontlineApi from "./FrontlineApi"; +import Iam from "./Iam"; import Insights from "./Insights"; import Intelligence from "./Intelligence"; import IpMessaging from "./IpMessaging"; @@ -95,6 +96,8 @@ class Twilio extends Client { _flexApi?: FlexApi; /** (Twilio.FrontlineApi) - frontlineApi domain */ _frontlineApi?: FrontlineApi; + /** (Twilio.Iam) - iam domain */ + _iam?: Iam; /** (Twilio.Insights) - insights domain */ _insights?: Insights; /** (Twilio.Intelligence) - intelligence domain */ @@ -174,6 +177,7 @@ class Twilio extends Client { this.events; this.flexApi; this.frontlineApi; + this.iam; this.insights; this.intelligence; this.ipMessaging; @@ -251,6 +255,13 @@ class Twilio extends Client { (this._frontlineApi = new (require("./FrontlineApi"))(this)) ); } + /** Getter for (Twilio.FrontlineApi) domain */ + get iam(): Iam { + return ( + this._iam ?? + (this._iam = new (require("./Iam"))(this)) + ); + } /** Getter for (Twilio.Insights) domain */ get insights(): Insights { return ( diff --git a/src/rest/iam/V1.ts b/src/rest/iam/V1.ts new file mode 100644 index 000000000..d2812bd0a --- /dev/null +++ b/src/rest/iam/V1.ts @@ -0,0 +1,56 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +import IamBase from "../IamBase"; +import Version from "../../base/Version"; +import { ApiKeyListInstance } from "./v1/apiKey"; +import { GetApiKeysListInstance } from "./v1/getApiKeys"; +import { KeyListInstance } from "./v1/key"; + +export default class V1 extends Version { + /** + * Initialize the V1 version of Iam + * + * @param domain - The Twilio (Twilio.Iam) domain + */ + constructor(domain: IamBase) { + super(domain, "v1"); + } + + /** apiKey - { Twilio.Iam.V1.ApiKeyListInstance } resource */ + protected _apiKey?: ApiKeyListInstance; + /** getApiKeys - { Twilio.Iam.V1.GetApiKeysListInstance } resource */ + protected _getApiKeys?: GetApiKeysListInstance; + /** keys - { Twilio.Iam.V1.KeyListInstance } resource */ + protected _keys?: KeyListInstance; + + /** Getter for apiKey resource */ + get apiKey(): ApiKeyListInstance { + this._apiKey = this._apiKey || ApiKeyListInstance(this); + return this._apiKey; + } + + /** Getter for getApiKeys resource */ + get getApiKeys(): GetApiKeysListInstance { + this._getApiKeys = this._getApiKeys || GetApiKeysListInstance(this); + return this._getApiKeys; + } + + /** Getter for keys resource */ + get keys(): KeyListInstance { + this._keys = this._keys || KeyListInstance(this); + return this._keys; + } + +} diff --git a/src/rest/iam/v1/apiKey.ts b/src/rest/iam/v1/apiKey.ts new file mode 100644 index 000000000..c105327e6 --- /dev/null +++ b/src/rest/iam/v1/apiKey.ts @@ -0,0 +1,349 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + + + + + +/** + * Options to pass to update a ApiKeyInstance + */ +export interface ApiKeyContextUpdateOptions { + /** A descriptive string that you create to describe the resource. It can be up to 64 characters long. */ + "friendlyName"?: string; + /** Collection of allow assertions. */ + "policy"?: any; +} + +export interface ApiKeyContext { + + /** + * Remove a ApiKeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed boolean + */ + remove(callback?: (error: Error | null, item?: boolean) => any): Promise + + /** + * Fetch a ApiKeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed ApiKeyInstance + */ + fetch(callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise + + /** + * Update a ApiKeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed ApiKeyInstance + */ + update(callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise; + /** + * Update a ApiKeyInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed ApiKeyInstance + */ + update(params: ApiKeyContextUpdateOptions, callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise; + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export interface ApiKeyContextSolution { + "accountSid": string; + "sid": string; +} + +export class ApiKeyContextImpl implements ApiKeyContext { + protected _solution: ApiKeyContextSolution; + protected _uri: string; + + + constructor(protected _version: V1, accountSid: string, sid: string) { + if (!isValidPathParam(accountSid)) { + throw new Error('Parameter \'accountSid\' is not valid.'); + } + + if (!isValidPathParam(sid)) { + throw new Error('Parameter \'sid\' is not valid.'); + } + + this._solution = { accountSid, sid, }; + this._uri = `/Accounts/${accountSid}/Keys/${sid}`; + } + + remove(callback?: (error: Error | null, item?: boolean) => any): Promise { + + const instance = this; + let operationVersion = instance._version, + operationPromise = operationVersion.remove({ uri: instance._uri, method: "delete" }); + + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + + } + + fetch(callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise { + + const instance = this; + let operationVersion = instance._version, + operationPromise = operationVersion.fetch({ uri: instance._uri, method: "get" }); + + operationPromise = operationPromise.then(payload => new ApiKeyInstance(operationVersion, payload, instance._solution.accountSid, instance._solution.sid)); + + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + + } + + update(params?: ApiKeyContextUpdateOptions | ((error: Error | null, item?: ApiKeyInstance) => any), callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + + if (params["friendlyName"] !== undefined) + data["FriendlyName"] = params["friendlyName"]; + if (params["policy"] !== undefined) + data["Policy"] = serialize.object(params["policy"]); + + + + const headers: any = {}; + headers["Content-Type"] = "application/x-www-form-urlencoded" + + const instance = this; + let operationVersion = instance._version, + operationPromise = operationVersion.update({ uri: instance._uri, method: "post", data, headers }); + + operationPromise = operationPromise.then(payload => new ApiKeyInstance(operationVersion, payload, instance._solution.accountSid, instance._solution.sid)); + + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + + } + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return this._solution; + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} + + +interface ApiKeyPayload extends ApiKeyResource {} + +interface ApiKeyResource { + sid: string; + friendly_name: string; + date_created: Date; + date_updated: Date; + policy: any; +} + +export class ApiKeyInstance { + protected _solution: ApiKeyContextSolution; + protected _context?: ApiKeyContext; + + constructor(protected _version: V1, payload: ApiKeyResource, accountSid: string, sid?: string) { + this.sid = (payload.sid); + this.friendlyName = (payload.friendly_name); + this.dateCreated = deserialize.rfc2822DateTime(payload.date_created); + this.dateUpdated = deserialize.rfc2822DateTime(payload.date_updated); + this.policy = (payload.policy); + + this._solution = { accountSid, sid: sid || this.sid, }; + } + + /** + * The unique string that that we created to identify the Key resource. + */ + sid: string; + /** + * The string that you assigned to describe the resource. + */ + friendlyName: string; + /** + * The date and time in GMT that the resource was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. + */ + dateCreated: Date; + /** + * The date and time in GMT that the resource was last updated specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. + */ + dateUpdated: Date; + /** + * Collection of allow assertions. + */ + policy: any; + + private get _proxy(): ApiKeyContext { + this._context = this._context || new ApiKeyContextImpl(this._version, this._solution.accountSid, this._solution.sid); + return this._context; + } + + /** + * Remove a ApiKeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed boolean + */ + remove(callback?: (error: Error | null, item?: boolean) => any): Promise + + { + return this._proxy.remove(callback); + } + + /** + * Fetch a ApiKeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed ApiKeyInstance + */ + fetch(callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise + + { + return this._proxy.fetch(callback); + } + + /** + * Update a ApiKeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed ApiKeyInstance + */ + update(callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise; + /** + * Update a ApiKeyInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed ApiKeyInstance + */ + update(params: ApiKeyContextUpdateOptions, callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise; + + update(params?: any, callback?: (error: Error | null, item?: ApiKeyInstance) => any): Promise + { + return this._proxy.update(params, callback); + } + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + sid: this.sid, + friendlyName: this.friendlyName, + dateCreated: this.dateCreated, + dateUpdated: this.dateUpdated, + policy: this.policy, + } + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} + + +export interface ApiKeySolution { +} + +export interface ApiKeyListInstance { + _version: V1; + _solution: ApiKeySolution; + _uri: string; + + (accountSid: string, sid: string, ): ApiKeyContext; + get(accountSid: string, sid: string, ): ApiKeyContext; + + + + + + + + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function ApiKeyListInstance(version: V1): ApiKeyListInstance { + const instance = ((sid, accountSid?, ) => instance.get(sid, accountSid, )) as ApiKeyListInstance; + + instance.get = function get(sid, accountSid?, ): ApiKeyContext { + accountSid = accountSid || version.domain.twilio.accountSid; + return new ApiKeyContextImpl(version, accountSid, sid); + } + + instance._version = version; + instance._solution = { }; + instance._uri = ``; + + instance.toJSON = function toJSON() { + return instance._solution; + } + + instance[inspect.custom] = function inspectImpl(_depth: any, options: InspectOptions) { + return inspect(instance.toJSON(), options); + } + + return instance; +} + + diff --git a/src/rest/iam/v1/getApiKeys.ts b/src/rest/iam/v1/getApiKeys.ts new file mode 100644 index 000000000..10774a333 --- /dev/null +++ b/src/rest/iam/v1/getApiKeys.ts @@ -0,0 +1,283 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import { inspect, InspectOptions } from "util"; +import Page, { TwilioResponsePayload } from "../../../base/Page"; +import Response from "../../../http/response"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + + +/** + * Options to pass to each + */ +export interface GetApiKeysListInstanceEachOptions { + /** How many resources to return in each list page. The default is 50, and the maximum is 1000. */ + "pageSize"?: number; + /** Function to process each record. If this and a positional callback are passed, this one will be used */ + callback?: (item: GetApiKeysInstance, done: (err?: Error) => void) => void; + /** Function to be called upon completion of streaming */ + done?: Function; + /** Upper limit for the number of records to return. each() guarantees never to return more than limit. Default is no limit */ + limit?: number; +} + +/** + * Options to pass to list + */ +export interface GetApiKeysListInstanceOptions { + /** How many resources to return in each list page. The default is 50, and the maximum is 1000. */ + "pageSize"?: number; + /** Upper limit for the number of records to return. list() guarantees never to return more than limit. Default is no limit */ + limit?: number; +} + +/** + * Options to pass to page + */ +export interface GetApiKeysListInstancePageOptions { + /** How many resources to return in each list page. The default is 50, and the maximum is 1000. */ + "pageSize"?: number; + /** Page Number, this value is simply for client state */ + pageNumber?: number; + /** PageToken provided by the API */ + pageToken?: string; +} + + + +export interface GetApiKeysSolution { + accountSid: string; +} + +export interface GetApiKeysListInstance { + _version: V1; + _solution: GetApiKeysSolution; + _uri: string; + + + + + /** + * Streams GetApiKeysInstance records from the API. + * + * This operation lazily loads records as efficiently as possible until the limit + * is reached. + * + * The results are passed into the callback function, so this operation is memory + * efficient. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param { GetApiKeysListInstanceEachOptions } [params] - Options for request + * @param { function } [callback] - Function to process each record + */ + each(callback?: (item: GetApiKeysInstance, done: (err?: Error) => void) => void): void; + each(params: GetApiKeysListInstanceEachOptions, callback?: (item: GetApiKeysInstance, done: (err?: Error) => void) => void): void; + /** + * Retrieve a single target page of GetApiKeysInstance records from the API. + * + * The request is executed immediately. + * + * @param { string } [targetUrl] - API-generated URL for the requested results page + * @param { function } [callback] - Callback to handle list of records + */ + getPage(targetUrl: string, callback?: (error: Error | null, items: GetApiKeysPage) => any): Promise; + /** + * Lists GetApiKeysInstance records from the API as a list. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param { GetApiKeysListInstanceOptions } [params] - Options for request + * @param { function } [callback] - Callback to handle list of records + */ + list(callback?: (error: Error | null, items: GetApiKeysInstance[]) => any): Promise; + list(params: GetApiKeysListInstanceOptions, callback?: (error: Error | null, items: GetApiKeysInstance[]) => any): Promise; + /** + * Retrieve a single page of GetApiKeysInstance records from the API. + * + * The request is executed immediately. + * + * If a function is passed as the first argument, it will be used as the callback + * function. + * + * @param { GetApiKeysListInstancePageOptions } [params] - Options for request + * @param { function } [callback] - Callback to handle list of records + */ + page(callback?: (error: Error | null, items: GetApiKeysPage) => any): Promise; + page(params: GetApiKeysListInstancePageOptions, callback?: (error: Error | null, items: GetApiKeysPage) => any): Promise; + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function GetApiKeysListInstance(version: V1): GetApiKeysListInstance { + const accountSid = version.domain.twilio.accountSid; + if (!isValidPathParam(accountSid)) { + throw new Error('Parameter \'accountSid\' is not valid.'); + } + + const instance = {} as GetApiKeysListInstance; + + instance._version = version; + instance._solution = { accountSid, }; + instance._uri = `/Accounts/${accountSid}/Keys`; + + instance.page = function page(params?: GetApiKeysListInstancePageOptions | ((error: Error | null, items: GetApiKeysPage) => any), callback?: (error: Error | null, items: GetApiKeysPage) => any): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + if (params["pageSize"] !== undefined) + data["PageSize"] = params["pageSize"]; + + + + if (params.pageNumber !== undefined) data["Page"] = params.pageNumber; + if (params.pageToken !== undefined) data["PageToken"] = params.pageToken; + + const headers: any = {}; + + let operationVersion = version, + operationPromise = operationVersion.page({ uri: instance._uri, method: "get", params: data, headers }); + + operationPromise = operationPromise.then(payload => new GetApiKeysPage(operationVersion, payload, instance._solution)); + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + } + instance.each = instance._version.each; + instance.list = instance._version.list; + + instance.getPage = function getPage(targetUrl: string, callback?: (error: Error | null, items: GetApiKeysPage) => any): Promise { + const operationPromise = instance._version._domain.twilio.request({method: "get", uri: targetUrl}); + + let pagePromise = operationPromise.then(payload => new GetApiKeysPage(instance._version, payload, instance._solution)); + pagePromise = instance._version.setPromiseCallback(pagePromise, callback); + return pagePromise; + } + + + instance.toJSON = function toJSON() { + return instance._solution; + } + + instance[inspect.custom] = function inspectImpl(_depth: any, options: InspectOptions) { + return inspect(instance.toJSON(), options); + } + + return instance; +} + +interface GetApiKeysPayload extends TwilioResponsePayload { + keys: GetApiKeysResource[]; +} + +interface GetApiKeysResource { + sid: string; + friendly_name: string; + date_created: Date; + date_updated: Date; +} + +export class GetApiKeysInstance { + + constructor(protected _version: V1, payload: GetApiKeysResource, accountSid?: string) { + this.sid = (payload.sid); + this.friendlyName = (payload.friendly_name); + this.dateCreated = deserialize.rfc2822DateTime(payload.date_created); + this.dateUpdated = deserialize.rfc2822DateTime(payload.date_updated); + + } + + /** + * The unique string that that we created to identify the Key resource. + */ + sid: string; + /** + * The string that you assigned to describe the resource. + */ + friendlyName: string; + /** + * The date and time in GMT that the resource was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. + */ + dateCreated: Date; + /** + * The date and time in GMT that the resource was last updated specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. + */ + dateUpdated: Date; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + sid: this.sid, + friendlyName: this.friendlyName, + dateCreated: this.dateCreated, + dateUpdated: this.dateUpdated, + } + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} + +export class GetApiKeysPage extends Page { +/** +* Initialize the GetApiKeysPage +* +* @param version - Version of the resource +* @param response - Response from the API +* @param solution - Path solution +*/ +constructor(version: V1, response: Response, solution: GetApiKeysSolution) { + super(version, response, solution); + } + + /** + * Build an instance of GetApiKeysInstance + * + * @param payload - Payload response from the API + */ + getInstance(payload: GetApiKeysResource): GetApiKeysInstance { + return new GetApiKeysInstance( + this._version, + payload, + this._solution.accountSid, + ); + } + + [inspect.custom](depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } + } + diff --git a/src/rest/iam/v1/key.ts b/src/rest/iam/v1/key.ts new file mode 100644 index 000000000..fe6db9776 --- /dev/null +++ b/src/rest/iam/v1/key.ts @@ -0,0 +1,203 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Twilio - Iam + * This is the public Twilio REST API. + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import { inspect, InspectOptions } from "util"; +import V1 from "../V1"; +const deserialize = require("../../../base/deserialize"); +const serialize = require("../../../base/serialize"); +import { isValidPathParam } from "../../../base/utility"; + + +export type KeyKeytype = 'restricted'; + + +/** + * Options to pass to create a KeyInstance + */ +export interface KeyListInstanceCreateOptions { + /** A descriptive string that you create to describe the resource. It can be up to 64 characters long. */ + "friendlyName"?: string; + /** */ + "keyType"?: KeyKeytype; + /** Collection of allow assertions. */ + "policy"?: any; +} + + +export interface KeySolution { + accountSid: string; +} + +export interface KeyListInstance { + _version: V1; + _solution: KeySolution; + _uri: string; + + + + /** + * Create a KeyInstance + * + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed KeyInstance + */ + create(callback?: (error: Error | null, item?: KeyInstance) => any): Promise; + /** + * Create a KeyInstance + * + * @param params - Parameter for request + * @param callback - Callback to handle processed record + * + * @returns Resolves to processed KeyInstance + */ + create(params: KeyListInstanceCreateOptions, callback?: (error: Error | null, item?: KeyInstance) => any): Promise; + + + /** + * Provide a user-friendly representation + */ + toJSON(): any; + [inspect.custom](_depth: any, options: InspectOptions): any; +} + +export function KeyListInstance(version: V1): KeyListInstance { + const accountSid = version.domain.twilio.accountSid; + if (!isValidPathParam(accountSid)) { + throw new Error('Parameter \'accountSid\' is not valid.'); + } + + const instance = {} as KeyListInstance; + + instance._version = version; + instance._solution = { accountSid, }; + instance._uri = `/Accounts/${accountSid}/Keys`; + + instance.create = function create(params?: KeyListInstanceCreateOptions | ((error: Error | null, items: KeyInstance) => any), callback?: (error: Error | null, items: KeyInstance) => any): Promise { + if (params instanceof Function) { + callback = params; + params = {}; + } else { + params = params || {}; + } + + let data: any = {}; + + + if (params["friendlyName"] !== undefined) + data["FriendlyName"] = params["friendlyName"]; + if (params["keyType"] !== undefined) + data["KeyType"] = params["keyType"]; + if (params["policy"] !== undefined) + data["Policy"] = serialize.object(params["policy"]); + + + + const headers: any = {}; + headers["Content-Type"] = "application/x-www-form-urlencoded" + + let operationVersion = version, + operationPromise = operationVersion.create({ uri: instance._uri, method: "post", data, headers }); + + operationPromise = operationPromise.then(payload => new KeyInstance(operationVersion, payload, instance._solution.accountSid)); + + + operationPromise = instance._version.setPromiseCallback(operationPromise,callback); + return operationPromise; + + + } + + instance.toJSON = function toJSON() { + return instance._solution; + } + + instance[inspect.custom] = function inspectImpl(_depth: any, options: InspectOptions) { + return inspect(instance.toJSON(), options); + } + + return instance; +} + +interface KeyPayload extends KeyResource {} + +interface KeyResource { + sid: string; + friendly_name: string; + date_created: Date; + date_updated: Date; + secret: string; + policy: any; +} + +export class KeyInstance { + + constructor(protected _version: V1, payload: KeyResource, accountSid?: string) { + this.sid = (payload.sid); + this.friendlyName = (payload.friendly_name); + this.dateCreated = deserialize.rfc2822DateTime(payload.date_created); + this.dateUpdated = deserialize.rfc2822DateTime(payload.date_updated); + this.secret = (payload.secret); + this.policy = (payload.policy); + + } + + /** + * The unique string that that we created to identify the NewKey resource. You will use this as the basic-auth `user` when authenticating to the API. + */ + sid: string; + /** + * The string that you assigned to describe the resource. + */ + friendlyName: string; + /** + * The date and time in GMT that the API Key was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. + */ + dateCreated: Date; + /** + * The date and time in GMT that the new API Key was last updated specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format. + */ + dateUpdated: Date; + /** + * The secret your application uses to sign Access Tokens and to authenticate to the REST API (you will use this as the basic-auth `password`). **Note that for security reasons, this field is ONLY returned when the API Key is first created.** + */ + secret: string; + /** + * Collection of allow assertions. + */ + policy: any; + + /** + * Provide a user-friendly representation + * + * @returns Object + */ + toJSON() { + return { + sid: this.sid, + friendlyName: this.friendlyName, + dateCreated: this.dateCreated, + dateUpdated: this.dateUpdated, + secret: this.secret, + policy: this.policy, + } + } + + [inspect.custom](_depth: any, options: InspectOptions) { + return inspect(this.toJSON(), options); + } +} + +