From 6f6cd97f7b3f57c839dc59d1bec9551a45a87f7a Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 22 Jul 2024 10:32:54 +0530 Subject: [PATCH 01/24] Changes for orgs api uptake --- .../BearerToken/BearerTokenResourceSet.cs | 122 +++ .../TwilioBearerTokenRestClient.cs | 317 +++++++ .../Clients/NoAuth/TwilioNoAuthRestClient.cs | 275 ++++++ src/Twilio/Constant/EnumConstants.cs | 1 + .../Http/BearerToken/BearerTokenHttpClient.cs | 41 + .../Http/BearerToken/BearerTokenRequest.cs | 300 +++++++ .../Http/BearerToken/OrgsTokenManager.cs | 65 ++ .../SystemNetBearerTokenHttpClient.cs | 142 ++++ src/Twilio/Http/BearerToken/TokenManager.cs | 18 + .../Http/Net35/WebBearerTokenRequestClient.cs | 94 +++ .../Http/Net35/WebNoAuthRequestClient.cs | 91 ++ src/Twilio/Http/NoAuth/NoAuthHttpClient.cs | 41 + src/Twilio/Http/NoAuth/NoAuthRequest.cs | 288 +++++++ .../Http/NoAuth/SystemNetNoAuthHttpClient.cs | 139 +++ .../Organizations/AccountOptions.cs | 95 +++ .../Organizations/AccountResource.cs | 327 ++++++++ .../Organizations/AuthorizeOptions.cs | 83 ++ .../Organizations/AuthorizeResource.cs | 159 ++++ .../Organizations/RoleAssignmentOptions.cs | 145 ++++ .../Organizations/RoleAssignmentResource.cs | 428 ++++++++++ .../PreviewIam/Organizations/TokenOptions.cs | 110 +++ .../PreviewIam/Organizations/TokenResource.cs | 195 +++++ .../PreviewIam/Organizations/UserOptions.cs | 225 +++++ .../PreviewIam/Organizations/UserResource.cs | 789 ++++++++++++++++++ src/Twilio/TwilioNoAuth.cs | 64 ++ src/Twilio/TwilioOrgsTokenAuth.cs | 160 ++++ 26 files changed, 4714 insertions(+) create mode 100644 src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs create mode 100644 src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs create mode 100644 src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs create mode 100644 src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs create mode 100644 src/Twilio/Http/BearerToken/BearerTokenRequest.cs create mode 100644 src/Twilio/Http/BearerToken/OrgsTokenManager.cs create mode 100644 src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs create mode 100644 src/Twilio/Http/BearerToken/TokenManager.cs create mode 100644 src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs create mode 100644 src/Twilio/Http/Net35/WebNoAuthRequestClient.cs create mode 100644 src/Twilio/Http/NoAuth/NoAuthHttpClient.cs create mode 100644 src/Twilio/Http/NoAuth/NoAuthRequest.cs create mode 100644 src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs create mode 100644 src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs create mode 100644 src/Twilio/TwilioNoAuth.cs create mode 100644 src/Twilio/TwilioOrgsTokenAuth.cs diff --git a/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs b/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs new file mode 100644 index 000000000..8f4e4ce98 --- /dev/null +++ b/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs @@ -0,0 +1,122 @@ +using System; +using System.Reflection; +using System.Collections.Generic; +using Twilio.Clients; +using Twilio.Clients.BearerToken; + +namespace Twilio.Base.BearerToken +{ + /// + /// A collection of resources of type T + /// + /// + /// Resource Type + public class BearerTokenResourceSet : IEnumerable where T : Resource + { + /// + /// Automatically iterate through pages of results + /// + public bool AutoPaging { get; set; } + + private readonly TwilioBearerTokenRestClient _client; + private readonly ReadOptions _options; + private readonly long _pageLimit; + + private long _pages; + private long _processed; + private Page _page; + private IEnumerator _iterator; + + /// + /// Create a new resource set + /// + /// + /// Page of resources + /// Read options + /// Client to make requests + public BearerTokenResourceSet(Page page, ReadOptions options, TwilioBearerTokenRestClient client) + { + _page = page; + _options = options; + _client = client; + + _iterator = page.Records.GetEnumerator(); + _processed = 0; + _pages = 1; + _pageLimit = long.MaxValue; + + AutoPaging = true; + + if (_options.Limit != null) + { + _pageLimit = (long) (Math.Ceiling((double) _options.Limit.Value / page.PageSize)); + } + } + + /// + /// Get iterator for resources + /// + /// + /// IEnumerator of resources + public IEnumerator GetEnumerator() + { + while (_page != null) + { + _iterator.Reset(); + while (_iterator.MoveNext()) + { + // Exit if we've reached item limit + if (_options.Limit != null && _processed > _options.Limit.Value) + { + yield break; + } + + _processed++; + yield return _iterator.Current; + } + + if (AutoPaging && _page.HasNextPage()) + { + FetchNextPage(); + } + else + { + break; + } + } + } + + /// + /// Get iterator for resources + /// + /// + /// IEnumerator of resources + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + private void FetchNextPage() + { + if (!_page.HasNextPage() || _pages >= _pageLimit) + { + _page = null; + _iterator = null; + return; + } + + _pages++; + _page = (Page)GetNextPage().Invoke(null, new object[]{ _page, _client }); + _iterator = _page.Records.GetEnumerator(); + } + + private static MethodInfo GetNextPage() + { +#if !NET35 + return typeof(T).GetRuntimeMethod("NextPage", new[]{ typeof(Page), typeof(TwilioBearerTokenRestClient) }); +#else + return typeof(T).GetMethod("NextPage", new[]{ typeof(Page), typeof(TwilioBearerTokenRestClient) }); +#endif + } + } +} diff --git a/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs new file mode 100644 index 000000000..42477abd4 --- /dev/null +++ b/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs @@ -0,0 +1,317 @@ + +using System; +using System.Net; +using System.Linq; +using Newtonsoft.Json; +using Twilio.Exceptions; +using Twilio.Http.BearerToken; +using Twilio.Jwt; + + +#if !NET35 +using System.Threading.Tasks; +#endif + +using Twilio.Http; +using Twilio.Http.BearerToken; +#if NET35 +using Twilio.Http.Net35; +#endif + + +namespace Twilio.Clients.BearerToken +{ + /// + /// Implementation of a TwilioRestClient. + /// + public class TwilioBearerTokenRestClient + { + /// + /// Client to make HTTP requests + /// + public BearerTokenHttpClient HttpClient { get; } + + /// + /// Twilio region to make requests to + /// + public string Region { get; } + + /// + /// Twilio edge to make requests to + /// + public string Edge { get; set; } + + /// + /// Additions to the user agent string + /// + public string[] UserAgentExtensions { get; set; } + + /// + /// Log level for logging + /// + public string LogLevel { get; set; } = Environment.GetEnvironmentVariable("TWILIO_LOG_LEVEL"); + + /// + /// Token Manage for managing and refreshing tokens + /// + private TokenManager _tokenManager { get; set; } + + /// + /// Access token used for rest calls with bearer token authentication method + /// + private string _accessToken; + + private readonly object lockObject = new object(); + + /// + /// Constructor for a TwilioRestClient + /// + /// + /// to manage access token for requests + /// account sid to make requests for + /// region to make requests for + /// http client used to make the requests + /// edge to make requests for + public TwilioBearerTokenRestClient( + TokenManager tokenManager, + string region = null, + BearerTokenHttpClient httpClient = null, + string edge = null + ) + { + _tokenManager = tokenManager; + + HttpClient = httpClient ?? DefaultClient(); + + Region = region; + Edge = edge; + } + + /// + /// Make a request to the Twilio API + /// + /// + /// request to make + /// response of the request + public Response Request(BearerTokenRequest request) + { + + if (_accessToken == null ){ + //|| isTokenExpired(_accessToken)) { + lock (lockObject){ + if (_accessToken == null){ + //|| isTokenExpired(_accessToken)) { + _accessToken = _tokenManager.fetchAccessToken(); + } + } + } + request.SetAuth(_accessToken); + + if (LogLevel == "debug") + LogRequest(request); + + if (Region != null) + request.Region = Region; + + if (Edge != null) + request.Edge = Edge; + + if (UserAgentExtensions != null) + request.UserAgentExtensions = UserAgentExtensions; + + Response response; + try + { + response = HttpClient.MakeRequest(request); + if (LogLevel == "debug") + { + Console.WriteLine("response.status: " + response.StatusCode); + Console.WriteLine("response.headers: " + response.Headers); + } + } + catch (Exception clientException) + { + throw new ApiConnectionException( + "Connection Error: " + request.Method + request.ConstructUrl(), + clientException + ); + } + return ProcessResponse(response); + } + + /// + /// To check if token is expired or not + /// + /// + /// token to validate + /// True if token is not expired, false otherwise +// public bool isTokenExpired(String token) { +// +// var tokenHandler = new JwtSecurityTokenHandler(); +// var jwtToken = tokenHandler.ReadJwtToken(token); +// var expirationTime = jwtToken.Payload.Exp.HasValue +// ? DateTimeOffset.FromUnixTimeSeconds(jwtToken.Payload.Exp.Value) +// : DateTimeOffset.MinValue; +// return expirationTime <= DateTimeOffset.UtcNow; +// } + +#if !NET35 + /// + /// Make a request to the Twilio API + /// + /// + /// request to make + /// Task that resolves to the response of the request + public async Task RequestAsync(BearerTokenRequest request) + { + request.SetAuth(_accessToken); + + if (Region != null) + request.Region = Region; + + if (Edge != null) + request.Edge = Edge; + + if (UserAgentExtensions != null) + request.UserAgentExtensions = UserAgentExtensions; + + Response response; + try + { + response = await HttpClient.MakeRequestAsync(request); + } + catch (Exception clientException) + { + throw new ApiConnectionException( + "Connection Error: " + request.Method + request.ConstructUrl(), + clientException + ); + } + return ProcessResponse(response); + } + + private static BearerTokenHttpClient DefaultClient() + { + return new SystemNetBearerTokenHttpClient(); + } +#else + private static BearerTokenHttpClient DefaultClient() + { + return new WebBearerTokenRequestClient(); + } +#endif + + private static Response ProcessResponse(Response response) + { + if (response == null) + { + throw new ApiConnectionException("Connection Error: No response received."); + } + + if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode < HttpStatusCode.BadRequest) + { + return response; + } + + // Deserialize and throw exception + RestException restException = null; + try + { + restException = RestException.FromJson(response.Content); + } + catch (JsonReaderException) { /* Allow null check below to handle */ } + + if (restException == null) + { + throw new ApiException("Api Error: " + response.StatusCode + " - " + (response.Content ?? "[no content]")); + } + + throw new ApiException( + restException.Code, + (int)response.StatusCode, + restException.Message ?? "Unable to make request, " + response.StatusCode, + restException.MoreInfo, + restException.Details + ); + } + + /// + /// Test if your environment is impacted by a TLS or certificate change + /// by sending an HTTP request to the test endpoint tls-test.twilio.com:443 + /// It's a bit easier to call this method from TwilioClient.ValidateSslCertificate(). + /// + public static void ValidateSslCertificate() + { + ValidateSslCertificate(DefaultClient()); + } + + /// + /// Test that this application can use updated SSL certificates on + /// tls-test.twilio.com:443. Generally, you'll want to use the version of this + /// function that takes no parameters unless you have a reason not to. + /// + /// + /// HTTP Client to use for testing the request + public static void ValidateSslCertificate(BearerTokenHttpClient client) + { + BearerTokenRequest request = new BearerTokenRequest("GET", "tls-test", ":443/", null); + + try + { + Response response = client.MakeRequest(request); + + if (!response.StatusCode.Equals(HttpStatusCode.OK)) + { + throw new CertificateValidationException( + "Unexpected response from certificate endpoint", + null, + response + ); + } + } + catch (CertificateValidationException e) + { + throw e; + } + catch (Exception e) + { + throw new CertificateValidationException( + "Connection to tls-test.twilio.com:443 failed", + e, + null + ); + } + } + + /// + /// Format request information when LogLevel is set to debug + /// + /// + /// HTTP request + private static void LogRequest(BearerTokenRequest request) + { + Console.WriteLine("-- BEGIN Twilio API Request --"); + Console.WriteLine("request.method: " + request.Method); + Console.WriteLine("request.URI: " + request.Uri); + + if (request.QueryParams != null) + { + request.QueryParams.ForEach(parameter => Console.WriteLine(parameter.Key + ":" + parameter.Value)); + } + + if (request.HeaderParams != null) + { + for (int i = 0; i < request.HeaderParams.Count; i++) + { + var lowercaseHeader = request.HeaderParams[i].Key.ToLower(); + if (lowercaseHeader.Contains("authorization") == false) + { + Console.WriteLine(request.HeaderParams[i].Key + ":" + request.HeaderParams[i].Value); + } + } + } + + Console.WriteLine("-- END Twilio API Request --"); + } + } +} diff --git a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs new file mode 100644 index 000000000..8a0fae478 --- /dev/null +++ b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs @@ -0,0 +1,275 @@ +using System; +using System.Net; +using System.Linq; +using Newtonsoft.Json; +using Twilio.Exceptions; +using Twilio.Http.BearerToken; +using Twilio.Jwt; + + +#if !NET35 +using System.Threading.Tasks; +#endif + +using Twilio.Http; +using Twilio.Http.NoAuth; +#if NET35 +using Twilio.Http.Net35; +#endif + + +namespace Twilio.Clients.NoAuth +{ + /// + /// Implementation of a TwilioRestClient. + /// + public class TwilioNoAuthRestClient + { + /// + /// Client to make HTTP requests + /// + public NoAuthHttpClient HttpClient { get; } + + /// + /// Twilio region to make requests to + /// + public string Region { get; } + + /// + /// Twilio edge to make requests to + /// + public string Edge { get; set; } + + /// + /// Additions to the user agent string + /// + public string[] UserAgentExtensions { get; set; } + + /// + /// Log level for logging + /// + public string LogLevel { get; set; } = Environment.GetEnvironmentVariable("TWILIO_LOG_LEVEL"); + + /// + /// Constructor for a TwilioRestClient + /// + /// + /// access token for requests + /// account sid to make requests for + /// region to make requests for + /// http client used to make the requests + /// edge to make requests for + public TwilioNoAuthRestClient( + string region = null, + NoAuthHttpClient httpClient = null, + string edge = null + ) + { + + HttpClient = httpClient ?? DefaultClient(); + + Region = region; + Edge = edge; + } + + /// + /// Make a request to the Twilio API + /// + /// + /// request to make + /// response of the request + public Response Request(NoAuthRequest request) + { + + if (LogLevel == "debug") + LogRequest(request); + + if (Region != null) + request.Region = Region; + + if (Edge != null) + request.Edge = Edge; + + if (UserAgentExtensions != null) + request.UserAgentExtensions = UserAgentExtensions; + + Response response; + try + { + response = HttpClient.MakeRequest(request); + if (LogLevel == "debug") + { + Console.WriteLine("response.status: " + response.StatusCode); + Console.WriteLine("response.headers: " + response.Headers); + } + } + catch (Exception clientException) + { + throw new ApiConnectionException( + "Connection Error: " + request.Method + request.ConstructUrl(), + clientException + ); + } + return ProcessResponse(response); + } + + +#if !NET35 + /// + /// Make a request to the Twilio API + /// + /// + /// request to make + /// Task that resolves to the response of the request + public async Task RequestAsync(NoAuthRequest request) + { + + if (Region != null) + request.Region = Region; + + if (Edge != null) + request.Edge = Edge; + + if (UserAgentExtensions != null) + request.UserAgentExtensions = UserAgentExtensions; + + Response response; + try + { + response = await HttpClient.MakeRequestAsync(request); + } + catch (Exception clientException) + { + throw new ApiConnectionException( + "Connection Error: " + request.Method + request.ConstructUrl(), + clientException + ); + } + return ProcessResponse(response); + } + + private static NoAuthHttpClient DefaultClient() + { + return new SystemNetNoAuthHttpClient(); + } +#else + private static NoAuthHttpClient DefaultClient() + { + return new WebNoAuthRequestClient(); + } +#endif + + private static Response ProcessResponse(Response response) + { + if (response == null) + { + throw new ApiConnectionException("Connection Error: No response received."); + } + + if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode < HttpStatusCode.BadRequest) + { + return response; + } + + // Deserialize and throw exception + RestException restException = null; + try + { + restException = RestException.FromJson(response.Content); + } + catch (JsonReaderException) { /* Allow null check below to handle */ } + + if (restException == null) + { + throw new ApiException("Api Error: " + response.StatusCode + " - " + (response.Content ?? "[no content]")); + } + + throw new ApiException( + restException.Code, + (int)response.StatusCode, + restException.Message ?? "Unable to make request, " + response.StatusCode, + restException.MoreInfo, + restException.Details + ); + } + + /// + /// Test if your environment is impacted by a TLS or certificate change + /// by sending an HTTP request to the test endpoint tls-test.twilio.com:443 + /// It's a bit easier to call this method from TwilioClient.ValidateSslCertificate(). + /// + public static void ValidateSslCertificate() + { + ValidateSslCertificate(DefaultClient()); + } + + /// + /// Test that this application can use updated SSL certificates on + /// tls-test.twilio.com:443. Generally, you'll want to use the version of this + /// function that takes no parameters unless you have a reason not to. + /// + /// + /// HTTP Client to use for testing the request + public static void ValidateSslCertificate(NoAuthHttpClient client) + { + NoAuthRequest request = new NoAuthRequest("GET", "tls-test", ":443/", null); + + try + { + Response response = client.MakeRequest(request); + + if (!response.StatusCode.Equals(HttpStatusCode.OK)) + { + throw new CertificateValidationException( + "Unexpected response from certificate endpoint", + null, + response + ); + } + } + catch (CertificateValidationException e) + { + throw e; + } + catch (Exception e) + { + throw new CertificateValidationException( + "Connection to tls-test.twilio.com:443 failed", + e, + null + ); + } + } + + /// + /// Format request information when LogLevel is set to debug + /// + /// + /// HTTP request + private static void LogRequest(NoAuthRequest request) + { + Console.WriteLine("-- BEGIN Twilio API Request --"); + Console.WriteLine("request.method: " + request.Method); + Console.WriteLine("request.URI: " + request.Uri); + + if (request.QueryParams != null) + { + request.QueryParams.ForEach(parameter => Console.WriteLine(parameter.Key + ":" + parameter.Value)); + } + + if (request.HeaderParams != null) + { + for (int i = 0; i < request.HeaderParams.Count; i++) + { + var lowercaseHeader = request.HeaderParams[i].Key.ToLower(); + if (lowercaseHeader.Contains("authorization") == false) + { + Console.WriteLine(request.HeaderParams[i].Key + ":" + request.HeaderParams[i].Value); + } + } + } + + Console.WriteLine("-- END Twilio API Request --"); + } + } +} diff --git a/src/Twilio/Constant/EnumConstants.cs b/src/Twilio/Constant/EnumConstants.cs index 9a9332e28..8be6a71f1 100644 --- a/src/Twilio/Constant/EnumConstants.cs +++ b/src/Twilio/Constant/EnumConstants.cs @@ -11,6 +11,7 @@ public sealed class ContentTypeEnum : StringEnum { private ContentTypeEnum(string value) : base(value) {} public static readonly ContentTypeEnum JSON = new ContentTypeEnum("application/json"); + public static readonly ContentTypeEnum SCIM = new ContentTypeEnum("application/scim"); public static readonly ContentTypeEnum FORM_URLENCODED = new ContentTypeEnum("application/x-www-form-urlencoded"); } } diff --git a/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs new file mode 100644 index 000000000..45f855da0 --- /dev/null +++ b/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs @@ -0,0 +1,41 @@ +using System; + +namespace Twilio.Http.BearerToken +{ + /// + /// Base http client used to make Twilio requests + /// + public abstract class BearerTokenHttpClient + { + /// + /// The last request made by this client + /// + public BearerTokenRequest LastRequest { get; protected set; } + + /// + /// The last response received by this client + /// + public Response LastResponse { get; protected set; } + + /// + /// Make a request to Twilio, returns non-2XX responses as well + /// + /// + /// request to make + /// throws exception on network or connection errors. + /// response of the request + public abstract Response MakeRequest(BearerTokenRequest request); + +#if !NET35 + /// + /// Make an async request to Twilio, returns non-2XX responses as well + /// + /// + /// request to make + /// throws exception on network or connection errors. + /// response of the request + public abstract System.Threading.Tasks.Task MakeRequestAsync(BearerTokenRequest request); +#endif + + } +} diff --git a/src/Twilio/Http/BearerToken/BearerTokenRequest.cs b/src/Twilio/Http/BearerToken/BearerTokenRequest.cs new file mode 100644 index 000000000..33f5915e2 --- /dev/null +++ b/src/Twilio/Http/BearerToken/BearerTokenRequest.cs @@ -0,0 +1,300 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Twilio.Constant; +using Twilio.Rest; + +#if !NET35 +using System.Net; +#else +using System.Web; +#endif + +namespace Twilio.Http.BearerToken +{ + /// + /// Twilio request object with bearer token authentication + /// + public class BearerTokenRequest + { + private static readonly string DEFAULT_REGION = "us1"; + + /// + /// HTTP Method + /// + public HttpMethod Method { get; } + + public Uri Uri { get; private set; } + + /// + /// Auth username + /// + public string AccessToken { get; set; } + + /// + /// Twilio region + /// + public string Region { get; set; } + + /// + /// Twilio edge + /// + public string Edge { get; set; } + + /// + /// Additions to the user agent string + /// + public string[] UserAgentExtensions { get; set; } + + /// + /// Query params + /// + public List> QueryParams { get; private set; } + + /// + /// Post params + /// + public List> PostParams { get; private set; } + + /// + /// Header params + /// + public List> HeaderParams { get; private set; } + + /// + /// Content Type + /// + public EnumConstants.ContentTypeEnum ContentType { get; set; } + + /// + /// Body + /// + public string Body { get; set; } + + /// + /// Create a new Twilio request + /// + /// HTTP Method + /// Request URL + public BearerTokenRequest(HttpMethod method, string url) + { + Method = method; + Uri = new Uri(url); + QueryParams = new List>(); + PostParams = new List>(); + HeaderParams = new List>(); + } + + /// + /// Create a new Twilio request + /// + /// HTTP method + /// Twilio subdomain + /// Request URI + /// Twilio region + /// Query parameters + /// Post data + /// Twilio edge + /// Custom header data + /// Content Type + /// Request Body + public BearerTokenRequest( + HttpMethod method, + Domain domain, + string uri, + string region = null, + List> queryParams = null, + List> postParams = null, + string edge = null, + List> headerParams = null, + EnumConstants.ContentTypeEnum contentType = null, + string body = null + ) + { + Method = method; + Uri = new Uri("https://" + domain + ".twilio.com" + uri); + Region = region; + Edge = edge; + + QueryParams = queryParams ?? new List>(); + PostParams = postParams ?? new List>(); + HeaderParams = headerParams ?? new List>(); + + ContentType = contentType; + Body = body; + } + + /// + /// Construct the request URL + /// + /// Built URL including query parameters + public Uri ConstructUrl() + { + var uri = buildUri(); + return QueryParams.Count > 0 ? + new Uri(uri.AbsoluteUri + "?" + EncodeParameters(QueryParams)) : + new Uri(uri.AbsoluteUri); + } + + public Uri buildUri() + { + if (Region != null || Edge != null) + { + var uriBuilder = new UriBuilder(Uri); + var pieces = uriBuilder.Host.Split('.'); + var product = pieces[0]; + var domain = String.Join(".", pieces.Skip(pieces.Length - 2).ToArray()); + + var region = Region; + var edge = Edge; + + if (pieces.Length == 4) // product.region.twilio.com + { + region = region ?? pieces[1]; + } + else if (pieces.Length == 5) // product.edge.region.twilio.com + { + edge = edge ?? pieces[1]; + region = region ?? pieces[2]; + } + + if (edge != null && region == null) + region = DEFAULT_REGION; + + string[] parts = { product, edge, region, domain }; + + uriBuilder.Host = String.Join(".", Array.FindAll(parts, part => !string.IsNullOrEmpty(part))); + return uriBuilder.Uri; + } + + return Uri; + } + + /// + /// Set auth for the request + /// + /// Auth accessToken + public void SetAuth(string accessToken) + { + AccessToken = accessToken; + } + + private static string EncodeParameters(IEnumerable> data) + { + var result = ""; + var first = true; + foreach (var pair in data) + { + if (first) + { + first = false; + } + else + { + result += "&"; + } + +#if !NET35 + result += WebUtility.UrlEncode(pair.Key) + "=" + WebUtility.UrlEncode(pair.Value); +#else + result += HttpUtility.UrlEncode(pair.Key) + "=" + HttpUtility.UrlEncode(pair.Value); +#endif + } + + return result; + } + + /// + /// Encode POST data for transfer + /// + /// Encoded byte array + public byte[] EncodePostParams() + { + return Encoding.UTF8.GetBytes(EncodeParameters(PostParams)); + } + + /// + /// Add query parameter to request + /// + /// name of parameter + /// value of parameter + public void AddQueryParam(string name, string value) + { + AddParam(QueryParams, name, value); + } + + /// + /// Add a parameter to the request payload + /// + /// name of parameter + /// value of parameter + public void AddPostParam(string name, string value) + { + AddParam(PostParams, name, value); + } + + /// + /// Add a header parameter + /// + /// name of parameter + /// value of parameter + public void AddHeaderParam(string name, string value) + { + AddParam(HeaderParams, name, value); + } + + private static void AddParam(ICollection> list, string name, string value) + { + list.Add(new KeyValuePair(name, value)); + } + + /// + /// Compare request + /// + /// object to compare to + /// true if requests are equal; false otherwise + public override bool Equals(object obj) + { + if (obj == null) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != typeof(Request)) + { + return false; + } + + var other = (Request)obj; + return Method.Equals(other.Method) && + buildUri().Equals(other.buildUri()) && + QueryParams.All(other.QueryParams.Contains) && + other.QueryParams.All(QueryParams.Contains) && + PostParams.All(other.PostParams.Contains) && + other.PostParams.All(PostParams.Contains) && + HeaderParams.All(other.HeaderParams.Contains) && + other.HeaderParams.All(HeaderParams.Contains); + } + + /// + /// Generate hash code for request + /// + /// generated hash code + public override int GetHashCode() + { + unchecked + { + return (Method?.GetHashCode() ?? 0) ^ + (buildUri()?.GetHashCode() ?? 0) ^ + (QueryParams?.GetHashCode() ?? 0) ^ + (PostParams?.GetHashCode() ?? 0) ^ + (HeaderParams?.GetHashCode() ?? 0); + } + } + } +} diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs new file mode 100644 index 000000000..55bf1c5ec --- /dev/null +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -0,0 +1,65 @@ +using Twilio.Rest.PreviewIam.Organizations; +using Twilio.Exceptions; +using System; + +namespace Twilio.Http.BearerToken{ + +/// + /// Implementation of a Token Manager + /// + public class OrgsTokenManager : TokenManager + { + + public string GrantType { get; } + public string ClientId { get; } + public string ClientSecret { get; set; } + public string Code { get; set; } + public string RedirectUri { get; set; } + public string Audience { get; set; } + public string RefreshToken { get; set; } + public string Scope { get; set; } + + /// Constructor for a OrgsTokenManager + public OrgsTokenManager( + string grantType, + string clientId, + string clientSecret, + string code = null, + string redirectUri = null, + string audience = null, + string refreshToken = null, + string scope = null + ){ + GrantType = grantType; + ClientId = clientId; + ClientSecret = clientSecret; + Code = code; + RedirectUri = redirectUri; + Audience = audience; + RefreshToken = refreshToken; + Scope = scope; + } + + public string fetchAccessToken(){ + CreateTokenOptions createTokenOptions = new CreateTokenOptions(GrantType, ClientId); + if(ClientSecret != null){ createTokenOptions.ClientSecret = ClientSecret;} + if(Code != null){ createTokenOptions.Code = Code; } + if(RedirectUri != null){ createTokenOptions.RedirectUri = RedirectUri; } + if(Audience != null){ createTokenOptions.Audience = Audience; } + if(RefreshToken != null){ createTokenOptions.RefreshToken = RefreshToken; } + if(Scope != null){ createTokenOptions.Scope = Scope; } + + TokenResource token; + try{ + token = TokenResource.Create(createTokenOptions); + if(token == null || token.AccessToken == null){ + throw new ApiException("Token creation failed"); + } + }catch(Exception e){ + throw new ApiException("Token creation failed" + e); + } + + return token.AccessToken; + } + } +} \ No newline at end of file diff --git a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs new file mode 100644 index 000000000..c4c1c0e3f --- /dev/null +++ b/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs @@ -0,0 +1,142 @@ +#if !NET35 +using System; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Text; +using Twilio.Constant; + +namespace Twilio.Http.BearerToken +{ + /// + /// Sample client to make HTTP requests + /// + public class SystemNetBearerTokenHttpClient : BearerTokenHttpClient + { +#if NET462 + private string PlatVersion = ".NET Framework 4.6.2+"; +#else + private string PlatVersion = RuntimeInformation.FrameworkDescription; +#endif + + private readonly System.Net.Http.HttpClient _httpClient; + + /// + /// Create new HttpClient + /// + /// HTTP client to use + public SystemNetBearerTokenHttpClient(System.Net.Http.HttpClient httpClient = null) + { + _httpClient = httpClient ?? new System.Net.Http.HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }); + } + + /// + /// Make a synchronous request + /// + /// Twilio request + /// Twilio response + public override Response MakeRequest(BearerTokenRequest request) + { + try + { + var task = MakeRequestAsync(request); + task.Wait(); + return task.Result; + } + catch (AggregateException ae) + { + // Combine nested AggregateExceptions + ae = ae.Flatten(); + throw ae.InnerExceptions[0]; + } + } + + /// + /// Make an asynchronous request + /// + /// Twilio response + /// Task that resolves to the response + public override async Task MakeRequestAsync(BearerTokenRequest request) + { + var httpRequest = BuildHttpRequest(request); + if (!Equals(request.Method, HttpMethod.Get)) + { + if (request.ContentType == null) + request.ContentType = EnumConstants.ContentTypeEnum.FORM_URLENCODED; + + if (Equals(request.ContentType, EnumConstants.ContentTypeEnum.JSON)) + httpRequest.Content = new StringContent(request.Body, Encoding.UTF8, "application/json"); + + else if (Equals(request.ContentType, EnumConstants.ContentTypeEnum.SCIM)) + httpRequest.Content = new StringContent(request.Body, Encoding.UTF8, "application/scim"); + + else if(Equals(request.ContentType, EnumConstants.ContentTypeEnum.FORM_URLENCODED)) + httpRequest.Content = new FormUrlEncodedContent(request.PostParams); + } + + this.LastRequest = request; + this.LastResponse = null; + + var httpResponse = await _httpClient.SendAsync(httpRequest).ConfigureAwait(false); + var reader = new StreamReader(await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false)); + + // Create and return a new Response. Keep a reference to the last + // response for debugging, but don't return it as it may be shared + // among threads. + var response = new Response(httpResponse.StatusCode, await reader.ReadToEndAsync().ConfigureAwait(false), httpResponse.Headers); + this.LastResponse = response; + return response; + } + + private HttpRequestMessage BuildHttpRequest(BearerTokenRequest request) + { + var httpRequest = new HttpRequestMessage( + new System.Net.Http.HttpMethod(request.Method.ToString()), + request.ConstructUrl() + ); + + var authBytes = request.AccessToken; + httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authBytes); + + httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + httpRequest.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("utf-8")); + + int lastSpaceIndex = PlatVersion.LastIndexOf(" "); + System.Text.StringBuilder PlatVersionSb= new System.Text.StringBuilder(PlatVersion); + PlatVersionSb[lastSpaceIndex] = '/'; + + string helperLibVersion = AssemblyInfomation.AssemblyInformationalVersion; + + string osName = "Unknown"; + osName = Environment.OSVersion.Platform.ToString(); + + string osArch; +#if !NET462 + osArch = RuntimeInformation.OSArchitecture.ToString(); +#else + osArch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") ?? "Unknown"; +#endif + var libraryVersion = String.Format("twilio-csharp/{0} ({1} {2}) {3}", helperLibVersion, osName, osArch, PlatVersionSb); + + if (request.UserAgentExtensions != null) + { + foreach (var extension in request.UserAgentExtensions) + { + libraryVersion += " " + extension; + } + } + + httpRequest.Headers.TryAddWithoutValidation("User-Agent", libraryVersion); + + foreach (var header in request.HeaderParams) + { + httpRequest.Headers.TryAddWithoutValidation(header.Key, header.Value); + } + + return httpRequest; + } + } +} +#endif diff --git a/src/Twilio/Http/BearerToken/TokenManager.cs b/src/Twilio/Http/BearerToken/TokenManager.cs new file mode 100644 index 000000000..11275b71b --- /dev/null +++ b/src/Twilio/Http/BearerToken/TokenManager.cs @@ -0,0 +1,18 @@ +namespace Twilio.Http.BearerToken +{ + /// + /// Interface for a Token Manager + /// + public interface TokenManager + { + + /// + /// Fetch/Create an access token + /// + /// + /// access token fetched from token endpoint + string fetchAccessToken(); + + } +} + diff --git a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs new file mode 100644 index 000000000..9a8bfedd0 --- /dev/null +++ b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs @@ -0,0 +1,94 @@ +#if NET35 +using System.IO; +using Twilio.Http.BearerToken; + +namespace Twilio.Http.Net35 +{ + + /// + /// Sample client to make requests + /// + public class WebBearerTokenRequestClient : BearerTokenHttpClient + { + private const string PlatVersion = ".NET/3.5"; + private HttpWebRequestFactory factory; + + public WebBearerTokenRequestClient(HttpWebRequestFactory factory = null) + { + this.factory = factory ?? new HttpWebRequestFactory(); + } + + /// + /// Make an HTTP request + /// + /// Twilio request + /// Twilio response + public override Response MakeRequest(BearerTokenRequest request) + { + + IHttpWebRequestWrapper httpRequest = BuildHttpRequest(request); + if (!Equals(request.Method, HttpMethod.Get)) + { + httpRequest.WriteBody(request.EncodePostParams()); + } + + this.LastRequest = request; + this.LastResponse = null; + try + { + IHttpWebResponseWrapper response = httpRequest.GetResponse(); + string content = GetResponseContent(response); + this.LastResponse = new Response(response.StatusCode, content, response.Headers); + } + catch (WebExceptionWrapper e) + { + if (e.Response == null) + { + // Network or connection error + throw e.RealException; + } + // Non 2XX status code + IHttpWebResponseWrapper errorResponse = e.Response; + this.LastResponse = new Response(errorResponse.StatusCode, GetResponseContent(errorResponse), errorResponse.Headers); + } + return this.LastResponse; + } + + private string GetResponseContent(IHttpWebResponseWrapper response) + { + var reader = new StreamReader(response.GetResponseStream()); + return reader.ReadToEnd(); + } + + private IHttpWebRequestWrapper BuildHttpRequest(BearerTokenRequest request) + { + IHttpWebRequestWrapper httpRequest = this.factory.Create(request.ConstructUrl()); + + string helperLibVersion = AssemblyInfomation.AssemblyInformationalVersion; + string osName = System.Environment.OSVersion.Platform.ToString(); + string osArch = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") ?? "Unknown"; + var libraryVersion = System.String.Format("twilio-csharp/{0} ({1} {2}) {3}", helperLibVersion, osName, osArch, PlatVersion); + + if (request.UserAgentExtensions != null) + { + foreach (var extension in request.UserAgentExtensions) + { + libraryVersion += " " + extension; + } + } + + httpRequest.UserAgent = libraryVersion; + + httpRequest.Method = request.Method.ToString(); + httpRequest.Accept = "application/json"; + httpRequest.Headers["Accept-Encoding"] = "utf-8"; + + var authBytes = request.AccessToken; + httpRequest.Headers["Authorization"] = "Bearer " + authBytes; + httpRequest.ContentType = "application/x-www-form-urlencoded"; + + return httpRequest; + } + } +} +#endif \ No newline at end of file diff --git a/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs b/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs new file mode 100644 index 000000000..6abd23688 --- /dev/null +++ b/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs @@ -0,0 +1,91 @@ +#if NET35 +using System.IO; +using Twilio.Http.NoAuth; + +namespace Twilio.Http.Net35 +{ + + /// + /// Sample client to make requests + /// + public class WebNoAuthRequestClient : NoAuthHttpClient + { + private const string PlatVersion = ".NET/3.5"; + private HttpWebRequestFactory factory; + + public WebNoAuthRequestClient(HttpWebRequestFactory factory = null) + { + this.factory = factory ?? new HttpWebRequestFactory(); + } + + /// + /// Make an HTTP request + /// + /// Twilio request + /// Twilio response + public override Response MakeRequest(NoAuthRequest request) + { + + IHttpWebRequestWrapper httpRequest = BuildHttpRequest(request); + if (!Equals(request.Method, HttpMethod.Get)) + { + httpRequest.WriteBody(request.EncodePostParams()); + } + + this.LastRequest = request; + this.LastResponse = null; + try + { + IHttpWebResponseWrapper response = httpRequest.GetResponse(); + string content = GetResponseContent(response); + this.LastResponse = new Response(response.StatusCode, content, response.Headers); + } + catch (WebExceptionWrapper e) + { + if (e.Response == null) + { + // Network or connection error + throw e.RealException; + } + // Non 2XX status code + IHttpWebResponseWrapper errorResponse = e.Response; + this.LastResponse = new Response(errorResponse.StatusCode, GetResponseContent(errorResponse), errorResponse.Headers); + } + return this.LastResponse; + } + + private string GetResponseContent(IHttpWebResponseWrapper response) + { + var reader = new StreamReader(response.GetResponseStream()); + return reader.ReadToEnd(); + } + + private IHttpWebRequestWrapper BuildHttpRequest(NoAuthRequest request) + { + IHttpWebRequestWrapper httpRequest = this.factory.Create(request.ConstructUrl()); + + string helperLibVersion = AssemblyInfomation.AssemblyInformationalVersion; + string osName = System.Environment.OSVersion.Platform.ToString(); + string osArch = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") ?? "Unknown"; + var libraryVersion = System.String.Format("twilio-csharp/{0} ({1} {2}) {3}", helperLibVersion, osName, osArch, PlatVersion); + + if (request.UserAgentExtensions != null) + { + foreach (var extension in request.UserAgentExtensions) + { + libraryVersion += " " + extension; + } + } + + httpRequest.UserAgent = libraryVersion; + + httpRequest.Method = request.Method.ToString(); + httpRequest.Accept = "application/json"; + httpRequest.Headers["Accept-Encoding"] = "utf-8"; + httpRequest.ContentType = "application/x-www-form-urlencoded"; + + return httpRequest; + } + } +} +#endif \ No newline at end of file diff --git a/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs b/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs new file mode 100644 index 000000000..8cac2637c --- /dev/null +++ b/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs @@ -0,0 +1,41 @@ +using System; + +namespace Twilio.Http.NoAuth +{ + /// + /// Base http client used to make Twilio requests + /// + public abstract class NoAuthHttpClient + { + /// + /// The last request made by this client + /// + public NoAuthRequest LastRequest { get; protected set; } + + /// + /// The last response received by this client + /// + public Response LastResponse { get; protected set; } + + /// + /// Make a request to Twilio, returns non-2XX responses as well + /// + /// + /// request to make + /// throws exception on network or connection errors. + /// response of the request + public abstract Response MakeRequest(NoAuthRequest request); + +#if !NET35 + /// + /// Make an async request to Twilio, returns non-2XX responses as well + /// + /// + /// request to make + /// throws exception on network or connection errors. + /// response of the request + public abstract System.Threading.Tasks.Task MakeRequestAsync(NoAuthRequest request); +#endif + + } +} diff --git a/src/Twilio/Http/NoAuth/NoAuthRequest.cs b/src/Twilio/Http/NoAuth/NoAuthRequest.cs new file mode 100644 index 000000000..f1ea6f400 --- /dev/null +++ b/src/Twilio/Http/NoAuth/NoAuthRequest.cs @@ -0,0 +1,288 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Twilio.Constant; +using Twilio.Rest; + +#if !NET35 +using System.Net; +#else +using System.Web; +#endif + +namespace Twilio.Http.NoAuth +{ + /// + /// Twilio request object with bearer token authentication + /// + public class NoAuthRequest + { + private static readonly string DEFAULT_REGION = "us1"; + + /// + /// HTTP Method + /// + public HttpMethod Method { get; } + + public Uri Uri { get; private set; } + + + /// + /// Twilio region + /// + public string Region { get; set; } + + /// + /// Twilio edge + /// + public string Edge { get; set; } + + /// + /// Additions to the user agent string + /// + public string[] UserAgentExtensions { get; set; } + + /// + /// Query params + /// + public List> QueryParams { get; private set; } + + /// + /// Post params + /// + public List> PostParams { get; private set; } + + /// + /// Header params + /// + public List> HeaderParams { get; private set; } + + /// + /// Content Type + /// + public EnumConstants.ContentTypeEnum ContentType { get; set; } + + /// + /// Body + /// + public string Body { get; set; } + + /// + /// Create a new Twilio request + /// + /// HTTP Method + /// Request URL + public NoAuthRequest(HttpMethod method, string url) + { + Method = method; + Uri = new Uri(url); + QueryParams = new List>(); + PostParams = new List>(); + HeaderParams = new List>(); + } + + /// + /// Create a new Twilio request + /// + /// HTTP method + /// Twilio subdomain + /// Request URI + /// Twilio region + /// Query parameters + /// Post data + /// Twilio edge + /// Custom header data + /// Content Type + /// Request Body + public NoAuthRequest( + HttpMethod method, + Domain domain, + string uri, + string region = null, + List> queryParams = null, + List> postParams = null, + string edge = null, + List> headerParams = null, + EnumConstants.ContentTypeEnum contentType = null, + string body = null + ) + { + Method = method; + Uri = new Uri("https://" + domain + ".twilio.com" + uri); + Region = region; + Edge = edge; + + QueryParams = queryParams ?? new List>(); + PostParams = postParams ?? new List>(); + HeaderParams = headerParams ?? new List>(); + + ContentType = contentType; + Body = body; + } + + /// + /// Construct the request URL + /// + /// Built URL including query parameters + public Uri ConstructUrl() + { + var uri = buildUri(); + return QueryParams.Count > 0 ? + new Uri(uri.AbsoluteUri + "?" + EncodeParameters(QueryParams)) : + new Uri(uri.AbsoluteUri); + } + + public Uri buildUri() + { + if (Region != null || Edge != null) + { + var uriBuilder = new UriBuilder(Uri); + var pieces = uriBuilder.Host.Split('.'); + var product = pieces[0]; + var domain = String.Join(".", pieces.Skip(pieces.Length - 2).ToArray()); + + var region = Region; + var edge = Edge; + + if (pieces.Length == 4) // product.region.twilio.com + { + region = region ?? pieces[1]; + } + else if (pieces.Length == 5) // product.edge.region.twilio.com + { + edge = edge ?? pieces[1]; + region = region ?? pieces[2]; + } + + if (edge != null && region == null) + region = DEFAULT_REGION; + + string[] parts = { product, edge, region, domain }; + + uriBuilder.Host = String.Join(".", Array.FindAll(parts, part => !string.IsNullOrEmpty(part))); + return uriBuilder.Uri; + } + + return Uri; + } + + + private static string EncodeParameters(IEnumerable> data) + { + var result = ""; + var first = true; + foreach (var pair in data) + { + if (first) + { + first = false; + } + else + { + result += "&"; + } + +#if !NET35 + result += WebUtility.UrlEncode(pair.Key) + "=" + WebUtility.UrlEncode(pair.Value); +#else + result += HttpUtility.UrlEncode(pair.Key) + "=" + HttpUtility.UrlEncode(pair.Value); +#endif + } + + return result; + } + + /// + /// Encode POST data for transfer + /// + /// Encoded byte array + public byte[] EncodePostParams() + { + return Encoding.UTF8.GetBytes(EncodeParameters(PostParams)); + } + + /// + /// Add query parameter to request + /// + /// name of parameter + /// value of parameter + public void AddQueryParam(string name, string value) + { + AddParam(QueryParams, name, value); + } + + /// + /// Add a parameter to the request payload + /// + /// name of parameter + /// value of parameter + public void AddPostParam(string name, string value) + { + AddParam(PostParams, name, value); + } + + /// + /// Add a header parameter + /// + /// name of parameter + /// value of parameter + public void AddHeaderParam(string name, string value) + { + AddParam(HeaderParams, name, value); + } + + private static void AddParam(ICollection> list, string name, string value) + { + list.Add(new KeyValuePair(name, value)); + } + + /// + /// Compare request + /// + /// object to compare to + /// true if requests are equal; false otherwise + public override bool Equals(object obj) + { + if (obj == null) + { + return false; + } + + if (ReferenceEquals(this, obj)) + { + return true; + } + if (obj.GetType() != typeof(Request)) + { + return false; + } + + var other = (Request)obj; + return Method.Equals(other.Method) && + buildUri().Equals(other.buildUri()) && + QueryParams.All(other.QueryParams.Contains) && + other.QueryParams.All(QueryParams.Contains) && + PostParams.All(other.PostParams.Contains) && + other.PostParams.All(PostParams.Contains) && + HeaderParams.All(other.HeaderParams.Contains) && + other.HeaderParams.All(HeaderParams.Contains); + } + + /// + /// Generate hash code for request + /// + /// generated hash code + public override int GetHashCode() + { + unchecked + { + return (Method?.GetHashCode() ?? 0) ^ + (buildUri()?.GetHashCode() ?? 0) ^ + (QueryParams?.GetHashCode() ?? 0) ^ + (PostParams?.GetHashCode() ?? 0) ^ + (HeaderParams?.GetHashCode() ?? 0); + } + } + } +} diff --git a/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs b/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs new file mode 100644 index 000000000..ba2e58a76 --- /dev/null +++ b/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs @@ -0,0 +1,139 @@ +#if !NET35 +using System; +using System.IO; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using System.Runtime.InteropServices; +using System.Text; +using Twilio.Constant; + +namespace Twilio.Http.NoAuth +{ + /// + /// Sample client to make HTTP requests + /// + public class SystemNetNoAuthHttpClient : NoAuthHttpClient + { +#if NET462 + private string PlatVersion = ".NET Framework 4.6.2+"; +#else + private string PlatVersion = RuntimeInformation.FrameworkDescription; +#endif + + private readonly System.Net.Http.HttpClient _httpClient; + + /// + /// Create new HttpClient + /// + /// HTTP client to use + public SystemNetNoAuthHttpClient(System.Net.Http.HttpClient httpClient = null) + { + _httpClient = httpClient ?? new System.Net.Http.HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }); + } + + /// + /// Make a synchronous request + /// + /// Twilio request + /// Twilio response + public override Response MakeRequest(NoAuthRequest request) + { + try + { + var task = MakeRequestAsync(request); + task.Wait(); + return task.Result; + } + catch (AggregateException ae) + { + // Combine nested AggregateExceptions + ae = ae.Flatten(); + throw ae.InnerExceptions[0]; + } + } + + /// + /// Make an asynchronous request + /// + /// Twilio response + /// Task that resolves to the response + public override async Task MakeRequestAsync(NoAuthRequest request) + { + var httpRequest = BuildHttpRequest(request); + if (!Equals(request.Method, HttpMethod.Get)) + { + if (request.ContentType == null) + request.ContentType = EnumConstants.ContentTypeEnum.FORM_URLENCODED; + + if (Equals(request.ContentType, EnumConstants.ContentTypeEnum.JSON)) + httpRequest.Content = new StringContent(request.Body, Encoding.UTF8, "application/json"); + + else if (Equals(request.ContentType, EnumConstants.ContentTypeEnum.SCIM)) + httpRequest.Content = new StringContent(request.Body, Encoding.UTF8, "application/scim"); + + else if(Equals(request.ContentType, EnumConstants.ContentTypeEnum.FORM_URLENCODED)) + httpRequest.Content = new FormUrlEncodedContent(request.PostParams); + } + + this.LastRequest = request; + this.LastResponse = null; + + var httpResponse = await _httpClient.SendAsync(httpRequest).ConfigureAwait(false); + var reader = new StreamReader(await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false)); + + // Create and return a new Response. Keep a reference to the last + // response for debugging, but don't return it as it may be shared + // among threads. + var response = new Response(httpResponse.StatusCode, await reader.ReadToEndAsync().ConfigureAwait(false), httpResponse.Headers); + this.LastResponse = response; + return response; + } + + private HttpRequestMessage BuildHttpRequest(NoAuthRequest request) + { + var httpRequest = new HttpRequestMessage( + new System.Net.Http.HttpMethod(request.Method.ToString()), + request.ConstructUrl() + ); + + httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + httpRequest.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("utf-8")); + + int lastSpaceIndex = PlatVersion.LastIndexOf(" "); + System.Text.StringBuilder PlatVersionSb= new System.Text.StringBuilder(PlatVersion); + PlatVersionSb[lastSpaceIndex] = '/'; + + string helperLibVersion = AssemblyInfomation.AssemblyInformationalVersion; + + string osName = "Unknown"; + osName = Environment.OSVersion.Platform.ToString(); + + string osArch; +#if !NET462 + osArch = RuntimeInformation.OSArchitecture.ToString(); +#else + osArch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") ?? "Unknown"; +#endif + var libraryVersion = String.Format("twilio-csharp/{0} ({1} {2}) {3}", helperLibVersion, osName, osArch, PlatVersionSb); + + if (request.UserAgentExtensions != null) + { + foreach (var extension in request.UserAgentExtensions) + { + libraryVersion += " " + extension; + } + } + + httpRequest.Headers.TryAddWithoutValidation("User-Agent", libraryVersion); + + foreach (var header in request.HeaderParams) + { + httpRequest.Headers.TryAddWithoutValidation(header.Key, header.Value); + } + + return httpRequest; + } + } +} +#endif diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs new file mode 100644 index 000000000..07a373203 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs @@ -0,0 +1,95 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Converters; + + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + /// fetch + public class FetchAccountOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public string PathAccountSid { get; } + + + + /// Construct a new FetchOrganizationAccountOptions + /// + /// + public FetchAccountOptions(string pathOrganizationSid, string pathAccountSid) + { + PathOrganizationSid = pathOrganizationSid; + PathAccountSid = pathAccountSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + return p; + } + + + + } + + + /// read + public class ReadAccountOptions : ReadOptions + { + + + public string PathOrganizationSid { get; } + + + + /// Construct a new ListOrganizationAccountsOptions + /// + public ReadAccountOptions(string pathOrganizationSid) + { + PathOrganizationSid = pathOrganizationSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + if (PageSize != null) + { + p.Add(new KeyValuePair("PageSize", PageSize.ToString())); + } + return p; + } + + + + } + +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs new file mode 100644 index 000000000..03d07481c --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs @@ -0,0 +1,327 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Clients; +using Twilio.Constant; +using Twilio.Converters; +using Twilio.Exceptions; +using Twilio.Http; +using Twilio.Types; +using Twilio.Base.BearerToken; +using Twilio.Clients.BearerToken; +using Twilio.Http.BearerToken; + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + public class AccountResource : Resource + { + + + + [JsonConverter(typeof(StringEnumConverter))] + public sealed class StatusEnum : StringEnum + { + private StatusEnum(string value) : base(value) {} + public StatusEnum() {} + public static implicit operator StatusEnum(string value) + { + return new StatusEnum(value); + } + public static readonly StatusEnum Active = new StatusEnum("active"); + public static readonly StatusEnum Suspended = new StatusEnum("suspended"); + public static readonly StatusEnum PendingClosure = new StatusEnum("pending_closure"); + public static readonly StatusEnum Closed = new StatusEnum("closed"); + + } + + + private static BearerTokenRequest BuildFetchRequest(FetchAccountOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/Accounts/{AccountSid}"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + string PathAccountSid = options.PathAccountSid.ToString(); + path = path.Replace("{"+"AccountSid"+"}", PathAccountSid); + + return new BearerTokenRequest( + HttpMethod.Get, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + + /// fetch + /// Fetch Account parameters + /// Client to make requests to Twilio + /// A single instance of Account + public static AccountResource Fetch(FetchAccountOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildFetchRequest(options, client)); + return FromJson(response.Content); + } + + #if !NET35 + /// fetch + /// Fetch Account parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Account + public static async System.Threading.Tasks.Task FetchAsync(FetchAccountOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildFetchRequest(options, client)); + return FromJson(response.Content); + } + #endif + /// fetch + /// + /// + /// Client to make requests to Twilio + /// A single instance of Account + public static AccountResource Fetch( + string pathOrganizationSid, + string pathAccountSid, + TwilioBearerTokenRestClient client = null) + { + var options = new FetchAccountOptions(pathOrganizationSid, pathAccountSid){ }; + return Fetch(options, client); + } + + #if !NET35 + /// fetch + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Account + public static async System.Threading.Tasks.Task FetchAsync(string pathOrganizationSid, string pathAccountSid, TwilioBearerTokenRestClient client = null) + { + var options = new FetchAccountOptions(pathOrganizationSid, pathAccountSid){ }; + return await FetchAsync(options, client); + } + #endif + + private static BearerTokenRequest BuildReadRequest(ReadAccountOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/Accounts"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + + return new BearerTokenRequest( + HttpMethod.Get, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + /// read + /// Read Account parameters + /// Client to make requests to Twilio + /// A single instance of Account + public static BearerTokenResourceSet Read(ReadAccountOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildReadRequest(options, client)); + var page = Page.FromJson("content", response.Content); + return new BearerTokenResourceSet(page, options, client); + } + + #if !NET35 + /// read + /// Read Account parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Account + public static async System.Threading.Tasks.Task> ReadAsync(ReadAccountOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildReadRequest(options, client)); + + var page = Page.FromJson("content", response.Content); + return new BearerTokenResourceSet(page, options, client); + } + #endif + /// read + /// + /// + /// Record limit + /// Client to make requests to Twilio + /// A single instance of Account + public static BearerTokenResourceSet Read( + string pathOrganizationSid, + int? pageSize = null, + long? limit = null, + TwilioBearerTokenRestClient client = null) + { + var options = new ReadAccountOptions(pathOrganizationSid){ PageSize = pageSize, Limit = limit}; + return Read(options, client); + } + + #if !NET35 + /// read + /// + /// + /// Record limit + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Account + public static async System.Threading.Tasks.Task> ReadAsync( + string pathOrganizationSid, + int? pageSize = null, + long? limit = null, + TwilioBearerTokenRestClient client = null) + { + var options = new ReadAccountOptions(pathOrganizationSid){ PageSize = pageSize, Limit = limit}; + return await ReadAsync(options, client); + } + #endif + + + /// Fetch the target page of records + /// API-generated URL for the requested results page + /// Client to make requests to Twilio + /// The target page of records + public static Page GetPage(string targetUrl, TwilioBearerTokenRestClient client) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + + var request = new BearerTokenRequest( + HttpMethod.Get, + targetUrl + ); + + var response = client.Request(request); + return Page.FromJson("content", response.Content); + } + + /// Fetch the next page of records + /// current page of records + /// Client to make requests to Twilio + /// The next page of records + public static Page NextPage(Page page, TwilioBearerTokenRestClient client) + { + var request = new BearerTokenRequest( + HttpMethod.Get, + page.GetNextPageUrl(Rest.Domain.Api) + ); + + var response = client.Request(request); + return Page.FromJson("content", response.Content); + } + + /// Fetch the previous page of records + /// current page of records + /// Client to make requests to Twilio + /// The previous page of records + public static Page PreviousPage(Page page, TwilioBearerTokenRestClient client) + { + var request = new BearerTokenRequest( + HttpMethod.Get, + page.GetPreviousPageUrl(Rest.Domain.Api) + ); + + var response = client.Request(request); + return Page.FromJson("content", response.Content); + } + + + /// + /// Converts a JSON string into a AccountResource object + /// + /// Raw JSON string + /// AccountResource object represented by the provided JSON + public static AccountResource FromJson(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + /// + /// Converts an object into a json string + /// + /// C# model + /// JSON string + public static string ToJson(object model) + { + try + { + return JsonConvert.SerializeObject(model); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + + + /// Twilio account sid + [JsonProperty("account_sid")] + public string AccountSid { get; private set; } + + /// Account friendly name + [JsonProperty("friendly_name")] + public string FriendlyName { get; private set; } + + /// Account status + [JsonProperty("status")] + public AccountResource.StatusEnum Status { get; private set; } + + /// Twilio account sid + [JsonProperty("owner_sid")] + public string OwnerSid { get; private set; } + + /// The date and time when the account was created in the system + [JsonProperty("date_created")] + public DateTime? DateCreated { get; private set; } + + /// Twilio-specific error code + [JsonProperty("code")] + public int? Code { get; private set; } + + /// Error message + [JsonProperty("message")] + public string Message { get; private set; } + + /// Link to Error Code References + [JsonProperty("moreInfo")] + public string MoreInfo { get; private set; } + + /// HTTP response status code + [JsonProperty("_status")] + public int? _Status { get; private set; } + + + + private AccountResource() { + + } + } +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs new file mode 100644 index 000000000..b793a88f2 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs @@ -0,0 +1,83 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Converters; + + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + /// fetch + public class FetchAuthorizeOptions : IOptions + { + + /// Response Type + public string ResponseType { get; set; } + + /// The Client Identifier + public string ClientId { get; set; } + + /// The url to which response will be redirected to + public string RedirectUri { get; set; } + + /// The scope of the access request + public string Scope { get; set; } + + /// An opaque value which can be used to maintain state between the request and callback + public string State { get; set; } + + + + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + if (ResponseType != null) + { + p.Add(new KeyValuePair("Response_type", ResponseType)); + } + if (ClientId != null) + { + p.Add(new KeyValuePair("Client_id", ClientId)); + } + if (RedirectUri != null) + { + p.Add(new KeyValuePair("Redirect_uri", RedirectUri)); + } + if (Scope != null) + { + p.Add(new KeyValuePair("Scope", Scope)); + } + if (State != null) + { + p.Add(new KeyValuePair("State", State)); + } + return p; + } + + + + } + + +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs new file mode 100644 index 000000000..554730147 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs @@ -0,0 +1,159 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Clients; +using Twilio.Constant; +using Twilio.Converters; +using Twilio.Exceptions; +using Twilio.Http; + + +using Twilio.Clients.NoAuth; +using Twilio.Http.NoAuth; + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + public class AuthorizeResource : Resource + { + + + + + + private static NoAuthRequest BuildFetchRequest(FetchAuthorizeOptions options, TwilioNoAuthRestClient client) + { + + string path = "/v1/authorize"; + + + return new NoAuthRequest( + HttpMethod.Get, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + + /// fetch + /// Fetch Authorize parameters + /// Client to make requests to Twilio + /// A single instance of Authorize + public static AuthorizeResource Fetch(FetchAuthorizeOptions options, TwilioNoAuthRestClient client = null) + { + client = client ?? TwilioNoAuthClient.GetRestClient(); + var response = client.Request(BuildFetchRequest(options, client)); + return FromJson(response.Content); + } + + #if !NET35 + /// fetch + /// Fetch Authorize parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Authorize + public static async System.Threading.Tasks.Task FetchAsync(FetchAuthorizeOptions options, TwilioNoAuthRestClient client = null) + { + client = client ?? TwilioNoAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildFetchRequest(options, client)); + return FromJson(response.Content); + } + #endif + /// fetch + /// Response Type + /// The Client Identifier + /// The url to which response will be redirected to + /// The scope of the access request + /// An opaque value which can be used to maintain state between the request and callback + /// Client to make requests to Twilio + /// A single instance of Authorize + public static AuthorizeResource Fetch( + string responseType = null, + string clientId = null, + string redirectUri = null, + string scope = null, + string state = null, + TwilioNoAuthRestClient client = null) + { + var options = new FetchAuthorizeOptions(){ ResponseType = responseType,ClientId = clientId,RedirectUri = redirectUri,Scope = scope,State = state }; + return Fetch(options, client); + } + + #if !NET35 + /// fetch + /// Response Type + /// The Client Identifier + /// The url to which response will be redirected to + /// The scope of the access request + /// An opaque value which can be used to maintain state between the request and callback + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Authorize + public static async System.Threading.Tasks.Task FetchAsync(string responseType = null, string clientId = null, string redirectUri = null, string scope = null, string state = null, TwilioNoAuthRestClient client = null) + { + var options = new FetchAuthorizeOptions(){ ResponseType = responseType,ClientId = clientId,RedirectUri = redirectUri,Scope = scope,State = state }; + return await FetchAsync(options, client); + } + #endif + + /// + /// Converts a JSON string into a AuthorizeResource object + /// + /// Raw JSON string + /// AuthorizeResource object represented by the provided JSON + public static AuthorizeResource FromJson(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + /// + /// Converts an object into a json string + /// + /// C# model + /// JSON string + public static string ToJson(object model) + { + try + { + return JsonConvert.SerializeObject(model); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + + + /// The callback URL + [JsonProperty("redirect_to")] + public Uri RedirectTo { get; private set; } + + + + private AuthorizeResource() { + + } + } +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs new file mode 100644 index 000000000..d5158ebc9 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs @@ -0,0 +1,145 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Converters; + + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + + /// Create a role assignment for the given organization + public class CreateRoleAssignmentOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest PublicApiCreateRoleAssignmentRequest { get; } + + + /// Construct a new CreateRoleAssignmentOptions + /// + /// + public CreateRoleAssignmentOptions(string pathOrganizationSid, RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest) + { + PathOrganizationSid = pathOrganizationSid; + PublicApiCreateRoleAssignmentRequest = publicApiCreateRoleAssignmentRequest; + } + + + /// Generate the request body + public string GetBody() + { + string body = ""; + + if (PublicApiCreateRoleAssignmentRequest != null) + { + body = RoleAssignmentResource.ToJson(PublicApiCreateRoleAssignmentRequest); + } + return body; + } + + + } + /// Delete a role assignment for the given organization + public class DeleteRoleAssignmentOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public string PathRoleAssignmentSid { get; } + + + + /// Construct a new DeleteRoleAssignmentOptions + /// + /// + public DeleteRoleAssignmentOptions(string pathOrganizationSid, string pathRoleAssignmentSid) + { + PathOrganizationSid = pathOrganizationSid; + PathRoleAssignmentSid = pathRoleAssignmentSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + return p; + } + + + + } + + + /// List role assignments for the given organization + public class ReadRoleAssignmentOptions : ReadOptions + { + + + public string PathOrganizationSid { get; } + + + public string Identity { get; set; } + + + public string Scope { get; set; } + + + + /// Construct a new ListRoleAssignmentsOptions + /// + public ReadRoleAssignmentOptions(string pathOrganizationSid) + { + PathOrganizationSid = pathOrganizationSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + if (PageSize != null) + { + p.Add(new KeyValuePair("PageSize", PageSize.ToString())); + } + if (Identity != null) + { + p.Add(new KeyValuePair("Identity", Identity.ToString())); + } + if (Scope != null) + { + p.Add(new KeyValuePair("Scope", Scope.ToString())); + } + return p; + } + + + + } + +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs new file mode 100644 index 000000000..05b26ce0c --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs @@ -0,0 +1,428 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Clients; +using Twilio.Constant; +using Twilio.Converters; +using Twilio.Exceptions; +using Twilio.Http; + +using Twilio.Base.BearerToken; +using Twilio.Clients.BearerToken; +using Twilio.Http.BearerToken; + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + public class RoleAssignmentResource : Resource + { + + public class PublicApiCreateRoleAssignmentRequest + { + [JsonProperty("role_sid")] + private string RoleSid {get; set;} + [JsonProperty("scope")] + private string Scope {get; set;} + [JsonProperty("identity")] + private string Identity {get; set;} + public PublicApiCreateRoleAssignmentRequest() { } + public class Builder + { + private PublicApiCreateRoleAssignmentRequest _publicApiCreateRoleAssignmentRequest = new PublicApiCreateRoleAssignmentRequest(); + public Builder() + { + } + public Builder WithRoleSid(string roleSid) + { + _publicApiCreateRoleAssignmentRequest.RoleSid= roleSid; + return this; + } + public Builder WithScope(string scope) + { + _publicApiCreateRoleAssignmentRequest.Scope= scope; + return this; + } + public Builder WithIdentity(string identity) + { + _publicApiCreateRoleAssignmentRequest.Identity= identity; + return this; + } + public PublicApiCreateRoleAssignmentRequest Build() + { + return _publicApiCreateRoleAssignmentRequest; + } + } + } + + + + + private static BearerTokenRequest BuildCreateRequest(CreateRoleAssignmentOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/RoleAssignments"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + + return new BearerTokenRequest( + HttpMethod.Post, + Rest.Domain.PreviewIam, + path, + + contentType: EnumConstants.ContentTypeEnum.JSON, + body: options.GetBody(), + headerParams: null + ); + } + + /// Create a role assignment for the given organization + /// Create RoleAssignment parameters + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + public static RoleAssignmentResource Create(CreateRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildCreateRequest(options, client)); + return FromJson(response.Content); + } + + #if !NET35 + /// Create a role assignment for the given organization + /// Create RoleAssignment parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of RoleAssignment + public static async System.Threading.Tasks.Task CreateAsync(CreateRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildCreateRequest(options, client)); + return FromJson(response.Content); + } + #endif + + /// Create a role assignment for the given organization + /// + /// + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + public static RoleAssignmentResource Create( + string pathOrganizationSid, + RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest, + TwilioBearerTokenRestClient client = null) + { + var options = new CreateRoleAssignmentOptions(pathOrganizationSid, publicApiCreateRoleAssignmentRequest){ }; + return Create(options, client); + } + + #if !NET35 + /// Create a role assignment for the given organization + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of RoleAssignment + public static async System.Threading.Tasks.Task CreateAsync( + string pathOrganizationSid, + RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest, + TwilioBearerTokenRestClient client = null) + { + var options = new CreateRoleAssignmentOptions(pathOrganizationSid, publicApiCreateRoleAssignmentRequest){ }; + return await CreateAsync(options, client); + } + #endif + + /// Delete a role assignment for the given organization + /// Delete RoleAssignment parameters + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + private static BearerTokenRequest BuildDeleteRequest(DeleteRoleAssignmentOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/RoleAssignments/{RoleAssignmentSid}"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + string PathRoleAssignmentSid = options.PathRoleAssignmentSid.ToString(); + path = path.Replace("{"+"RoleAssignmentSid"+"}", PathRoleAssignmentSid); + + return new BearerTokenRequest( + HttpMethod.Delete, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + + /// Delete a role assignment for the given organization + /// Delete RoleAssignment parameters + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + public static bool Delete(DeleteRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildDeleteRequest(options, client)); + return response.StatusCode == System.Net.HttpStatusCode.NoContent; + } + + #if !NET35 + /// Delete a role assignment for the given organization + /// Delete RoleAssignment parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of RoleAssignment + public static async System.Threading.Tasks.Task DeleteAsync(DeleteRoleAssignmentOptions options, + TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildDeleteRequest(options, client)); + return response.StatusCode == System.Net.HttpStatusCode.NoContent; + } + #endif + + /// Delete a role assignment for the given organization + /// + /// + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + public static bool Delete(string pathOrganizationSid, string pathRoleAssignmentSid, TwilioBearerTokenRestClient client = null) + { + var options = new DeleteRoleAssignmentOptions(pathOrganizationSid, pathRoleAssignmentSid) ; + return Delete(options, client); + } + + #if !NET35 + /// Delete a role assignment for the given organization + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of RoleAssignment + public static async System.Threading.Tasks.Task DeleteAsync(string pathOrganizationSid, string pathRoleAssignmentSid, TwilioBearerTokenRestClient client = null) + { + var options = new DeleteRoleAssignmentOptions(pathOrganizationSid, pathRoleAssignmentSid) ; + return await DeleteAsync(options, client); + } + #endif + + private static BearerTokenRequest BuildReadRequest(ReadRoleAssignmentOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/RoleAssignments"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + + return new BearerTokenRequest( + HttpMethod.Get, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + /// List role assignments for the given organization + /// Read RoleAssignment parameters + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + public static BearerTokenResourceSet Read(ReadRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildReadRequest(options, client)); + var page = Page.FromJson("content", response.Content); + return new BearerTokenResourceSet(page, options, client); + } + + #if !NET35 + /// List role assignments for the given organization + /// Read RoleAssignment parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of RoleAssignment + public static async System.Threading.Tasks.Task> ReadAsync(ReadRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildReadRequest(options, client)); + + var page = Page.FromJson("content", response.Content); + return new BearerTokenResourceSet(page, options, client); + } + #endif + /// List role assignments for the given organization + /// + /// + /// + /// + /// Record limit + /// Client to make requests to Twilio + /// A single instance of RoleAssignment + public static BearerTokenResourceSet Read( + string pathOrganizationSid, + int? pageSize = null, + string identity = null, + string scope = null, + long? limit = null, + TwilioBearerTokenRestClient client = null) + { + var options = new ReadRoleAssignmentOptions(pathOrganizationSid){ PageSize = pageSize, Identity = identity, Scope = scope, Limit = limit}; + return Read(options, client); + } + + #if !NET35 + /// List role assignments for the given organization + /// + /// + /// + /// + /// Record limit + /// Client to make requests to Twilio + /// Task that resolves to A single instance of RoleAssignment + public static async System.Threading.Tasks.Task> ReadAsync( + string pathOrganizationSid, + int? pageSize = null, + string identity = null, + string scope = null, + long? limit = null, + TwilioBearerTokenRestClient client = null) + { + var options = new ReadRoleAssignmentOptions(pathOrganizationSid){ PageSize = pageSize, Identity = identity, Scope = scope, Limit = limit}; + return await ReadAsync(options, client); + } + #endif + + + /// Fetch the target page of records + /// API-generated URL for the requested results page + /// Client to make requests to Twilio + /// The target page of records + public static Page GetPage(string targetUrl, TwilioBearerTokenRestClient client) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + + var request = new BearerTokenRequest( + HttpMethod.Get, + targetUrl + ); + + var response = client.Request(request); + return Page.FromJson("content", response.Content); + } + + /// Fetch the next page of records + /// current page of records + /// Client to make requests to Twilio + /// The next page of records + public static Page NextPage(Page page, TwilioBearerTokenRestClient client) + { + var request = new BearerTokenRequest( + HttpMethod.Get, + page.GetNextPageUrl(Rest.Domain.Api) + ); + + var response = client.Request(request); + return Page.FromJson("content", response.Content); + } + + /// Fetch the previous page of records + /// current page of records + /// Client to make requests to Twilio + /// The previous page of records + public static Page PreviousPage(Page page, TwilioBearerTokenRestClient client) + { + var request = new BearerTokenRequest( + HttpMethod.Get, + page.GetPreviousPageUrl(Rest.Domain.Api) + ); + + var response = client.Request(request); + return Page.FromJson("content", response.Content); + } + + + /// + /// Converts a JSON string into a RoleAssignmentResource object + /// + /// Raw JSON string + /// RoleAssignmentResource object represented by the provided JSON + public static RoleAssignmentResource FromJson(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + /// + /// Converts an object into a json string + /// + /// C# model + /// JSON string + public static string ToJson(object model) + { + try + { + return JsonConvert.SerializeObject(model); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + + + /// Twilio Role Assignment Sid representing this role assignment + [JsonProperty("sid")] + public string Sid { get; private set; } + + /// Twilio Role Sid representing assigned role + [JsonProperty("role_sid")] + public string RoleSid { get; private set; } + + /// Twilio Sid representing identity of this assignment + [JsonProperty("scope")] + public string Scope { get; private set; } + + /// Twilio Sid representing scope of this assignment + [JsonProperty("identity")] + public string Identity { get; private set; } + + /// Twilio-specific error code + [JsonProperty("code")] + public int? Code { get; private set; } + + /// Error message + [JsonProperty("message")] + public string Message { get; private set; } + + /// Link to Error Code References + [JsonProperty("moreInfo")] + public string MoreInfo { get; private set; } + + /// HTTP response status code + [JsonProperty("status")] + public int? Status { get; private set; } + + + + private RoleAssignmentResource() { + + } + } +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs new file mode 100644 index 000000000..dfe3dedf9 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs @@ -0,0 +1,110 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Converters; + + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + + /// create + public class CreateTokenOptions : IOptions + { + + /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + public string GrantType { get; } + + /// A 34 character string that uniquely identifies this OAuth App. + public string ClientId { get; } + + /// The credential for confidential OAuth App. + public string ClientSecret { get; set; } + + /// JWT token related to the authorization code grant type. + public string Code { get; set; } + + /// The redirect uri + public string RedirectUri { get; set; } + + /// The targeted audience uri + public string Audience { get; set; } + + /// JWT token related to refresh access token. + public string RefreshToken { get; set; } + + /// The scope of token + public string Scope { get; set; } + + + /// Construct a new CreateTokenOptions + /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + /// A 34 character string that uniquely identifies this OAuth App. + public CreateTokenOptions(string grantType, string clientId) + { + GrantType = grantType; + ClientId = clientId; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + if (GrantType != null) + { + p.Add(new KeyValuePair("grant_type", GrantType)); + } + if (ClientId != null) + { + p.Add(new KeyValuePair("client_id", ClientId)); + } + if (ClientSecret != null) + { + p.Add(new KeyValuePair("client_secret", ClientSecret)); + } + if (Code != null) + { + p.Add(new KeyValuePair("code", Code)); + } + if (RedirectUri != null) + { + p.Add(new KeyValuePair("redirect_uri", RedirectUri)); + } + if (Audience != null) + { + p.Add(new KeyValuePair("audience", Audience)); + } + if (RefreshToken != null) + { + p.Add(new KeyValuePair("refresh_token", RefreshToken)); + } + if (Scope != null) + { + p.Add(new KeyValuePair("scope", Scope)); + } + return p; + } + + + + } +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs new file mode 100644 index 000000000..eeaf13623 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs @@ -0,0 +1,195 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Clients; +using Twilio.Constant; +using Twilio.Converters; +using Twilio.Exceptions; +using Twilio.Http; + + +using Twilio.Clients.NoAuth; +using Twilio.Http.NoAuth; + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + public class TokenResource : Resource + { + + + + + + private static NoAuthRequest BuildCreateRequest(CreateTokenOptions options, TwilioNoAuthRestClient client) + { + + string path = "/v1/token"; + + + return new NoAuthRequest( + HttpMethod.Post, + Rest.Domain.PreviewIam, + path, + contentType: EnumConstants.ContentTypeEnum.FORM_URLENCODED, + postParams: options.GetParams(), + headerParams: null + ); + } + + /// create + /// Create Token parameters + /// Client to make requests to Twilio + /// A single instance of Token + public static TokenResource Create(CreateTokenOptions options, TwilioNoAuthRestClient client = null) + { + client = client ?? TwilioNoAuthClient.GetRestClient(); + var response = client.Request(BuildCreateRequest(options, client)); + return FromJson(response.Content); + } + + #if !NET35 + /// create + /// Create Token parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Token + public static async System.Threading.Tasks.Task CreateAsync(CreateTokenOptions options, TwilioNoAuthRestClient client = null) + { + client = client ?? TwilioNoAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildCreateRequest(options, client)); + return FromJson(response.Content); + } + #endif + + /// create + /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + /// A 34 character string that uniquely identifies this OAuth App. + /// The credential for confidential OAuth App. + /// JWT token related to the authorization code grant type. + /// The redirect uri + /// The targeted audience uri + /// JWT token related to refresh access token. + /// The scope of token + /// Client to make requests to Twilio + /// A single instance of Token + public static TokenResource Create( + string grantType, + string clientId, + string clientSecret = null, + string code = null, + string redirectUri = null, + string audience = null, + string refreshToken = null, + string scope = null, + TwilioNoAuthRestClient client = null) + { + var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; + return Create(options, client); + } + + #if !NET35 + /// create + /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + /// A 34 character string that uniquely identifies this OAuth App. + /// The credential for confidential OAuth App. + /// JWT token related to the authorization code grant type. + /// The redirect uri + /// The targeted audience uri + /// JWT token related to refresh access token. + /// The scope of token + /// Client to make requests to Twilio + /// Task that resolves to A single instance of Token + public static async System.Threading.Tasks.Task CreateAsync( + string grantType, + string clientId, + string clientSecret = null, + string code = null, + string redirectUri = null, + string audience = null, + string refreshToken = null, + string scope = null, + TwilioNoAuthRestClient 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); + } + #endif + + /// + /// Converts a JSON string into a TokenResource object + /// + /// Raw JSON string + /// TokenResource object represented by the provided JSON + public static TokenResource FromJson(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + /// + /// Converts an object into a json string + /// + /// C# model + /// JSON string + public static string ToJson(object model) + { + try + { + return JsonConvert.SerializeObject(model); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + + + /// Token which carries the necessary information to access a Twilio resource directly. + [JsonProperty("access_token")] + public string AccessToken { get; private set; } + + /// Token which carries the information necessary to get a new access token. + [JsonProperty("refresh_token")] + public string RefreshToken { get; private set; } + + /// Token which carries the information necessary of user profile. + [JsonProperty("id_token")] + public string IdToken { get; private set; } + + /// Token type + [JsonProperty("token_type")] + public string TokenType { get; private set; } + + /// The expires_in + [JsonProperty("expires_in")] + public long? ExpiresIn { get; private set; } + + + + private TokenResource() { + + } + } +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs new file mode 100644 index 000000000..e18b74dd0 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs @@ -0,0 +1,225 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Converters; + + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + + /// create + public class CreateUserOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public UserResource.ScimUser ScimUser { get; } + + + /// Construct a new CreateOrganizationUserOptions + /// + /// + public CreateUserOptions(string pathOrganizationSid, UserResource.ScimUser scimUser) + { + PathOrganizationSid = pathOrganizationSid; + ScimUser = scimUser; + } + + + /// Generate the request body + public string GetBody() + { + string body = ""; + + if (ScimUser != null) + { + body = UserResource.ToJson(ScimUser); + } + return body; + } + + + } + /// delete + public class DeleteUserOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public string PathUserSid { get; } + + + + /// Construct a new DeleteOrganizationUserOptions + /// + /// + public DeleteUserOptions(string pathOrganizationSid, string pathUserSid) + { + PathOrganizationSid = pathOrganizationSid; + PathUserSid = pathUserSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + return p; + } + + + + } + + + /// fetch + public class FetchUserOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public string PathUserSid { get; } + + + + /// Construct a new FetchOrganizationUserOptions + /// + /// + public FetchUserOptions(string pathOrganizationSid, string pathUserSid) + { + PathOrganizationSid = pathOrganizationSid; + PathUserSid = pathUserSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + return p; + } + + + + } + + + /// read + public class ReadUserOptions : ReadOptions + { + + + public string PathOrganizationSid { get; } + + + public string Filter { get; set; } + + + + /// Construct a new ListOrganizationUsersOptions + /// + public ReadUserOptions(string pathOrganizationSid) + { + PathOrganizationSid = pathOrganizationSid; + } + + + /// Generate the necessary parameters + public List> GetParams() + { + var p = new List>(); + + if (Filter != null) + { + p.Add(new KeyValuePair("Filter", Filter)); + } + return p; + } + + + + } + + /// update + public class UpdateUserOptions : IOptions + { + + + public string PathOrganizationSid { get; } + + + public string PathUserSid { get; } + + + public UserResource.ScimUser ScimUser { get; } + + + public string IfMatch { get; set; } + + + + /// Construct a new UpdateOrganizationUserOptions + /// + /// + /// + public UpdateUserOptions(string pathOrganizationSid, string pathUserSid, UserResource.ScimUser scimUser) + { + PathOrganizationSid = pathOrganizationSid; + PathUserSid = pathUserSid; + ScimUser = scimUser; + } + + + /// Generate the request body + public string GetBody() + { + string body = ""; + + if (ScimUser != null) + { + body = UserResource.ToJson(ScimUser); + } + return body; + } + + /// Generate the necessary header parameters + public List> GetHeaderParams() + { + var p = new List>(); + if (IfMatch != null) + { + p.Add(new KeyValuePair("If-Match", IfMatch)); + } + return p; + } + + } + + +} + diff --git a/src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs new file mode 100644 index 000000000..351e65912 --- /dev/null +++ b/src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs @@ -0,0 +1,789 @@ +/* + * This code was generated by + * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ + * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ + * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ + * + * Organization Public API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * NOTE: This class is auto generated by OpenAPI Generator. + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using Twilio.Base; +using Twilio.Clients; +using Twilio.Constant; +using Twilio.Converters; +using Twilio.Exceptions; +using Twilio.Http; +using Twilio.Types; +using Twilio.Base.BearerToken; +using Twilio.Clients.BearerToken; +using Twilio.Http.BearerToken; + + + +namespace Twilio.Rest.PreviewIam.Organizations +{ + public class UserResource : Resource + { + + public class ScimName + { + [JsonProperty("givenName")] + private string GivenName {get; set;} + [JsonProperty("familyName")] + private string FamilyName {get; set;} + public ScimName() { } + public class Builder + { + private ScimName _scimName = new ScimName(); + public Builder() + { + } + public Builder WithGivenName(string givenName) + { + _scimName.GivenName= givenName; + return this; + } + public Builder WithFamilyName(string familyName) + { + _scimName.FamilyName= familyName; + return this; + } + public ScimName Build() + { + return _scimName; + } + } + } + public class ScimEmailAddress + { + [JsonProperty("primary")] + private bool? Primary {get; set;} + [JsonProperty("value")] + private string Value {get; set;} + [JsonProperty("type")] + private string Type {get; set;} + public ScimEmailAddress() { } + public class Builder + { + private ScimEmailAddress _scimEmailAddress = new ScimEmailAddress(); + public Builder() + { + } + public Builder WithPrimary(bool? primary) + { + _scimEmailAddress.Primary= primary; + return this; + } + public Builder WithValue(string value) + { + _scimEmailAddress.Value= value; + return this; + } + public Builder WithType(string type) + { + _scimEmailAddress.Type= type; + return this; + } + public ScimEmailAddress Build() + { + return _scimEmailAddress; + } + } + } + public class ScimMeta + { + [JsonProperty("resourceType")] + private string ResourceType {get; set;} + [JsonProperty("created")] + private DateTime? Created {get; set;} + [JsonProperty("lastModified")] + private DateTime? LastModified {get; set;} + [JsonProperty("version")] + private string Version {get; set;} + public ScimMeta() { } + public class Builder + { + private ScimMeta _scimMeta = new ScimMeta(); + public Builder() + { + } + public Builder WithResourceType(string resourceType) + { + _scimMeta.ResourceType= resourceType; + return this; + } + public Builder WithCreated(DateTime? created) + { + _scimMeta.Created= created; + return this; + } + public Builder WithLastModified(DateTime? lastModified) + { + _scimMeta.LastModified= lastModified; + return this; + } + public Builder WithVersion(string version) + { + _scimMeta.Version= version; + return this; + } + public ScimMeta Build() + { + return _scimMeta; + } + } + } + public class ScimUser + { + [JsonProperty("id")] + private string Id {get; set;} + [JsonProperty("externalId")] + private string ExternalId {get; set;} + [JsonProperty("userName")] + private string UserName {get; set;} + [JsonProperty("displayName")] + private string DisplayName {get; set;} + [JsonProperty("name")] + private ScimName Name {get; set;} + [JsonProperty("emails")] + private List Emails {get; set;} + [JsonProperty("active")] + private bool? Active {get; set;} + [JsonProperty("locale")] + private string Locale {get; set;} + [JsonProperty("timezone")] + private string Timezone {get; set;} + [JsonProperty("schemas")] + private List Schemas {get; set;} + [JsonProperty("meta")] + private ScimMeta Meta {get; set;} + public ScimUser() { } + public class Builder + { + private ScimUser _scimUser = new ScimUser(); + public Builder() + { + } + public Builder WithId(string id) + { + _scimUser.Id= id; + return this; + } + public Builder WithExternalId(string externalId) + { + _scimUser.ExternalId= externalId; + return this; + } + public Builder WithUserName(string userName) + { + _scimUser.UserName= userName; + return this; + } + public Builder WithDisplayName(string displayName) + { + _scimUser.DisplayName= displayName; + return this; + } + public Builder WithName(ScimName name) + { + _scimUser.Name= name; + return this; + } + public Builder WithEmails(List emails) + { + _scimUser.Emails= emails; + return this; + } + public Builder WithActive(bool? active) + { + _scimUser.Active= active; + return this; + } + public Builder WithLocale(string locale) + { + _scimUser.Locale= locale; + return this; + } + public Builder WithTimezone(string timezone) + { + _scimUser.Timezone= timezone; + return this; + } + public Builder WithSchemas(List schemas) + { + _scimUser.Schemas= schemas; + return this; + } + public Builder WithMeta(ScimMeta meta) + { + _scimUser.Meta= meta; + return this; + } + public ScimUser Build() + { + return _scimUser; + } + } + } + + + [JsonConverter(typeof(StringEnumConverter))] + public sealed class ScimTypeEnum : StringEnum + { + private ScimTypeEnum(string value) : base(value) {} + public ScimTypeEnum() {} + public static implicit operator ScimTypeEnum(string value) + { + return new ScimTypeEnum(value); + } + public static readonly ScimTypeEnum Invalidfilter = new ScimTypeEnum("invalidFilter"); + public static readonly ScimTypeEnum Uniqueness = new ScimTypeEnum("uniqueness"); + public static readonly ScimTypeEnum Mutability = new ScimTypeEnum("mutability"); + public static readonly ScimTypeEnum Invalidvalue = new ScimTypeEnum("invalidValue"); + public static readonly ScimTypeEnum Invalidsyntax = new ScimTypeEnum("invalidSyntax"); + + } + + + private static BearerTokenRequest BuildCreateRequest(CreateUserOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/scim/Users"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + + return new BearerTokenRequest( + HttpMethod.Post, + Rest.Domain.PreviewIam, + path, + + contentType: EnumConstants.ContentTypeEnum.JSON, + body: options.GetBody(), + headerParams: null + ); + } + + /// create + /// Create User parameters + /// Client to make requests to Twilio + /// A single instance of User + public static UserResource Create(CreateUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildCreateRequest(options, client)); + return FromJson(response.Content); + } + + #if !NET35 + /// create + /// Create User parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task CreateAsync(CreateUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildCreateRequest(options, client)); + return FromJson(response.Content); + } + #endif + + /// create + /// + /// + /// Client to make requests to Twilio + /// A single instance of User + public static UserResource Create( + string pathOrganizationSid, + UserResource.ScimUser scimUser, + TwilioBearerTokenRestClient client = null) + { + var options = new CreateUserOptions(pathOrganizationSid, scimUser){ }; + return Create(options, client); + } + + #if !NET35 + /// create + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task CreateAsync( + string pathOrganizationSid, + UserResource.ScimUser scimUser, + TwilioBearerTokenRestClient client = null) + { + var options = new CreateUserOptions(pathOrganizationSid, scimUser){ }; + return await CreateAsync(options, client); + } + #endif + + /// delete + /// Delete User parameters + /// Client to make requests to Twilio + /// A single instance of User + private static BearerTokenRequest BuildDeleteRequest(DeleteUserOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + string PathUserSid = options.PathUserSid.ToString(); + path = path.Replace("{"+"UserSid"+"}", PathUserSid); + + return new BearerTokenRequest( + HttpMethod.Delete, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + + /// delete + /// Delete User parameters + /// Client to make requests to Twilio + /// A single instance of User + public static bool Delete(DeleteUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildDeleteRequest(options, client)); + return response.StatusCode == System.Net.HttpStatusCode.NoContent; + } + + #if !NET35 + /// delete + /// Delete User parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task DeleteAsync(DeleteUserOptions options, + TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildDeleteRequest(options, client)); + return response.StatusCode == System.Net.HttpStatusCode.NoContent; + } + #endif + + /// delete + /// + /// + /// Client to make requests to Twilio + /// A single instance of User + public static bool Delete(string pathOrganizationSid, string pathUserSid, TwilioBearerTokenRestClient client = null) + { + var options = new DeleteUserOptions(pathOrganizationSid, pathUserSid) ; + return Delete(options, client); + } + + #if !NET35 + /// delete + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task DeleteAsync(string pathOrganizationSid, string pathUserSid, TwilioBearerTokenRestClient client = null) + { + var options = new DeleteUserOptions(pathOrganizationSid, pathUserSid) ; + return await DeleteAsync(options, client); + } + #endif + + private static BearerTokenRequest BuildFetchRequest(FetchUserOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + string PathUserSid = options.PathUserSid.ToString(); + path = path.Replace("{"+"UserSid"+"}", PathUserSid); + + return new BearerTokenRequest( + HttpMethod.Get, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + + /// fetch + /// Fetch User parameters + /// Client to make requests to Twilio + /// A single instance of User + public static UserResource Fetch(FetchUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildFetchRequest(options, client)); + return FromJson(response.Content); + } + + #if !NET35 + /// fetch + /// Fetch User parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task FetchAsync(FetchUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildFetchRequest(options, client)); + return FromJson(response.Content); + } + #endif + /// fetch + /// + /// + /// Client to make requests to Twilio + /// A single instance of User + public static UserResource Fetch( + string pathOrganizationSid, + string pathUserSid, + TwilioBearerTokenRestClient client = null) + { + var options = new FetchUserOptions(pathOrganizationSid, pathUserSid){ }; + return Fetch(options, client); + } + + #if !NET35 + /// fetch + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task FetchAsync(string pathOrganizationSid, string pathUserSid, TwilioBearerTokenRestClient client = null) + { + var options = new FetchUserOptions(pathOrganizationSid, pathUserSid){ }; + return await FetchAsync(options, client); + } + #endif + + private static BearerTokenRequest BuildReadRequest(ReadUserOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/scim/Users"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + + return new BearerTokenRequest( + HttpMethod.Get, + Rest.Domain.PreviewIam, + path, + queryParams: options.GetParams(), + headerParams: null + ); + } + /// read + /// Read User parameters + /// Client to make requests to Twilio + /// A single instance of User + public static BearerTokenResourceSet Read(ReadUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildReadRequest(options, client)); + var page = Page.FromJson("Resources", response.Content); + return new BearerTokenResourceSet(page, options, client); + } + + #if !NET35 + /// read + /// Read User parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task> ReadAsync(ReadUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildReadRequest(options, client)); + + var page = Page.FromJson("Resources", response.Content); + return new BearerTokenResourceSet(page, options, client); + } + #endif + /// read + /// + /// + /// Record limit + /// Client to make requests to Twilio + /// A single instance of User + public static BearerTokenResourceSet Read( + string pathOrganizationSid, + string filter = null, + long? limit = null, + TwilioBearerTokenRestClient client = null) + { + var options = new ReadUserOptions(pathOrganizationSid){ Filter = filter, Limit = limit}; + return Read(options, client); + } + + #if !NET35 + /// read + /// + /// + /// Record limit + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task> ReadAsync( + string pathOrganizationSid, + string filter = null, + long? limit = null, + TwilioBearerTokenRestClient client = null) + { + var options = new ReadUserOptions(pathOrganizationSid){ Filter = filter, Limit = limit}; + return await ReadAsync(options, client); + } + #endif + + + /// Fetch the target page of records + /// API-generated URL for the requested results page + /// Client to make requests to Twilio + /// The target page of records + public static Page GetPage(string targetUrl, TwilioBearerTokenRestClient client) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + + var request = new BearerTokenRequest( + HttpMethod.Get, + targetUrl + ); + + var response = client.Request(request); + return Page.FromJson("Resources", response.Content); + } + + /// Fetch the next page of records + /// current page of records + /// Client to make requests to Twilio + /// The next page of records + public static Page NextPage(Page page, TwilioBearerTokenRestClient client) + { + var request = new BearerTokenRequest( + HttpMethod.Get, + page.GetNextPageUrl(Rest.Domain.Api) + ); + + var response = client.Request(request); + return Page.FromJson("Resources", response.Content); + } + + /// Fetch the previous page of records + /// current page of records + /// Client to make requests to Twilio + /// The previous page of records + public static Page PreviousPage(Page page, TwilioBearerTokenRestClient client) + { + var request = new BearerTokenRequest( + HttpMethod.Get, + page.GetPreviousPageUrl(Rest.Domain.Api) + ); + + var response = client.Request(request); + return Page.FromJson("Resources", response.Content); + } + + + private static BearerTokenRequest BuildUpdateRequest(UpdateUserOptions options, TwilioBearerTokenRestClient client) + { + + string path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; + + string PathOrganizationSid = options.PathOrganizationSid.ToString(); + path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); + string PathUserSid = options.PathUserSid.ToString(); + path = path.Replace("{"+"UserSid"+"}", PathUserSid); + + return new BearerTokenRequest( + HttpMethod.Put, + Rest.Domain.PreviewIam, + path, + + contentType: EnumConstants.ContentTypeEnum.JSON, + body: options.GetBody(), + headerParams: options.GetHeaderParams() + ); + } + + /// update + /// Update User parameters + /// Client to make requests to Twilio + /// A single instance of User + public static UserResource Update(UpdateUserOptions options, TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = client.Request(BuildUpdateRequest(options, client)); + return FromJson(response.Content); + } + + /// update + /// Update User parameters + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + #if !NET35 + public static async System.Threading.Tasks.Task UpdateAsync(UpdateUserOptions options, + TwilioBearerTokenRestClient client = null) + { + client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); + var response = await client.RequestAsync(BuildUpdateRequest(options, client)); + return FromJson(response.Content); + } + #endif + + /// update + /// + /// + /// + /// + /// Client to make requests to Twilio + /// A single instance of User + public static UserResource Update( + string pathOrganizationSid, + string pathUserSid, + UserResource.ScimUser scimUser, + string ifMatch = null, + TwilioBearerTokenRestClient client = null) + { + var options = new UpdateUserOptions(pathOrganizationSid, pathUserSid, scimUser){ IfMatch = ifMatch }; + return Update(options, client); + } + + #if !NET35 + /// update + /// + /// + /// + /// + /// Client to make requests to Twilio + /// Task that resolves to A single instance of User + public static async System.Threading.Tasks.Task UpdateAsync( + string pathOrganizationSid, + string pathUserSid, + UserResource.ScimUser scimUser, + string ifMatch = null, + TwilioBearerTokenRestClient client = null) + { + var options = new UpdateUserOptions(pathOrganizationSid, pathUserSid, scimUser){ IfMatch = ifMatch }; + return await UpdateAsync(options, client); + } + #endif + + /// + /// Converts a JSON string into a UserResource object + /// + /// Raw JSON string + /// UserResource object represented by the provided JSON + public static UserResource FromJson(string json) + { + try + { + return JsonConvert.DeserializeObject(json); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + /// + /// Converts an object into a json string + /// + /// C# model + /// JSON string + public static string ToJson(object model) + { + try + { + return JsonConvert.SerializeObject(model); + } + catch (JsonException e) + { + throw new ApiException(e.Message, e); + } + } + + + /// Unique Twilio user sid + [JsonProperty("id")] + public string Id { get; private set; } + + /// External unique resource id defined by provisioning client + [JsonProperty("externalId")] + public string ExternalId { get; private set; } + + /// Unique username, MUST be same as primary email address + [JsonProperty("userName")] + public string UserName { get; } + + /// User friendly display name + [JsonProperty("displayName")] + public string DisplayName { get; private set; } + + /// The name + [JsonProperty("name")] + public ScimName Name { get; private set; } + + /// Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. + [JsonProperty("emails")] + public List Emails { get; private set; } + + /// Indicates whether the user is active + [JsonProperty("active")] + public bool? Active { get; private set; } + + /// User's locale + [JsonProperty("locale")] + public string Locale { get; private set; } + + /// User's time zone + [JsonProperty("timezone")] + public string Timezone { get; private set; } + + /// An array of URIs that indicate the schemas supported for this user resource + [JsonProperty("schemas")] + public List Schemas { get; private set; } + + /// The meta + [JsonProperty("meta")] + public ScimMeta Meta { get; private set; } + + /// Schema URIs that define the contents of the error structure + [JsonProperty("_schemas")] + public List _Schemas { get; private set; } + + /// A human-readable description of the error + [JsonProperty("detail")] + public string Detail { get; private set; } + + /// A scimType error code as defined in RFC7644 + [JsonProperty("scimType")] + public UserResource.ScimTypeEnum ScimType { get; private set; } + + /// Http status code + [JsonProperty("status")] + public string Status { get; private set; } + + /// Twilio-specific error code + [JsonProperty("code")] + public int? Code { get; private set; } + + /// Link to Error Code References + [JsonProperty("moreInfo")] + public string MoreInfo { get; private set; } + + + + private UserResource() { + + } + } +} + diff --git a/src/Twilio/TwilioNoAuth.cs b/src/Twilio/TwilioNoAuth.cs new file mode 100644 index 000000000..8e3a32a1f --- /dev/null +++ b/src/Twilio/TwilioNoAuth.cs @@ -0,0 +1,64 @@ +using Twilio.Clients; +using Twilio.Exceptions; +using Twilio.Clients.NoAuth; + +namespace Twilio +{ + /// + /// Default Twilio Client + /// + public class TwilioNoAuthClient + { + + private static string _region; + private static string _edge; + private static TwilioNoAuthRestClient _restClient; + private static string _logLevel; + + private TwilioNoAuthClient() { } + + /// + /// Get the rest client + /// + /// The rest client + public static TwilioNoAuthRestClient GetRestClient() + { + if (_restClient != null) + { + return _restClient; + } + + _restClient = new TwilioNoAuthRestClient(region: _region, edge: _edge) + { + LogLevel = _logLevel + }; + return _restClient; + } + + /// + /// Set the rest client + /// + /// Rest Client to use + public static void SetRestClient(TwilioNoAuthRestClient restClient) + { + _restClient = restClient; + } + + /// + /// Clear out the Rest Client + /// + public static void Invalidate() + { + _restClient = null; + } + + /// + /// Test if your environment is impacted by a TLS or certificate change + /// by sending an HTTP request to the test endpoint tls-test.twilio.com:443 + /// + public static void ValidateSslCertificate() + { + TwilioNoAuthRestClient.ValidateSslCertificate(); + } + } +} diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs new file mode 100644 index 000000000..c204e7f9f --- /dev/null +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -0,0 +1,160 @@ +using Twilio.Clients; +using Twilio.Clients.BearerToken; +using Twilio.Exceptions; +using Twilio.Http.BearerToken; + +namespace Twilio +{ + /// + /// Default Twilio Client for bearer token authentication + /// + public class TwilioOrgsTokenAuthClient + { + private static string _accessToken; + private static string _region; + private static string _edge; + private static TwilioBearerTokenRestClient _restClient; + private static string _logLevel; + private static TokenManager _tokenManager; + + private TwilioOrgsTokenAuthClient() { } + + /// + /// Initialize base client with username and password + /// + public static void Init(string grantType, string clientId, string clientSecret) + { + validateCredentials(grantType, clientId, clientSecret); + _tokenManager = new OrgsTokenManager(grantType, clientId, clientSecret); + } + + + /// + /// Initialize base client + /// + public static void Init(string grantType, string clientId, string clientSecret, + string code = null, + string redirectUri = null, + string audience = null, + string refreshToken = null, + string scope = null) + { + validateCredentials(grantType, clientId, clientSecret); + _tokenManager = new OrgsTokenManager(grantType, clientId, clientSecret, code, redirectUri, audience, refreshToken, scope); + } + + + /// + /// Validate grant type, client id and client secret and verify none of them are null + /// + public static void validateCredentials(string grantType, string clientId, string clientSecret) + { + if (grantType == null) + { + throw new AuthenticationException("grantType can not be null"); + } + if (clientId == null) + { + throw new AuthenticationException("clientId can not be null"); + } + if (clientSecret == null) + { + throw new AuthenticationException("clientSecret can not be null"); + } + + } + + /// + /// Set the client region + /// + /// Client region + public static void SetRegion(string region) + { + if (region != _region) + { + Invalidate(); + } + + _region = region; + } + + /// + /// Set the client edge + /// + /// Client edge + public static void SetEdge(string edge) + { + if (edge != _edge) + { + Invalidate(); + } + + _edge = edge; + } + + /// + /// Set the logging level + /// + /// log level + public static void SetLogLevel(string loglevel) + { + if (loglevel != _logLevel) + { + Invalidate(); + } + + _logLevel = loglevel; + } + + /// + /// Get the rest client + /// + /// The rest client + public static TwilioBearerTokenRestClient GetRestClient() + { + if (_restClient != null) + { + return _restClient; + } + + if (_tokenManager == null) + { + throw new AuthenticationException( + "TwilioBearerTokenRestClient was used before token manager was set, please call TwilioClient.init()" + ); + } + + _restClient = new TwilioBearerTokenRestClient(_tokenManager, region: _region, edge: _edge) + { + LogLevel = _logLevel + }; + return _restClient; + } + + /// + /// Set the rest client + /// + /// Rest Client to use + public static void SetRestClient(TwilioBearerTokenRestClient restClient) + { + _restClient = restClient; + } + + /// + /// Clear out the Rest Client + /// + public static void Invalidate() + { + _restClient = null; + } + + /// + /// Test if your environment is impacted by a TLS or certificate change + /// by sending an HTTP request to the test endpoint tls-test.twilio.com:443 + /// + public static void ValidateSslCertificate() + { + TwilioRestClient.ValidateSslCertificate(); + } + } +} From 5667bece2e2958480923a350d4651f6d10d052d8 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 31 Jul 2024 08:09:26 +0530 Subject: [PATCH 02/24] uptake of review comments --- .../Clients/NoAuth/TwilioNoAuthRestClient.cs | 8 +++----- src/Twilio/TwilioNoAuth.cs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs index 8a0fae478..fb8c7f951 100644 --- a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs +++ b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs @@ -54,11 +54,9 @@ public class TwilioNoAuthRestClient /// Constructor for a TwilioRestClient /// /// - /// access token for requests - /// account sid to make requests for - /// region to make requests for - /// http client used to make the requests - /// edge to make requests for + /// Region to make requests for + /// HTTP client used to make the requests + /// Edge to make requests for public TwilioNoAuthRestClient( string region = null, NoAuthHttpClient httpClient = null, diff --git a/src/Twilio/TwilioNoAuth.cs b/src/Twilio/TwilioNoAuth.cs index 8e3a32a1f..e43d1f192 100644 --- a/src/Twilio/TwilioNoAuth.cs +++ b/src/Twilio/TwilioNoAuth.cs @@ -35,6 +35,20 @@ public static TwilioNoAuthRestClient GetRestClient() return _restClient; } + /// + /// Set the logging level + /// + /// log level + public static void SetLogLevel(string loglevel) + { + if (loglevel != _logLevel) + { + Invalidate(); + } + + _logLevel = loglevel; + } + /// /// Set the rest client /// From a769eac48fd5d502530fd34e87008c3ffa32d359 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 31 Jul 2024 08:19:07 +0530 Subject: [PATCH 03/24] adding examples for bearer token authentication --- examples/BearerTokenAuthentication.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/BearerTokenAuthentication.md diff --git a/examples/BearerTokenAuthentication.md b/examples/BearerTokenAuthentication.md new file mode 100644 index 000000000..30578bf09 --- /dev/null +++ b/examples/BearerTokenAuthentication.md @@ -0,0 +1,21 @@ +using System; +using Twilio; +using Twilio.Base; +using Twilio.Exceptions; +using Twilio.Rest.Api.V2010.Account; +using Twilio.Rest.PreviewIam.Organizations; + +//Find client id, client secret and organisation sid from admin center of your organisation +//path account sid is the sid of the account withing the organisation +class Program +{ + static void Main(string[] args) + { + TwilioOrgsTokenAuthClient.Init(GRANT_TYPE, CLIENT_ID, CLIENT_SECRET); + Twilio.Base.BearerToken.BearerTokenResourceSet accountList = null; + accountList = Twilio.Rest.PreviewIam.Organizations.AccountResource.Read(pathOrganizationSid: ORGS_SID); + Console.WriteLine(accountList.ElementAt(0).FriendlyName); + var account = Twilio.Rest.PreviewIam.Organizations.AccountResource.Fetch(pathOrganizationSid: ORGS_SID, pathAccountSid: PATH_ACCOUNT_SID); + Console.WriteLine(account.FriendlyName); + } +} From 4816bc86c5c80f53788c4b111b5dff0247b5c9f4 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 31 Jul 2024 08:23:45 +0530 Subject: [PATCH 04/24] Update documentation for bearer token auth rest calls --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 07f5306ec..a1299be00 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,8 @@ var message = MessageResource.Create( Console.WriteLine(message.Sid); ``` +Examples on how to make rest calls with bearer token authentication is added [here][examples/BearerTokenAuthentication.md] + ## Specify Region and/or Edge To take advantage of Twilio's [Global Infrastructure](https://www.twilio.com/docs/global-infrastructure), specify the target Region and/or Edge for the client: @@ -82,7 +84,7 @@ TwilioClient.SetRegion("au1"); TwilioClient.SetEdge("sydney"); ``` -This will result in the `hostname` transforming from `api.twilio.com` to `api.sydney.au1.twilio.com`. +This will result in the `hostname` transforming from `api.twilio.com` to `api.sydney.au1.twilio.com`. Use appropriate client depending on the type of authentication used ## Enable debug logging From 78ac734952008dea053e39e38103646c0da2424b Mon Sep 17 00:00:00 2001 From: Athira Sabu <102021496+AsabuHere@users.noreply.github.com> Date: Wed, 31 Jul 2024 08:24:59 +0530 Subject: [PATCH 05/24] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1299be00..a64913ae5 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ var message = MessageResource.Create( Console.WriteLine(message.Sid); ``` -Examples on how to make rest calls with bearer token authentication is added [here][examples/BearerTokenAuthentication.md] +Examples on how to make rest calls with bearer token authentication is added [here][[[examples/BearerTokenAuthentication.md](https://github.com/twilio/twilio-csharp/blob/orgs_api_uptake/examples/BearerTokenAuthentication.md)](https://github.com/twilio/twilio-csharp/blob/orgs_api_uptake/examples/BearerTokenAuthentication.md)] ## Specify Region and/or Edge From 388a4c3ff61c52695f5a3af12301227e376e6bbc Mon Sep 17 00:00:00 2001 From: Athira Sabu <102021496+AsabuHere@users.noreply.github.com> Date: Wed, 31 Jul 2024 08:25:41 +0530 Subject: [PATCH 06/24] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a64913ae5..ea98de730 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ var message = MessageResource.Create( Console.WriteLine(message.Sid); ``` -Examples on how to make rest calls with bearer token authentication is added [here][[[examples/BearerTokenAuthentication.md](https://github.com/twilio/twilio-csharp/blob/orgs_api_uptake/examples/BearerTokenAuthentication.md)](https://github.com/twilio/twilio-csharp/blob/orgs_api_uptake/examples/BearerTokenAuthentication.md)] +Examples on how to make rest calls with bearer token authentication is added [here](https://github.com/twilio/twilio-csharp/blob/orgs_api_uptake/examples/BearerTokenAuthentication.md) ## Specify Region and/or Edge From c5b46b454c0a65474c647d53619bfdd68a5d9604 Mon Sep 17 00:00:00 2001 From: Athira Sabu <102021496+AsabuHere@users.noreply.github.com> Date: Wed, 31 Jul 2024 08:26:49 +0530 Subject: [PATCH 07/24] Update BearerTokenAuthentication.md --- examples/BearerTokenAuthentication.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/BearerTokenAuthentication.md b/examples/BearerTokenAuthentication.md index 30578bf09..7f654508a 100644 --- a/examples/BearerTokenAuthentication.md +++ b/examples/BearerTokenAuthentication.md @@ -1,3 +1,4 @@ +```csharp using System; using Twilio; using Twilio.Base; @@ -19,3 +20,4 @@ class Program Console.WriteLine(account.FriendlyName); } } +``` From ed6f6b2e5df2da16bcdfc864959df375d45c96c4 Mon Sep 17 00:00:00 2001 From: Athira Sabu <102021496+AsabuHere@users.noreply.github.com> Date: Tue, 3 Sep 2024 16:56:18 +0530 Subject: [PATCH 08/24] fix: Adding jwt token expiry check function (#754) * Adding jwt token expiry check function * Adding jwt token expiry check function * sharing variables between clients * sharing variables between clients --- src/Twilio/Base/Page.cs | 53 ++++---- src/Twilio/ClientProperties.cs | 45 +++++++ src/Twilio/Clients/Base64UrlEncoder.cs | 30 +++++ .../TwilioBearerTokenRestClient.cs | 119 ++++++++++++++---- .../SystemNetBearerTokenHttpClient.cs | 1 + src/Twilio/TwilioNoAuth.cs | 18 +-- src/Twilio/TwilioOrgsTokenAuth.cs | 7 +- 7 files changed, 210 insertions(+), 63 deletions(-) create mode 100644 src/Twilio/ClientProperties.cs create mode 100644 src/Twilio/Clients/Base64UrlEncoder.cs diff --git a/src/Twilio/Base/Page.cs b/src/Twilio/Base/Page.cs index cf1a72234..50b95e66e 100644 --- a/src/Twilio/Base/Page.cs +++ b/src/Twilio/Base/Page.cs @@ -125,36 +125,43 @@ public static Page FromJson(string recordKey, string json) var parsedRecords = records.Children().Select( record => JsonConvert.DeserializeObject(record.ToString()) ).ToList(); + + if(root["uri"] != null){ + var uriNode = root["uri"]; + if (uriNode != null) + { + JToken pageSize; + JToken firstPageUri; + JToken nextPageUri; + JToken previousPageUri; - var uriNode = root["uri"]; - if (uriNode != null) - { - JToken pageSize; - JToken firstPageUri; - JToken nextPageUri; - JToken previousPageUri; + // v2010 API + return new Page( + parsedRecords, + root.TryGetValue("page_size", out pageSize) ? root["page_size"].Value() : parsedRecords.Count, + uri: uriNode.Value(), + firstPageUri: root.TryGetValue("first_page_uri", out firstPageUri) ? root["first_page_uri"].Value() : null, + nextPageUri: root.TryGetValue("next_page_uri", out nextPageUri) ? root["next_page_uri"].Value() : null, + previousPageUri: root.TryGetValue("previous_page_uri", out previousPageUri) ? root["previous_page_uri"].Value() : null + ); + } + } - // v2010 API + // next-gen API + if(root["meta"] != null){ + var meta = root["meta"]; return new Page( parsedRecords, - root.TryGetValue("page_size", out pageSize) ? root["page_size"].Value() : parsedRecords.Count, - uri: uriNode.Value(), - firstPageUri: root.TryGetValue("first_page_uri", out firstPageUri) ? root["first_page_uri"].Value() : null, - nextPageUri: root.TryGetValue("next_page_uri", out nextPageUri) ? root["next_page_uri"].Value() : null, - previousPageUri: root.TryGetValue("previous_page_uri", out previousPageUri) ? root["previous_page_uri"].Value() : null + meta["page_size"].Value(), + url: meta["url"].Value(), + firstPageUrl: meta["first_page_url"].Value(), + nextPageUrl: meta["next_page_url"].Value(), + previousPageUrl: meta["previous_page_url"].Value() ); } - // next-gen API - var meta = root["meta"]; - return new Page( - parsedRecords, - meta["page_size"].Value(), - url: meta["url"].Value(), - firstPageUrl: meta["first_page_url"].Value(), - nextPageUrl: meta["next_page_url"].Value(), - previousPageUrl: meta["previous_page_url"].Value() - ); + return new Page(parsedRecords, 0, null, null, null, null); + } } } diff --git a/src/Twilio/ClientProperties.cs b/src/Twilio/ClientProperties.cs new file mode 100644 index 000000000..8e605f977 --- /dev/null +++ b/src/Twilio/ClientProperties.cs @@ -0,0 +1,45 @@ +using Twilio.Clients; +using Twilio.Clients.BearerToken; +using Twilio.Exceptions; +using Twilio.Http.BearerToken; + +namespace Twilio +{ + public class ClientProperties + { + public static string region; + public static string edge; + public static string logLevel; + + public ClientProperties() { } + + + /// + /// Set the client region + /// + /// Client region + public static void SetRegion(string region) + { + region = region; + } + + /// + /// Set the client edge + /// + /// Client edge + public static void SetEdge(string edge) + { + edge = edge; + } + + /// + /// Set the logging level + /// + /// log level + public static void SetLogLevel(string loglevel) + { + logLevel = loglevel; + } + + } +} diff --git a/src/Twilio/Clients/Base64UrlEncoder.cs b/src/Twilio/Clients/Base64UrlEncoder.cs new file mode 100644 index 000000000..a47662072 --- /dev/null +++ b/src/Twilio/Clients/Base64UrlEncoder.cs @@ -0,0 +1,30 @@ +#if NET35 +using System; +using System.Collections.Generic; +using System.Text; +using System.Web.Script.Serialization; + +namespace Twilio.Clients{ + + public abstract class Base64UrlEncoder + { + public static string Decode(string base64Url) + { + // Replace URL-safe characters with Base64 characters + string base64 = base64Url + .Replace('-', '+') + .Replace('_', '/'); + + // Add padding if necessary + switch (base64.Length % 4) + { + case 2: base64 += "=="; break; + case 3: base64 += "="; break; + } + + byte[] bytes = Convert.FromBase64String(base64); + return Encoding.UTF8.GetString(bytes); + } + } +} +#endif diff --git a/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs index 42477abd4..066ba671b 100644 --- a/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs +++ b/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs @@ -1,14 +1,14 @@ - -using System; +using System; using System.Net; using System.Linq; using Newtonsoft.Json; using Twilio.Exceptions; using Twilio.Http.BearerToken; using Twilio.Jwt; - +using Twilio.Clients; #if !NET35 +using System.IdentityModel.Tokens.Jwt; using System.Threading.Tasks; #endif @@ -16,6 +16,9 @@ using Twilio.Http.BearerToken; #if NET35 using Twilio.Http.Net35; +using System.Collections.Generic; +using System.Text; +using System.Web.Script.Serialization; #endif @@ -87,6 +90,21 @@ public TwilioBearerTokenRestClient( Edge = edge; } + /// + /// Check if an access token is expired or not. Use the System.IdentityModel.Tokens.Jwt; for versions other + /// than net35 and use redirect to custom function if net35 + /// + /// + /// access token for which expiry have to be checked + /// true if expired, false otherwise + public bool tokenExpired(String accessToken){ + #if NET35 + return IsTokenExpired(accessToken); + #else + return isTokenExpired(accessToken); + #endif + } + /// /// Make a request to the Twilio API /// @@ -95,12 +113,9 @@ public TwilioBearerTokenRestClient( /// response of the request public Response Request(BearerTokenRequest request) { - - if (_accessToken == null ){ - //|| isTokenExpired(_accessToken)) { + if ((_accessToken == null )|| tokenExpired(_accessToken)) { lock (lockObject){ - if (_accessToken == null){ - //|| isTokenExpired(_accessToken)) { + if ((_accessToken == null) || tokenExpired(_accessToken)) { _accessToken = _tokenManager.fetchAccessToken(); } } @@ -139,21 +154,78 @@ public Response Request(BearerTokenRequest request) return ProcessResponse(response); } - /// - /// To check if token is expired or not - /// - /// - /// token to validate - /// True if token is not expired, false otherwise -// public bool isTokenExpired(String token) { -// -// var tokenHandler = new JwtSecurityTokenHandler(); -// var jwtToken = tokenHandler.ReadJwtToken(token); -// var expirationTime = jwtToken.Payload.Exp.HasValue -// ? DateTimeOffset.FromUnixTimeSeconds(jwtToken.Payload.Exp.Value) -// : DateTimeOffset.MinValue; -// return expirationTime <= DateTimeOffset.UtcNow; -// } +#if NET35 + public static bool IsTokenExpired(string token) + { + try + { + // Split the token into its components + var parts = token.Split('.'); + if (parts.Length != 3) + throw new ArgumentException("Malformed token received"); + + // Decode the payload (the second part of the JWT) + string payload = Base64UrlEncoder.Decode(parts[1]); + + // Parse the payload JSON + var serializer = new JavaScriptSerializer(); + var payloadData = serializer.Deserialize>(payload); + + // Check the 'exp' claim + if (payloadData.TryGetValue("exp", out object expObj)) + { + if (long.TryParse(expObj.ToString(), out long exp)) + { + DateTime expirationDate = UnixTimeStampToDateTime(exp); + return DateTime.UtcNow > expirationDate; + } + } + + // If 'exp' claim is missing or not a valid timestamp, consider the token expired + throw new ApiConnectionException("token expired 1"); + return true; + } + catch (Exception ex) + { + // Handle exceptions (e.g., malformed token or invalid JSON) + Console.WriteLine($"Error checking token expiration: {ex.Message}"); + throw new ApiConnectionException("token expired 2"); + return true; // Consider as expired if there's an error + } + } + + private static DateTime UnixTimeStampToDateTime(long unixTimeStamp) + { + // Unix timestamp is seconds past epoch + var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); + return epoch.AddSeconds(unixTimeStamp); + } +#endif + +#if !NET35 + public bool isTokenExpired(string token){ + var handler = new JwtSecurityTokenHandler(); + try{ + var jwtToken = handler.ReadJwtToken(token); + var exp = jwtToken.Payload.Exp; + if (exp.HasValue) + { + var expirationDate = DateTimeOffset.FromUnixTimeSeconds(exp.Value).UtcDateTime; + return DateTime.UtcNow > expirationDate; + } + else + { + return true; // Assuming token is expired if exp claim is missing + } + } + catch (Exception ex) + { + Console.WriteLine($"Error reading token: {ex.Message}"); + + return true; // Treat as expired if there is an error + } + } +#endif #if !NET35 /// @@ -208,6 +280,7 @@ private static Response ProcessResponse(Response response) throw new ApiConnectionException("Connection Error: No response received."); } + if (response.StatusCode >= HttpStatusCode.OK && response.StatusCode < HttpStatusCode.BadRequest) { return response; diff --git a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs index c4c1c0e3f..c146c8406 100644 --- a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs @@ -101,6 +101,7 @@ private HttpRequestMessage BuildHttpRequest(BearerTokenRequest request) httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authBytes); httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + httpRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/scim+json")); httpRequest.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("utf-8")); int lastSpaceIndex = PlatVersion.LastIndexOf(" "); diff --git a/src/Twilio/TwilioNoAuth.cs b/src/Twilio/TwilioNoAuth.cs index e43d1f192..bce5a73e7 100644 --- a/src/Twilio/TwilioNoAuth.cs +++ b/src/Twilio/TwilioNoAuth.cs @@ -14,6 +14,7 @@ public class TwilioNoAuthClient private static string _edge; private static TwilioNoAuthRestClient _restClient; private static string _logLevel; + private static ClientProperties clientProperties; private TwilioNoAuthClient() { } @@ -28,6 +29,9 @@ public static TwilioNoAuthRestClient GetRestClient() return _restClient; } + if(_region == null && ClientProperties.region != null) _region = ClientProperties.region; + if(_edge == null && ClientProperties.edge != null) _edge = ClientProperties.edge; + if(_logLevel == null && ClientProperties.logLevel != null) _logLevel = ClientProperties.logLevel; _restClient = new TwilioNoAuthRestClient(region: _region, edge: _edge) { LogLevel = _logLevel @@ -35,20 +39,6 @@ public static TwilioNoAuthRestClient GetRestClient() return _restClient; } - /// - /// Set the logging level - /// - /// log level - public static void SetLogLevel(string loglevel) - { - if (loglevel != _logLevel) - { - Invalidate(); - } - - _logLevel = loglevel; - } - /// /// Set the rest client /// diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs index c204e7f9f..1b8641f16 100644 --- a/src/Twilio/TwilioOrgsTokenAuth.cs +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -16,6 +16,7 @@ public class TwilioOrgsTokenAuthClient private static TwilioBearerTokenRestClient _restClient; private static string _logLevel; private static TokenManager _tokenManager; + private static ClientProperties clientProperties; private TwilioOrgsTokenAuthClient() { } @@ -74,7 +75,7 @@ public static void SetRegion(string region) { Invalidate(); } - + ClientProperties.SetRegion(region); _region = region; } @@ -88,7 +89,7 @@ public static void SetEdge(string edge) { Invalidate(); } - + ClientProperties.SetEdge(edge); _edge = edge; } @@ -102,7 +103,7 @@ public static void SetLogLevel(string loglevel) { Invalidate(); } - + ClientProperties.SetLogLevel(_logLevel); _logLevel = loglevel; } From 04e9e317636c9cbc1d8a3f1cf248ca1f2534ae2b Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Tue, 3 Sep 2024 18:52:41 +0530 Subject: [PATCH 09/24] review comments uptake --- src/Twilio/ClientProperties.cs | 45 ------------ .../Organizations/AuthorizeResource.cs | 4 +- .../PreviewIam/Organizations/TokenResource.cs | 4 +- src/Twilio/Twilio.csproj | 5 ++ src/Twilio/TwilioNoAuth.cs | 68 ------------------- src/Twilio/TwilioOrgsTokenAuth.cs | 25 +++++-- 6 files changed, 30 insertions(+), 121 deletions(-) delete mode 100644 src/Twilio/ClientProperties.cs delete mode 100644 src/Twilio/TwilioNoAuth.cs diff --git a/src/Twilio/ClientProperties.cs b/src/Twilio/ClientProperties.cs deleted file mode 100644 index 8e605f977..000000000 --- a/src/Twilio/ClientProperties.cs +++ /dev/null @@ -1,45 +0,0 @@ -using Twilio.Clients; -using Twilio.Clients.BearerToken; -using Twilio.Exceptions; -using Twilio.Http.BearerToken; - -namespace Twilio -{ - public class ClientProperties - { - public static string region; - public static string edge; - public static string logLevel; - - public ClientProperties() { } - - - /// - /// Set the client region - /// - /// Client region - public static void SetRegion(string region) - { - region = region; - } - - /// - /// Set the client edge - /// - /// Client edge - public static void SetEdge(string edge) - { - edge = edge; - } - - /// - /// Set the logging level - /// - /// log level - public static void SetLogLevel(string loglevel) - { - logLevel = loglevel; - } - - } -} diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs index 554730147..4535c7921 100644 --- a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs +++ b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs @@ -58,7 +58,7 @@ private static NoAuthRequest BuildFetchRequest(FetchAuthorizeOptions options, Tw /// A single instance of Authorize public static AuthorizeResource Fetch(FetchAuthorizeOptions options, TwilioNoAuthRestClient client = null) { - client = client ?? TwilioNoAuthClient.GetRestClient(); + client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient(); var response = client.Request(BuildFetchRequest(options, client)); return FromJson(response.Content); } @@ -70,7 +70,7 @@ public static AuthorizeResource Fetch(FetchAuthorizeOptions options, TwilioNoAut /// Task that resolves to A single instance of Authorize public static async System.Threading.Tasks.Task FetchAsync(FetchAuthorizeOptions options, TwilioNoAuthRestClient client = null) { - client = client ?? TwilioNoAuthClient.GetRestClient(); + client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient(); var response = await client.RequestAsync(BuildFetchRequest(options, client)); return FromJson(response.Content); } diff --git a/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs index eeaf13623..688068aef 100644 --- a/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs +++ b/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs @@ -59,7 +59,7 @@ private static NoAuthRequest BuildCreateRequest(CreateTokenOptions options, Twil /// A single instance of Token public static TokenResource Create(CreateTokenOptions options, TwilioNoAuthRestClient client = null) { - client = client ?? TwilioNoAuthClient.GetRestClient(); + client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient(); var response = client.Request(BuildCreateRequest(options, client)); return FromJson(response.Content); } @@ -71,7 +71,7 @@ public static TokenResource Create(CreateTokenOptions options, TwilioNoAuthRestC /// Task that resolves to A single instance of Token public static async System.Threading.Tasks.Task CreateAsync(CreateTokenOptions options, TwilioNoAuthRestClient client = null) { - client = client ?? TwilioNoAuthClient.GetRestClient(); + client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient(); var response = await client.RequestAsync(BuildCreateRequest(options, client)); return FromJson(response.Content); } diff --git a/src/Twilio/Twilio.csproj b/src/Twilio/Twilio.csproj index 0b08004fb..d8e64ad4f 100644 --- a/src/Twilio/Twilio.csproj +++ b/src/Twilio/Twilio.csproj @@ -28,6 +28,11 @@ + + + C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\System.Web.Extensions.dll + + diff --git a/src/Twilio/TwilioNoAuth.cs b/src/Twilio/TwilioNoAuth.cs deleted file mode 100644 index bce5a73e7..000000000 --- a/src/Twilio/TwilioNoAuth.cs +++ /dev/null @@ -1,68 +0,0 @@ -using Twilio.Clients; -using Twilio.Exceptions; -using Twilio.Clients.NoAuth; - -namespace Twilio -{ - /// - /// Default Twilio Client - /// - public class TwilioNoAuthClient - { - - private static string _region; - private static string _edge; - private static TwilioNoAuthRestClient _restClient; - private static string _logLevel; - private static ClientProperties clientProperties; - - private TwilioNoAuthClient() { } - - /// - /// Get the rest client - /// - /// The rest client - public static TwilioNoAuthRestClient GetRestClient() - { - if (_restClient != null) - { - return _restClient; - } - - if(_region == null && ClientProperties.region != null) _region = ClientProperties.region; - if(_edge == null && ClientProperties.edge != null) _edge = ClientProperties.edge; - if(_logLevel == null && ClientProperties.logLevel != null) _logLevel = ClientProperties.logLevel; - _restClient = new TwilioNoAuthRestClient(region: _region, edge: _edge) - { - LogLevel = _logLevel - }; - return _restClient; - } - - /// - /// Set the rest client - /// - /// Rest Client to use - public static void SetRestClient(TwilioNoAuthRestClient restClient) - { - _restClient = restClient; - } - - /// - /// Clear out the Rest Client - /// - public static void Invalidate() - { - _restClient = null; - } - - /// - /// Test if your environment is impacted by a TLS or certificate change - /// by sending an HTTP request to the test endpoint tls-test.twilio.com:443 - /// - public static void ValidateSslCertificate() - { - TwilioNoAuthRestClient.ValidateSslCertificate(); - } - } -} diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs index 1b8641f16..16a6ac8ab 100644 --- a/src/Twilio/TwilioOrgsTokenAuth.cs +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -1,4 +1,5 @@ using Twilio.Clients; +using Twilio.Clients.NoAuth; using Twilio.Clients.BearerToken; using Twilio.Exceptions; using Twilio.Http.BearerToken; @@ -14,9 +15,9 @@ public class TwilioOrgsTokenAuthClient private static string _region; private static string _edge; private static TwilioBearerTokenRestClient _restClient; + private static TwilioNoAuthRestClient _noAuthRestClient; private static string _logLevel; private static TokenManager _tokenManager; - private static ClientProperties clientProperties; private TwilioOrgsTokenAuthClient() { } @@ -75,7 +76,6 @@ public static void SetRegion(string region) { Invalidate(); } - ClientProperties.SetRegion(region); _region = region; } @@ -89,7 +89,6 @@ public static void SetEdge(string edge) { Invalidate(); } - ClientProperties.SetEdge(edge); _edge = edge; } @@ -103,7 +102,6 @@ public static void SetLogLevel(string loglevel) { Invalidate(); } - ClientProperties.SetLogLevel(_logLevel); _logLevel = loglevel; } @@ -132,6 +130,25 @@ public static TwilioBearerTokenRestClient GetRestClient() return _restClient; } + + /// + /// Get the noauth rest client + /// + /// The not auth rest client + public static TwilioNoAuthRestClient GetNoAuthRestClient() + { + if (_noAuthRestClient != null) + { + return _noAuthRestClient; + } + + _noAuthRestClient = new TwilioNoAuthRestClient(region: _region, edge: _edge) + { + LogLevel = _logLevel + }; + return _noAuthRestClient; + } + /// /// Set the rest client /// From 692e59d2d6834f9a26fac3743645b174bb65e003 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 22:03:10 +0530 Subject: [PATCH 10/24] Renaming TwilioBearerTokenAuthClient to TwilioOrgsTokenAuthClient --- .../BearerToken/BearerTokenResourceSet.cs | 8 ++++---- ...Client.cs => TwilioOrgsTokenRestClient.cs} | 4 ++-- src/Twilio/TwilioOrgsTokenAuth.cs | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) rename src/Twilio/Clients/BearerToken/{TwilioBearerTokenRestClient.cs => TwilioOrgsTokenRestClient.cs} (99%) diff --git a/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs b/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs index 8f4e4ce98..c37eb6ff1 100644 --- a/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs +++ b/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs @@ -18,7 +18,7 @@ public class BearerTokenResourceSet : IEnumerable where T : Resource /// public bool AutoPaging { get; set; } - private readonly TwilioBearerTokenRestClient _client; + private readonly TwilioOrgsTokenRestClient _client; private readonly ReadOptions _options; private readonly long _pageLimit; @@ -34,7 +34,7 @@ public class BearerTokenResourceSet : IEnumerable where T : Resource /// Page of resources /// Read options /// Client to make requests - public BearerTokenResourceSet(Page page, ReadOptions options, TwilioBearerTokenRestClient client) + public BearerTokenResourceSet(Page page, ReadOptions options, TwilioOrgsTokenRestClient client) { _page = page; _options = options; @@ -113,9 +113,9 @@ private void FetchNextPage() private static MethodInfo GetNextPage() { #if !NET35 - return typeof(T).GetRuntimeMethod("NextPage", new[]{ typeof(Page), typeof(TwilioBearerTokenRestClient) }); + return typeof(T).GetRuntimeMethod("NextPage", new[]{ typeof(Page), typeof(TwilioOrgsTokenRestClient) }); #else - return typeof(T).GetMethod("NextPage", new[]{ typeof(Page), typeof(TwilioBearerTokenRestClient) }); + return typeof(T).GetMethod("NextPage", new[]{ typeof(Page), typeof(TwilioOrgsTokenRestClient) }); #endif } } diff --git a/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs similarity index 99% rename from src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs rename to src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs index 066ba671b..fdec8ae3c 100644 --- a/src/Twilio/Clients/BearerToken/TwilioBearerTokenRestClient.cs +++ b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs @@ -27,7 +27,7 @@ namespace Twilio.Clients.BearerToken /// /// Implementation of a TwilioRestClient. /// - public class TwilioBearerTokenRestClient + public class TwilioOrgsTokenRestClient { /// /// Client to make HTTP requests @@ -75,7 +75,7 @@ public class TwilioBearerTokenRestClient /// region to make requests for /// http client used to make the requests /// edge to make requests for - public TwilioBearerTokenRestClient( + public TwilioOrgsTokenRestClient( TokenManager tokenManager, string region = null, BearerTokenHttpClient httpClient = null, diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs index 16a6ac8ab..63ab18015 100644 --- a/src/Twilio/TwilioOrgsTokenAuth.cs +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -14,7 +14,7 @@ public class TwilioOrgsTokenAuthClient private static string _accessToken; private static string _region; private static string _edge; - private static TwilioBearerTokenRestClient _restClient; + private static TwilioOrgsTokenRestClient _restClient; private static TwilioNoAuthRestClient _noAuthRestClient; private static string _logLevel; private static TokenManager _tokenManager; @@ -75,6 +75,7 @@ public static void SetRegion(string region) if (region != _region) { Invalidate(); + InvalidateNoAuthClient(); } _region = region; } @@ -88,6 +89,7 @@ public static void SetEdge(string edge) if (edge != _edge) { Invalidate(); + InvalidateNoAuthClient(); } _edge = edge; } @@ -101,6 +103,7 @@ public static void SetLogLevel(string loglevel) if (loglevel != _logLevel) { Invalidate(); + InvalidateNoAuthClient(); } _logLevel = loglevel; } @@ -109,7 +112,7 @@ public static void SetLogLevel(string loglevel) /// Get the rest client /// /// The rest client - public static TwilioBearerTokenRestClient GetRestClient() + public static TwilioOrgsTokenRestClient GetRestClient() { if (_restClient != null) { @@ -123,7 +126,7 @@ public static TwilioBearerTokenRestClient GetRestClient() ); } - _restClient = new TwilioBearerTokenRestClient(_tokenManager, region: _region, edge: _edge) + _restClient = new TwilioOrgsTokenRestClient(_tokenManager, region: _region, edge: _edge) { LogLevel = _logLevel }; @@ -153,7 +156,7 @@ public static TwilioNoAuthRestClient GetNoAuthRestClient() /// Set the rest client /// /// Rest Client to use - public static void SetRestClient(TwilioBearerTokenRestClient restClient) + public static void SetRestClient(TwilioOrgsTokenRestClient restClient) { _restClient = restClient; } @@ -166,6 +169,14 @@ public static void Invalidate() _restClient = null; } + /// + /// Clear out the Rest Client + /// + public static void InvalidateNoAuthClient() + { + _noAuthRestClient = null; + } + /// /// Test if your environment is impacted by a TLS or certificate change /// by sending an HTTP request to the test endpoint tls-test.twilio.com:443 From 3e0344421ddb9077ef3bd3abef3fba201c96c002 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 22:10:23 +0530 Subject: [PATCH 11/24] hardcoding client credentials --- .../Http/BearerToken/OrgsTokenManager.cs | 3 +-- src/Twilio/TwilioOrgsTokenAuth.cs | 19 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs index 55bf1c5ec..848e6ec00 100644 --- a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -21,7 +21,6 @@ public class OrgsTokenManager : TokenManager /// Constructor for a OrgsTokenManager public OrgsTokenManager( - string grantType, string clientId, string clientSecret, string code = null, @@ -30,7 +29,7 @@ public OrgsTokenManager( string refreshToken = null, string scope = null ){ - GrantType = grantType; + GrantType = "client_credentials"; ClientId = clientId; ClientSecret = clientSecret; Code = code; diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs index 63ab18015..37e103f0f 100644 --- a/src/Twilio/TwilioOrgsTokenAuth.cs +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -24,37 +24,33 @@ private TwilioOrgsTokenAuthClient() { } /// /// Initialize base client with username and password /// - public static void Init(string grantType, string clientId, string clientSecret) + public static void Init(string clientId, string clientSecret) { - validateCredentials(grantType, clientId, clientSecret); - _tokenManager = new OrgsTokenManager(grantType, clientId, clientSecret); + validateCredentials(clientId, clientSecret); + _tokenManager = new OrgsTokenManager(clientId, clientSecret); } /// /// Initialize base client /// - public static void Init(string grantType, string clientId, string clientSecret, + public static void Init(string clientId, string clientSecret, string code = null, string redirectUri = null, string audience = null, string refreshToken = null, string scope = null) { - validateCredentials(grantType, clientId, clientSecret); - _tokenManager = new OrgsTokenManager(grantType, clientId, clientSecret, code, redirectUri, audience, refreshToken, scope); + validateCredentials(clientId, clientSecret); + _tokenManager = new OrgsTokenManager(clientId, clientSecret, code, redirectUri, audience, refreshToken, scope); } /// /// Validate grant type, client id and client secret and verify none of them are null /// - public static void validateCredentials(string grantType, string clientId, string clientSecret) + public static void validateCredentials(string clientId, string clientSecret) { - if (grantType == null) - { - throw new AuthenticationException("grantType can not be null"); - } if (clientId == null) { throw new AuthenticationException("clientId can not be null"); @@ -63,7 +59,6 @@ public static void validateCredentials(string grantType, string clientId, string { throw new AuthenticationException("clientSecret can not be null"); } - } /// From b4d23b10b711ab87b977d3a5b2c42e4f4bc5fb54 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 22:18:35 +0530 Subject: [PATCH 12/24] invalidate rest clients on change of client id, client secret and token manager --- src/Twilio/TwilioOrgsTokenAuth.cs | 61 +++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs index 37e103f0f..1fd54d039 100644 --- a/src/Twilio/TwilioOrgsTokenAuth.cs +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -18,6 +18,8 @@ public class TwilioOrgsTokenAuthClient private static TwilioNoAuthRestClient _noAuthRestClient; private static string _logLevel; private static TokenManager _tokenManager; + private static string _clientId; + private static string _clientSecret; private TwilioOrgsTokenAuthClient() { } @@ -26,8 +28,9 @@ private TwilioOrgsTokenAuthClient() { } /// public static void Init(string clientId, string clientSecret) { - validateCredentials(clientId, clientSecret); - _tokenManager = new OrgsTokenManager(clientId, clientSecret); + SetClientId(clientId); + SetClientSecret(clientSecret); + SetTokenManager(new OrgsTokenManager(clientId, clientSecret)); } @@ -41,24 +44,66 @@ public static void Init(string clientId, string clientSecret, string refreshToken = null, string scope = null) { - validateCredentials(clientId, clientSecret); - _tokenManager = new OrgsTokenManager(clientId, clientSecret, code, redirectUri, audience, refreshToken, scope); + SetClientId(clientId); + SetClientSecret(clientSecret); + SetTokenManager(new OrgsTokenManager(clientId, clientSecret, code, redirectUri, audience, refreshToken, scope)); } + /// + /// Set the token manager + /// + /// token manager + public static void SetTokenManager(TokenManager tokenManager) + { + if (tokenManager == null) + { + throw new AuthenticationException("Token Manager can not be null"); + } + + if (tokenManager != _tokenManager) + { + Invalidate(); + } + + _tokenManager = tokenManager; + } /// - /// Validate grant type, client id and client secret and verify none of them are null + /// Set the client id /// - public static void validateCredentials(string clientId, string clientSecret) + /// client id of the organisation + public static void SetClientId(string clientId) { if (clientId == null) { - throw new AuthenticationException("clientId can not be null"); + throw new AuthenticationException("Client Id can not be null"); + } + + if (clientId != _clientId) + { + Invalidate(); } + + _clientId = clientId; + } + + /// + /// Set the client secret + /// + /// client secret of the organisation + public static void SetClientSecret(string clientSecret) + { if (clientSecret == null) { - throw new AuthenticationException("clientSecret can not be null"); + throw new AuthenticationException("Client Secret can not be null"); + } + + if (clientSecret != _clientSecret) + { + Invalidate(); } + + _clientSecret = clientSecret; } /// From e72b107fb970dad09d8233d028babbb99ba0cff2 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 23:04:39 +0530 Subject: [PATCH 13/24] Rename Request classes --- .../Clients/BearerToken/TwilioOrgsTokenRestClient.cs | 8 ++++---- src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs | 6 +++--- .../Http/BearerToken/SystemNetBearerTokenHttpClient.cs | 6 +++--- .../{BearerTokenRequest.cs => TokenRequest.cs} | 6 +++--- src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) rename src/Twilio/Http/BearerToken/{BearerTokenRequest.cs => TokenRequest.cs} (98%) diff --git a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs index fdec8ae3c..34bf69df5 100644 --- a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs +++ b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs @@ -111,7 +111,7 @@ public bool tokenExpired(String accessToken){ /// /// request to make /// response of the request - public Response Request(BearerTokenRequest request) + public Response Request(TokenRequest request) { if ((_accessToken == null )|| tokenExpired(_accessToken)) { lock (lockObject){ @@ -234,7 +234,7 @@ public bool isTokenExpired(string token){ /// /// request to make /// Task that resolves to the response of the request - public async Task RequestAsync(BearerTokenRequest request) + public async Task RequestAsync(TokenRequest request) { request.SetAuth(_accessToken); @@ -327,7 +327,7 @@ public static void ValidateSslCertificate() /// HTTP Client to use for testing the request public static void ValidateSslCertificate(BearerTokenHttpClient client) { - BearerTokenRequest request = new BearerTokenRequest("GET", "tls-test", ":443/", null); + TokenRequest request = new TokenRequest("GET", "tls-test", ":443/", null); try { @@ -361,7 +361,7 @@ public static void ValidateSslCertificate(BearerTokenHttpClient client) /// /// /// HTTP request - private static void LogRequest(BearerTokenRequest request) + private static void LogRequest(TokenRequest request) { Console.WriteLine("-- BEGIN Twilio API Request --"); Console.WriteLine("request.method: " + request.Method); diff --git a/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs index 45f855da0..710a9dcc0 100644 --- a/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs @@ -10,7 +10,7 @@ public abstract class BearerTokenHttpClient /// /// The last request made by this client /// - public BearerTokenRequest LastRequest { get; protected set; } + public TokenRequest LastRequest { get; protected set; } /// /// The last response received by this client @@ -24,7 +24,7 @@ public abstract class BearerTokenHttpClient /// request to make /// throws exception on network or connection errors. /// response of the request - public abstract Response MakeRequest(BearerTokenRequest request); + public abstract Response MakeRequest(TokenRequest request); #if !NET35 /// @@ -34,7 +34,7 @@ public abstract class BearerTokenHttpClient /// request to make /// throws exception on network or connection errors. /// response of the request - public abstract System.Threading.Tasks.Task MakeRequestAsync(BearerTokenRequest request); + public abstract System.Threading.Tasks.Task MakeRequestAsync(TokenRequest request); #endif } diff --git a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs index c146c8406..6d0e98449 100644 --- a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs @@ -37,7 +37,7 @@ public SystemNetBearerTokenHttpClient(System.Net.Http.HttpClient httpClient = nu /// /// Twilio request /// Twilio response - public override Response MakeRequest(BearerTokenRequest request) + public override Response MakeRequest(TokenRequest request) { try { @@ -58,7 +58,7 @@ public override Response MakeRequest(BearerTokenRequest request) /// /// Twilio response /// Task that resolves to the response - public override async Task MakeRequestAsync(BearerTokenRequest request) + public override async Task MakeRequestAsync(TokenRequest request) { var httpRequest = BuildHttpRequest(request); if (!Equals(request.Method, HttpMethod.Get)) @@ -90,7 +90,7 @@ public override async Task MakeRequestAsync(BearerTokenRequest request return response; } - private HttpRequestMessage BuildHttpRequest(BearerTokenRequest request) + private HttpRequestMessage BuildHttpRequest(TokenRequest request) { var httpRequest = new HttpRequestMessage( new System.Net.Http.HttpMethod(request.Method.ToString()), diff --git a/src/Twilio/Http/BearerToken/BearerTokenRequest.cs b/src/Twilio/Http/BearerToken/TokenRequest.cs similarity index 98% rename from src/Twilio/Http/BearerToken/BearerTokenRequest.cs rename to src/Twilio/Http/BearerToken/TokenRequest.cs index 33f5915e2..fbc9dc70e 100644 --- a/src/Twilio/Http/BearerToken/BearerTokenRequest.cs +++ b/src/Twilio/Http/BearerToken/TokenRequest.cs @@ -16,7 +16,7 @@ namespace Twilio.Http.BearerToken /// /// Twilio request object with bearer token authentication /// - public class BearerTokenRequest + public class TokenRequest { private static readonly string DEFAULT_REGION = "us1"; @@ -77,7 +77,7 @@ public class BearerTokenRequest /// /// HTTP Method /// Request URL - public BearerTokenRequest(HttpMethod method, string url) + public TokenRequest(HttpMethod method, string url) { Method = method; Uri = new Uri(url); @@ -99,7 +99,7 @@ public BearerTokenRequest(HttpMethod method, string url) /// Custom header data /// Content Type /// Request Body - public BearerTokenRequest( + public TokenRequest( HttpMethod method, Domain domain, string uri, diff --git a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs index 9a8bfedd0..4df6b1dac 100644 --- a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs +++ b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs @@ -23,7 +23,7 @@ public WebBearerTokenRequestClient(HttpWebRequestFactory factory = null) /// /// Twilio request /// Twilio response - public override Response MakeRequest(BearerTokenRequest request) + public override Response MakeRequest(TokenRequest request) { IHttpWebRequestWrapper httpRequest = BuildHttpRequest(request); @@ -60,7 +60,7 @@ private string GetResponseContent(IHttpWebResponseWrapper response) return reader.ReadToEnd(); } - private IHttpWebRequestWrapper BuildHttpRequest(BearerTokenRequest request) + private IHttpWebRequestWrapper BuildHttpRequest(TokenRequest request) { IHttpWebRequestWrapper httpRequest = this.factory.Create(request.ConstructUrl()); From eb6a2bda036be1fa17ec3bcd7df0e629315729d4 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 23:12:25 +0530 Subject: [PATCH 14/24] Renaming resourceset --- examples/BearerTokenAuthentication.md | 2 +- .../{BearerTokenResourceSet.cs => TokenResourceSet.cs} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename src/Twilio/Base/BearerToken/{BearerTokenResourceSet.cs => TokenResourceSet.cs} (94%) diff --git a/examples/BearerTokenAuthentication.md b/examples/BearerTokenAuthentication.md index 7f654508a..29dd6952a 100644 --- a/examples/BearerTokenAuthentication.md +++ b/examples/BearerTokenAuthentication.md @@ -13,7 +13,7 @@ class Program static void Main(string[] args) { TwilioOrgsTokenAuthClient.Init(GRANT_TYPE, CLIENT_ID, CLIENT_SECRET); - Twilio.Base.BearerToken.BearerTokenResourceSet accountList = null; + Twilio.Base.BearerToken.TokenResourceSet accountList = null; accountList = Twilio.Rest.PreviewIam.Organizations.AccountResource.Read(pathOrganizationSid: ORGS_SID); Console.WriteLine(accountList.ElementAt(0).FriendlyName); var account = Twilio.Rest.PreviewIam.Organizations.AccountResource.Fetch(pathOrganizationSid: ORGS_SID, pathAccountSid: PATH_ACCOUNT_SID); diff --git a/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs b/src/Twilio/Base/BearerToken/TokenResourceSet.cs similarity index 94% rename from src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs rename to src/Twilio/Base/BearerToken/TokenResourceSet.cs index c37eb6ff1..37b032d2d 100644 --- a/src/Twilio/Base/BearerToken/BearerTokenResourceSet.cs +++ b/src/Twilio/Base/BearerToken/TokenResourceSet.cs @@ -11,7 +11,7 @@ namespace Twilio.Base.BearerToken /// /// /// Resource Type - public class BearerTokenResourceSet : IEnumerable where T : Resource + public class TokenResourceSet : IEnumerable where T : Resource { /// /// Automatically iterate through pages of results @@ -34,7 +34,7 @@ public class BearerTokenResourceSet : IEnumerable where T : Resource /// Page of resources /// Read options /// Client to make requests - public BearerTokenResourceSet(Page page, ReadOptions options, TwilioOrgsTokenRestClient client) + public TokenResourceSet(Page page, ReadOptions options, TwilioOrgsTokenRestClient client) { _page = page; _options = options; From cfa2eb921ac0af89a28e9b042088e0eb5a51627d Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 23:16:04 +0530 Subject: [PATCH 15/24] renaming http clients --- .../Clients/BearerToken/TwilioOrgsTokenRestClient.cs | 12 ++++++------ ...okenHttpClient.cs => SystemNetTokenHttpClient.cs} | 4 ++-- .../{BearerTokenHttpClient.cs => TokenHttpClient.cs} | 2 +- src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) rename src/Twilio/Http/BearerToken/{SystemNetBearerTokenHttpClient.cs => SystemNetTokenHttpClient.cs} (97%) rename src/Twilio/Http/BearerToken/{BearerTokenHttpClient.cs => TokenHttpClient.cs} (96%) diff --git a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs index 34bf69df5..73247aa12 100644 --- a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs +++ b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs @@ -32,7 +32,7 @@ public class TwilioOrgsTokenRestClient /// /// Client to make HTTP requests /// - public BearerTokenHttpClient HttpClient { get; } + public TokenHttpClient HttpClient { get; } /// /// Twilio region to make requests to @@ -78,7 +78,7 @@ public class TwilioOrgsTokenRestClient public TwilioOrgsTokenRestClient( TokenManager tokenManager, string region = null, - BearerTokenHttpClient httpClient = null, + TokenHttpClient httpClient = null, string edge = null ) { @@ -262,12 +262,12 @@ public async Task RequestAsync(TokenRequest request) return ProcessResponse(response); } - private static BearerTokenHttpClient DefaultClient() + private static TokenHttpClient DefaultClient() { - return new SystemNetBearerTokenHttpClient(); + return new SystemNetTokenHttpClient(); } #else - private static BearerTokenHttpClient DefaultClient() + private static TokenHttpClient DefaultClient() { return new WebBearerTokenRequestClient(); } @@ -325,7 +325,7 @@ public static void ValidateSslCertificate() /// /// /// HTTP Client to use for testing the request - public static void ValidateSslCertificate(BearerTokenHttpClient client) + public static void ValidateSslCertificate(TokenHttpClient client) { TokenRequest request = new TokenRequest("GET", "tls-test", ":443/", null); diff --git a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs similarity index 97% rename from src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs rename to src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs index 6d0e98449..63dc28100 100644 --- a/src/Twilio/Http/BearerToken/SystemNetBearerTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs @@ -13,7 +13,7 @@ namespace Twilio.Http.BearerToken /// /// Sample client to make HTTP requests /// - public class SystemNetBearerTokenHttpClient : BearerTokenHttpClient + public class SystemNetTokenHttpClient : TokenHttpClient { #if NET462 private string PlatVersion = ".NET Framework 4.6.2+"; @@ -27,7 +27,7 @@ public class SystemNetBearerTokenHttpClient : BearerTokenHttpClient /// Create new HttpClient /// /// HTTP client to use - public SystemNetBearerTokenHttpClient(System.Net.Http.HttpClient httpClient = null) + public SystemNetTokenHttpClient(System.Net.Http.HttpClient httpClient = null) { _httpClient = httpClient ?? new System.Net.Http.HttpClient(new HttpClientHandler() { AllowAutoRedirect = false }); } diff --git a/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs b/src/Twilio/Http/BearerToken/TokenHttpClient.cs similarity index 96% rename from src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs rename to src/Twilio/Http/BearerToken/TokenHttpClient.cs index 710a9dcc0..86e5ff79d 100644 --- a/src/Twilio/Http/BearerToken/BearerTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/TokenHttpClient.cs @@ -5,7 +5,7 @@ namespace Twilio.Http.BearerToken /// /// Base http client used to make Twilio requests /// - public abstract class BearerTokenHttpClient + public abstract class TokenHttpClient { /// /// The last request made by this client diff --git a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs index 4df6b1dac..48c5f3aab 100644 --- a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs +++ b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs @@ -8,7 +8,7 @@ namespace Twilio.Http.Net35 /// /// Sample client to make requests /// - public class WebBearerTokenRequestClient : BearerTokenHttpClient + public class WebBearerTokenRequestClient : TokenHttpClient { private const string PlatVersion = ".NET/3.5"; private HttpWebRequestFactory factory; From 10c9f08674a960cc0c6c36fd44a3834634fdfde7 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Wed, 4 Sep 2024 23:18:56 +0530 Subject: [PATCH 16/24] adding dependencies --- src/Twilio/Twilio.csproj | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Twilio/Twilio.csproj b/src/Twilio/Twilio.csproj index d8e64ad4f..958b55a65 100644 --- a/src/Twilio/Twilio.csproj +++ b/src/Twilio/Twilio.csproj @@ -28,11 +28,10 @@ - - - C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\System.Web.Extensions.dll - - + + + + From 1e5926c6f7fe0d60b2cfce6407ea2199891e3e8b Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 12:57:15 +0530 Subject: [PATCH 17/24] Changes to make previewiam version less --- .../Http/BearerToken/OrgsTokenManager.cs | 2 +- .../Organizations/AccountOptions.cs | 95 --- .../Organizations/AccountResource.cs | 327 -------- .../Organizations/AuthorizeOptions.cs | 83 -- .../Organizations/AuthorizeResource.cs | 159 ---- .../Organizations/RoleAssignmentOptions.cs | 145 ---- .../Organizations/RoleAssignmentResource.cs | 428 ---------- .../PreviewIam/Organizations/UserOptions.cs | 225 ----- .../PreviewIam/Organizations/UserResource.cs | 789 ------------------ .../{Organizations => V1}/TokenOptions.cs | 2 +- .../{Organizations => V1}/TokenResource.cs | 2 +- 11 files changed, 3 insertions(+), 2254 deletions(-) delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs delete mode 100644 src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs rename src/Twilio/Rest/PreviewIam/{Organizations => V1}/TokenOptions.cs (98%) rename src/Twilio/Rest/PreviewIam/{Organizations => V1}/TokenResource.cs (99%) diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs index 848e6ec00..80635aae3 100644 --- a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -1,4 +1,4 @@ -using Twilio.Rest.PreviewIam.Organizations; +using Twilio.Rest.PreviewIam.V1; using Twilio.Exceptions; using System; diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs deleted file mode 100644 index 07a373203..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/AccountOptions.cs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Converters; - - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - /// fetch - public class FetchAccountOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public string PathAccountSid { get; } - - - - /// Construct a new FetchOrganizationAccountOptions - /// - /// - public FetchAccountOptions(string pathOrganizationSid, string pathAccountSid) - { - PathOrganizationSid = pathOrganizationSid; - PathAccountSid = pathAccountSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - return p; - } - - - - } - - - /// read - public class ReadAccountOptions : ReadOptions - { - - - public string PathOrganizationSid { get; } - - - - /// Construct a new ListOrganizationAccountsOptions - /// - public ReadAccountOptions(string pathOrganizationSid) - { - PathOrganizationSid = pathOrganizationSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - if (PageSize != null) - { - p.Add(new KeyValuePair("PageSize", PageSize.ToString())); - } - return p; - } - - - - } - -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs deleted file mode 100644 index 03d07481c..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/AccountResource.cs +++ /dev/null @@ -1,327 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Clients; -using Twilio.Constant; -using Twilio.Converters; -using Twilio.Exceptions; -using Twilio.Http; -using Twilio.Types; -using Twilio.Base.BearerToken; -using Twilio.Clients.BearerToken; -using Twilio.Http.BearerToken; - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - public class AccountResource : Resource - { - - - - [JsonConverter(typeof(StringEnumConverter))] - public sealed class StatusEnum : StringEnum - { - private StatusEnum(string value) : base(value) {} - public StatusEnum() {} - public static implicit operator StatusEnum(string value) - { - return new StatusEnum(value); - } - public static readonly StatusEnum Active = new StatusEnum("active"); - public static readonly StatusEnum Suspended = new StatusEnum("suspended"); - public static readonly StatusEnum PendingClosure = new StatusEnum("pending_closure"); - public static readonly StatusEnum Closed = new StatusEnum("closed"); - - } - - - private static BearerTokenRequest BuildFetchRequest(FetchAccountOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/Accounts/{AccountSid}"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - string PathAccountSid = options.PathAccountSid.ToString(); - path = path.Replace("{"+"AccountSid"+"}", PathAccountSid); - - return new BearerTokenRequest( - HttpMethod.Get, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - - /// fetch - /// Fetch Account parameters - /// Client to make requests to Twilio - /// A single instance of Account - public static AccountResource Fetch(FetchAccountOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildFetchRequest(options, client)); - return FromJson(response.Content); - } - - #if !NET35 - /// fetch - /// Fetch Account parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of Account - public static async System.Threading.Tasks.Task FetchAsync(FetchAccountOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildFetchRequest(options, client)); - return FromJson(response.Content); - } - #endif - /// fetch - /// - /// - /// Client to make requests to Twilio - /// A single instance of Account - public static AccountResource Fetch( - string pathOrganizationSid, - string pathAccountSid, - TwilioBearerTokenRestClient client = null) - { - var options = new FetchAccountOptions(pathOrganizationSid, pathAccountSid){ }; - return Fetch(options, client); - } - - #if !NET35 - /// fetch - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of Account - public static async System.Threading.Tasks.Task FetchAsync(string pathOrganizationSid, string pathAccountSid, TwilioBearerTokenRestClient client = null) - { - var options = new FetchAccountOptions(pathOrganizationSid, pathAccountSid){ }; - return await FetchAsync(options, client); - } - #endif - - private static BearerTokenRequest BuildReadRequest(ReadAccountOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/Accounts"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - - return new BearerTokenRequest( - HttpMethod.Get, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - /// read - /// Read Account parameters - /// Client to make requests to Twilio - /// A single instance of Account - public static BearerTokenResourceSet Read(ReadAccountOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildReadRequest(options, client)); - var page = Page.FromJson("content", response.Content); - return new BearerTokenResourceSet(page, options, client); - } - - #if !NET35 - /// read - /// Read Account parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of Account - public static async System.Threading.Tasks.Task> ReadAsync(ReadAccountOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildReadRequest(options, client)); - - var page = Page.FromJson("content", response.Content); - return new BearerTokenResourceSet(page, options, client); - } - #endif - /// read - /// - /// - /// Record limit - /// Client to make requests to Twilio - /// A single instance of Account - public static BearerTokenResourceSet Read( - string pathOrganizationSid, - int? pageSize = null, - long? limit = null, - TwilioBearerTokenRestClient client = null) - { - var options = new ReadAccountOptions(pathOrganizationSid){ PageSize = pageSize, Limit = limit}; - return Read(options, client); - } - - #if !NET35 - /// read - /// - /// - /// Record limit - /// Client to make requests to Twilio - /// Task that resolves to A single instance of Account - public static async System.Threading.Tasks.Task> ReadAsync( - string pathOrganizationSid, - int? pageSize = null, - long? limit = null, - TwilioBearerTokenRestClient client = null) - { - var options = new ReadAccountOptions(pathOrganizationSid){ PageSize = pageSize, Limit = limit}; - return await ReadAsync(options, client); - } - #endif - - - /// Fetch the target page of records - /// API-generated URL for the requested results page - /// Client to make requests to Twilio - /// The target page of records - public static Page GetPage(string targetUrl, TwilioBearerTokenRestClient client) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - - var request = new BearerTokenRequest( - HttpMethod.Get, - targetUrl - ); - - var response = client.Request(request); - return Page.FromJson("content", response.Content); - } - - /// Fetch the next page of records - /// current page of records - /// Client to make requests to Twilio - /// The next page of records - public static Page NextPage(Page page, TwilioBearerTokenRestClient client) - { - var request = new BearerTokenRequest( - HttpMethod.Get, - page.GetNextPageUrl(Rest.Domain.Api) - ); - - var response = client.Request(request); - return Page.FromJson("content", response.Content); - } - - /// Fetch the previous page of records - /// current page of records - /// Client to make requests to Twilio - /// The previous page of records - public static Page PreviousPage(Page page, TwilioBearerTokenRestClient client) - { - var request = new BearerTokenRequest( - HttpMethod.Get, - page.GetPreviousPageUrl(Rest.Domain.Api) - ); - - var response = client.Request(request); - return Page.FromJson("content", response.Content); - } - - - /// - /// Converts a JSON string into a AccountResource object - /// - /// Raw JSON string - /// AccountResource object represented by the provided JSON - public static AccountResource FromJson(string json) - { - try - { - return JsonConvert.DeserializeObject(json); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - /// - /// Converts an object into a json string - /// - /// C# model - /// JSON string - public static string ToJson(object model) - { - try - { - return JsonConvert.SerializeObject(model); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - - - /// Twilio account sid - [JsonProperty("account_sid")] - public string AccountSid { get; private set; } - - /// Account friendly name - [JsonProperty("friendly_name")] - public string FriendlyName { get; private set; } - - /// Account status - [JsonProperty("status")] - public AccountResource.StatusEnum Status { get; private set; } - - /// Twilio account sid - [JsonProperty("owner_sid")] - public string OwnerSid { get; private set; } - - /// The date and time when the account was created in the system - [JsonProperty("date_created")] - public DateTime? DateCreated { get; private set; } - - /// Twilio-specific error code - [JsonProperty("code")] - public int? Code { get; private set; } - - /// Error message - [JsonProperty("message")] - public string Message { get; private set; } - - /// Link to Error Code References - [JsonProperty("moreInfo")] - public string MoreInfo { get; private set; } - - /// HTTP response status code - [JsonProperty("_status")] - public int? _Status { get; private set; } - - - - private AccountResource() { - - } - } -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs deleted file mode 100644 index b793a88f2..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeOptions.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Converters; - - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - /// fetch - public class FetchAuthorizeOptions : IOptions - { - - /// Response Type - public string ResponseType { get; set; } - - /// The Client Identifier - public string ClientId { get; set; } - - /// The url to which response will be redirected to - public string RedirectUri { get; set; } - - /// The scope of the access request - public string Scope { get; set; } - - /// An opaque value which can be used to maintain state between the request and callback - public string State { get; set; } - - - - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - if (ResponseType != null) - { - p.Add(new KeyValuePair("Response_type", ResponseType)); - } - if (ClientId != null) - { - p.Add(new KeyValuePair("Client_id", ClientId)); - } - if (RedirectUri != null) - { - p.Add(new KeyValuePair("Redirect_uri", RedirectUri)); - } - if (Scope != null) - { - p.Add(new KeyValuePair("Scope", Scope)); - } - if (State != null) - { - p.Add(new KeyValuePair("State", State)); - } - return p; - } - - - - } - - -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs deleted file mode 100644 index 4535c7921..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/AuthorizeResource.cs +++ /dev/null @@ -1,159 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Clients; -using Twilio.Constant; -using Twilio.Converters; -using Twilio.Exceptions; -using Twilio.Http; - - -using Twilio.Clients.NoAuth; -using Twilio.Http.NoAuth; - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - public class AuthorizeResource : Resource - { - - - - - - private static NoAuthRequest BuildFetchRequest(FetchAuthorizeOptions options, TwilioNoAuthRestClient client) - { - - string path = "/v1/authorize"; - - - return new NoAuthRequest( - HttpMethod.Get, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - - /// fetch - /// Fetch Authorize parameters - /// Client to make requests to Twilio - /// A single instance of Authorize - public static AuthorizeResource Fetch(FetchAuthorizeOptions options, TwilioNoAuthRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient(); - var response = client.Request(BuildFetchRequest(options, client)); - return FromJson(response.Content); - } - - #if !NET35 - /// fetch - /// Fetch Authorize parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of Authorize - public static async System.Threading.Tasks.Task FetchAsync(FetchAuthorizeOptions options, TwilioNoAuthRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetNoAuthRestClient(); - var response = await client.RequestAsync(BuildFetchRequest(options, client)); - return FromJson(response.Content); - } - #endif - /// fetch - /// Response Type - /// The Client Identifier - /// The url to which response will be redirected to - /// The scope of the access request - /// An opaque value which can be used to maintain state between the request and callback - /// Client to make requests to Twilio - /// A single instance of Authorize - public static AuthorizeResource Fetch( - string responseType = null, - string clientId = null, - string redirectUri = null, - string scope = null, - string state = null, - TwilioNoAuthRestClient client = null) - { - var options = new FetchAuthorizeOptions(){ ResponseType = responseType,ClientId = clientId,RedirectUri = redirectUri,Scope = scope,State = state }; - return Fetch(options, client); - } - - #if !NET35 - /// fetch - /// Response Type - /// The Client Identifier - /// The url to which response will be redirected to - /// The scope of the access request - /// An opaque value which can be used to maintain state between the request and callback - /// Client to make requests to Twilio - /// Task that resolves to A single instance of Authorize - public static async System.Threading.Tasks.Task FetchAsync(string responseType = null, string clientId = null, string redirectUri = null, string scope = null, string state = null, TwilioNoAuthRestClient client = null) - { - var options = new FetchAuthorizeOptions(){ ResponseType = responseType,ClientId = clientId,RedirectUri = redirectUri,Scope = scope,State = state }; - return await FetchAsync(options, client); - } - #endif - - /// - /// Converts a JSON string into a AuthorizeResource object - /// - /// Raw JSON string - /// AuthorizeResource object represented by the provided JSON - public static AuthorizeResource FromJson(string json) - { - try - { - return JsonConvert.DeserializeObject(json); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - /// - /// Converts an object into a json string - /// - /// C# model - /// JSON string - public static string ToJson(object model) - { - try - { - return JsonConvert.SerializeObject(model); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - - - /// The callback URL - [JsonProperty("redirect_to")] - public Uri RedirectTo { get; private set; } - - - - private AuthorizeResource() { - - } - } -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs deleted file mode 100644 index d5158ebc9..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentOptions.cs +++ /dev/null @@ -1,145 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Converters; - - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - - /// Create a role assignment for the given organization - public class CreateRoleAssignmentOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest PublicApiCreateRoleAssignmentRequest { get; } - - - /// Construct a new CreateRoleAssignmentOptions - /// - /// - public CreateRoleAssignmentOptions(string pathOrganizationSid, RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest) - { - PathOrganizationSid = pathOrganizationSid; - PublicApiCreateRoleAssignmentRequest = publicApiCreateRoleAssignmentRequest; - } - - - /// Generate the request body - public string GetBody() - { - string body = ""; - - if (PublicApiCreateRoleAssignmentRequest != null) - { - body = RoleAssignmentResource.ToJson(PublicApiCreateRoleAssignmentRequest); - } - return body; - } - - - } - /// Delete a role assignment for the given organization - public class DeleteRoleAssignmentOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public string PathRoleAssignmentSid { get; } - - - - /// Construct a new DeleteRoleAssignmentOptions - /// - /// - public DeleteRoleAssignmentOptions(string pathOrganizationSid, string pathRoleAssignmentSid) - { - PathOrganizationSid = pathOrganizationSid; - PathRoleAssignmentSid = pathRoleAssignmentSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - return p; - } - - - - } - - - /// List role assignments for the given organization - public class ReadRoleAssignmentOptions : ReadOptions - { - - - public string PathOrganizationSid { get; } - - - public string Identity { get; set; } - - - public string Scope { get; set; } - - - - /// Construct a new ListRoleAssignmentsOptions - /// - public ReadRoleAssignmentOptions(string pathOrganizationSid) - { - PathOrganizationSid = pathOrganizationSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - if (PageSize != null) - { - p.Add(new KeyValuePair("PageSize", PageSize.ToString())); - } - if (Identity != null) - { - p.Add(new KeyValuePair("Identity", Identity.ToString())); - } - if (Scope != null) - { - p.Add(new KeyValuePair("Scope", Scope.ToString())); - } - return p; - } - - - - } - -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs deleted file mode 100644 index 05b26ce0c..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/RoleAssignmentResource.cs +++ /dev/null @@ -1,428 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Clients; -using Twilio.Constant; -using Twilio.Converters; -using Twilio.Exceptions; -using Twilio.Http; - -using Twilio.Base.BearerToken; -using Twilio.Clients.BearerToken; -using Twilio.Http.BearerToken; - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - public class RoleAssignmentResource : Resource - { - - public class PublicApiCreateRoleAssignmentRequest - { - [JsonProperty("role_sid")] - private string RoleSid {get; set;} - [JsonProperty("scope")] - private string Scope {get; set;} - [JsonProperty("identity")] - private string Identity {get; set;} - public PublicApiCreateRoleAssignmentRequest() { } - public class Builder - { - private PublicApiCreateRoleAssignmentRequest _publicApiCreateRoleAssignmentRequest = new PublicApiCreateRoleAssignmentRequest(); - public Builder() - { - } - public Builder WithRoleSid(string roleSid) - { - _publicApiCreateRoleAssignmentRequest.RoleSid= roleSid; - return this; - } - public Builder WithScope(string scope) - { - _publicApiCreateRoleAssignmentRequest.Scope= scope; - return this; - } - public Builder WithIdentity(string identity) - { - _publicApiCreateRoleAssignmentRequest.Identity= identity; - return this; - } - public PublicApiCreateRoleAssignmentRequest Build() - { - return _publicApiCreateRoleAssignmentRequest; - } - } - } - - - - - private static BearerTokenRequest BuildCreateRequest(CreateRoleAssignmentOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/RoleAssignments"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - - return new BearerTokenRequest( - HttpMethod.Post, - Rest.Domain.PreviewIam, - path, - - contentType: EnumConstants.ContentTypeEnum.JSON, - body: options.GetBody(), - headerParams: null - ); - } - - /// Create a role assignment for the given organization - /// Create RoleAssignment parameters - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - public static RoleAssignmentResource Create(CreateRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildCreateRequest(options, client)); - return FromJson(response.Content); - } - - #if !NET35 - /// Create a role assignment for the given organization - /// Create RoleAssignment parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of RoleAssignment - public static async System.Threading.Tasks.Task CreateAsync(CreateRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildCreateRequest(options, client)); - return FromJson(response.Content); - } - #endif - - /// Create a role assignment for the given organization - /// - /// - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - public static RoleAssignmentResource Create( - string pathOrganizationSid, - RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest, - TwilioBearerTokenRestClient client = null) - { - var options = new CreateRoleAssignmentOptions(pathOrganizationSid, publicApiCreateRoleAssignmentRequest){ }; - return Create(options, client); - } - - #if !NET35 - /// Create a role assignment for the given organization - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of RoleAssignment - public static async System.Threading.Tasks.Task CreateAsync( - string pathOrganizationSid, - RoleAssignmentResource.PublicApiCreateRoleAssignmentRequest publicApiCreateRoleAssignmentRequest, - TwilioBearerTokenRestClient client = null) - { - var options = new CreateRoleAssignmentOptions(pathOrganizationSid, publicApiCreateRoleAssignmentRequest){ }; - return await CreateAsync(options, client); - } - #endif - - /// Delete a role assignment for the given organization - /// Delete RoleAssignment parameters - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - private static BearerTokenRequest BuildDeleteRequest(DeleteRoleAssignmentOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/RoleAssignments/{RoleAssignmentSid}"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - string PathRoleAssignmentSid = options.PathRoleAssignmentSid.ToString(); - path = path.Replace("{"+"RoleAssignmentSid"+"}", PathRoleAssignmentSid); - - return new BearerTokenRequest( - HttpMethod.Delete, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - - /// Delete a role assignment for the given organization - /// Delete RoleAssignment parameters - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - public static bool Delete(DeleteRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildDeleteRequest(options, client)); - return response.StatusCode == System.Net.HttpStatusCode.NoContent; - } - - #if !NET35 - /// Delete a role assignment for the given organization - /// Delete RoleAssignment parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of RoleAssignment - public static async System.Threading.Tasks.Task DeleteAsync(DeleteRoleAssignmentOptions options, - TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildDeleteRequest(options, client)); - return response.StatusCode == System.Net.HttpStatusCode.NoContent; - } - #endif - - /// Delete a role assignment for the given organization - /// - /// - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - public static bool Delete(string pathOrganizationSid, string pathRoleAssignmentSid, TwilioBearerTokenRestClient client = null) - { - var options = new DeleteRoleAssignmentOptions(pathOrganizationSid, pathRoleAssignmentSid) ; - return Delete(options, client); - } - - #if !NET35 - /// Delete a role assignment for the given organization - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of RoleAssignment - public static async System.Threading.Tasks.Task DeleteAsync(string pathOrganizationSid, string pathRoleAssignmentSid, TwilioBearerTokenRestClient client = null) - { - var options = new DeleteRoleAssignmentOptions(pathOrganizationSid, pathRoleAssignmentSid) ; - return await DeleteAsync(options, client); - } - #endif - - private static BearerTokenRequest BuildReadRequest(ReadRoleAssignmentOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/RoleAssignments"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - - return new BearerTokenRequest( - HttpMethod.Get, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - /// List role assignments for the given organization - /// Read RoleAssignment parameters - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - public static BearerTokenResourceSet Read(ReadRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildReadRequest(options, client)); - var page = Page.FromJson("content", response.Content); - return new BearerTokenResourceSet(page, options, client); - } - - #if !NET35 - /// List role assignments for the given organization - /// Read RoleAssignment parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of RoleAssignment - public static async System.Threading.Tasks.Task> ReadAsync(ReadRoleAssignmentOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildReadRequest(options, client)); - - var page = Page.FromJson("content", response.Content); - return new BearerTokenResourceSet(page, options, client); - } - #endif - /// List role assignments for the given organization - /// - /// - /// - /// - /// Record limit - /// Client to make requests to Twilio - /// A single instance of RoleAssignment - public static BearerTokenResourceSet Read( - string pathOrganizationSid, - int? pageSize = null, - string identity = null, - string scope = null, - long? limit = null, - TwilioBearerTokenRestClient client = null) - { - var options = new ReadRoleAssignmentOptions(pathOrganizationSid){ PageSize = pageSize, Identity = identity, Scope = scope, Limit = limit}; - return Read(options, client); - } - - #if !NET35 - /// List role assignments for the given organization - /// - /// - /// - /// - /// Record limit - /// Client to make requests to Twilio - /// Task that resolves to A single instance of RoleAssignment - public static async System.Threading.Tasks.Task> ReadAsync( - string pathOrganizationSid, - int? pageSize = null, - string identity = null, - string scope = null, - long? limit = null, - TwilioBearerTokenRestClient client = null) - { - var options = new ReadRoleAssignmentOptions(pathOrganizationSid){ PageSize = pageSize, Identity = identity, Scope = scope, Limit = limit}; - return await ReadAsync(options, client); - } - #endif - - - /// Fetch the target page of records - /// API-generated URL for the requested results page - /// Client to make requests to Twilio - /// The target page of records - public static Page GetPage(string targetUrl, TwilioBearerTokenRestClient client) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - - var request = new BearerTokenRequest( - HttpMethod.Get, - targetUrl - ); - - var response = client.Request(request); - return Page.FromJson("content", response.Content); - } - - /// Fetch the next page of records - /// current page of records - /// Client to make requests to Twilio - /// The next page of records - public static Page NextPage(Page page, TwilioBearerTokenRestClient client) - { - var request = new BearerTokenRequest( - HttpMethod.Get, - page.GetNextPageUrl(Rest.Domain.Api) - ); - - var response = client.Request(request); - return Page.FromJson("content", response.Content); - } - - /// Fetch the previous page of records - /// current page of records - /// Client to make requests to Twilio - /// The previous page of records - public static Page PreviousPage(Page page, TwilioBearerTokenRestClient client) - { - var request = new BearerTokenRequest( - HttpMethod.Get, - page.GetPreviousPageUrl(Rest.Domain.Api) - ); - - var response = client.Request(request); - return Page.FromJson("content", response.Content); - } - - - /// - /// Converts a JSON string into a RoleAssignmentResource object - /// - /// Raw JSON string - /// RoleAssignmentResource object represented by the provided JSON - public static RoleAssignmentResource FromJson(string json) - { - try - { - return JsonConvert.DeserializeObject(json); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - /// - /// Converts an object into a json string - /// - /// C# model - /// JSON string - public static string ToJson(object model) - { - try - { - return JsonConvert.SerializeObject(model); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - - - /// Twilio Role Assignment Sid representing this role assignment - [JsonProperty("sid")] - public string Sid { get; private set; } - - /// Twilio Role Sid representing assigned role - [JsonProperty("role_sid")] - public string RoleSid { get; private set; } - - /// Twilio Sid representing identity of this assignment - [JsonProperty("scope")] - public string Scope { get; private set; } - - /// Twilio Sid representing scope of this assignment - [JsonProperty("identity")] - public string Identity { get; private set; } - - /// Twilio-specific error code - [JsonProperty("code")] - public int? Code { get; private set; } - - /// Error message - [JsonProperty("message")] - public string Message { get; private set; } - - /// Link to Error Code References - [JsonProperty("moreInfo")] - public string MoreInfo { get; private set; } - - /// HTTP response status code - [JsonProperty("status")] - public int? Status { get; private set; } - - - - private RoleAssignmentResource() { - - } - } -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs b/src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs deleted file mode 100644 index e18b74dd0..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/UserOptions.cs +++ /dev/null @@ -1,225 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Converters; - - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - - /// create - public class CreateUserOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public UserResource.ScimUser ScimUser { get; } - - - /// Construct a new CreateOrganizationUserOptions - /// - /// - public CreateUserOptions(string pathOrganizationSid, UserResource.ScimUser scimUser) - { - PathOrganizationSid = pathOrganizationSid; - ScimUser = scimUser; - } - - - /// Generate the request body - public string GetBody() - { - string body = ""; - - if (ScimUser != null) - { - body = UserResource.ToJson(ScimUser); - } - return body; - } - - - } - /// delete - public class DeleteUserOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public string PathUserSid { get; } - - - - /// Construct a new DeleteOrganizationUserOptions - /// - /// - public DeleteUserOptions(string pathOrganizationSid, string pathUserSid) - { - PathOrganizationSid = pathOrganizationSid; - PathUserSid = pathUserSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - return p; - } - - - - } - - - /// fetch - public class FetchUserOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public string PathUserSid { get; } - - - - /// Construct a new FetchOrganizationUserOptions - /// - /// - public FetchUserOptions(string pathOrganizationSid, string pathUserSid) - { - PathOrganizationSid = pathOrganizationSid; - PathUserSid = pathUserSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - return p; - } - - - - } - - - /// read - public class ReadUserOptions : ReadOptions - { - - - public string PathOrganizationSid { get; } - - - public string Filter { get; set; } - - - - /// Construct a new ListOrganizationUsersOptions - /// - public ReadUserOptions(string pathOrganizationSid) - { - PathOrganizationSid = pathOrganizationSid; - } - - - /// Generate the necessary parameters - public List> GetParams() - { - var p = new List>(); - - if (Filter != null) - { - p.Add(new KeyValuePair("Filter", Filter)); - } - return p; - } - - - - } - - /// update - public class UpdateUserOptions : IOptions - { - - - public string PathOrganizationSid { get; } - - - public string PathUserSid { get; } - - - public UserResource.ScimUser ScimUser { get; } - - - public string IfMatch { get; set; } - - - - /// Construct a new UpdateOrganizationUserOptions - /// - /// - /// - public UpdateUserOptions(string pathOrganizationSid, string pathUserSid, UserResource.ScimUser scimUser) - { - PathOrganizationSid = pathOrganizationSid; - PathUserSid = pathUserSid; - ScimUser = scimUser; - } - - - /// Generate the request body - public string GetBody() - { - string body = ""; - - if (ScimUser != null) - { - body = UserResource.ToJson(ScimUser); - } - return body; - } - - /// Generate the necessary header parameters - public List> GetHeaderParams() - { - var p = new List>(); - if (IfMatch != null) - { - p.Add(new KeyValuePair("If-Match", IfMatch)); - } - return p; - } - - } - - -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs b/src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs deleted file mode 100644 index 351e65912..000000000 --- a/src/Twilio/Rest/PreviewIam/Organizations/UserResource.cs +++ /dev/null @@ -1,789 +0,0 @@ -/* - * This code was generated by - * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ - * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ - * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ - * - * Organization Public API - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * NOTE: This class is auto generated by OpenAPI Generator. - * https://openapi-generator.tech - * Do not edit the class manually. - */ - - -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using Twilio.Base; -using Twilio.Clients; -using Twilio.Constant; -using Twilio.Converters; -using Twilio.Exceptions; -using Twilio.Http; -using Twilio.Types; -using Twilio.Base.BearerToken; -using Twilio.Clients.BearerToken; -using Twilio.Http.BearerToken; - - - -namespace Twilio.Rest.PreviewIam.Organizations -{ - public class UserResource : Resource - { - - public class ScimName - { - [JsonProperty("givenName")] - private string GivenName {get; set;} - [JsonProperty("familyName")] - private string FamilyName {get; set;} - public ScimName() { } - public class Builder - { - private ScimName _scimName = new ScimName(); - public Builder() - { - } - public Builder WithGivenName(string givenName) - { - _scimName.GivenName= givenName; - return this; - } - public Builder WithFamilyName(string familyName) - { - _scimName.FamilyName= familyName; - return this; - } - public ScimName Build() - { - return _scimName; - } - } - } - public class ScimEmailAddress - { - [JsonProperty("primary")] - private bool? Primary {get; set;} - [JsonProperty("value")] - private string Value {get; set;} - [JsonProperty("type")] - private string Type {get; set;} - public ScimEmailAddress() { } - public class Builder - { - private ScimEmailAddress _scimEmailAddress = new ScimEmailAddress(); - public Builder() - { - } - public Builder WithPrimary(bool? primary) - { - _scimEmailAddress.Primary= primary; - return this; - } - public Builder WithValue(string value) - { - _scimEmailAddress.Value= value; - return this; - } - public Builder WithType(string type) - { - _scimEmailAddress.Type= type; - return this; - } - public ScimEmailAddress Build() - { - return _scimEmailAddress; - } - } - } - public class ScimMeta - { - [JsonProperty("resourceType")] - private string ResourceType {get; set;} - [JsonProperty("created")] - private DateTime? Created {get; set;} - [JsonProperty("lastModified")] - private DateTime? LastModified {get; set;} - [JsonProperty("version")] - private string Version {get; set;} - public ScimMeta() { } - public class Builder - { - private ScimMeta _scimMeta = new ScimMeta(); - public Builder() - { - } - public Builder WithResourceType(string resourceType) - { - _scimMeta.ResourceType= resourceType; - return this; - } - public Builder WithCreated(DateTime? created) - { - _scimMeta.Created= created; - return this; - } - public Builder WithLastModified(DateTime? lastModified) - { - _scimMeta.LastModified= lastModified; - return this; - } - public Builder WithVersion(string version) - { - _scimMeta.Version= version; - return this; - } - public ScimMeta Build() - { - return _scimMeta; - } - } - } - public class ScimUser - { - [JsonProperty("id")] - private string Id {get; set;} - [JsonProperty("externalId")] - private string ExternalId {get; set;} - [JsonProperty("userName")] - private string UserName {get; set;} - [JsonProperty("displayName")] - private string DisplayName {get; set;} - [JsonProperty("name")] - private ScimName Name {get; set;} - [JsonProperty("emails")] - private List Emails {get; set;} - [JsonProperty("active")] - private bool? Active {get; set;} - [JsonProperty("locale")] - private string Locale {get; set;} - [JsonProperty("timezone")] - private string Timezone {get; set;} - [JsonProperty("schemas")] - private List Schemas {get; set;} - [JsonProperty("meta")] - private ScimMeta Meta {get; set;} - public ScimUser() { } - public class Builder - { - private ScimUser _scimUser = new ScimUser(); - public Builder() - { - } - public Builder WithId(string id) - { - _scimUser.Id= id; - return this; - } - public Builder WithExternalId(string externalId) - { - _scimUser.ExternalId= externalId; - return this; - } - public Builder WithUserName(string userName) - { - _scimUser.UserName= userName; - return this; - } - public Builder WithDisplayName(string displayName) - { - _scimUser.DisplayName= displayName; - return this; - } - public Builder WithName(ScimName name) - { - _scimUser.Name= name; - return this; - } - public Builder WithEmails(List emails) - { - _scimUser.Emails= emails; - return this; - } - public Builder WithActive(bool? active) - { - _scimUser.Active= active; - return this; - } - public Builder WithLocale(string locale) - { - _scimUser.Locale= locale; - return this; - } - public Builder WithTimezone(string timezone) - { - _scimUser.Timezone= timezone; - return this; - } - public Builder WithSchemas(List schemas) - { - _scimUser.Schemas= schemas; - return this; - } - public Builder WithMeta(ScimMeta meta) - { - _scimUser.Meta= meta; - return this; - } - public ScimUser Build() - { - return _scimUser; - } - } - } - - - [JsonConverter(typeof(StringEnumConverter))] - public sealed class ScimTypeEnum : StringEnum - { - private ScimTypeEnum(string value) : base(value) {} - public ScimTypeEnum() {} - public static implicit operator ScimTypeEnum(string value) - { - return new ScimTypeEnum(value); - } - public static readonly ScimTypeEnum Invalidfilter = new ScimTypeEnum("invalidFilter"); - public static readonly ScimTypeEnum Uniqueness = new ScimTypeEnum("uniqueness"); - public static readonly ScimTypeEnum Mutability = new ScimTypeEnum("mutability"); - public static readonly ScimTypeEnum Invalidvalue = new ScimTypeEnum("invalidValue"); - public static readonly ScimTypeEnum Invalidsyntax = new ScimTypeEnum("invalidSyntax"); - - } - - - private static BearerTokenRequest BuildCreateRequest(CreateUserOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/scim/Users"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - - return new BearerTokenRequest( - HttpMethod.Post, - Rest.Domain.PreviewIam, - path, - - contentType: EnumConstants.ContentTypeEnum.JSON, - body: options.GetBody(), - headerParams: null - ); - } - - /// create - /// Create User parameters - /// Client to make requests to Twilio - /// A single instance of User - public static UserResource Create(CreateUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildCreateRequest(options, client)); - return FromJson(response.Content); - } - - #if !NET35 - /// create - /// Create User parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task CreateAsync(CreateUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildCreateRequest(options, client)); - return FromJson(response.Content); - } - #endif - - /// create - /// - /// - /// Client to make requests to Twilio - /// A single instance of User - public static UserResource Create( - string pathOrganizationSid, - UserResource.ScimUser scimUser, - TwilioBearerTokenRestClient client = null) - { - var options = new CreateUserOptions(pathOrganizationSid, scimUser){ }; - return Create(options, client); - } - - #if !NET35 - /// create - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task CreateAsync( - string pathOrganizationSid, - UserResource.ScimUser scimUser, - TwilioBearerTokenRestClient client = null) - { - var options = new CreateUserOptions(pathOrganizationSid, scimUser){ }; - return await CreateAsync(options, client); - } - #endif - - /// delete - /// Delete User parameters - /// Client to make requests to Twilio - /// A single instance of User - private static BearerTokenRequest BuildDeleteRequest(DeleteUserOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - string PathUserSid = options.PathUserSid.ToString(); - path = path.Replace("{"+"UserSid"+"}", PathUserSid); - - return new BearerTokenRequest( - HttpMethod.Delete, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - - /// delete - /// Delete User parameters - /// Client to make requests to Twilio - /// A single instance of User - public static bool Delete(DeleteUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildDeleteRequest(options, client)); - return response.StatusCode == System.Net.HttpStatusCode.NoContent; - } - - #if !NET35 - /// delete - /// Delete User parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task DeleteAsync(DeleteUserOptions options, - TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildDeleteRequest(options, client)); - return response.StatusCode == System.Net.HttpStatusCode.NoContent; - } - #endif - - /// delete - /// - /// - /// Client to make requests to Twilio - /// A single instance of User - public static bool Delete(string pathOrganizationSid, string pathUserSid, TwilioBearerTokenRestClient client = null) - { - var options = new DeleteUserOptions(pathOrganizationSid, pathUserSid) ; - return Delete(options, client); - } - - #if !NET35 - /// delete - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task DeleteAsync(string pathOrganizationSid, string pathUserSid, TwilioBearerTokenRestClient client = null) - { - var options = new DeleteUserOptions(pathOrganizationSid, pathUserSid) ; - return await DeleteAsync(options, client); - } - #endif - - private static BearerTokenRequest BuildFetchRequest(FetchUserOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - string PathUserSid = options.PathUserSid.ToString(); - path = path.Replace("{"+"UserSid"+"}", PathUserSid); - - return new BearerTokenRequest( - HttpMethod.Get, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - - /// fetch - /// Fetch User parameters - /// Client to make requests to Twilio - /// A single instance of User - public static UserResource Fetch(FetchUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildFetchRequest(options, client)); - return FromJson(response.Content); - } - - #if !NET35 - /// fetch - /// Fetch User parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task FetchAsync(FetchUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildFetchRequest(options, client)); - return FromJson(response.Content); - } - #endif - /// fetch - /// - /// - /// Client to make requests to Twilio - /// A single instance of User - public static UserResource Fetch( - string pathOrganizationSid, - string pathUserSid, - TwilioBearerTokenRestClient client = null) - { - var options = new FetchUserOptions(pathOrganizationSid, pathUserSid){ }; - return Fetch(options, client); - } - - #if !NET35 - /// fetch - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task FetchAsync(string pathOrganizationSid, string pathUserSid, TwilioBearerTokenRestClient client = null) - { - var options = new FetchUserOptions(pathOrganizationSid, pathUserSid){ }; - return await FetchAsync(options, client); - } - #endif - - private static BearerTokenRequest BuildReadRequest(ReadUserOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/scim/Users"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - - return new BearerTokenRequest( - HttpMethod.Get, - Rest.Domain.PreviewIam, - path, - queryParams: options.GetParams(), - headerParams: null - ); - } - /// read - /// Read User parameters - /// Client to make requests to Twilio - /// A single instance of User - public static BearerTokenResourceSet Read(ReadUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildReadRequest(options, client)); - var page = Page.FromJson("Resources", response.Content); - return new BearerTokenResourceSet(page, options, client); - } - - #if !NET35 - /// read - /// Read User parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task> ReadAsync(ReadUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildReadRequest(options, client)); - - var page = Page.FromJson("Resources", response.Content); - return new BearerTokenResourceSet(page, options, client); - } - #endif - /// read - /// - /// - /// Record limit - /// Client to make requests to Twilio - /// A single instance of User - public static BearerTokenResourceSet Read( - string pathOrganizationSid, - string filter = null, - long? limit = null, - TwilioBearerTokenRestClient client = null) - { - var options = new ReadUserOptions(pathOrganizationSid){ Filter = filter, Limit = limit}; - return Read(options, client); - } - - #if !NET35 - /// read - /// - /// - /// Record limit - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task> ReadAsync( - string pathOrganizationSid, - string filter = null, - long? limit = null, - TwilioBearerTokenRestClient client = null) - { - var options = new ReadUserOptions(pathOrganizationSid){ Filter = filter, Limit = limit}; - return await ReadAsync(options, client); - } - #endif - - - /// Fetch the target page of records - /// API-generated URL for the requested results page - /// Client to make requests to Twilio - /// The target page of records - public static Page GetPage(string targetUrl, TwilioBearerTokenRestClient client) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - - var request = new BearerTokenRequest( - HttpMethod.Get, - targetUrl - ); - - var response = client.Request(request); - return Page.FromJson("Resources", response.Content); - } - - /// Fetch the next page of records - /// current page of records - /// Client to make requests to Twilio - /// The next page of records - public static Page NextPage(Page page, TwilioBearerTokenRestClient client) - { - var request = new BearerTokenRequest( - HttpMethod.Get, - page.GetNextPageUrl(Rest.Domain.Api) - ); - - var response = client.Request(request); - return Page.FromJson("Resources", response.Content); - } - - /// Fetch the previous page of records - /// current page of records - /// Client to make requests to Twilio - /// The previous page of records - public static Page PreviousPage(Page page, TwilioBearerTokenRestClient client) - { - var request = new BearerTokenRequest( - HttpMethod.Get, - page.GetPreviousPageUrl(Rest.Domain.Api) - ); - - var response = client.Request(request); - return Page.FromJson("Resources", response.Content); - } - - - private static BearerTokenRequest BuildUpdateRequest(UpdateUserOptions options, TwilioBearerTokenRestClient client) - { - - string path = "/Organizations/{OrganizationSid}/scim/Users/{UserSid}"; - - string PathOrganizationSid = options.PathOrganizationSid.ToString(); - path = path.Replace("{"+"OrganizationSid"+"}", PathOrganizationSid); - string PathUserSid = options.PathUserSid.ToString(); - path = path.Replace("{"+"UserSid"+"}", PathUserSid); - - return new BearerTokenRequest( - HttpMethod.Put, - Rest.Domain.PreviewIam, - path, - - contentType: EnumConstants.ContentTypeEnum.JSON, - body: options.GetBody(), - headerParams: options.GetHeaderParams() - ); - } - - /// update - /// Update User parameters - /// Client to make requests to Twilio - /// A single instance of User - public static UserResource Update(UpdateUserOptions options, TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = client.Request(BuildUpdateRequest(options, client)); - return FromJson(response.Content); - } - - /// update - /// Update User parameters - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - #if !NET35 - public static async System.Threading.Tasks.Task UpdateAsync(UpdateUserOptions options, - TwilioBearerTokenRestClient client = null) - { - client = client ?? TwilioOrgsTokenAuthClient.GetRestClient(); - var response = await client.RequestAsync(BuildUpdateRequest(options, client)); - return FromJson(response.Content); - } - #endif - - /// update - /// - /// - /// - /// - /// Client to make requests to Twilio - /// A single instance of User - public static UserResource Update( - string pathOrganizationSid, - string pathUserSid, - UserResource.ScimUser scimUser, - string ifMatch = null, - TwilioBearerTokenRestClient client = null) - { - var options = new UpdateUserOptions(pathOrganizationSid, pathUserSid, scimUser){ IfMatch = ifMatch }; - return Update(options, client); - } - - #if !NET35 - /// update - /// - /// - /// - /// - /// Client to make requests to Twilio - /// Task that resolves to A single instance of User - public static async System.Threading.Tasks.Task UpdateAsync( - string pathOrganizationSid, - string pathUserSid, - UserResource.ScimUser scimUser, - string ifMatch = null, - TwilioBearerTokenRestClient client = null) - { - var options = new UpdateUserOptions(pathOrganizationSid, pathUserSid, scimUser){ IfMatch = ifMatch }; - return await UpdateAsync(options, client); - } - #endif - - /// - /// Converts a JSON string into a UserResource object - /// - /// Raw JSON string - /// UserResource object represented by the provided JSON - public static UserResource FromJson(string json) - { - try - { - return JsonConvert.DeserializeObject(json); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - /// - /// Converts an object into a json string - /// - /// C# model - /// JSON string - public static string ToJson(object model) - { - try - { - return JsonConvert.SerializeObject(model); - } - catch (JsonException e) - { - throw new ApiException(e.Message, e); - } - } - - - /// Unique Twilio user sid - [JsonProperty("id")] - public string Id { get; private set; } - - /// External unique resource id defined by provisioning client - [JsonProperty("externalId")] - public string ExternalId { get; private set; } - - /// Unique username, MUST be same as primary email address - [JsonProperty("userName")] - public string UserName { get; } - - /// User friendly display name - [JsonProperty("displayName")] - public string DisplayName { get; private set; } - - /// The name - [JsonProperty("name")] - public ScimName Name { get; private set; } - - /// Email address list of the user. Primary email must be defined if there are more than 1 email. Primary email must match the username. - [JsonProperty("emails")] - public List Emails { get; private set; } - - /// Indicates whether the user is active - [JsonProperty("active")] - public bool? Active { get; private set; } - - /// User's locale - [JsonProperty("locale")] - public string Locale { get; private set; } - - /// User's time zone - [JsonProperty("timezone")] - public string Timezone { get; private set; } - - /// An array of URIs that indicate the schemas supported for this user resource - [JsonProperty("schemas")] - public List Schemas { get; private set; } - - /// The meta - [JsonProperty("meta")] - public ScimMeta Meta { get; private set; } - - /// Schema URIs that define the contents of the error structure - [JsonProperty("_schemas")] - public List _Schemas { get; private set; } - - /// A human-readable description of the error - [JsonProperty("detail")] - public string Detail { get; private set; } - - /// A scimType error code as defined in RFC7644 - [JsonProperty("scimType")] - public UserResource.ScimTypeEnum ScimType { get; private set; } - - /// Http status code - [JsonProperty("status")] - public string Status { get; private set; } - - /// Twilio-specific error code - [JsonProperty("code")] - public int? Code { get; private set; } - - /// Link to Error Code References - [JsonProperty("moreInfo")] - public string MoreInfo { get; private set; } - - - - private UserResource() { - - } - } -} - diff --git a/src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs b/src/Twilio/Rest/PreviewIam/V1/TokenOptions.cs similarity index 98% rename from src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs rename to src/Twilio/Rest/PreviewIam/V1/TokenOptions.cs index dfe3dedf9..95adbbe9f 100644 --- a/src/Twilio/Rest/PreviewIam/Organizations/TokenOptions.cs +++ b/src/Twilio/Rest/PreviewIam/V1/TokenOptions.cs @@ -21,7 +21,7 @@ -namespace Twilio.Rest.PreviewIam.Organizations +namespace Twilio.Rest.PreviewIam.V1 { /// create diff --git a/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs b/src/Twilio/Rest/PreviewIam/V1/TokenResource.cs similarity index 99% rename from src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs rename to src/Twilio/Rest/PreviewIam/V1/TokenResource.cs index 688068aef..9f79ada3c 100644 --- a/src/Twilio/Rest/PreviewIam/Organizations/TokenResource.cs +++ b/src/Twilio/Rest/PreviewIam/V1/TokenResource.cs @@ -28,7 +28,7 @@ using Twilio.Http.NoAuth; -namespace Twilio.Rest.PreviewIam.Organizations +namespace Twilio.Rest.PreviewIam.V1 { public class TokenResource : Resource { From 5fda91df300a1b23a60280fe3ebd34fb98acdfbc Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 13:27:29 +0530 Subject: [PATCH 18/24] Marking the new feature as Beta --- src/Twilio/Annotations/Beta.cs | 15 +++++++++++++++ src/Twilio/Annotations/Preview.cs | 15 +++++++++++++++ src/Twilio/TwilioOrgsTokenAuth.cs | 3 +++ 3 files changed, 33 insertions(+) create mode 100644 src/Twilio/Annotations/Beta.cs create mode 100644 src/Twilio/Annotations/Preview.cs diff --git a/src/Twilio/Annotations/Beta.cs b/src/Twilio/Annotations/Beta.cs new file mode 100644 index 000000000..9a97aeb66 --- /dev/null +++ b/src/Twilio/Annotations/Beta.cs @@ -0,0 +1,15 @@ +using System; + +namespace Twilio.Annotations +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] + public class Beta : Attribute + { + public string Message { get; } + + public Beta(string message = "This feature is in beta and may change in future versions.") + { + Message = message; + } + } +} diff --git a/src/Twilio/Annotations/Preview.cs b/src/Twilio/Annotations/Preview.cs new file mode 100644 index 000000000..3b6aa1470 --- /dev/null +++ b/src/Twilio/Annotations/Preview.cs @@ -0,0 +1,15 @@ +using System; + +namespace Twilio.Annotations +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = false)] + public sealed class Preview : Attribute + { + public string Value { get; } + + public Preview(string value = "This class/method is under preview and is subject to change. Use with caution.") + { + Value = value; + } + } +} diff --git a/src/Twilio/TwilioOrgsTokenAuth.cs b/src/Twilio/TwilioOrgsTokenAuth.cs index 1fd54d039..0593af2e4 100644 --- a/src/Twilio/TwilioOrgsTokenAuth.cs +++ b/src/Twilio/TwilioOrgsTokenAuth.cs @@ -3,12 +3,15 @@ using Twilio.Clients.BearerToken; using Twilio.Exceptions; using Twilio.Http.BearerToken; +using Twilio.Annotations; + namespace Twilio { /// /// Default Twilio Client for bearer token authentication /// + [Beta] public class TwilioOrgsTokenAuthClient { private static string _accessToken; From 0516f4a6a7cff2ff7e4262347abdfb6c2da42d64 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 13:36:16 +0530 Subject: [PATCH 19/24] Adding to domain file --- src/Twilio/Rest/Domain.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Twilio/Rest/Domain.cs b/src/Twilio/Rest/Domain.cs index b2b389717..bfa2139ab 100644 --- a/src/Twilio/Rest/Domain.cs +++ b/src/Twilio/Rest/Domain.cs @@ -58,6 +58,7 @@ public static implicit operator Domain(string value) public static readonly Domain Video = new Domain("video"); public static readonly Domain Voice = new Domain("voice"); public static readonly Domain Wireless = new Domain("wireless"); + public static readonly Domain PreviewIam = new Domain("preview-iam"); } } \ No newline at end of file From 0e049877a20a97e25a1a955c8ba93ac9bee8e761 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 13:38:11 +0530 Subject: [PATCH 20/24] Adding to domain file --- src/Twilio/Rest/Domain.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Twilio/Rest/Domain.cs b/src/Twilio/Rest/Domain.cs index bfa2139ab..b2b389717 100644 --- a/src/Twilio/Rest/Domain.cs +++ b/src/Twilio/Rest/Domain.cs @@ -58,7 +58,6 @@ public static implicit operator Domain(string value) public static readonly Domain Video = new Domain("video"); public static readonly Domain Voice = new Domain("voice"); public static readonly Domain Wireless = new Domain("wireless"); - public static readonly Domain PreviewIam = new Domain("preview-iam"); } } \ No newline at end of file From 5227874f5c9d62d1109f7ecd97ab055265594076 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 14:20:27 +0530 Subject: [PATCH 21/24] Marking all new classes as beta --- src/Twilio/Base/BearerToken/TokenResourceSet.cs | 1 + src/Twilio/Clients/Base64UrlEncoder.cs | 1 + src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs | 1 + src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs | 1 + src/Twilio/Http/BearerToken/OrgsTokenManager.cs | 1 + src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs | 1 + src/Twilio/Http/BearerToken/TokenHttpClient.cs | 1 + src/Twilio/Http/BearerToken/TokenManager.cs | 1 + src/Twilio/Http/BearerToken/TokenRequest.cs | 1 + src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs | 1 + src/Twilio/Http/Net35/WebNoAuthRequestClient.cs | 1 + src/Twilio/Http/NoAuth/NoAuthHttpClient.cs | 1 + src/Twilio/Http/NoAuth/NoAuthRequest.cs | 1 + src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs | 1 + 14 files changed, 14 insertions(+) diff --git a/src/Twilio/Base/BearerToken/TokenResourceSet.cs b/src/Twilio/Base/BearerToken/TokenResourceSet.cs index 37b032d2d..2caf2a2f9 100644 --- a/src/Twilio/Base/BearerToken/TokenResourceSet.cs +++ b/src/Twilio/Base/BearerToken/TokenResourceSet.cs @@ -11,6 +11,7 @@ namespace Twilio.Base.BearerToken /// /// /// Resource Type + [Beta] public class TokenResourceSet : IEnumerable where T : Resource { /// diff --git a/src/Twilio/Clients/Base64UrlEncoder.cs b/src/Twilio/Clients/Base64UrlEncoder.cs index a47662072..e86c8d2ed 100644 --- a/src/Twilio/Clients/Base64UrlEncoder.cs +++ b/src/Twilio/Clients/Base64UrlEncoder.cs @@ -6,6 +6,7 @@ namespace Twilio.Clients{ + [Beta] public abstract class Base64UrlEncoder { public static string Decode(string base64Url) diff --git a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs index 73247aa12..c9011140a 100644 --- a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs +++ b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs @@ -27,6 +27,7 @@ namespace Twilio.Clients.BearerToken /// /// Implementation of a TwilioRestClient. /// + [Beta] public class TwilioOrgsTokenRestClient { /// diff --git a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs index fb8c7f951..67bf20bcf 100644 --- a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs +++ b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs @@ -23,6 +23,7 @@ namespace Twilio.Clients.NoAuth /// /// Implementation of a TwilioRestClient. /// + [Beta] public class TwilioNoAuthRestClient { /// diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs index 80635aae3..895194d75 100644 --- a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -7,6 +7,7 @@ namespace Twilio.Http.BearerToken{ /// /// Implementation of a Token Manager /// + [Beta] public class OrgsTokenManager : TokenManager { diff --git a/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs b/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs index 63dc28100..d421fe5f6 100644 --- a/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs @@ -13,6 +13,7 @@ namespace Twilio.Http.BearerToken /// /// Sample client to make HTTP requests /// + [Beta] public class SystemNetTokenHttpClient : TokenHttpClient { #if NET462 diff --git a/src/Twilio/Http/BearerToken/TokenHttpClient.cs b/src/Twilio/Http/BearerToken/TokenHttpClient.cs index 86e5ff79d..4b8e77261 100644 --- a/src/Twilio/Http/BearerToken/TokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/TokenHttpClient.cs @@ -5,6 +5,7 @@ namespace Twilio.Http.BearerToken /// /// Base http client used to make Twilio requests /// + [Beta] public abstract class TokenHttpClient { /// diff --git a/src/Twilio/Http/BearerToken/TokenManager.cs b/src/Twilio/Http/BearerToken/TokenManager.cs index 11275b71b..86955bdb8 100644 --- a/src/Twilio/Http/BearerToken/TokenManager.cs +++ b/src/Twilio/Http/BearerToken/TokenManager.cs @@ -3,6 +3,7 @@ namespace Twilio.Http.BearerToken /// /// Interface for a Token Manager /// + [Beta] public interface TokenManager { diff --git a/src/Twilio/Http/BearerToken/TokenRequest.cs b/src/Twilio/Http/BearerToken/TokenRequest.cs index fbc9dc70e..a9ba30e0b 100644 --- a/src/Twilio/Http/BearerToken/TokenRequest.cs +++ b/src/Twilio/Http/BearerToken/TokenRequest.cs @@ -16,6 +16,7 @@ namespace Twilio.Http.BearerToken /// /// Twilio request object with bearer token authentication /// + [Beta] public class TokenRequest { private static readonly string DEFAULT_REGION = "us1"; diff --git a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs index 48c5f3aab..8a24c37d8 100644 --- a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs +++ b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs @@ -8,6 +8,7 @@ namespace Twilio.Http.Net35 /// /// Sample client to make requests /// + [Beta] public class WebBearerTokenRequestClient : TokenHttpClient { private const string PlatVersion = ".NET/3.5"; diff --git a/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs b/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs index 6abd23688..4ad09f405 100644 --- a/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs +++ b/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs @@ -8,6 +8,7 @@ namespace Twilio.Http.Net35 /// /// Sample client to make requests /// + [Beta] public class WebNoAuthRequestClient : NoAuthHttpClient { private const string PlatVersion = ".NET/3.5"; diff --git a/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs b/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs index 8cac2637c..dd35aa4e0 100644 --- a/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs +++ b/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs @@ -5,6 +5,7 @@ namespace Twilio.Http.NoAuth /// /// Base http client used to make Twilio requests /// + [Beta] public abstract class NoAuthHttpClient { /// diff --git a/src/Twilio/Http/NoAuth/NoAuthRequest.cs b/src/Twilio/Http/NoAuth/NoAuthRequest.cs index f1ea6f400..3760beec9 100644 --- a/src/Twilio/Http/NoAuth/NoAuthRequest.cs +++ b/src/Twilio/Http/NoAuth/NoAuthRequest.cs @@ -16,6 +16,7 @@ namespace Twilio.Http.NoAuth /// /// Twilio request object with bearer token authentication /// + [Beta] public class NoAuthRequest { private static readonly string DEFAULT_REGION = "us1"; diff --git a/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs b/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs index ba2e58a76..0dfa0d024 100644 --- a/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs +++ b/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs @@ -13,6 +13,7 @@ namespace Twilio.Http.NoAuth /// /// Sample client to make HTTP requests /// + [Beta] public class SystemNetNoAuthHttpClient : NoAuthHttpClient { #if NET462 From 383cdf866713e6bbc4e7b8b76253ac3afbbae1ad Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 14:24:00 +0530 Subject: [PATCH 22/24] Marking all new classes as beta --- src/Twilio/Base/BearerToken/TokenResourceSet.cs | 1 + src/Twilio/Clients/Base64UrlEncoder.cs | 1 + src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs | 1 + src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs | 1 + src/Twilio/Http/BearerToken/OrgsTokenManager.cs | 1 + src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs | 1 + src/Twilio/Http/BearerToken/TokenHttpClient.cs | 1 + src/Twilio/Http/BearerToken/TokenManager.cs | 2 ++ src/Twilio/Http/BearerToken/TokenRequest.cs | 1 + src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs | 1 + src/Twilio/Http/Net35/WebNoAuthRequestClient.cs | 1 + src/Twilio/Http/NoAuth/NoAuthHttpClient.cs | 1 + src/Twilio/Http/NoAuth/NoAuthRequest.cs | 1 + src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs | 1 + 14 files changed, 15 insertions(+) diff --git a/src/Twilio/Base/BearerToken/TokenResourceSet.cs b/src/Twilio/Base/BearerToken/TokenResourceSet.cs index 2caf2a2f9..dfaec4c39 100644 --- a/src/Twilio/Base/BearerToken/TokenResourceSet.cs +++ b/src/Twilio/Base/BearerToken/TokenResourceSet.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using Twilio.Clients; using Twilio.Clients.BearerToken; +using Twilio.Annotations; namespace Twilio.Base.BearerToken { diff --git a/src/Twilio/Clients/Base64UrlEncoder.cs b/src/Twilio/Clients/Base64UrlEncoder.cs index e86c8d2ed..2ad8aa66d 100644 --- a/src/Twilio/Clients/Base64UrlEncoder.cs +++ b/src/Twilio/Clients/Base64UrlEncoder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text; using System.Web.Script.Serialization; +using Twilio.Annotations; namespace Twilio.Clients{ diff --git a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs index c9011140a..6302b0c7a 100644 --- a/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs +++ b/src/Twilio/Clients/BearerToken/TwilioOrgsTokenRestClient.cs @@ -6,6 +6,7 @@ using Twilio.Http.BearerToken; using Twilio.Jwt; using Twilio.Clients; +using Twilio.Annotations; #if !NET35 using System.IdentityModel.Tokens.Jwt; diff --git a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs index 67bf20bcf..c9e823310 100644 --- a/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs +++ b/src/Twilio/Clients/NoAuth/TwilioNoAuthRestClient.cs @@ -5,6 +5,7 @@ using Twilio.Exceptions; using Twilio.Http.BearerToken; using Twilio.Jwt; +using Twilio.Annotations; #if !NET35 diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs index 895194d75..0efc7cc66 100644 --- a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -1,6 +1,7 @@ using Twilio.Rest.PreviewIam.V1; using Twilio.Exceptions; using System; +using Twilio.Annotations; namespace Twilio.Http.BearerToken{ diff --git a/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs b/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs index d421fe5f6..18febed18 100644 --- a/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/SystemNetTokenHttpClient.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using System.Text; using Twilio.Constant; +using Twilio.Annotations; namespace Twilio.Http.BearerToken { diff --git a/src/Twilio/Http/BearerToken/TokenHttpClient.cs b/src/Twilio/Http/BearerToken/TokenHttpClient.cs index 4b8e77261..6ccccaa91 100644 --- a/src/Twilio/Http/BearerToken/TokenHttpClient.cs +++ b/src/Twilio/Http/BearerToken/TokenHttpClient.cs @@ -1,4 +1,5 @@ using System; +using Twilio.Annotations; namespace Twilio.Http.BearerToken { diff --git a/src/Twilio/Http/BearerToken/TokenManager.cs b/src/Twilio/Http/BearerToken/TokenManager.cs index 86955bdb8..fd1062b96 100644 --- a/src/Twilio/Http/BearerToken/TokenManager.cs +++ b/src/Twilio/Http/BearerToken/TokenManager.cs @@ -1,3 +1,5 @@ +using Twilio.Annotations; + namespace Twilio.Http.BearerToken { /// diff --git a/src/Twilio/Http/BearerToken/TokenRequest.cs b/src/Twilio/Http/BearerToken/TokenRequest.cs index a9ba30e0b..9af9a283d 100644 --- a/src/Twilio/Http/BearerToken/TokenRequest.cs +++ b/src/Twilio/Http/BearerToken/TokenRequest.cs @@ -4,6 +4,7 @@ using System.Text; using Twilio.Constant; using Twilio.Rest; +using Twilio.Annotations; #if !NET35 using System.Net; diff --git a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs index 8a24c37d8..9e8e40f89 100644 --- a/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs +++ b/src/Twilio/Http/Net35/WebBearerTokenRequestClient.cs @@ -1,6 +1,7 @@ #if NET35 using System.IO; using Twilio.Http.BearerToken; +using Twilio.Annotations; namespace Twilio.Http.Net35 { diff --git a/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs b/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs index 4ad09f405..a66e76f33 100644 --- a/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs +++ b/src/Twilio/Http/Net35/WebNoAuthRequestClient.cs @@ -1,6 +1,7 @@ #if NET35 using System.IO; using Twilio.Http.NoAuth; +using Twilio.Annotations; namespace Twilio.Http.Net35 { diff --git a/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs b/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs index dd35aa4e0..dfda2fbcb 100644 --- a/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs +++ b/src/Twilio/Http/NoAuth/NoAuthHttpClient.cs @@ -1,4 +1,5 @@ using System; +using Twilio.Annotations; namespace Twilio.Http.NoAuth { diff --git a/src/Twilio/Http/NoAuth/NoAuthRequest.cs b/src/Twilio/Http/NoAuth/NoAuthRequest.cs index 3760beec9..b50cf6d24 100644 --- a/src/Twilio/Http/NoAuth/NoAuthRequest.cs +++ b/src/Twilio/Http/NoAuth/NoAuthRequest.cs @@ -4,6 +4,7 @@ using System.Text; using Twilio.Constant; using Twilio.Rest; +using Twilio.Annotations; #if !NET35 using System.Net; diff --git a/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs b/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs index 0dfa0d024..b58cbf8d2 100644 --- a/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs +++ b/src/Twilio/Http/NoAuth/SystemNetNoAuthHttpClient.cs @@ -7,6 +7,7 @@ using System.Runtime.InteropServices; using System.Text; using Twilio.Constant; +using Twilio.Annotations; namespace Twilio.Http.NoAuth { From 25a9ee5a6a0ed1d9f03f6701c49fce8db940d251 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 14:27:00 +0530 Subject: [PATCH 23/24] Marking all new classes as beta --- src/Twilio/Http/BearerToken/TokenManager.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Twilio/Http/BearerToken/TokenManager.cs b/src/Twilio/Http/BearerToken/TokenManager.cs index fd1062b96..c2c530bf8 100644 --- a/src/Twilio/Http/BearerToken/TokenManager.cs +++ b/src/Twilio/Http/BearerToken/TokenManager.cs @@ -1,11 +1,9 @@ -using Twilio.Annotations; namespace Twilio.Http.BearerToken { /// /// Interface for a Token Manager /// - [Beta] public interface TokenManager { From 3ecb2d79a3cd87539d53ac73f39ea1456ba2a998 Mon Sep 17 00:00:00 2001 From: AsabuHere Date: Mon, 23 Sep 2024 15:46:41 +0530 Subject: [PATCH 24/24] Updating readme regarding new annotations --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index ea98de730..45c17ea44 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,14 @@ Console.WriteLine(response); To use a custom HTTP client with this helper library, please see the [advanced example of how to do so](./advanced-examples/custom-http-client.md). +## Annotations + +### Beta +Features marked with the `[Beta]` attribute are in a beta stage and may undergo changes in future releases. Use these features with caution as they may not be stable. + +### Preview +Features marked with the `[Preview]` attribute are in a preview stage and are intended for evaluation purposes. They are subject to change and should not be used in production without thorough testing. + ## Docker Image The `Dockerfile` present in this repository and its respective `twilio/twilio-csharp` Docker image are used by Twilio for testing purposes.