Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Public OAuth changes for twilio-c# #618

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/main/java/com/twilio/oai/TwilioCsharpGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,18 @@ public OperationsMap postProcessOperationsWithModels(final OperationsMap objs, L
final List<CodegenOperation> opList = directoryStructureService.processOperations(results);
CsharpApiResources apiResources = processCodegenOperations(opList);
apiResources.setAuthMethod(processAuthMethods(opList));
apiResources.setResourceSetPrefix(setResourceSetPrefix(apiResources.getAuthMethod()));
apiResources.setDomainClass(fetchDomainClass(apiResources.getAuthMethod()));
apiResources.setRestClientMethodName(fetchRestClientClassName(apiResources.getAuthMethod()));
apiResources.setClientName(fetchClientName(apiResources.getAuthMethod()));
apiResources.setRequestName(fetchRequestName(apiResources.getAuthMethod()));
results.put("resources", apiResources);
return results;
}

private String fetchDomainClass(String authMethod) {
if(authMethod == BEARER_TOKEN_PREFIX || authMethod == NO_AUTH_PREFIX) return ORGS_TOKEN_CLIENT;
return BASIC_CLIENT;
}

private String setResourceSetPrefix(String authMethod){
return authMethod == BEARER_TOKEN_PREFIX ? "Token" : EMPTY_STRING;
}

private String fetchClientName(String authMethod){
if(authMethod == BEARER_TOKEN_PREFIX) return "TwilioOrgsTokenRestClient";
if(authMethod == NO_AUTH_PREFIX) return "TwilioNoAuthRestClient";
return "ITwilioRestClient";
}

private String fetchRequestName(String authMethod){
if(authMethod == BEARER_TOKEN_PREFIX) return "Token";
if(authMethod == NO_AUTH_PREFIX) return "NoAuth";
return EMPTY_STRING;
}

