Skip to content

Commit

Permalink
feat: Public OAuth changes for twilio-c# (#618)
Browse files Browse the repository at this point in the history
<!--
We appreciate the effort for this pull request but before that please
make sure you read the contribution guidelines, then fill out the blanks
below.

Please format the PR title appropriately based on the type of change:
  <type>[!]: <description>
Where <type> is one of: docs, chore, feat, fix, test, misc.
Add a '!' after the type for breaking changes (e.g. feat!: new breaking
feature).

**All third-party contributors acknowledge that any contributions they
provide will be made under the same open-source license that the
open-source project is provided under.**

Please enter each Issue number you are resolving in your PR after one of
the following words [Fixes, Closes, Resolves]. This will auto-link these
issues and close them when this PR is merged!
e.g.
Fixes #1
Closes #2
-->

# Fixes #

A short description of what this PR does.
Public OAuth changes for twilio-c#
### Checklist
- [x] I acknowledge that all my contributions will be made under the
project's license
- [ ] Run `make test-docker`
- [ ] Verify affected language:
- [ ] Generate [twilio-go](https://github.com/twilio/twilio-go) from our
[OpenAPI specification](https://github.com/twilio/twilio-oai) using the
[build_twilio_go.py](./examples/build_twilio_go.py) using `python
examples/build_twilio_go.py path/to/twilio-oai/spec/yaml
path/to/twilio-go` and inspect the diff
    - [ ] Run `make test` in `twilio-go`
    - [ ] Create a pull request in `twilio-go`
    - [ ] Provide a link below to the pull request
- [ ] I have made a material change to the repo (functionality, testing,
spelling, grammar)
- [ ] I have read the [Contribution
Guidelines](https://github.com/twilio/twilio-oai-generator/blob/main/CONTRIBUTING.md)
and my PR follows them
- [ ] I have titled the PR appropriately
- [ ] I have updated my branch with the main branch
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added the necessary documentation about the functionality
in the appropriate .md file
- [ ] I have added inline documentation to the code I modified

If you have questions, please create a GitHub Issue in this repository.
  • Loading branch information
AsabuHere authored Oct 23, 2024
1 parent 78f7596 commit e10a054
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
using Twilio.Types;




namespace Twilio.Rest.Api.V2010.Account.Call
{
public class FeedbackCallSummaryResource : Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
using Twilio.Types;




namespace Twilio.Rest.Api.V2010.Account
{
public class CallResource : Resource
Expand Down
2 changes: 0 additions & 2 deletions examples/csharp/src/Twilio/Rest/Api/V2010/AccountResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
using Twilio.Types;




namespace Twilio.Rest.Api.V2010
{
public class AccountResource : Resource
Expand Down
2 changes: 0 additions & 2 deletions examples/csharp/src/Twilio/Rest/FlexApi/V1/CallResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@





namespace Twilio.Rest.FlexApi.V1
{
public class CallResource : Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@





namespace Twilio.Rest.FlexApi.V1.Credential.Aws
{
public class HistoryResource : Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@





namespace Twilio.Rest.FlexApi.V1.Credential
{
public class AwsResource : Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
using Twilio.Types;




namespace Twilio.Rest.FlexApi.V1.Credential
{
public class NewCredentialsResource : Resource
Expand Down

Large diffs are not rendered by default.

19 changes: 8 additions & 11 deletions examples/csharp/src/Twilio/Rest/PreviewIam/V1/TokenResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
using Twilio.Http;


using Twilio.Clients.NoAuth;
using Twilio.Http.NoAuth;


namespace Twilio.Rest.PreviewIam.V1
{
Expand All @@ -37,13 +34,13 @@ public class TokenResource : Resource



private static NoAuthRequest BuildCreateRequest(CreateTokenOptions options, TwilioNoAuthRestClient client)
private static Request BuildCreateRequest(CreateTokenOptions options, ITwilioRestClient client)
{

string path = "/v1/token";


return new NoAuthRequest(
return new Request(
HttpMethod.Post,
Rest.Domain.PreviewIam,
path,
Expand All @@ -57,9 +54,9 @@ private static NoAuthRequest BuildCreateRequest(CreateTokenOptions options, Twil
/// <param name="options"> Create Token parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Token </returns>
public static TokenResource Create(CreateTokenOptions options, TwilioNoAuthRestClient client = null)
public static TokenResource Create(CreateTokenOptions options, ITwilioRestClient client = null)
{
client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient();
client = client ?? TwilioClient.GetNoAuthRestClient();
var response = client.Request(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
Expand All @@ -69,9 +66,9 @@ public static TokenResource Create(CreateTokenOptions options, TwilioNoAuthRestC
/// <param name="options"> Create Token parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Token </returns>
public static async System.Threading.Tasks.Task<TokenResource> CreateAsync(CreateTokenOptions options, TwilioNoAuthRestClient client = null)
public static async System.Threading.Tasks.Task<TokenResource> CreateAsync(CreateTokenOptions options, ITwilioRestClient client = null)
{
client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient();
client = client ?? TwilioClient.GetNoAuthRestClient();
var response = await client.RequestAsync(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
Expand All @@ -97,7 +94,7 @@ public static TokenResource Create(
string audience = null,
string refreshToken = null,
string scope = null,
TwilioNoAuthRestClient client = null)
ITwilioRestClient client = null)
{
var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope };
return Create(options, client);
Expand All @@ -124,7 +121,7 @@ public static async System.Threading.Tasks.Task<TokenResource> CreateAsync(
string audience = null,
string refreshToken = null,
string scope = null,
TwilioNoAuthRestClient client = null)
ITwilioRestClient client = null)
{
var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope };
return await CreateAsync(options, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@





namespace Twilio.Rest.Versionless.DeployedDevices
{
public class FleetResource : Resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@





namespace Twilio.Rest.Versionless.Understand
{
public class AssistantResource : Resource
Expand Down
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
Loading

0 comments on commit e10a054

Please sign in to comment.