Skip to content

Commit

Permalink
Split multi-recipient Smart Invites calls
Browse files Browse the repository at this point in the history
As the behavior and shape of requests and responses differs, it feels
better to use a different branch rather than have a single path which
requires null checks and similar.
  • Loading branch information
gshutler committed Oct 22, 2018
1 parent 54c5216 commit 8d340f2
Show file tree
Hide file tree
Showing 11 changed files with 631 additions and 115 deletions.
4 changes: 4 additions & 0 deletions src/Cronofy/Cronofy.csproj
Expand Up @@ -164,6 +164,10 @@
<Compile Include="Responses\SequencedAvailabilityResponse.cs" />
<Compile Include="RealTimeSequencingRequestBuilder.cs" />
<Compile Include="Responses\RealTimeSequencingResponse.cs" />
<Compile Include="SmartInviteMultiRecipientRequestBuilder.cs" />
<Compile Include="Requests\SmartInviteMultiRecipientRequest.cs" />
<Compile Include="SmartInviteMultiRecipient.cs" />
<Compile Include="Responses\SmartInviteMultiRecipientResponse.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages/StyleCop.MSBuild.5.0.0\build\StyleCop.MSBuild.targets" />
Expand Down
43 changes: 43 additions & 0 deletions src/Cronofy/CronofyOAuthClient.cs
Expand Up @@ -320,6 +320,9 @@ public SmartInvite CreateInvite(SmartInviteRequest smartInviteRequest)
/// <inheritdoc/>
public SmartInvite CancelInvite(string smartInviteId, string recipientEmail)
{
Preconditions.NotEmpty("smartInviteId", smartInviteId);
Preconditions.NotEmpty("emailAddress", recipientEmail);

var request = new HttpRequest
{
Method = "POST",
Expand All @@ -338,6 +341,9 @@ public SmartInvite CancelInvite(string smartInviteId, string recipientEmail)
/// <inheritdoc/>
public SmartInvite GetSmartInvite(string smartInviteId, string emailAddress)
{
Preconditions.NotEmpty("smartInviteId", smartInviteId);
Preconditions.NotEmpty("emailAddress", emailAddress);

var request = new HttpRequest
{
Method = "GET",
Expand All @@ -355,6 +361,43 @@ public SmartInvite GetSmartInvite(string smartInviteId, string emailAddress)
return response.ToSmartInvite();
}

/// <inheritdoc/>
public SmartInviteMultiRecipient CreateInvite(SmartInviteMultiRecipientRequest smartInviteRequest)
{
var request = new HttpRequest
{
Method = "POST",
Url = this.urlProvider.SmartInviteUrl
};

request.AddOAuthAuthorization(this.clientSecret);
request.SetJsonBody(smartInviteRequest);

var response = this.HttpClient.GetJsonResponse<SmartInviteMultiRecipientResponse>(request);
return response.ToSmartInvite();
}

/// <inheritdoc/>
public SmartInviteMultiRecipient GetSmartInvite(string smartInviteId)
{
Preconditions.NotEmpty("smartInviteId", smartInviteId);

var request = new HttpRequest
{
Method = "GET",
Url = this.urlProvider.SmartInviteUrl,
QueryString = new HttpRequest.QueryStringCollection
{
{ "smart_invite_id", smartInviteId }
}
};

request.AddOAuthAuthorization(this.clientSecret);

var response = this.HttpClient.GetJsonResponse<SmartInviteMultiRecipientResponse>(request);
return response.ToSmartInvite();
}

/// <inheritdoc />
public OAuthToken ApplicationCalendar(string applicationCalendarId)
{
Expand Down
40 changes: 34 additions & 6 deletions src/Cronofy/ICronofyOAuthClient.cs
Expand Up @@ -140,34 +140,34 @@ public interface ICronofyOAuthClient
string RealTimeSequencing(RealTimeSequencingRequest realTimeSequencingRequest);

/// <summary>
/// Creates a smart invite for the given request.
/// Creates a Smart Invite for the given request.
/// </summary>
/// <param name="smartInviteRequest">
/// The details of the invite, must not be <code>null</code>.
/// </param>
/// <returns>
/// A smart invite for the given request.
/// A Smart Invite for the given request.
/// </returns>
/// <exception cref="CronofyException">
/// Thrown if an error is encountered whilst making the request.
/// </exception>
SmartInvite CreateInvite(SmartInviteRequest smartInviteRequest);

/// <summary>
/// Cancels a smart invite for the given request.
/// Cancels a Smart Invite for the given request.
/// </summary>
/// <param name="smartInviteId">The invite id to cancel.</param>
/// <param name="recipientEmail">The recipient for the cancellation.</param>
/// <returns>
/// A smart invite for the given request.
/// A Smart Invite for the given request.
/// </returns>
/// <exception cref="CronofyException">
/// Thrown if an error is encountered whilst making the request.
/// </exception>
SmartInvite CancelInvite(string smartInviteId, string recipientEmail);

/// <summary>
/// Retreives detials of a smart invite.
/// Retreives details of a Smart Invite.
/// </summary>
/// <param name="smartInviteId">
/// The invite id.
Expand All @@ -176,11 +176,39 @@ public interface ICronofyOAuthClient
/// The email address of the invitee.
/// </param>
/// <returns>
/// A smart invite for the given request.
/// A Smart Invite for the given request.
/// </returns>
/// <exception cref="CronofyException">
/// Thrown if an error is encountered whilst making the request.
/// </exception>
SmartInvite GetSmartInvite(string smartInviteId, string emailAddress);

/// <summary>
/// Creates a Smart Invite for the given request.
/// </summary>
/// <param name="smartInviteRequest">
/// The details of the invite, must not be <code>null</code>.
/// </param>
/// <returns>
/// A Smart Invite for the given request.
/// </returns>
/// <exception cref="CronofyException">
/// Thrown if an error is encountered whilst making the request.
/// </exception>
SmartInviteMultiRecipient CreateInvite(SmartInviteMultiRecipientRequest smartInviteRequest);

/// <summary>
/// Retreives details of a Smart Invite.
/// </summary>
/// <param name="smartInviteId">
/// The invite id.
/// </param>
/// <returns>
/// A Smart Invite for the given request.
/// </returns>
/// <exception cref="CronofyException">
/// Thrown if an error is encountered whilst making the request.
/// </exception>
SmartInviteMultiRecipient GetSmartInvite(string smartInviteId);
}
}
95 changes: 95 additions & 0 deletions src/Cronofy/Requests/SmartInviteMultiRecipientRequest.cs
@@ -0,0 +1,95 @@
namespace Cronofy.Requests
{
using System.Collections.Generic;
using Newtonsoft.Json;

/// <summary>
/// Class for the serialization of an smart invite request.
/// </summary>
public sealed class SmartInviteMultiRecipientRequest
{
/// <summary>
/// Gets or sets the method for the invite.
/// </summary>
/// <value>
/// The method of the invite.
/// </value>
[JsonProperty("method")]
public string Method { get; set; }

/// <summary>
/// Gets or sets the Id for the invite.
/// </summary>
/// <value>
/// The Id of the invite.
/// </value>
[JsonProperty("smart_invite_id")]
public string SmartInviteId { get; set; }

/// <summary>
/// Gets or sets the callback url for notifications.
/// </summary>
/// <value>
/// The callback url for notifications.
/// </value>
[JsonProperty("callback_url")]
public string CallbackUrl { get; set; }

/// <summary>
/// Gets or sets the recipients for the invite.
/// </summary>
/// <value>
/// The recipients for the invite.
/// </value>
[JsonProperty("recipients")]
public IEnumerable<InviteRecipient> Recipients { get; set; }

/// <summary>
/// Gets or sets the details for the event.
/// </summary>
/// <value>
/// The details for the event.
/// </value>
[JsonProperty("event")]
public SmartInviteEventRequest Event { get; set; }

/// <summary>
/// Gets or sets the organizer for the invite.
/// </summary>
/// <value>
/// The organizer for the invite.
/// </value>
[JsonProperty("organizer")]
public InviteOrganizer Organizer { get; set; }

/// <summary>
/// Class for the serialization of an smart invite request recipient.
/// </summary>
public sealed class InviteRecipient
{
/// <summary>
/// Gets or sets the email address.
/// </summary>
/// <value>
/// The email address.
/// </value>
[JsonProperty("email")]
public string Email { get; set; }
}

/// <summary>
/// Class for the serialization of an smart invite request organizer.
/// </summary>
public sealed class InviteOrganizer
{
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>
/// The name.
/// </value>
[JsonProperty("name")]
public string Name { get; set; }
}
}
}
9 changes: 0 additions & 9 deletions src/Cronofy/Requests/SmartInviteRequest.cs
Expand Up @@ -44,15 +44,6 @@ public sealed class SmartInviteRequest
[JsonProperty("recipient")]
public InviteRecipient Recipient { get; set; }

/// <summary>
/// Gets or sets the recipients for the invite.
/// </summary>
/// <value>
/// The recipients for the invite.
/// </value>
[JsonProperty("recipients")]
public IEnumerable<InviteRecipient> Recipients { get; set; }

/// <summary>
/// Gets or sets the details for the event.
/// </summary>
Expand Down
83 changes: 83 additions & 0 deletions src/Cronofy/Responses/SmartInviteMultiRecipientResponse.cs
@@ -0,0 +1,83 @@
namespace Cronofy.Responses
{
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;

/// <summary>
/// Class to represent a smart invite response.
/// </summary>
internal sealed class SmartInviteMultiRecipientResponse
{
/// <summary>
/// Gets or sets the method for the invite.
/// </summary>
/// <value>
/// The method of the invite.
/// </value>
[JsonProperty("method")]
public string Method { get; set; }

/// <summary>
/// Gets or sets the smart invite identifier.
/// </summary>
/// <value>The smart invite identifier.</value>
[JsonProperty("smart_invite_id")]
public string SmartInviteId { get; set; }

/// <summary>
/// Gets or sets the callback URL.
/// </summary>
/// <value>The callback URL.</value>
[JsonProperty("callback_url")]
public string CallbackUrl { get; set; }

/// <summary>
/// Gets or sets the recipients list.
/// </summary>
/// <value>The recipient.</value>
[JsonProperty("recipients")]
public SmartInviteResponse.ResponseAttendee[] Recipients { get; set; }

/// <summary>
/// Gets or sets the event.
/// </summary>
/// <value>The event.</value>
[JsonProperty("event")]
public ReadEventsResponse.EventResponse Event { get; set; }

/// <summary>
/// Gets or sets the attachments.
/// </summary>
/// <value>The attachments.</value>
[JsonProperty("attachments")]
public SmartInviteResponse.AttachmentsResponse Attachments { get; set; }

/// <summary>
/// Converts this response to a SmartInviteMultiRecipient object.
/// </summary>
/// <returns>A Smart invite object.</returns>
public SmartInviteMultiRecipient ToSmartInvite()
{
var invite = new SmartInviteMultiRecipient();

invite.SmartInviteId = this.SmartInviteId;
invite.CallbackUrl = this.CallbackUrl;
invite.Method = this.Method;

if (this.Recipients != null)
{
invite.Recipients = this.Recipients.Select(t => t.ToAttendee());
}
else
{
invite.Recipients = Enumerable.Empty<SmartInvite.Attendee>();
}

invite.Event = this.Event.ToEvent();
invite.Attachments = this.Attachments.ToAttachments();

return invite;
}
}
}
16 changes: 0 additions & 16 deletions src/Cronofy/Responses/SmartInviteResponse.cs
Expand Up @@ -46,13 +46,6 @@ internal sealed class SmartInviteResponse
[JsonProperty("recipient")]
public ResponseAttendee Recipient { get; set; }

/// <summary>
/// Gets or sets the recipients list.
/// </summary>
/// <value>The recipient.</value>
[JsonProperty("recipients")]
public IEnumerable<ResponseAttendee> Recipients { get; set; }

/// <summary>
/// Gets or sets the event.
/// </summary>
Expand Down Expand Up @@ -92,15 +85,6 @@ public SmartInvite ToSmartInvite()
invite.Recipient = this.Recipient.ToAttendee();
}

if (this.Recipients != null)
{
invite.Recipients = this.Recipients.Select(t => t.ToAttendee());
}
else
{
invite.Recipients = Enumerable.Empty<SmartInvite.Attendee>();
}

invite.Event = this.Event.ToEvent();
invite.Attachments = this.Attachments.ToAttachments();

Expand Down

0 comments on commit 8d340f2

Please sign in to comment.