Skip to content

Commit

Permalink
feat: added example spec file to test query param support
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwarishubham635 committed Nov 20, 2023
1 parent d64c342 commit 0ed2d08
Show file tree
Hide file tree
Showing 24 changed files with 2,584 additions and 0 deletions.
115 changes: 115 additions & 0 deletions examples/csharp/src/Twilio/Rest/Accounts/V1/SafelistOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Accounts
* This is the public Twilio REST API.
*
* 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.Accounts.V1
{

/// <summary> Add a new phone number to SafeList. </summary>
public class CreateSafelistOptions : IOptions<SafelistResource>
{

///<summary> The phone number to be added in SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </summary>
public string PhoneNumber { get; }


/// <summary> Construct a new CreateSafelistOptions </summary>
/// <param name="phoneNumber"> The phone number to be added in SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </param>
public CreateSafelistOptions(string phoneNumber)
{
PhoneNumber = phoneNumber;
}


/// <summary> Generate the necessary parameters </summary>
public List<KeyValuePair<string, string>> GetParams()
{
var p = new List<KeyValuePair<string, string>>();

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



}
/// <summary> Remove a phone number from SafeList. </summary>
public class DeleteSafelistOptions : IOptions<SafelistResource>
{

///<summary> The phone number to be removed from SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </summary>
public string PhoneNumber { get; set; }





/// <summary> Generate the necessary parameters </summary>
public List<KeyValuePair<string, string>> GetParams()
{
var p = new List<KeyValuePair<string, string>>();

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



}


/// <summary> Check if a phone number exists in SafeList. </summary>
public class FetchSafelistOptions : IOptions<SafelistResource>
{

///<summary> The phone number to be fetched from SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </summary>
public string PhoneNumber { get; set; }





/// <summary> Generate the necessary parameters </summary>
public List<KeyValuePair<string, string>> GetParams()
{
var p = new List<KeyValuePair<string, string>>();

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



}


}

279 changes: 279 additions & 0 deletions examples/csharp/src/Twilio/Rest/Accounts/V1/SafelistResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Accounts
* This is the public Twilio REST API.
*
* 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;



namespace Twilio.Rest.Accounts.V1
{
public class SafelistResource : Resource
{





private static Request BuildCreateRequest(CreateSafelistOptions options, ITwilioRestClient client)
{

string path = "/v1/SafeList/Numbers";


return new Request(
HttpMethod.Post,
Rest.Domain.Accounts,
path,
postParams: options.GetParams(),
headerParams: null
);
}

/// <summary> Add a new phone number to SafeList. </summary>
/// <param name="options"> Create Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
public static SafelistResource Create(CreateSafelistOptions options, ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = client.Request(BuildCreateRequest(options, client));
return FromJson(response.Content);
}

#if !NET35
/// <summary> Add a new phone number to SafeList. </summary>
/// <param name="options"> Create Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Safelist </returns>
public static async System.Threading.Tasks.Task<SafelistResource> CreateAsync(CreateSafelistOptions options,
ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = await client.RequestAsync(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
#endif

/// <summary> Add a new phone number to SafeList. </summary>
/// <param name="phoneNumber"> The phone number to be added in SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
public static SafelistResource Create(
string phoneNumber,
ITwilioRestClient client = null)
{
var options = new CreateSafelistOptions(phoneNumber){ };
return Create(options, client);
}

#if !NET35
/// <summary> Add a new phone number to SafeList. </summary>
/// <param name="phoneNumber"> The phone number to be added in SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Safelist </returns>
public static async System.Threading.Tasks.Task<SafelistResource> CreateAsync(
string phoneNumber,
ITwilioRestClient client = null)
{
var options = new CreateSafelistOptions(phoneNumber){ };
return await CreateAsync(options, client);
}
#endif

/// <summary> Remove a phone number from SafeList. </summary>
/// <param name="options"> Delete Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
private static Request BuildDeleteRequest(DeleteSafelistOptions options, ITwilioRestClient client)
{

string path = "/v1/SafeList/Numbers";


return new Request(
HttpMethod.Delete,
Rest.Domain.Accounts,
path,
queryParams: options.GetParams(),
headerParams: null
);
}

/// <summary> Remove a phone number from SafeList. </summary>
/// <param name="options"> Delete Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
public static bool Delete(DeleteSafelistOptions options, ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = client.Request(BuildDeleteRequest(options, client));
return response.StatusCode == System.Net.HttpStatusCode.NoContent;
}

#if !NET35
/// <summary> Remove a phone number from SafeList. </summary>
/// <param name="options"> Delete Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Safelist </returns>
public static async System.Threading.Tasks.Task<bool> DeleteAsync(DeleteSafelistOptions options,
ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = await client.RequestAsync(BuildDeleteRequest(options, client));
return response.StatusCode == System.Net.HttpStatusCode.NoContent;
}
#endif

/// <summary> Remove a phone number from SafeList. </summary>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
public static bool Delete(ITwilioRestClient client = null)
{
var options = new DeleteSafelistOptions() ;
return Delete(options, client);
}

#if !NET35
/// <summary> Remove a phone number from SafeList. </summary>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Safelist </returns>
public static async System.Threading.Tasks.Task<bool> DeleteAsync(ITwilioRestClient client = null)
{
var options = new DeleteSafelistOptions() ;
return await DeleteAsync(options, client);
}
#endif

private static Request BuildFetchRequest(FetchSafelistOptions options, ITwilioRestClient client)
{

string path = "/v1/SafeList/Numbers";


return new Request(
HttpMethod.Get,
Rest.Domain.Accounts,
path,
queryParams: options.GetParams(),
headerParams: null
);
}

/// <summary> Check if a phone number exists in SafeList. </summary>
/// <param name="options"> Fetch Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
public static SafelistResource Fetch(FetchSafelistOptions options, ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = client.Request(BuildFetchRequest(options, client));
return FromJson(response.Content);
}

#if !NET35
/// <summary> Check if a phone number exists in SafeList. </summary>
/// <param name="options"> Fetch Safelist parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Safelist </returns>
public static async System.Threading.Tasks.Task<SafelistResource> FetchAsync(FetchSafelistOptions options,
ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = await client.RequestAsync(BuildFetchRequest(options, client));
return FromJson(response.Content);
}
#endif
/// <summary> Check if a phone number exists in SafeList. </summary>
/// <param name="phoneNumber"> The phone number to be fetched from SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Safelist </returns>
public static SafelistResource Fetch(
string phoneNumber = null,
ITwilioRestClient client = null)
{
var options = new FetchSafelistOptions(){ PhoneNumber = phoneNumber };
return Fetch(options, client);
}

#if !NET35
/// <summary> Check if a phone number exists in SafeList. </summary>
/// <param name="phoneNumber"> The phone number to be fetched from SafeList. Phone numbers must be in [E.164 format](https://www.twilio.com/docs/glossary/what-e164). </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Safelist </returns>
public static async System.Threading.Tasks.Task<SafelistResource> FetchAsync(string phoneNumber = null, ITwilioRestClient client = null)
{
var options = new FetchSafelistOptions(){ PhoneNumber = phoneNumber };
return await FetchAsync(options, client);
}
#endif

/// <summary>
/// Converts a JSON string into a SafelistResource object
/// </summary>
/// <param name="json"> Raw JSON string </param>
/// <returns> SafelistResource object represented by the provided JSON </returns>
public static SafelistResource FromJson(string json)
{
try
{
return JsonConvert.DeserializeObject<SafelistResource>(json);
}
catch (JsonException e)
{
throw new ApiException(e.Message, e);
}
}
/// <summary>
/// Converts an object into a json string
/// </summary>
/// <param name="model"> C# model </param>
/// <returns> JSON string </returns>
public static string ToJson(object model)
{
try
{
return JsonConvert.SerializeObject(model);
}
catch (JsonException e)
{
throw new ApiException(e.Message, e);
}
}


///<summary> The unique string that we created to identify the SafeList resource. </summary>
[JsonProperty("sid")]
public string Sid { get; private set; }

///<summary> The phone number in SafeList. </summary>
[JsonProperty("phone_number")]
public string PhoneNumber { get; private set; }



private SafelistResource() {

}
}
}

Loading

0 comments on commit 0ed2d08

Please sign in to comment.