-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSinchOptions.cs
152 lines (126 loc) · 5.23 KB
/
SinchOptions.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
using System;
using System.Net.Http;
using Microsoft.Extensions.Logging;
using Sinch.Conversation;
using Sinch.Fax;
using Sinch.SMS;
namespace Sinch
{
public sealed class SinchOptions
{
/// <summary>
/// A logger factory used to create ILogger inside the SDK to enable logging
/// </summary>
public ILoggerFactory? LoggerFactory { get; set; }
/// <summary>
/// A HttpClient to use. If not provided, HttpClient will be created and managed by <see cref="SinchClient"></see>
/// itself
/// </summary>
public HttpClient? HttpClient { get; set; }
/// <summary>
/// Set's the region for the SMS service.
/// <br/><br/>
/// The difference between this option and
/// <see href="https://developers.sinch.com/docs/sms/api-reference/#base-url">SMS base URL</see>
/// is that your account is NOT region locked because SDK utilizes `project_id` API set instead of `service_plan_id`,
/// and utilizes region to store the data.
/// <br /><br />
/// Defaults to "us"
/// </summary>
public SmsRegion SmsRegion { get; set; } = SmsRegion.Us;
/// <summary>
/// Set's the regions for the Conversation api.
/// Defaults to "us"
/// </summary>
public ConversationRegion ConversationRegion { get; set; } = ConversationRegion.Us;
/// <summary>
/// Set's the regions for the Fax api.
/// </summary>
public FaxRegion? FaxRegion { get; set; }
/// <inheritdoc cref="ApiUrlOverrides"/>
public ApiUrlOverrides? ApiUrlOverrides { get; set; }
internal ServicePlanIdOptions? ServicePlanIdOptions { get; private set; }
/// <summary>
/// Use SMS API with `service plan id` and compatible region.
/// `service_plan_id` will be used in place of `project_id`
/// </summary>
/// <param name="servicePlanId">Your service plan id</param>
/// <param name="apiToken"></param>
/// <param name="servicePlanIdRegion">Region to use. Defaults to <see cref="SmsServicePlanIdRegion.Us" /></param>
/// <exception cref="ArgumentNullException">throws if service plan id or region is null or an empty string</exception>
public void UseServicePlanIdWithSms(string servicePlanId,
string apiToken, SmsServicePlanIdRegion? servicePlanIdRegion = default)
{
servicePlanIdRegion ??= SmsServicePlanIdRegion.Us;
ServicePlanIdOptions = new ServicePlanIdOptions(servicePlanId, servicePlanIdRegion, apiToken);
}
}
internal class ServicePlanIdOptions
{
public ServicePlanIdOptions(string servicePlanId, SmsServicePlanIdRegion region, string apiToken)
{
if (string.IsNullOrEmpty(servicePlanId))
{
throw new ArgumentNullException(nameof(servicePlanId), "Should have a value");
}
if (region is null)
{
throw new ArgumentNullException(nameof(region), "Should have a value");
}
if (string.IsNullOrEmpty(apiToken))
{
throw new ArgumentNullException(nameof(apiToken), "Should have a value");
}
ServicePlanId = servicePlanId;
Region = region;
ApiToken = apiToken;
}
public string ApiToken { get; }
public SmsServicePlanIdRegion Region { get; }
public string ServicePlanId { get; }
}
/// <summary>
/// If you want to set your own url for proxy or testing, you can do it here for each API endpoint.
/// </summary>
public sealed class ApiUrlOverrides
{
/// <summary>
/// Overrides SMS api base url
/// </summary>
public string? SmsUrl { get; init; }
/// <summary>
/// Overrides Conversation api base url
/// </summary>
public string? ConversationUrl { get; init; }
/// <summary>
/// Overrides Templates api base url.
/// Templates are treated as part of conversation api, but it has another base address.
/// </summary>
public string? TemplatesUrl { get; init; }
/// <summary>
/// Overrides Voice api base url
/// </summary>
public string? VoiceUrl { get; init; }
/// <summary>
/// Overrides Voice api application management base url.
/// Voice Application Management is treated as voice api, but it has another base address.
/// </summary>
public string? VoiceApplicationManagementUrl { get; init; }
/// <summary>
/// Overrides Verification api base url
/// </summary>
public string? VerificationUrl { get; init; }
/// <summary>
/// Overrides Auth api base url
/// </summary>
public string? AuthUrl { get; init; }
/// <summary>
/// Overrides Numbers api base url
/// </summary>
public string? NumbersUrl { get; init; }
/// <summary>
/// Overrides Fax api base url
/// </summary>
public string? FaxUrl { get; init; }
}
}