-
Notifications
You must be signed in to change notification settings - Fork 51
/
MailboxesActions.cs
206 lines (192 loc) · 6.99 KB
/
MailboxesActions.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
AsterNET ARI Framework
Automatically generated file @ 31/08/2020 12:42:41
*/
using System.Collections.Generic;
using System.Linq;
using AsterNET.ARI.Middleware;
using AsterNET.ARI.Models;
using Newtonsoft.Json;
using System.Threading.Tasks;
namespace AsterNET.ARI.Actions
{
public class MailboxesActions : ARIBaseAction, IMailboxesActions
{
public MailboxesActions(IActionConsumer consumer)
: base(consumer)
{}
/// <summary>
/// List all mailboxes..
/// </summary>
public List<Mailbox> List()
{
string path = "mailboxes";
var request = GetNewRequest(path, HttpMethod.GET);
var response = Execute<List<Mailbox>>(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return response.Data;
switch((int)response.StatusCode)
{
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// Retrieve the current state of a mailbox..
/// </summary>
/// <param name="mailboxName">Name of the mailbox</param>
public Mailbox Get(string mailboxName)
{
string path = "mailboxes/{mailboxName}";
var request = GetNewRequest(path, HttpMethod.GET);
if(mailboxName != null)
request.AddUrlSegment("mailboxName", mailboxName);
var response = Execute<Mailbox>(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return response.Data;
switch((int)response.StatusCode)
{
case 404:
throw new AriException("Mailbox not found", (int)response.StatusCode);
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// Change the state of a mailbox. (Note - implicitly creates the mailbox)..
/// </summary>
/// <param name="mailboxName">Name of the mailbox</param>
/// <param name="oldMessages">Count of old messages in the mailbox</param>
/// <param name="newMessages">Count of new messages in the mailbox</param>
public void Update(string mailboxName, int oldMessages, int newMessages)
{
string path = "mailboxes/{mailboxName}";
var request = GetNewRequest(path, HttpMethod.PUT);
if(mailboxName != null)
request.AddUrlSegment("mailboxName", mailboxName);
if(oldMessages != null)
request.AddParameter("oldMessages", oldMessages, ParameterType.QueryString);
if(newMessages != null)
request.AddParameter("newMessages", newMessages, ParameterType.QueryString);
var response = Execute(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return;
switch((int)response.StatusCode)
{
case 404:
throw new AriException("Mailbox not found", (int)response.StatusCode);
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// Destroy a mailbox..
/// </summary>
/// <param name="mailboxName">Name of the mailbox</param>
public void Delete(string mailboxName)
{
string path = "mailboxes/{mailboxName}";
var request = GetNewRequest(path, HttpMethod.DELETE);
if(mailboxName != null)
request.AddUrlSegment("mailboxName", mailboxName);
var response = Execute(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return;
switch((int)response.StatusCode)
{
case 404:
throw new AriException("Mailbox not found", (int)response.StatusCode);
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// List all mailboxes..
/// </summary>
public async Task<List<Mailbox>> ListAsync()
{
string path = "mailboxes";
var request = GetNewRequest(path, HttpMethod.GET);
var response = await ExecuteTask<List<Mailbox>>(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return response.Data;
switch((int)response.StatusCode)
{
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// Retrieve the current state of a mailbox..
/// </summary>
public async Task<Mailbox> GetAsync(string mailboxName)
{
string path = "mailboxes/{mailboxName}";
var request = GetNewRequest(path, HttpMethod.GET);
if(mailboxName != null)
request.AddUrlSegment("mailboxName", mailboxName);
var response = await ExecuteTask<Mailbox>(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return response.Data;
switch((int)response.StatusCode)
{
case 404:
throw new AriException("Mailbox not found", (int)response.StatusCode);
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// Change the state of a mailbox. (Note - implicitly creates the mailbox)..
/// </summary>
public async Task UpdateAsync(string mailboxName, int oldMessages, int newMessages)
{
string path = "mailboxes/{mailboxName}";
var request = GetNewRequest(path, HttpMethod.PUT);
if(mailboxName != null)
request.AddUrlSegment("mailboxName", mailboxName);
if(oldMessages != null)
request.AddParameter("oldMessages", oldMessages, ParameterType.QueryString);
if(newMessages != null)
request.AddParameter("newMessages", newMessages, ParameterType.QueryString);
var response = await ExecuteTask(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return;
switch((int)response.StatusCode)
{
case 404:
throw new AriException("Mailbox not found", (int)response.StatusCode);
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
/// <summary>
/// Destroy a mailbox..
/// </summary>
public async Task DeleteAsync(string mailboxName)
{
string path = "mailboxes/{mailboxName}";
var request = GetNewRequest(path, HttpMethod.DELETE);
if(mailboxName != null)
request.AddUrlSegment("mailboxName", mailboxName);
var response = await ExecuteTask(request);
if((int)response.StatusCode >= 200 && (int)response.StatusCode < 300)
return;
switch((int)response.StatusCode)
{
case 404:
throw new AriException("Mailbox not found", (int)response.StatusCode);
default:
// Unknown server response
throw new AriException(string.Format("Unknown response code {0} from ARI.", response.StatusCode), (int)response.StatusCode);
}
}
}
}