|
| 1 | +/* |
| 2 | + * This code was generated by |
| 3 | + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ |
| 4 | + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ |
| 5 | + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ |
| 6 | + * |
| 7 | + * Twilio - Api |
| 8 | + * This is the public Twilio REST API. |
| 9 | + * |
| 10 | + * NOTE: This class is auto generated by OpenAPI Generator. |
| 11 | + * https://openapi-generator.tech |
| 12 | + * Do not edit the class manually. |
| 13 | + */ |
| 14 | + |
| 15 | +import { inspect, InspectOptions } from "util"; |
| 16 | +import V2010 from "../V2010"; |
| 17 | +const deserialize = require("../../../base/deserialize"); |
| 18 | +const serialize = require("../../../base/serialize"); |
| 19 | +import { isValidPathParam } from "../../../base/utility"; |
| 20 | + |
| 21 | +/** |
| 22 | + * Options to pass to create a SafelistInstance |
| 23 | + */ |
| 24 | +export interface SafelistListInstanceCreateOptions { |
| 25 | + /** The phone number to be added in SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). */ |
| 26 | + phoneNumber: string; |
| 27 | +} |
| 28 | + |
| 29 | +/** |
| 30 | + * Options to pass to remove a SafelistInstance |
| 31 | + */ |
| 32 | +export interface SafelistListInstanceRemoveOptions { |
| 33 | + /** The phone number to be removed from SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). */ |
| 34 | + phoneNumber?: string; |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * Options to pass to fetch a SafelistInstance |
| 39 | + */ |
| 40 | +export interface SafelistListInstanceFetchOptions { |
| 41 | + /** The phone number to be fetched from SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). */ |
| 42 | + phoneNumber?: string; |
| 43 | +} |
| 44 | + |
| 45 | +export interface SafelistSolution {} |
| 46 | + |
| 47 | +export interface SafelistListInstance { |
| 48 | + _version: V2010; |
| 49 | + _solution: SafelistSolution; |
| 50 | + _uri: string; |
| 51 | + |
| 52 | + /** |
| 53 | + * Create a SafelistInstance |
| 54 | + * |
| 55 | + * @param params - Parameter for request |
| 56 | + * @param callback - Callback to handle processed record |
| 57 | + * |
| 58 | + * @returns Resolves to processed SafelistInstance |
| 59 | + */ |
| 60 | + create( |
| 61 | + params: SafelistListInstanceCreateOptions, |
| 62 | + callback?: (error: Error | null, item?: SafelistInstance) => any |
| 63 | + ): Promise<SafelistInstance>; |
| 64 | + |
| 65 | + /** |
| 66 | + * Remove a SafelistInstance |
| 67 | + * |
| 68 | + * @param callback - Callback to handle processed record |
| 69 | + * |
| 70 | + * @returns Resolves to processed boolean |
| 71 | + */ |
| 72 | + remove( |
| 73 | + callback?: (error: Error | null, item?: boolean) => any |
| 74 | + ): Promise<boolean>; |
| 75 | + /** |
| 76 | + * Remove a SafelistInstance |
| 77 | + * |
| 78 | + * @param params - Parameter for request |
| 79 | + * @param callback - Callback to handle processed record |
| 80 | + * |
| 81 | + * @returns Resolves to processed SafelistInstance |
| 82 | + */ |
| 83 | + remove( |
| 84 | + params: SafelistListInstanceRemoveOptions, |
| 85 | + callback?: (error: Error | null, item?: boolean) => any |
| 86 | + ): Promise<boolean>; |
| 87 | + |
| 88 | + /** |
| 89 | + * Fetch a SafelistInstance |
| 90 | + * |
| 91 | + * @param callback - Callback to handle processed record |
| 92 | + * |
| 93 | + * @returns Resolves to processed SafelistInstance |
| 94 | + */ |
| 95 | + fetch( |
| 96 | + callback?: (error: Error | null, item?: SafelistInstance) => any |
| 97 | + ): Promise<SafelistInstance>; |
| 98 | + /** |
| 99 | + * Fetch a SafelistInstance |
| 100 | + * |
| 101 | + * @param params - Parameter for request |
| 102 | + * @param callback - Callback to handle processed record |
| 103 | + * |
| 104 | + * @returns Resolves to processed SafelistInstance |
| 105 | + */ |
| 106 | + fetch( |
| 107 | + params: SafelistListInstanceFetchOptions, |
| 108 | + callback?: (error: Error | null, item?: SafelistInstance) => any |
| 109 | + ): Promise<SafelistInstance>; |
| 110 | + |
| 111 | + /** |
| 112 | + * Provide a user-friendly representation |
| 113 | + */ |
| 114 | + toJSON(): any; |
| 115 | + [inspect.custom](_depth: any, options: InspectOptions): any; |
| 116 | +} |
| 117 | + |
| 118 | +export function SafelistListInstance(version: V2010): SafelistListInstance { |
| 119 | + const instance = {} as SafelistListInstance; |
| 120 | + |
| 121 | + instance._version = version; |
| 122 | + instance._solution = {}; |
| 123 | + instance._uri = `/SafeList/Numbers.json`; |
| 124 | + |
| 125 | + instance.create = function create( |
| 126 | + params: SafelistListInstanceCreateOptions, |
| 127 | + callback?: (error: Error | null, items: SafelistInstance) => any |
| 128 | + ): Promise<SafelistInstance> { |
| 129 | + if (params === null || params === undefined) { |
| 130 | + throw new Error('Required parameter "params" missing.'); |
| 131 | + } |
| 132 | + |
| 133 | + if (params["phoneNumber"] === null || params["phoneNumber"] === undefined) { |
| 134 | + throw new Error("Required parameter \"params['phoneNumber']\" missing."); |
| 135 | + } |
| 136 | + |
| 137 | + let data: any = {}; |
| 138 | + |
| 139 | + data["PhoneNumber"] = params["phoneNumber"]; |
| 140 | + |
| 141 | + const headers: any = {}; |
| 142 | + headers["Content-Type"] = "application/x-www-form-urlencoded"; |
| 143 | + |
| 144 | + let operationVersion = version, |
| 145 | + operationPromise = operationVersion.create({ |
| 146 | + uri: instance._uri, |
| 147 | + method: "post", |
| 148 | + data, |
| 149 | + headers, |
| 150 | + }); |
| 151 | + |
| 152 | + operationPromise = operationPromise.then( |
| 153 | + (payload) => new SafelistInstance(operationVersion, payload) |
| 154 | + ); |
| 155 | + |
| 156 | + operationPromise = instance._version.setPromiseCallback( |
| 157 | + operationPromise, |
| 158 | + callback |
| 159 | + ); |
| 160 | + return operationPromise; |
| 161 | + }; |
| 162 | + |
| 163 | + instance.remove = function remove( |
| 164 | + params?: |
| 165 | + | SafelistListInstanceRemoveOptions |
| 166 | + | ((error: Error | null, items: boolean) => any), |
| 167 | + callback?: (error: Error | null, items: boolean) => any |
| 168 | + ): Promise<boolean> { |
| 169 | + if (params instanceof Function) { |
| 170 | + callback = params; |
| 171 | + params = {}; |
| 172 | + } else { |
| 173 | + params = params || {}; |
| 174 | + } |
| 175 | + |
| 176 | + let data: any = {}; |
| 177 | + |
| 178 | + if (params["phoneNumber"] !== undefined) |
| 179 | + data["PhoneNumber"] = params["phoneNumber"]; |
| 180 | + |
| 181 | + const headers: any = {}; |
| 182 | + |
| 183 | + let operationVersion = version, |
| 184 | + operationPromise = operationVersion.remove({ |
| 185 | + uri: instance._uri, |
| 186 | + method: "delete", |
| 187 | + params: data, |
| 188 | + headers, |
| 189 | + }); |
| 190 | + |
| 191 | + operationPromise = instance._version.setPromiseCallback( |
| 192 | + operationPromise, |
| 193 | + callback |
| 194 | + ); |
| 195 | + return operationPromise; |
| 196 | + }; |
| 197 | + |
| 198 | + instance.fetch = function fetch( |
| 199 | + params?: |
| 200 | + | SafelistListInstanceFetchOptions |
| 201 | + | ((error: Error | null, items: SafelistInstance) => any), |
| 202 | + callback?: (error: Error | null, items: SafelistInstance) => any |
| 203 | + ): Promise<SafelistInstance> { |
| 204 | + if (params instanceof Function) { |
| 205 | + callback = params; |
| 206 | + params = {}; |
| 207 | + } else { |
| 208 | + params = params || {}; |
| 209 | + } |
| 210 | + |
| 211 | + let data: any = {}; |
| 212 | + |
| 213 | + if (params["phoneNumber"] !== undefined) |
| 214 | + data["PhoneNumber"] = params["phoneNumber"]; |
| 215 | + |
| 216 | + const headers: any = {}; |
| 217 | + |
| 218 | + let operationVersion = version, |
| 219 | + operationPromise = operationVersion.fetch({ |
| 220 | + uri: instance._uri, |
| 221 | + method: "get", |
| 222 | + params: data, |
| 223 | + headers, |
| 224 | + }); |
| 225 | + |
| 226 | + operationPromise = operationPromise.then( |
| 227 | + (payload) => new SafelistInstance(operationVersion, payload) |
| 228 | + ); |
| 229 | + |
| 230 | + operationPromise = instance._version.setPromiseCallback( |
| 231 | + operationPromise, |
| 232 | + callback |
| 233 | + ); |
| 234 | + return operationPromise; |
| 235 | + }; |
| 236 | + |
| 237 | + instance.toJSON = function toJSON() { |
| 238 | + return instance._solution; |
| 239 | + }; |
| 240 | + |
| 241 | + instance[inspect.custom] = function inspectImpl( |
| 242 | + _depth: any, |
| 243 | + options: InspectOptions |
| 244 | + ) { |
| 245 | + return inspect(instance.toJSON(), options); |
| 246 | + }; |
| 247 | + |
| 248 | + return instance; |
| 249 | +} |
| 250 | + |
| 251 | +interface SafelistPayload extends SafelistResource {} |
| 252 | + |
| 253 | +interface SafelistResource { |
| 254 | + sid: string; |
| 255 | + phone_number: string; |
| 256 | +} |
| 257 | + |
| 258 | +export class SafelistInstance { |
| 259 | + constructor(protected _version: V2010, payload: SafelistResource) { |
| 260 | + this.sid = payload.sid; |
| 261 | + this.phoneNumber = payload.phone_number; |
| 262 | + } |
| 263 | + |
| 264 | + /** |
| 265 | + * The unique string that we created to identify the SafeList resource. |
| 266 | + */ |
| 267 | + sid: string; |
| 268 | + /** |
| 269 | + * The phone number in SafeList. |
| 270 | + */ |
| 271 | + phoneNumber: string; |
| 272 | + |
| 273 | + /** |
| 274 | + * Provide a user-friendly representation |
| 275 | + * |
| 276 | + * @returns Object |
| 277 | + */ |
| 278 | + toJSON() { |
| 279 | + return { |
| 280 | + sid: this.sid, |
| 281 | + phoneNumber: this.phoneNumber, |
| 282 | + }; |
| 283 | + } |
| 284 | + |
| 285 | + [inspect.custom](_depth: any, options: InspectOptions) { |
| 286 | + return inspect(this.toJSON(), options); |
| 287 | + } |
| 288 | +} |
0 commit comments