Skip to content

Commit

Permalink
Adds support for extended_transparency on Events APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevett committed Jan 23, 2025
1 parent 17ffb66 commit 437eac9
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.12.8]
* Add support for extended_transparency for events. [#142]

## [1.12.7]
* Add support for Availability Rules endpoints. [#139]

Expand Down Expand Up @@ -341,6 +344,7 @@
[1.12.5]: https://github.com/cronofy/cronofy-csharp/releases/tag/rel-1.12.5
[1.12.6]: https://github.com/cronofy/cronofy-csharp/releases/tag/rel-1.12.6
[1.12.7]: https://github.com/cronofy/cronofy-csharp/releases/tag/rel-1.12.7
[1.12.8]: https://github.com/cronofy/cronofy-csharp/releases/tag/rel-1.12.8

[#3]: https://github.com/cronofy/cronofy-csharp/pull/3
[#10]: https://github.com/cronofy/cronofy-csharp/pull/10
Expand Down Expand Up @@ -416,3 +420,4 @@
[#135]: https://github.com/cronofy/cronofy-csharp/pull/135
[#137]: https://github.com/cronofy/cronofy-csharp/pull/137
[#139]: https://github.com/cronofy/cronofy-csharp/pull/139
[#142]: https://github.com/cronofy/cronofy-csharp/pull/142
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.7
1.12.8
12 changes: 12 additions & 0 deletions src/Cronofy/Event.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ public sealed class Event
/// </remarks>
public string Transparency { get; set; }

/// <summary>
/// Gets or sets the extended transparency of the event.
/// </summary>
/// <value>
/// The extended transparency of the event.
/// </value>
/// <remarks>
/// See <see cref="Cronofy.ExtendedTransparency"/> for potential values.
/// </remarks>
public string ExtendedTransparency { get; set; }

/// <summary>
/// Gets or sets the status of the event.
/// </summary>
Expand Down Expand Up @@ -261,6 +272,7 @@ public bool Equals(Event other)
&& this.Description == other.Description
&& this.ParticipationStatus == other.ParticipationStatus
&& this.Transparency == other.Transparency
&& this.ExtendedTransparency == other.ExtendedTransparency
&& this.EventStatus == other.EventStatus
&& this.Recurring == other.Recurring
&& this.MeetingUrl == other.MeetingUrl
Expand Down
39 changes: 39 additions & 0 deletions src/Cronofy/ExtendedTransparency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Cronofy
{
/// <summary>
/// Potential extended_transparency values.
/// </summary>
public static class ExtendedTransparency
{
/// <summary>
/// The account should appear as busy for the duration of the event.
/// </summary>
public const string Opaque = "opaque";

/// <summary>
/// The account should not appear as busy for the duration of the event.
/// </summary>
public const string Transparent = "transparent";

/// <summary>
/// Indicates the user is working away from their normal site.
/// </summary>
public const string WorkingElsewhere = "working_elsewhere";

/// <summary>
/// Indicates an event being only tentatively accepted.
/// </summary>
public const string Tentative = "tentative";

/// <summary>
/// Indicates the user is unavailable due to being out of the office, such as being on vacation.
/// </summary>
public const string OutOfOffice = "out_of_office";

/// <summary>
/// The appearance of the account for the duration of the event is not
/// known.
/// </summary>
public const string Unknown = "unknown";
}
}
9 changes: 9 additions & 0 deletions src/Cronofy/Requests/UpsertEventRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public sealed class UpsertEventRequest : BaseEventRequest
[JsonProperty("attachments")]
public IEnumerable<Attachment> Attachments { get; set; }

/// <summary>
/// Gets or sets the extended_transparency of the event.
/// </summary>
/// <value>
/// The extended_transparency of the event.
/// </value>
[JsonProperty("extended_transparency")]
public string ExtendedTransparency { get; set; }

/// <summary>
/// Class for the serialization of the attendees for an upsert event
/// request.
Expand Down
10 changes: 10 additions & 0 deletions src/Cronofy/Responses/ReadEventsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ internal sealed class EventResponse
[JsonProperty("transparency")]
public string Transparency { get; set; }

/// <summary>
/// Gets or sets the extended transparency of the event.
/// </summary>
/// <value>
/// The extended transparency of the event.
/// </value>
[JsonProperty("extended_transparency")]
public string ExtendedTransparency { get; set; }

/// <summary>
/// Gets or sets the status of the event.
/// </summary>
Expand Down Expand Up @@ -286,6 +295,7 @@ public Event ToEvent()
Deleted = this.Deleted,
ParticipationStatus = this.ParticipationStatus,
Transparency = this.Transparency,
ExtendedTransparency = this.ExtendedTransparency,
EventStatus = this.EventStatus,
Categories = this.Categories,
Created = this.Created,
Expand Down
30 changes: 30 additions & 0 deletions src/Cronofy/UpsertEventRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public sealed class UpsertEventRequestBuilder : IBuilder<UpsertEventRequest>
/// </summary>
private string transparency;

/// <summary>
/// The extended_transparency of the event.
/// </summary>
private string extendedTransparency;

/// <summary>
/// The color of the event.
/// </summary>
Expand Down Expand Up @@ -601,6 +606,30 @@ public UpsertEventRequestBuilder Transparency(string transparency)
return this;
}

/// <summary>
/// Sets the extended transparency of the event.
/// </summary>
/// <param name="extendedTransparency">
/// ExtendedTransparency, must not be empty.
/// </param>
/// <returns>
/// A reference to the modified builder.
/// </returns>
/// <exception cref="ArgumentException">
/// Thrown if <paramref name="extendedTransparency"/> is not
/// transparent, opaque, working_elsewhere, tentative, or out_of_office.
/// </exception>
public UpsertEventRequestBuilder ExtendedTransparency(string extendedTransparency)
{
Preconditions.True(
new[] { "transparent", "opaque", "working_elsewhere", "tentative", "out_of_office" }.Contains(extendedTransparency),
"ExtendedTransparency must be `transparent`, `opaque`, `working_elsewhere`, `tentative`, or `out_of_office`.");

this.extendedTransparency = extendedTransparency;

return this;
}

/// <summary>
/// Sets the color of the event.
/// </summary>
Expand Down Expand Up @@ -793,6 +822,7 @@ public UpsertEventRequest Build()
End = GetEventTime("End", this.endTime, this.endDate, this.endTimeZoneId),
Url = this.url,
Transparency = this.transparency,
ExtendedTransparency = this.extendedTransparency,
TimeZoneId = this.timeZoneId,
Color = this.color,
RemindersCreateOnly = this.remindersCreateOnly,
Expand Down
94 changes: 94 additions & 0 deletions test/Cronofy.Test/CronofyAccountClientTests/GetEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,100 @@ public void CanGetEventWithMeetingUrl()
events);
}

[Test]
public void CanGetEventWithExtendedTransparency()
{
this.Http.Stub(
HttpGet
.Url("https://api.cronofy.com/v1/events?tzid=Etc%2FUTC&localized_times=true")
.RequestHeader("Authorization", "Bearer " + AccessToken)
.ResponseCode(200)
.ResponseBody(
@"{
""pages"": {
""current"": 1,
""total"": 1
},
""events"": [
{
""calendar_id"": ""cal_U9uuErStTG@EAAAB_IsAsykA2DBTWqQTf-f0kJw"",
""event_uid"": ""evt_external_54008b1a4a41730f8d5c6037"",
""summary"": ""Company Retreat"",
""description"": ""Escape to the country"",
""start"": ""2014-09-06"",
""end"": ""2014-09-08"",
""deleted"": false,
""recurring"": true,
""series_identifier"": ""identifier"",
""participation_status"": ""needs_action"",
""transparency"": ""opaque"",
""extended_transparency"": ""working_elsewhere"",
""status"": ""confirmed"",
""categories"": [],
""attendees"": [
{
""email"": ""[email protected]"",
""display_name"": ""Example Person"",
""status"": ""needs_action""
}
],
""created"": ""2014-09-01T08:00:01Z"",
""updated"": ""2014-09-01T09:24:16Z"",
""options"": {
""delete"": true,
""update"": true,
""change_participation_status"": true
},
""meeting_url"": ""https://meet.example.com/ABCD1234""
}
]
}"));

var events = this.Client.GetEvents();

CollectionAssert.AreEqual(
new List<Event>
{
new Event
{
CalendarId = "cal_U9uuErStTG@EAAAB_IsAsykA2DBTWqQTf-f0kJw",
EventUid = "evt_external_54008b1a4a41730f8d5c6037",
Summary = "Company Retreat",
Description = "Escape to the country",
Start = new EventTime(new Date(2014, 9, 6), "Etc/UTC"),
End = new EventTime(new Date(2014, 9, 8), "Etc/UTC"),
Location = null,
Deleted = false,
Recurring = true,
SeriesIdentifier = "identifier",
ParticipationStatus = AttendeeStatus.NeedsAction,
Transparency = Transparency.Opaque,
ExtendedTransparency = ExtendedTransparency.WorkingElsewhere,
EventStatus = EventStatus.Confirmed,
Categories = new string[] { },
Created = new DateTime(2014, 9, 1, 8, 0, 1, DateTimeKind.Utc),
Updated = new DateTime(2014, 9, 1, 9, 24, 16, DateTimeKind.Utc),
Attendees = new[]
{
new Attendee
{
Email = "[email protected]",
DisplayName = "Example Person",
Status = AttendeeStatus.NeedsAction,
},
},
Options = new EventOptions()
{
Delete = true,
Update = true,
ChangeParticipationStatus = true,
},
MeetingUrl = "https://meet.example.com/ABCD1234",
},
},
events);
}

[Test]
public void CanGetEventWithOldAuditTimes()
{
Expand Down
46 changes: 46 additions & 0 deletions test/Cronofy.Test/CronofyAccountClientTests/UpsertEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,51 @@ public void CanUpsertRemovingSubscriptions()

this.Client.UpsertEvent(CalendarId, builder);
}

[Test]
public void CanUpsertEventWithExtendedTransparency()
{
const string eventId = "qTtZdczOccgaPncGJaCiLg";
const string summary = "Board meeting";
const string description = "Discuss plans for the next quarter";
const string startTimeString = "2014-08-05 15:30:00Z";
const string endTimeString = "2014-08-05 17:00:00Z";
const string locationDescription = "Board room";
const string extendedTransparency = ExtendedTransparency.OutOfOffice;

this.Http.Stub(
HttpPost
.Url("https://api.cronofy.com/v1/calendars/" + CalendarId + "/events")
.RequestHeader("Authorization", "Bearer " + AccessToken)
.RequestHeader("Content-Type", "application/json; charset=utf-8")
.RequestBodyFormat(
"{{\"event_id\":\"{0}\"," +
"\"extended_transparency\":\"{1}\"," +
"\"summary\":\"{2}\"," +
"\"description\":\"{3}\"," +
"\"start\":{{\"time\":\"{4}\",\"tzid\":\"Etc/UTC\"}}," +
"\"end\":{{\"time\":\"{5}\",\"tzid\":\"Etc/UTC\"}}," +
"\"location\":{{\"description\":\"{6}\"}}" +
"}}",
eventId,
extendedTransparency,
summary,
description,
startTimeString,
endTimeString,
locationDescription)
.ResponseCode(202));

var builder = new UpsertEventRequestBuilder()
.EventId(eventId)
.Summary(summary)
.Description(description)
.Start(new DateTime(2014, 8, 5, 15, 30, 0, DateTimeKind.Utc))
.End(new DateTime(2014, 8, 5, 17, 0, 0, DateTimeKind.Utc))
.Location(locationDescription)
.ExtendedTransparency(extendedTransparency);

this.Client.UpsertEvent(CalendarId, builder);
}
}
}

0 comments on commit 437eac9

Please sign in to comment.