Skip to content

Commit c79993a

Browse files
committed
Upsert and get responses should be nested in a top level object rather than deserialized directly
1 parent c348d2c commit c79993a

File tree

7 files changed

+99
-53
lines changed

7 files changed

+99
-53
lines changed

src/Cronofy/AvailabilityRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public override string ToString()
9292
this.AvailabilityRuleId,
9393
this.TimeZoneId,
9494
this.CalendarIds,
95-
this.WeeklyPeriods);
95+
string.Join(", ", this.WeeklyPeriods.Select(weeklyPeriod => weeklyPeriod.ToString())));
9696
}
9797

9898
/// <summary>

src/Cronofy/CronofyAccountClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ public AvailabilityRule GetAvailabilityRule(string availabilityRuleId)
571571
request.Url = string.Format(this.UrlProvider.AvailabilityRuleUrl, availabilityRuleId);
572572
request.AddOAuthAuthorization(this.AccessToken);
573573

574-
var response = this.HttpClient.GetJsonResponse<AvailabilityRuleResponse>(request);
574+
var response = this.HttpClient.GetJsonResponse<GetAvailabilityRulesResponse>(request);
575575

576-
return response.ToAvailabilityRule();
576+
return response.AvailabilityRule.ToAvailabilityRule();
577577
}
578578

579579
/// <inheritdoc/>
@@ -602,9 +602,9 @@ public AvailabilityRule UpsertAvailabilityRule(UpsertAvailabilityRuleRequest ups
602602
request.AddOAuthAuthorization(this.AccessToken);
603603
request.SetJsonBody(upsertAvailabilityRuleRequest);
604604

605-
var response = this.HttpClient.GetJsonResponse<AvailabilityRuleResponse>(request);
605+
var response = this.HttpClient.GetJsonResponse<UpsertAvailabilityRulesResponse>(request);
606606

607-
return response.ToAvailabilityRule();
607+
return response.AvailabilityRule.ToAvailabilityRule();
608608
}
609609

610610
/// <inheritdoc/>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Cronofy.Responses
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json;
6+
7+
/// <summary>
8+
/// Class for the deserialization of a get availability rule response.
9+
/// </summary>
10+
internal sealed class GetAvailabilityRulesResponse
11+
{
12+
/// <summary>
13+
/// Gets or sets the availability rule.
14+
/// </summary>
15+
/// <value>
16+
/// The availability rule.
17+
/// </value>
18+
[JsonProperty("availability_rule")]
19+
public AvailabilityRuleResponse AvailabilityRule { get; set; }
20+
}
21+
}

src/Cronofy/Responses/ListAvailabilityRulesResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace Cronofy.Responses
1010
internal sealed class ListAvailabilityRulesResponse
1111
{
1212
/// <summary>
13-
/// Gets or sets the weekly recurring periods for the availability rule.
13+
/// Gets or sets the list of discovered availability rules.
1414
/// </summary>
1515
/// <value>
16-
/// The weekly recurring periods for the availability rule.
16+
/// The list of discovered availability rules.
1717
/// </value>
1818
[JsonProperty("availability_rules")]
1919
public IEnumerable<AvailabilityRuleResponse> AvailabilityRules { get; set; }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace Cronofy.Responses
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using Newtonsoft.Json;
6+
7+
/// <summary>
8+
/// Class for the deserialization of an upsert availability rules response.
9+
/// </summary>
10+
internal sealed class UpsertAvailabilityRulesResponse
11+
{
12+
/// <summary>
13+
/// Gets or sets the created or updated availability rule.
14+
/// </summary>
15+
/// <value>
16+
/// The created or updated availability rule.
17+
/// </value>
18+
[JsonProperty("availability_rule")]
19+
public AvailabilityRuleResponse AvailabilityRule { get; set; }
20+
}
21+
}

test/Cronofy.Test/CronofyAccountClientTests/GetAvailabilityRule.cs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,32 @@ public void CanGetAvailabilityRule()
1616
.ResponseCode(200)
1717
.ResponseBodyFormat(
1818
@"
19-
{{
20-
""availability_rule_id"": ""{0}"",
21-
""tzid"": ""America/Chicago"",
22-
""calendar_ids"": [
23-
""cal_n23kjnwrw2_jsdfjksn234""
24-
],
25-
""weekly_periods"": [
26-
{{
27-
""day"": ""monday"",
28-
""start_time"": ""09:30"",
29-
""end_time"": ""12:30""
30-
}},
31-
{{
32-
""day"": ""monday"",
33-
""start_time"": ""14:00"",
34-
""end_time"": ""17:00""
35-
}},
36-
{{
37-
""day"": ""wednesday"",
38-
""start_time"": ""09:30"",
39-
""end_time"": ""12:30""
40-
}}
41-
]
42-
}}
19+
{{
20+
""availability_rule"": {{
21+
""availability_rule_id"": ""{0}"",
22+
""tzid"": ""America/Chicago"",
23+
""calendar_ids"": [
24+
""cal_n23kjnwrw2_jsdfjksn234""
25+
],
26+
""weekly_periods"": [
27+
{{
28+
""day"": ""monday"",
29+
""start_time"": ""09:30"",
30+
""end_time"": ""12:30""
31+
}},
32+
{{
33+
""day"": ""monday"",
34+
""start_time"": ""14:00"",
35+
""end_time"": ""17:00""
36+
}},
37+
{{
38+
""day"": ""wednesday"",
39+
""start_time"": ""09:30"",
40+
""end_time"": ""12:30""
41+
}}
42+
]
43+
}}
44+
}}
4345
", AvailabilityRuleId));
4446

4547
var actualResponse = this.Client.GetAvailabilityRule(AvailabilityRuleId);

test/Cronofy.Test/CronofyAccountClientTests/UpsertAvailabilityRule.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,30 @@ public void CanUpsertAvailabilityRule()
4040
.ResponseCode(200)
4141
.ResponseBody(@"
4242
{
43-
""availability_rule_id"": ""default"",
44-
""tzid"": ""America/Chicago"",
45-
""calendar_ids"": [
46-
""cal_n23kjnwrw2_jsdfjksn234""
47-
],
48-
""weekly_periods"": [
49-
{
50-
""day"": ""monday"",
51-
""start_time"": ""09:30"",
52-
""end_time"": ""12:30""
53-
},
54-
{
55-
""day"": ""monday"",
56-
""start_time"": ""14:00"",
57-
""end_time"": ""17:00""
58-
},
59-
{
60-
""day"": ""wednesday"",
61-
""start_time"": ""09:30"",
62-
""end_time"": ""12:30""
63-
}
64-
]
43+
""availability_rule"": {
44+
""availability_rule_id"": ""default"",
45+
""tzid"": ""America/Chicago"",
46+
""calendar_ids"": [
47+
""cal_n23kjnwrw2_jsdfjksn234""
48+
],
49+
""weekly_periods"": [
50+
{
51+
""day"": ""monday"",
52+
""start_time"": ""09:30"",
53+
""end_time"": ""12:30""
54+
},
55+
{
56+
""day"": ""monday"",
57+
""start_time"": ""14:00"",
58+
""end_time"": ""17:00""
59+
},
60+
{
61+
""day"": ""wednesday"",
62+
""start_time"": ""09:30"",
63+
""end_time"": ""12:30""
64+
}
65+
]
66+
}
6567
}
6668
"));
6769

0 commit comments

Comments
 (0)