Skip to content

Commit

Permalink
chore: Remove signature overloading (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiachua authored Jan 5, 2023
1 parent 7d7c287 commit 71e2f4a
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public override List<KeyValuePair<string, string>> GetParams()
{
var p = new List<KeyValuePair<string, string>>();

if (PageSize != null)
{
p.Add(new KeyValuePair<string, string>("PageSize", PageSize.ToString()));
}
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,31 @@ public static async System.Threading.Tasks.Task<ResourceSet<AssistantResource>>
}
#endif
/// <summary> read </summary>
/// <param name="pageSize"> How many resources to return in each list page. The default is 50, and the maximum is 1000. </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <param name="limit"> Record limit </param>
/// <returns> A single instance of Assistant </returns>
public static ResourceSet<AssistantResource> Read(
int? pageSize = null,
long? limit = null,
ITwilioRestClient client = null)
{
var options = new ReadAssistantOptions(){ Limit = limit};
var options = new ReadAssistantOptions(){ PageSize = pageSize, Limit = limit};
return Read(options, client);
}

#if !NET35
/// <summary> read </summary>
/// <param name="pageSize"> How many resources to return in each list page. The default is 50, and the maximum is 1000. </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <param name="limit"> Record limit </param>
/// <returns> Task that resolves to A single instance of Assistant </returns>
public static async System.Threading.Tasks.Task<ResourceSet<AssistantResource>> ReadAsync(
int? pageSize = null,
long? limit = null,
ITwilioRestClient client = null)
{
var options = new ReadAssistantOptions(){ Limit = limit};
var options = new ReadAssistantOptions(){ PageSize = pageSize, Limit = limit};
return await ReadAsync(options, client);
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@
import lombok.ToString;

public class AssistantReader extends Reader<Assistant> {
private Integer pageSize;

public AssistantReader(){
}

public AssistantReader setPageSize(final Integer pageSize){
this.pageSize = pageSize;
return this;
}

@Override
public ResourceSet<Assistant> read(final TwilioRestClient client) {
Expand All @@ -65,6 +70,7 @@ public Page<Assistant> firstPage(final TwilioRestClient client) {
path
);

addQueryParams(request);
return pageForRequest(client, request);
}

Expand Down Expand Up @@ -117,4 +123,14 @@ public Page<Assistant> getPage(final String targetUrl, final TwilioRestClient cl

return pageForRequest(client, request);
}
private void addQueryParams(final Request request) {
if (pageSize != null) {

request.addQueryParam("PageSize", pageSize.toString());
}

if(getPageSize() != null) {
request.addQueryParam("PageSize", Integer.toString(getPageSize()));
}
}
}
109 changes: 36 additions & 73 deletions examples/node/lib/rest/api/v2010/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ export interface AccountContext {
params: AccountContextUpdateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance>;
update(params: any, callback?: any): Promise<AccountInstance>;

/**
* Provide a user-friendly representation
Expand Down Expand Up @@ -187,7 +186,9 @@ export class AccountContextImpl implements AccountContext {
return this._calls;
}

remove(callback?: any): Promise<boolean> {
remove(
callback?: (error: Error | null, item?: boolean) => any
): Promise<boolean> {
const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.remove({
Expand All @@ -202,7 +203,9 @@ export class AccountContextImpl implements AccountContext {
return operationPromise;
}

fetch(callback?: any): Promise<AccountInstance> {
fetch(
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance> {
const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.fetch({
Expand All @@ -222,7 +225,12 @@ export class AccountContextImpl implements AccountContext {
return operationPromise;
}

update(params: any, callback?: any): Promise<AccountInstance> {
update(
params:
| AccountContextUpdateOptions
| ((error: Error | null, item?: AccountInstance) => any),
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance> {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
}
Expand Down Expand Up @@ -396,7 +404,11 @@ export class AccountInstance {
params: AccountContextUpdateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance>;
update(params: any, callback?: any): Promise<AccountInstance> {

update(
params?: any,
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance> {
return this._proxy.update(params, callback);
}

Expand Down Expand Up @@ -470,7 +482,6 @@ export interface AccountListInstance {
params: AccountListInstanceCreateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
): Promise<AccountInstance>;
create(params?: any, callback?: any): Promise<AccountInstance>;

/**
* Streams AccountInstance records from the API.
Expand All @@ -484,85 +495,44 @@ export interface AccountListInstance {
* If a function is passed as the first argument, it will be used as the callback
* function.
*
* @param { AccountListInstanceEachOptions } [params] - Options for request
* @param { function } [callback] - Function to process each record
*/
each(
callback?: (item: AccountInstance, done: (err?: Error) => void) => void
): void;
/**
* Streams AccountInstance 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 { AccountListInstanceEachOptions } [params] - Options for request
* @param { function } [callback] - Function to process each record
*/
each(
params?: AccountListInstanceEachOptions,
params: AccountListInstanceEachOptions,
callback?: (item: AccountInstance, done: (err?: Error) => void) => void
): void;
each(params?: any, callback?: any): void;
/**
* Retrieve a single target page of AccountInstance 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 { function } [callback] - Callback to handle list of records
*/
getPage(
callback?: (error: Error | null, items: AccountPage) => any
): Promise<AccountPage>;
/**
* Retrieve a single target page of AccountInstance 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 { string } [targetUrl] - API-generated URL for the requested results page
* @param { function } [callback] - Callback to handle list of records
*/
getPage(
targetUrl?: string,
targetUrl: string,
callback?: (error: Error | null, items: AccountPage) => any
): Promise<AccountPage>;
getPage(params?: any, callback?: any): Promise<AccountPage>;
/**
* Lists AccountInstance 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 { AccountListInstanceOptions } [params] - Options for request
* @param { function } [callback] - Callback to handle list of records
*/
list(
callback?: (error: Error | null, items: AccountInstance[]) => any
): Promise<AccountInstance[]>;
/**
* Lists AccountInstance 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 { AccountListInstanceOptions } [params] - Options for request
* @param { function } [callback] - Callback to handle list of records
*/
list(
params?: AccountListInstanceOptions,
params: AccountListInstanceOptions,
callback?: (error: Error | null, items: AccountInstance[]) => any
): Promise<AccountInstance[]>;
list(params?: any, callback?: any): Promise<AccountInstance[]>;
/**
* Retrieve a single page of AccountInstance records from the API.
*
Expand All @@ -571,27 +541,16 @@ export interface AccountListInstance {
* If a function is passed as the first argument, it will be used as the callback
* function.
*
* @param { AccountListInstancePageOptions } [params] - Options for request
* @param { function } [callback] - Callback to handle list of records
*/
page(
callback?: (error: Error | null, items: AccountPage) => any
): Promise<AccountPage>;
/**
* Retrieve a single page of AccountInstance 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 { AccountListInstancePageOptions } [params] - Options for request
* @param { function } [callback] - Callback to handle list of records
*/
page(
params: AccountListInstancePageOptions,
callback?: (error: Error | null, items: AccountPage) => any
): Promise<AccountPage>;
page(params?: any, callback?: any): Promise<AccountPage>;

/**
* Provide a user-friendly representation
Expand All @@ -612,10 +571,12 @@ export function AccountListInstance(version: V2010): AccountListInstance {
instance._uri = `/Accounts.json`;

instance.create = function create(
params?: any,
callback?: any
params?:
| AccountListInstanceCreateOptions
| ((error: Error | null, items: AccountInstance) => any),
callback?: (error: Error | null, items: AccountInstance) => any
): Promise<AccountInstance> {
if (typeof params === "function") {
if (params instanceof Function) {
callback = params;
params = {};
} else {
Expand Down Expand Up @@ -657,10 +618,12 @@ export function AccountListInstance(version: V2010): AccountListInstance {
};

instance.page = function page(
params?: any,
callback?: any
params?:
| AccountListInstancePageOptions
| ((error: Error | null, items: AccountPage) => any),
callback?: (error: Error | null, items: AccountPage) => any
): Promise<AccountPage> {
if (typeof params === "function") {
if (params instanceof Function) {
callback = params;
params = {};
} else {
Expand All @@ -683,7 +646,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {
);
if (params["pageSize"] !== undefined) data["PageSize"] = params["pageSize"];

if (params.page !== undefined) data["Page"] = params.pageNumber;
if (params.pageNumber !== undefined) data["Page"] = params.pageNumber;
if (params.pageToken !== undefined) data["PageToken"] = params.pageToken;

const headers: any = {};
Expand Down Expand Up @@ -711,8 +674,8 @@ export function AccountListInstance(version: V2010): AccountListInstance {
instance.list = instance._version.list;

instance.getPage = function getPage(
targetUrl?: any,
callback?: any
targetUrl: string,
callback?: (error: Error | null, items: AccountPage) => any
): Promise<AccountPage> {
const operationPromise = instance._version._domain.twilio.request({
method: "get",
Expand Down
13 changes: 8 additions & 5 deletions examples/node/lib/rest/api/v2010/account/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ export class CallContextImpl implements CallContext {
this._uri = `/Accounts/${accountSid}/Calls/${testInteger}.json`;
}

remove(callback?: any): Promise<boolean> {
remove(
callback?: (error: Error | null, item?: boolean) => any
): Promise<boolean> {
const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.remove({
Expand All @@ -118,7 +120,9 @@ export class CallContextImpl implements CallContext {
return operationPromise;
}

fetch(callback?: any): Promise<CallInstance> {
fetch(
callback?: (error: Error | null, item?: CallInstance) => any
): Promise<CallInstance> {
const instance = this;
let operationVersion = instance._version,
operationPromise = operationVersion.fetch({
Expand Down Expand Up @@ -329,7 +333,6 @@ export interface CallListInstance {
params: CallListInstanceCreateOptions,
callback?: (error: Error | null, item?: CallInstance) => any
): Promise<CallInstance>;
create(params: any, callback?: any): Promise<CallInstance>;

/**
* Provide a user-friendly representation
Expand Down Expand Up @@ -370,8 +373,8 @@ export function CallListInstance(
});

instance.create = function create(
params: any,
callback?: any
params: CallListInstanceCreateOptions,
callback?: (error: Error | null, items: CallInstance) => any
): Promise<CallInstance> {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export interface FeedbackCallSummaryContext {
params: FeedbackCallSummaryContextUpdateOptions,
callback?: (error: Error | null, item?: FeedbackCallSummaryInstance) => any
): Promise<FeedbackCallSummaryInstance>;
update(params: any, callback?: any): Promise<FeedbackCallSummaryInstance>;

/**
* Provide a user-friendly representation
Expand Down Expand Up @@ -90,7 +89,12 @@ export class FeedbackCallSummaryContextImpl
this._uri = `/Accounts/${accountSid}/Calls/Feedback/Summary/${sid}.json`;
}

update(params: any, callback?: any): Promise<FeedbackCallSummaryInstance> {
update(
params:
| FeedbackCallSummaryContextUpdateOptions
| ((error: Error | null, item?: FeedbackCallSummaryInstance) => any),
callback?: (error: Error | null, item?: FeedbackCallSummaryInstance) => any
): Promise<FeedbackCallSummaryInstance> {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
}
Expand Down Expand Up @@ -252,7 +256,11 @@ export class FeedbackCallSummaryInstance {
params: FeedbackCallSummaryContextUpdateOptions,
callback?: (error: Error | null, item?: FeedbackCallSummaryInstance) => any
): Promise<FeedbackCallSummaryInstance>;
update(params: any, callback?: any): Promise<FeedbackCallSummaryInstance> {

update(
params?: any,
callback?: (error: Error | null, item?: FeedbackCallSummaryInstance) => any
): Promise<FeedbackCallSummaryInstance> {
return this._proxy.update(params, callback);
}

Expand Down
Loading

0 comments on commit 71e2f4a

Please sign in to comment.