-
Notifications
You must be signed in to change notification settings - Fork 303
/
TokenResource.cs
153 lines (141 loc) · 5.91 KB
/
TokenResource.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/// This code was generated by
/// \ / _ _ _| _ _
/// | (_)\/(_)(_|\/| |(/_ v1.0.0
/// / /
/// <summary>
/// TokenResource
/// </summary>
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Twilio.Base;
using Twilio.Clients;
using Twilio.Converters;
using Twilio.Exceptions;
using Twilio.Http;
using Twilio.Types;
namespace Twilio.Rest.Api.V2010.Account
{
public class TokenResource : Resource
{
private static Request BuildCreateRequest(CreateTokenOptions options, ITwilioRestClient client)
{
return new Request(
HttpMethod.Post,
Rest.Domain.Api,
"/2010-04-01/Accounts/" + (options.PathAccountSid ?? client.AccountSid) + "/Tokens.json",
postParams: options.GetParams()
);
}
/// <summary>
/// Create a new token for ICE servers
/// </summary>
/// <param name="options"> Create Token parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Token </returns>
public static TokenResource Create(CreateTokenOptions options, ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = client.Request(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
#if !NET35
/// <summary>
/// Create a new token for ICE servers
/// </summary>
/// <param name="options"> Create Token parameters </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Token </returns>
public static async System.Threading.Tasks.Task<TokenResource> CreateAsync(CreateTokenOptions options,
ITwilioRestClient client = null)
{
client = client ?? TwilioClient.GetRestClient();
var response = await client.RequestAsync(BuildCreateRequest(options, client));
return FromJson(response.Content);
}
#endif
/// <summary>
/// Create a new token for ICE servers
/// </summary>
/// <param name="pathAccountSid"> The SID of the Account that will create the resource </param>
/// <param name="ttl"> The duration in seconds the credentials are valid </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> A single instance of Token </returns>
public static TokenResource Create(string pathAccountSid = null, int? ttl = null, ITwilioRestClient client = null)
{
var options = new CreateTokenOptions(){PathAccountSid = pathAccountSid, Ttl = ttl};
return Create(options, client);
}
#if !NET35
/// <summary>
/// Create a new token for ICE servers
/// </summary>
/// <param name="pathAccountSid"> The SID of the Account that will create the resource </param>
/// <param name="ttl"> The duration in seconds the credentials are valid </param>
/// <param name="client"> Client to make requests to Twilio </param>
/// <returns> Task that resolves to A single instance of Token </returns>
public static async System.Threading.Tasks.Task<TokenResource> CreateAsync(string pathAccountSid = null,
int? ttl = null,
ITwilioRestClient client = null)
{
var options = new CreateTokenOptions(){PathAccountSid = pathAccountSid, Ttl = ttl};
return await CreateAsync(options, client);
}
#endif
/// <summary>
/// Converts a JSON string into a TokenResource object
/// </summary>
/// <param name="json"> Raw JSON string </param>
/// <returns> TokenResource object represented by the provided JSON </returns>
public static TokenResource FromJson(string json)
{
// Convert all checked exceptions to Runtime
try
{
return JsonConvert.DeserializeObject<TokenResource>(json);
}
catch (JsonException e)
{
throw new ApiException(e.Message, e);
}
}
/// <summary>
/// The SID of the Account that created the resource
/// </summary>
[JsonProperty("account_sid")]
public string AccountSid { get; private set; }
/// <summary>
/// The RFC 2822 date and time in GMT that the resource was created
/// </summary>
[JsonProperty("date_created")]
public DateTime? DateCreated { get; private set; }
/// <summary>
/// The RFC 2822 date and time in GMT that the resource was last updated
/// </summary>
[JsonProperty("date_updated")]
public DateTime? DateUpdated { get; private set; }
/// <summary>
/// An array representing the ephemeral credentials
/// </summary>
[JsonProperty("ice_servers")]
public List<IceServer> IceServers { get; private set; }
/// <summary>
/// The temporary password used for authenticating
/// </summary>
[JsonProperty("password")]
public string Password { get; private set; }
/// <summary>
/// The duration in seconds the credentials are valid
/// </summary>
[JsonProperty("ttl")]
public string Ttl { get; private set; }
/// <summary>
/// The temporary username that uniquely identifies a Token
/// </summary>
[JsonProperty("username")]
public string Username { get; private set; }
private TokenResource()
{
}
}
}