Skip to content

Commit b9275ca

Browse files
committed
Boilerplate attachments API support
1 parent 2673f54 commit b9275ca

File tree

6 files changed

+268
-0
lines changed

6 files changed

+268
-0
lines changed

src/Cronofy/Attachment.cs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
namespace Cronofy
2+
{
3+
using Newtonsoft.Json;
4+
5+
/// <summary>
6+
/// Class for the deserialization of an attachment summary
7+
/// response.
8+
/// </summary>
9+
public sealed class Attachment
10+
{
11+
/// <summary>
12+
/// Gets or sets the attachment ID.
13+
/// </summary>
14+
/// <value>
15+
/// The ID of the attachment.
16+
/// </value>
17+
[JsonProperty("attachment_id")]
18+
public string AttachmentId { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the file name for the attachment.
22+
/// </summary>
23+
/// <value>
24+
/// The file name for the attachment.
25+
/// </value>
26+
[JsonProperty("file_name")]
27+
public string FileName { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the MIME content type for the attachment.
31+
/// </summary>
32+
/// <value>
33+
/// The MIME content type for the attachment.
34+
/// </value>
35+
[JsonProperty("content_type")]
36+
public string ContentType { get; set; }
37+
38+
/// <summary>
39+
/// Gets or sets the MD5 hash of the attachment content.
40+
/// </summary>
41+
/// <value>
42+
/// The MD5 hash of the attachment content.
43+
/// </value>
44+
[JsonProperty("md5")]
45+
public string MD5 { get; set; }
46+
47+
/// <inheritdoc/>
48+
public override bool Equals(object obj)
49+
{
50+
if (ReferenceEquals(null, obj))
51+
{
52+
return false;
53+
}
54+
55+
if (ReferenceEquals(this, obj))
56+
{
57+
return true;
58+
}
59+
60+
return obj is Attachment && this.Equals((Attachment)obj);
61+
}
62+
63+
/// <inheritdoc/>
64+
public override int GetHashCode()
65+
{
66+
return this.AttachmentId.GetHashCode();
67+
}
68+
69+
/// <summary>
70+
/// Determines whether the specified <see cref="Cronofy.Attachment"/>
71+
/// is equal to the current <see cref="Cronofy.Attachment"/>.
72+
/// </summary>
73+
/// <param name="other">
74+
/// The <see cref="Cronofy.Attachment"/> to compare with the current
75+
/// <see cref="Cronofy.Attachment"/>.
76+
/// </param>
77+
/// <returns>
78+
/// <c>true</c> if the specified <see cref="Cronofy.Attachment"/> is
79+
/// equal to the current <see cref="Cronofy.Attachment"/>; otherwise,
80+
/// <c>false</c>.
81+
/// </returns>
82+
public bool Equals(Attachment other)
83+
{
84+
return this.AttachmentId == other.AttachmentId && this.FileName == other.FileName
85+
&& this.ContentType == other.ContentType && this.MD5 == other.MD5;
86+
}
87+
88+
/// <inheritdoc/>
89+
public override string ToString()
90+
{
91+
return string.Format(
92+
"<{0} AttachmentId={1}, FileName={2}>",
93+
this.GetType(),
94+
this.AttachmentId,
95+
this.FileName);
96+
}
97+
}
98+
}

src/Cronofy/CronofyOAuthClient.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,28 @@ public ElementToken GetElementToken(ElementTokenRequest elementTokenRequest)
518518
return elementTokenResponse.ToElementToken();
519519
}
520520

521+
/// <inheritdoc/>
522+
public Attachment CreateAttachment(CreateAttachmentRequest createAttachmentRequest)
523+
{
524+
Preconditions.NotNull(nameof(createAttachmentRequest), createAttachmentRequest);
525+
Preconditions.NotEmpty(nameof(createAttachmentRequest.FileName), createAttachmentRequest.FileName);
526+
Preconditions.NotEmpty(nameof(createAttachmentRequest.ContentType), createAttachmentRequest.ContentType);
527+
Preconditions.NotEmpty(nameof(createAttachmentRequest.Base64Content), createAttachmentRequest.Base64Content);
528+
529+
var request = new HttpRequest
530+
{
531+
Method = "POST",
532+
Url = this.urlProvider.AttachmentsUrl,
533+
};
534+
535+
request.AddOAuthAuthorization(this.clientSecret);
536+
request.SetJsonBody(createAttachmentRequest);
537+
538+
var attachmentResponse = this.HttpClient.GetJsonResponse<AttachmentResponse>(request);
539+
540+
return attachmentResponse.ToAttachment();
541+
}
542+
521543
/// <summary>
522544
/// Builder class for authorization URLs.
523545
/// </summary>

src/Cronofy/ICronofyOAuthClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,7 @@ public interface ICronofyOAuthClient
396396
/// Thrown if <paramref name="redirectUri"/> is null or empty.
397397
/// </exception>
398398
IAuthorizationUrlBuilder GetEnterpriseConnectAuthorizationUrlBuilder(string redirectUri);
399+
400+
Attachment CreateAttachment(CreateAttachmentRequest createAttachmentRequest);
399401
}
400402
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
namespace Cronofy.Requests
2+
{
3+
using Newtonsoft.Json;
4+
using System.Collections.Generic;
5+
6+
/// <summary>
7+
/// Class for the serialization of a create attachment request.
8+
/// </summary>
9+
public sealed class CreateAttachmentRequest
10+
{
11+
/// <summary>
12+
/// Gets or sets the file name for the attachment.
13+
/// </summary>
14+
/// <value>
15+
/// The file name for the attachment.
16+
/// </value>
17+
[JsonProperty("file_name")]
18+
public string FileName { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the MIME content type for the attachment.
22+
/// </summary>
23+
/// <value>
24+
/// The MIME content type for the attachment.
25+
/// </value>
26+
[JsonProperty("content_type")]
27+
public string ContentType { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the Base64-encoded content of the attachment.
31+
/// </summary>
32+
/// <value>
33+
/// The Base64-encoded content of the attachment.
34+
/// </value>
35+
[JsonProperty("base64_content")]
36+
public string Base64Content { get; set; }
37+
38+
/// <summary>
39+
/// Class for the serialization of attachment subscriptions.
40+
/// </summary>
41+
public sealed class RequestSubscription
42+
{
43+
/// <summary>
44+
/// Gets or sets the type of the subscription.
45+
/// </summary>
46+
/// <value>
47+
/// The type of the subscription.
48+
/// </value>
49+
[JsonProperty("type")]
50+
public string Type { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets the destination URI Cronofy will call when the subscription is triggered.
54+
/// </summary>
55+
/// <value>
56+
/// The destination URI Cronofy will call when the subscription is triggered.
57+
/// </value>
58+
[JsonProperty("uri")]
59+
public string Uri { get; set; }
60+
61+
/// <summary>
62+
/// Gets or sets the interactions subscribed to.
63+
/// </summary>
64+
/// <value>
65+
/// The interactions subscribed to.
66+
/// </value>
67+
[JsonProperty("interactions")]
68+
public IEnumerable<Interaction> Interactions { get; set; }
69+
70+
/// <summary>
71+
/// Class for the serialization of event subscription interactions.
72+
/// </summary>
73+
public sealed class Interaction
74+
{
75+
/// <summary>
76+
/// Gets or sets the type of the interaction.
77+
/// </summary>
78+
/// <value>
79+
/// The type of the interaction.
80+
/// </value>
81+
[JsonProperty("type")]
82+
public string Type { get; set; }
83+
}
84+
}
85+
}
86+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
namespace Cronofy.Responses
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using Newtonsoft.Json;
7+
8+
/// <summary>
9+
/// Class for the deserialization of an availability response.
10+
/// </summary>
11+
internal sealed class AttachmentResponse
12+
{
13+
/// <summary>
14+
/// Gets or sets the available periods of the response.
15+
/// </summary>
16+
/// <value>
17+
/// The available periods of the response.
18+
/// </value>
19+
[JsonProperty("attachment")]
20+
public AttachmentSummary Attachment { get; set; }
21+
22+
internal sealed class AttachmentSummary
23+
{
24+
[JsonProperty("attachment_id")]
25+
public string AttachmentId { get; set; }
26+
27+
[JsonProperty("file_name")]
28+
public string FileName { get; set; }
29+
30+
[JsonProperty("content_type")]
31+
public string ContentType { get; set; }
32+
33+
[JsonProperty("md5")]
34+
public string MD5 { get; set; }
35+
}
36+
37+
public Attachment ToAttachment()
38+
{
39+
return new Attachment
40+
{
41+
AttachmentId = this.Attachment.AttachmentId,
42+
FileName = this.Attachment.FileName,
43+
ContentType = this.Attachment.ContentType,
44+
MD5 = this.Attachment.MD5,
45+
};
46+
}
47+
}
48+
}

src/Cronofy/UrlProvider.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public sealed class UrlProvider
170170
/// </summary>
171171
private const string ConferencingServiceAuthorizationUrlFormat = "https://api{0}.cronofy.com/v1/conferencing_service_authorizations";
172172

173+
/// <summary>
174+
/// The URL of the Attachments endpoint.
175+
/// </summary>
176+
private const string AttachmentsUrlFormat = "https://api{0}.cronofy.com/v1/attachments";
177+
173178
/// <summary>
174179
/// Initializes a new instance of the <see cref="UrlProvider"/> class.
175180
/// </summary>
@@ -218,6 +223,7 @@ internal UrlProvider(string dataCenter)
218223
this.ProvisionApplicationUrl = string.Format(ProvisionApplicationUrlFormat, suffix);
219224
this.ElementTokensUrl = string.Format(ElementTokensUrlFormat, suffix);
220225
this.ConferencingServiceAuthorizationUrl = string.Format(ConferencingServiceAuthorizationUrlFormat, suffix);
226+
this.AttachmentsUrl = string.Format(AttachmentsUrlFormat, suffix);
221227
}
222228

223229
/// <summary>
@@ -567,5 +573,11 @@ public string BatchUrl
567573
/// </summary>
568574
/// <value>The conferencing service authorization URL.</value>
569575
public string ConferencingServiceAuthorizationUrl { get; private set; }
576+
577+
/// <summary>
578+
/// Gets the attachments URL.
579+
/// </summary>
580+
/// <value>The attachments URL.</value>
581+
public string AttachmentsUrl { get; private set; }
570582
}
571583
}

0 commit comments

Comments
 (0)