private String fetchRestClientClassName(String authMethod){
return authMethod == NO_AUTH_PREFIX ? "GetNoAuthRestClient" : "GetRestClient";
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/twilio/oai/api/CsharpApiResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

public class CsharpApiResources extends ApiResources {
@Getter @Setter private String authMethod;
@Getter @Setter private String resourceSetPrefix;
@Getter @Setter private String domainClass;
@Getter @Setter private String restClientMethodName;
@Getter @Setter private String clientName;
@Getter @Setter private String requestName;
List<IJsonSchemaValidationProperties> enums = new ArrayList<>(OperationStore.getInstance().getEnums().values());

public String resourceConstant = ApplicationConstants.RESOURCE;
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/twilio-csharp/Pagination.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
/// <param name="targetUrl"> API-generated URL for the requested results page </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> The target page of records </returns>
public static Page<{{apiName}}{{resourceConstant}}> GetPage(string targetUrl, {{clientName}} client)
public static Page<{{apiName}}{{resourceConstant}}> GetPage(string targetUrl, ITwilioRestClient client)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();

var request = new {{requestName}}Request(
var request = new Request(
HttpMethod.Get,
targetUrl
);
Expand All @@ -20,9 +20,9 @@
/// <param name="page"> current page of records </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> The next page of records </returns>
public static Page<{{apiName}}{{resourceConstant}}> NextPage(Page<{{apiName}}{{resourceConstant}}> page, {{clientName}} client)
public static Page<{{apiName}}{{resourceConstant}}> NextPage(Page<{{apiName}}{{resourceConstant}}> page, ITwilioRestClient client)
{
var request = new {{requestName}}Request(
var request = new Request(
HttpMethod.Get,
page.GetNextPageUrl(Rest.Domain.Api)
);
Expand All @@ -35,9 +35,9 @@
/// <param name="page"> current page of records </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> The previous page of records </returns>
public static Page<{{apiName}}{{resourceConstant}}> PreviousPage(Page<{{apiName}}{{resourceConstant}}> page, {{clientName}} client)
public static Page<{{apiName}}{{resourceConstant}}> PreviousPage(Page<{{apiName}}{{resourceConstant}}> page, ITwilioRestClient client)
{
var request = new {{requestName}}Request(
var request = new Request(
HttpMethod.Get,
page.GetPreviousPageUrl(Rest.Domain.Api)
);
Expand Down
7 changes: 1 addition & 6 deletions src/main/resources/twilio-csharp/ResourceUsings.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,4 @@ using Twilio.Constant;
using Twilio.Converters;
using Twilio.Exceptions;
using Twilio.Http;
{{#metaProperties}}{{#enum-exists-resource}}using Twilio.Types;{{/enum-exists-resource}}{{/metaProperties}}
{{#metaProperties}}{{#auth_method-bearer-token}}using Twilio.Base.BearerToken;
using Twilio.Clients.BearerToken;
using Twilio.Http.BearerToken;{{/auth_method-bearer-token}}{{/metaProperties}}
{{#metaProperties}}{{#auth_method-no-auth}}using Twilio.Clients.NoAuth;
using Twilio.Http.NoAuth;{{/auth_method-no-auth}}{{/metaProperties}}
{{#metaProperties}}{{#enum-exists-resource}}using Twilio.Types;{{/enum-exists-resource}}{{/metaProperties}}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

private static {{requestName}}Request BuildCreateRequest(Create{{apiName}}Options options, {{clientName}} client)
private static Request BuildCreateRequest(Create{{apiName}}Options options, ITwilioRestClient client)
{
{{>resource/GeneratePath}}
return new {{requestName}}Request(
return new Request(
{{vendorExtensions.x-http-method}},
Rest.Domain.{{domainPackage}},
path,
Expand All @@ -21,9 +21,9 @@
/// <param name="options"> Create {{apiName}} parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnComments}}
public static {{apiName}}{{resourceConstant}} Create(Create{{apiName}}Options options, {{clientName}} client = null)
public static {{apiName}}{{resourceConstant}} Create(Create{{apiName}}Options options, ITwilioRestClient client = null)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();
var response = client.Request(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
Expand All @@ -33,9 +33,9 @@
/// <param name="options"> Create {{apiName}} parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnCommentsAsync}}
public static async System.Threading.Tasks.Task<{{apiName}}{{resourceConstant}}> CreateAsync(Create{{apiName}}Options options, {{clientName}} client = null)
public static async System.Threading.Tasks.Task<{{apiName}}{{resourceConstant}}> CreateAsync(Create{{apiName}}Options options, ITwilioRestClient client = null)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();
var response = await client.RequestAsync(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
Expand All @@ -45,7 +45,7 @@
{{>resource/ReturnComments}}
public static {{apiName}}{{resourceConstant}} Create({{#vendorExtensions.x-request-body-param}}
{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}},{{/vendorExtensions.x-request-body-param}}
{{clientName}} client = null)
ITwilioRestClient client = null)
{
var options = new Create{{apiName}}Options({{#requiredParams}}{{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}}, {{/-last}}{{/requiredParams}}){ {{#vendorExtensions.x-request-body-param}}{{^required}} {{paramName}} = {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}},{{/-last}}{{/required}}{{/vendorExtensions.x-request-body-param}} };
return Create(options, client);
Expand All @@ -56,7 +56,7 @@
{{>resource/ReturnCommentsAsync}}
public static async System.Threading.Tasks.Task<{{apiName}}{{resourceConstant}}> CreateAsync({{#vendorExtensions.x-request-body-param}}
{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}},{{/vendorExtensions.x-request-body-param}}
{{clientName}} client = null)
ITwilioRestClient client = null)
{
var options = new Create{{apiName}}Options({{#requiredParams}}{{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}}, {{/-last}}{{/requiredParams}}){ {{#vendorExtensions.x-request-body-param}}{{^required}} {{paramName}} = {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}},{{/-last}}{{/required}}{{/vendorExtensions.x-request-body-param}} };
return await CreateAsync(options, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/// <param name="options"> Delete {{apiName}} parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnComments}}
private static {{requestName}}Request BuildDeleteRequest(Delete{{apiName}}Options options, {{clientName}} client)
private static Request BuildDeleteRequest(Delete{{apiName}}Options options, ITwilioRestClient client)
{
{{>resource/GeneratePath}}
return new {{requestName}}Request(
return new Request(
{{vendorExtensions.x-http-method}},
Rest.Domain.{{domainPackage}},
path,
Expand All @@ -19,9 +19,9 @@
/// <param name="options"> Delete {{apiName}} parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnComments}}
public static bool Delete(Delete{{apiName}}Options options, {{clientName}} client = null)
public static bool Delete(Delete{{apiName}}Options options, ITwilioRestClient client = null)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();
var response = client.Request(BuildDeleteRequest(options, client));
return response.StatusCode == System.Net.HttpStatusCode.NoContent;
}
Expand All @@ -32,17 +32,17 @@
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnCommentsAsync}}
public static async System.Threading.Tasks.Task<bool> DeleteAsync(Delete{{apiName}}Options options,
{{clientName}} client = null)
ITwilioRestClient client = null)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();
var response = await client.RequestAsync(BuildDeleteRequest(options, client));
return response.StatusCode == System.Net.HttpStatusCode.NoContent;
}
#endif

{{>Summary}}{{>resource/MethodsComments}}
{{>resource/ReturnComments}}
public static bool Delete({{#vendorExtensions.x-request-body-param}}{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}{{clientName}} client = null)
public static bool Delete({{#vendorExtensions.x-request-body-param}}{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}ITwilioRestClient client = null)
{
var options = new Delete{{apiName}}Options({{#requiredParams}}{{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}}, {{/-last}}{{/requiredParams}}) {{#vendorExtensions.x-request-body-param}} {{^required}} { {{paramName}} = {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}},{{/-last}} }{{/required}} {{/vendorExtensions.x-request-body-param}} ;
return Delete(options, client);
Expand All @@ -51,7 +51,7 @@
#if !NET35
{{>Summary}}{{>resource/MethodsComments}}
{{>resource/ReturnCommentsAsync}}
public static async System.Threading.Tasks.Task<bool> DeleteAsync({{#vendorExtensions.x-request-body-param}}{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}{{clientName}} client = null)
public static async System.Threading.Tasks.Task<bool> DeleteAsync({{#vendorExtensions.x-request-body-param}}{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}ITwilioRestClient client = null)
{
var options = new Delete{{apiName}}Options({{#requiredParams}}{{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}}, {{/-last}}{{/requiredParams}}) {{#vendorExtensions.x-request-body-param}}{{^required}} { {{paramName}} = {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}},{{/-last}} }{{/required}}{{/vendorExtensions.x-request-body-param}};
return await DeleteAsync(options, client);
Expand Down
16 changes: 8 additions & 8 deletions src/main/resources/twilio-csharp/resource/FetchResource.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

private static {{requestName}}Request BuildFetchRequest(Fetch{{apiName}}Options options, {{clientName}} client)
private static Request BuildFetchRequest(Fetch{{apiName}}Options options, ITwilioRestClient client)
{
{{>resource/GeneratePath}}
return new {{requestName}}Request(
return new Request(
{{vendorExtensions.x-http-method}},
Rest.Domain.{{domainPackage}},
path,
Expand All @@ -15,9 +15,9 @@
/// <param name="options"> Fetch {{apiName}} parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnComments}}
public static {{apiName}}Resource Fetch(Fetch{{apiName}}Options options, {{clientName}} client = null)
public static {{apiName}}Resource Fetch(Fetch{{apiName}}Options options, ITwilioRestClient client = null)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();
var response = client.Request(BuildFetchRequest(options, client));
return FromJson(response.Content);
}
Expand All @@ -27,9 +27,9 @@
/// <param name="options"> Fetch {{apiName}} parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
{{>resource/ReturnCommentsAsync}}
public static async System.Threading.Tasks.Task<{{apiName}}Resource> FetchAsync(Fetch{{apiName}}Options options, {{clientName}} client = null)
public static async System.Threading.Tasks.Task<{{apiName}}Resource> FetchAsync(Fetch{{apiName}}Options options, ITwilioRestClient client = null)
{
client = client ?? {{domainClass}}.{{restClientMethodName}}();
client = client ?? TwilioClient.{{restClientMethodName}}();
var response = await client.RequestAsync(BuildFetchRequest(options, client));
return FromJson(response.Content);
}
Expand All @@ -38,7 +38,7 @@
{{>resource/ReturnComments}}
public static {{apiName}}{{resourceConstant}} Fetch({{#vendorExtensions.x-request-body-param}}
{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}
{{clientName}} client = null)
ITwilioRestClient client = null)
{
var options = new Fetch{{apiName}}Options({{#requiredParams}}{{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}}, {{/-last}}{{/requiredParams}}){ {{#vendorExtensions.x-request-body-param}}{{^required}}{{paramName}} = {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}},{{/-last}}{{/required}}{{/vendorExtensions.x-request-body-param}} };
return Fetch(options, client);
Expand All @@ -47,7 +47,7 @@
#if !NET35
{{>Summary}}{{>resource/MethodsComments}}
{{>resource/ReturnCommentsAsync}}
public static async System.Threading.Tasks.Task<{{apiName}}{{resourceConstant}}> FetchAsync({{#vendorExtensions.x-request-body-param}}{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}{{clientName}} client = null)
public static async System.Threading.Tasks.Task<{{apiName}}{{resourceConstant}}> FetchAsync({{#vendorExtensions.x-request-body-param}}{{{dataType}}} {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^required}} = null{{/required}}, {{/vendorExtensions.x-request-body-param}}ITwilioRestClient client = null)
{
var options = new Fetch{{apiName}}Options({{#requiredParams}}{{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}}, {{/-last}}{{/requiredParams}}){ {{#vendorExtensions.x-request-body-param}}{{^required}}{{paramName}} = {{#lambda.camelcase}}{{paramName}}{{/lambda.camelcase}}{{^-last}},{{/-last}}{{/required}}{{/vendorExtensions.x-request-body-param}} };
return await FetchAsync(options, client);
Expand Down
Loading
Loading