Skip to content

Commit 8d99810

Browse files
committed
Release 0.9.0
1 parent 25e3f4a commit 8d99810

File tree

102 files changed

+4110
-377
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+4110
-377
lines changed

src/Vapi.Net.Test/Core/Pagination/StringCursorTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class StringCursorTest
1010
private const string? Cursor1 = null;
1111
private const string Cursor2 = "cursor2";
1212
private const string Cursor3 = "cursor3";
13+
private const string Cursor4 = "";
1314

1415
[Test]
1516
public async SystemTask CursorPagerShouldWorkWithStringCursor()
@@ -80,6 +81,69 @@ public async SystemTask CursorPagerShouldWorkWithStringCursor()
8081
Assert.That(await pageEnumerator.MoveNextAsync(), Is.False);
8182
}
8283

84+
[Test]
85+
public async SystemTask CursorPagerShouldWorkWithStringCursor_EmptyStringCursor()
86+
{
87+
var responses = new List<Response>
88+
{
89+
new()
90+
{
91+
Data = new Data { Items = ["item1", "item2"] },
92+
Cursor = new Cursor { Next = Cursor2 },
93+
},
94+
new()
95+
{
96+
Data = new Data { Items = ["item1"] },
97+
Cursor = new Cursor { Next = Cursor4 },
98+
},
99+
new()
100+
{
101+
Data = new Data { Items = ["item2"] },
102+
Cursor = new Cursor { Next = Cursor3 },
103+
},
104+
}.GetEnumerator();
105+
var cursorCopy = Cursor1;
106+
Pager<object> pager = await CursorPager<
107+
Request,
108+
object?,
109+
Response,
110+
string,
111+
object
112+
>.CreateInstanceAsync(
113+
new Request { Cursor = Cursor1 },
114+
null,
115+
(_, _, _) =>
116+
{
117+
responses.MoveNext();
118+
return SystemTask.FromResult(responses.Current);
119+
},
120+
(request, cursor) =>
121+
{
122+
request.Cursor = cursor;
123+
cursorCopy = cursor;
124+
},
125+
response => response?.Cursor?.Next,
126+
response => response?.Data?.Items?.ToList()
127+
);
128+
129+
var pageEnumerator = pager.AsPagesAsync().GetAsyncEnumerator();
130+
131+
// first page
132+
Assert.That(await pageEnumerator.MoveNextAsync(), Is.True);
133+
var page = pageEnumerator.Current;
134+
Assert.That(page.Items, Has.Count.EqualTo(2));
135+
Assert.That(cursorCopy, Is.EqualTo(Cursor2));
136+
137+
// second page (cursor is empty string)
138+
Assert.That(await pageEnumerator.MoveNextAsync(), Is.True);
139+
page = pageEnumerator.Current;
140+
Assert.That(page.Items, Has.Count.EqualTo(1));
141+
Assert.That(cursorCopy, Is.EqualTo(Cursor4));
142+
143+
// no more (should not reach third response)
144+
Assert.That(await pageEnumerator.MoveNextAsync(), Is.False);
145+
}
146+
83147
private class Request
84148
{
85149
public required string? Cursor { get; set; }

src/Vapi.Net.sln

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31903.59
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vapi.Net", "Vapi.Net\Vapi.Net.csproj", "{9ACE15F5-3E83-4328-A360-4A442AF66591}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vapi.Net", "Vapi.Net\Vapi.Net.csproj", "{74F65784-02D6-4418-84AE-A2461575A533}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vapi.Net.Test", "Vapi.Net.Test\Vapi.Net.Test.csproj", "{60260668-093D-4F1C-8377-6792D0C4CB84}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vapi.Net.Test", "Vapi.Net.Test\Vapi.Net.Test.csproj", "{CB0026F5-105D-4790-A64D-A62D8D97028F}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -16,13 +16,13 @@ Global
1616
HideSolutionNode = FALSE
1717
EndGlobalSection
1818
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19-
{9ACE15F5-3E83-4328-A360-4A442AF66591}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20-
{9ACE15F5-3E83-4328-A360-4A442AF66591}.Debug|Any CPU.Build.0 = Debug|Any CPU
21-
{9ACE15F5-3E83-4328-A360-4A442AF66591}.Release|Any CPU.ActiveCfg = Release|Any CPU
22-
{9ACE15F5-3E83-4328-A360-4A442AF66591}.Release|Any CPU.Build.0 = Release|Any CPU
23-
{60260668-093D-4F1C-8377-6792D0C4CB84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24-
{60260668-093D-4F1C-8377-6792D0C4CB84}.Debug|Any CPU.Build.0 = Debug|Any CPU
25-
{60260668-093D-4F1C-8377-6792D0C4CB84}.Release|Any CPU.ActiveCfg = Release|Any CPU
26-
{60260668-093D-4F1C-8377-6792D0C4CB84}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{74F65784-02D6-4418-84AE-A2461575A533}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{74F65784-02D6-4418-84AE-A2461575A533}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{74F65784-02D6-4418-84AE-A2461575A533}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{74F65784-02D6-4418-84AE-A2461575A533}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{CB0026F5-105D-4790-A64D-A62D8D97028F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{CB0026F5-105D-4790-A64D-A62D8D97028F}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{CB0026F5-105D-4790-A64D-A62D8D97028F}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{CB0026F5-105D-4790-A64D-A62D8D97028F}.Release|Any CPU.Build.0 = Release|Any CPU
2727
EndGlobalSection
2828
EndGlobal

src/Vapi.Net/Campaigns/CampaignsClient.cs

Lines changed: 18 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,29 @@ internal CampaignsClient(RawClient client)
1414
_client = client;
1515
}
1616

17-
public async Task<IEnumerable<Campaign>> CampaignControllerFindAllAsync(
17+
public async Task<CampaignPaginatedResponse> CampaignControllerFindAllAsync(
1818
CampaignControllerFindAllRequest request,
1919
RequestOptions? options = null,
2020
CancellationToken cancellationToken = default
2121
)
2222
{
2323
var _query = new Dictionary<string, object>();
24+
if (request.Id != null)
25+
{
26+
_query["id"] = request.Id;
27+
}
28+
if (request.Status != null)
29+
{
30+
_query["status"] = request.Status.Value.ToString();
31+
}
32+
if (request.Page != null)
33+
{
34+
_query["page"] = request.Page.Value.ToString();
35+
}
36+
if (request.SortOrder != null)
37+
{
38+
_query["sortOrder"] = request.SortOrder.Value.ToString();
39+
}
2440
if (request.Limit != null)
2541
{
2642
_query["limit"] = request.Limit.Value.ToString();
@@ -75,7 +91,7 @@ public async Task<IEnumerable<Campaign>> CampaignControllerFindAllAsync(
7591
var responseBody = await response.Raw.Content.ReadAsStringAsync();
7692
try
7793
{
78-
return JsonUtils.Deserialize<IEnumerable<Campaign>>(responseBody)!;
94+
return JsonUtils.Deserialize<CampaignPaginatedResponse>(responseBody)!;
7995
}
8096
catch (JsonException e)
8197
{
@@ -136,101 +152,6 @@ public async Task<Campaign> CampaignControllerCreateAsync(
136152
}
137153
}
138154

139-
public async Task<Campaign> CampaignControllerFindAllPaginatedAsync(
140-
CampaignControllerFindAllPaginatedRequest request,
141-
RequestOptions? options = null,
142-
CancellationToken cancellationToken = default
143-
)
144-
{
145-
var _query = new Dictionary<string, object>();
146-
if (request.Id != null)
147-
{
148-
_query["id"] = request.Id;
149-
}
150-
if (request.Status != null)
151-
{
152-
_query["status"] = request.Status.Value.ToString();
153-
}
154-
if (request.Page != null)
155-
{
156-
_query["page"] = request.Page.Value.ToString();
157-
}
158-
if (request.SortOrder != null)
159-
{
160-
_query["sortOrder"] = request.SortOrder.Value.ToString();
161-
}
162-
if (request.Limit != null)
163-
{
164-
_query["limit"] = request.Limit.Value.ToString();
165-
}
166-
if (request.CreatedAtGt != null)
167-
{
168-
_query["createdAtGt"] = request.CreatedAtGt.Value.ToString();
169-
}
170-
if (request.CreatedAtLt != null)
171-
{
172-
_query["createdAtLt"] = request.CreatedAtLt.Value.ToString();
173-
}
174-
if (request.CreatedAtGe != null)
175-
{
176-
_query["createdAtGe"] = request.CreatedAtGe.Value.ToString();
177-
}
178-
if (request.CreatedAtLe != null)
179-
{
180-
_query["createdAtLe"] = request.CreatedAtLe.Value.ToString();
181-
}
182-
if (request.UpdatedAtGt != null)
183-
{
184-
_query["updatedAtGt"] = request.UpdatedAtGt.Value.ToString();
185-
}
186-
if (request.UpdatedAtLt != null)
187-
{
188-
_query["updatedAtLt"] = request.UpdatedAtLt.Value.ToString();
189-
}
190-
if (request.UpdatedAtGe != null)
191-
{
192-
_query["updatedAtGe"] = request.UpdatedAtGe.Value.ToString();
193-
}
194-
if (request.UpdatedAtLe != null)
195-
{
196-
_query["updatedAtLe"] = request.UpdatedAtLe.Value.ToString();
197-
}
198-
var response = await _client
199-
.SendRequestAsync(
200-
new JsonRequest
201-
{
202-
BaseUrl = _client.Options.BaseUrl,
203-
Method = HttpMethod.Get,
204-
Path = "campaign/paginated",
205-
Query = _query,
206-
Options = options,
207-
},
208-
cancellationToken
209-
)
210-
.ConfigureAwait(false);
211-
if (response.StatusCode is >= 200 and < 400)
212-
{
213-
var responseBody = await response.Raw.Content.ReadAsStringAsync();
214-
try
215-
{
216-
return JsonUtils.Deserialize<Campaign>(responseBody)!;
217-
}
218-
catch (JsonException e)
219-
{
220-
throw new VapiClientException("Failed to deserialize response", e);
221-
}
222-
}
223-
224-
{
225-
var responseBody = await response.Raw.Content.ReadAsStringAsync();
226-
throw new VapiClientApiException(
227-
$"Error with status code {response.StatusCode}",
228-
response.StatusCode,
229-
responseBody
230-
);
231-
}
232-
}
233-
234155
public async Task<Campaign> CampaignControllerFindOneAsync(
235156
string id,
236157
RequestOptions? options = null,

src/Vapi.Net/Campaigns/Requests/CampaignControllerFindAllPaginatedRequest.cs

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/Vapi.Net/Campaigns/Requests/CampaignControllerFindAllRequest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ namespace Vapi.Net;
66
[Serializable]
77
public record CampaignControllerFindAllRequest
88
{
9+
[JsonIgnore]
10+
public string? Id { get; set; }
11+
12+
[JsonIgnore]
13+
public CampaignControllerFindAllRequestStatus? Status { get; set; }
14+
15+
/// <summary>
16+
/// This is the page number to return. Defaults to 1.
17+
/// </summary>
18+
[JsonIgnore]
19+
public double? Page { get; set; }
20+
21+
/// <summary>
22+
/// This is the sort order for pagination. Defaults to 'DESC'.
23+
/// </summary>
24+
[JsonIgnore]
25+
public CampaignControllerFindAllRequestSortOrder? SortOrder { get; set; }
26+
927
/// <summary>
1028
/// This is the maximum number of items to return. Defaults to 100.
1129
/// </summary>

src/Vapi.Net/Campaigns/Requests/CreateCampaignDto.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public record CreateCampaignDto
3434
/// This is the schedule plan for the campaign.
3535
/// </summary>
3636
[JsonPropertyName("schedulePlan")]
37-
public required SchedulePlan SchedulePlan { get; set; }
37+
public SchedulePlan? SchedulePlan { get; set; }
3838

3939
/// <summary>
4040
/// These are the customers that will be called in the campaign.

src/Vapi.Net/Campaigns/Types/CampaignControllerFindAllPaginatedRequestSortOrder.cs renamed to src/Vapi.Net/Campaigns/Types/CampaignControllerFindAllRequestSortOrder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Vapi.Net;
66

7-
[JsonConverter(typeof(EnumSerializer<CampaignControllerFindAllPaginatedRequestSortOrder>))]
8-
public enum CampaignControllerFindAllPaginatedRequestSortOrder
7+
[JsonConverter(typeof(EnumSerializer<CampaignControllerFindAllRequestSortOrder>))]
8+
public enum CampaignControllerFindAllRequestSortOrder
99
{
1010
[EnumMember(Value = "ASC")]
1111
Asc,

src/Vapi.Net/Campaigns/Types/CampaignControllerFindAllPaginatedRequestStatus.cs renamed to src/Vapi.Net/Campaigns/Types/CampaignControllerFindAllRequestStatus.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Vapi.Net;
66

7-
[JsonConverter(typeof(EnumSerializer<CampaignControllerFindAllPaginatedRequestStatus>))]
8-
public enum CampaignControllerFindAllPaginatedRequestStatus
7+
[JsonConverter(typeof(EnumSerializer<CampaignControllerFindAllRequestStatus>))]
8+
public enum CampaignControllerFindAllRequestStatus
99
{
1010
[EnumMember(Value = "scheduled")]
1111
Scheduled,

0 commit comments

Comments
 (0)