Skip to content

Commit 0686de7

Browse files
authored
Merge pull request #208 from digipost/document_status
Add support to fetch DocumentStatus for a sent document
2 parents 0023b95 + f46da1d commit 0686de7

File tree

16 files changed

+349
-14
lines changed

16 files changed

+349
-14
lines changed

Digipost.Api.Client.Archive.Tests/Smoke/ArchiveSmokeTestsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class ArchiveSmokeTestsHelper
1616
{
1717
public static readonly string ArchiveName = "SmokeTestArchive";
1818
private readonly TestSender _testSender;
19-
private readonly ArchiveApi _archiveApi;
19+
private readonly IArchiveApi _archiveApi;
2020
private Archive _archivesWithDocuments;
2121
private Archive _archive;
2222
private Archive _byAttribute;

Digipost.Api.Client.Archive/ArchiveApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Digipost.Api.Client.Archive
1414
{
15-
internal interface IArchiveApi
15+
public interface IArchiveApi
1616
{
1717
/// <summary>
1818
/// List all the archives available to the current sender
@@ -52,7 +52,7 @@ internal interface IArchiveApi
5252
Task<ArchiveDocumentContent> GetDocumentContent(ArchiveDocumentContentUri archiveDocumentContentUri);
5353
}
5454

55-
public class ArchiveApi : IArchiveApi
55+
internal class ArchiveApi : IArchiveApi
5656
{
5757
private readonly Root _root;
5858
private readonly RequestHelper _requestHelper;

Digipost.Api.Client.Common/DataTransferObjectConverter.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,20 @@ public static SearchDetailsResult FromDataTransferObject(Recipients recipients)
414414
})
415415
};
416416
}
417+
418+
public static HashAlgoritm ToHashAlgoritm(this V8.Hash_Algorithm hashAlgorithm)
419+
{
420+
switch (hashAlgorithm)
421+
{
422+
case Hash_Algorithm.NONE:
423+
return HashAlgoritm.NONE;
424+
case Hash_Algorithm.MD5:
425+
return HashAlgoritm.MD5;
426+
case Hash_Algorithm.SHA256:
427+
return HashAlgoritm.SHA256;
428+
default:
429+
throw new ArgumentOutOfRangeException();
430+
}
431+
}
417432
}
418433
}

Digipost.Api.Client.Common/Entrypoint/Entrypoint.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public GetArchiveDocumentByUuidUri GetGetArchiveDocumentsByUuidUri(Guid guid)
7070
{
7171
return new GetArchiveDocumentByUuidUri(Links["GET_ARCHIVE_DOCUMENT_BY_UUID"], guid);
7272
}
73+
74+
public DocumentStatusUri GetDocumentStatusUri(Guid guid)
75+
{
76+
return new DocumentStatusUri(Links["DOCUMENT_STATUS"], guid);
77+
}
7378
}
7479

7580
public class Link
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Digipost.Api.Client.Common.Enums
2+
{
3+
public enum HashAlgoritm
4+
{
5+
NONE,
6+
MD5,
7+
SHA256
8+
}
9+
}

Digipost.Api.Client.Common/Relations/ApiRelations.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public ApiRootUri(Sender senderId = null)
1616
}
1717
}
1818

19-
2019
public class SendMessageUri : Uri
2120
{
2221
public SendMessageUri(Link link)
@@ -160,4 +159,17 @@ public ArchiveDocumentDeleteUri(Link link)
160159
{
161160
}
162161
}
162+
163+
public class DocumentStatusUri : Uri
164+
{
165+
public DocumentStatusUri(Link link, Guid guid)
166+
: base($"{link.Uri}{guid.ToString()}", UriKind.Absolute)
167+
{
168+
}
169+
170+
public DocumentStatusUri(Link link)
171+
: base(link.Uri, UriKind.Absolute)
172+
{
173+
}
174+
}
163175
}

Digipost.Api.Client.Docs/ArchiveExamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private async Task ArchiveADocument()
2626
new ArchiveDocument(Guid.NewGuid(), "attachment_123123.pdf", "pdf", "application/psd", readFileFromDisk("attachment_123123.pdf"))
2727
});
2828

29-
var savedArchive = await client.GetArchive().ArchiveDocuments(archive);
29+
var savedArchive = client.GetArchive().ArchiveDocuments(archive);
3030
}
3131

3232
private async Task ArchiveADocumentWithAutoDelete()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using Digipost.Api.Client.Common;
3+
using Digipost.Api.Client.Send;
4+
5+
namespace Digipost.Api.Client.Docs
6+
{
7+
public class DocumentsExamples
8+
{
9+
private static readonly DigipostClient client;
10+
private static readonly Sender sender;
11+
12+
public void Hent_document_status()
13+
{
14+
DocumentStatus documentStatus = client.GetDocumentStatus(sender)
15+
.GetDocumentStatus(Guid.Parse("10ff4c99-8560-4741-83f0-1093dc4deb1c"))
16+
.Result;
17+
18+
// example information:
19+
// documentStatus.DeliveryStatus => DELIVERED
20+
// documentStatus.DeliveryMethod => PRINT
21+
}
22+
}
23+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using System;
2+
using Digipost.Api.Client.Common;
3+
using Digipost.Api.Client.Common.Enums;
4+
5+
namespace Digipost.Api.Client.Send
6+
{
7+
public class DocumentStatus
8+
{
9+
public DocumentStatus(
10+
string guid,
11+
long senderId,
12+
DateTime created,
13+
DocumentDeliveryStatus documentDeliveryStatus,
14+
Read? read,
15+
DeliveryMethod deliveryMethod,
16+
string contentHash,
17+
DateTime? delivered,
18+
Boolean? isPrimaryDocument,
19+
HashAlgoritm? contentHashAlgoritm
20+
)
21+
{
22+
Guid = guid;
23+
Sender = new Sender(senderId);
24+
Created = created;
25+
DeliveryStatus = documentDeliveryStatus;
26+
DocumentRead = read;
27+
DeliveryMethod = deliveryMethod;
28+
ContentHash = contentHash;
29+
Delivered = delivered;
30+
IsPrimaryDocument = isPrimaryDocument;
31+
ContentHashAlgoritm = contentHashAlgoritm;
32+
}
33+
34+
public string Guid { get; }
35+
36+
public Sender Sender { get; }
37+
38+
public DateTime Created { get; }
39+
40+
/**
41+
* If DeliveryStatus is NOT_DELIVERED, Delivered will not have a value
42+
*/
43+
public DateTime? Delivered { get; }
44+
45+
public DocumentDeliveryStatus DeliveryStatus { get; }
46+
47+
public Read? DocumentRead { get; }
48+
49+
public DeliveryMethod DeliveryMethod { get; }
50+
51+
public String ContentHash { get; }
52+
53+
public HashAlgoritm? ContentHashAlgoritm { get; }
54+
55+
/**
56+
* isPrimaryDocument has value only if you ask api are the actual sender asking for DocumentStatus.
57+
* If you are, then this will be true for the primary document else false.
58+
*/
59+
public Boolean? IsPrimaryDocument { get; }
60+
61+
public enum DocumentDeliveryStatus
62+
{
63+
/**
64+
* The document has been delivered
65+
*/
66+
DELIVERED,
67+
68+
/**
69+
* The document is still being processed
70+
*/
71+
NOT_DELIVERED
72+
}
73+
74+
/**
75+
* Indicates whether the document is read or not
76+
*/
77+
public enum Read
78+
{
79+
YES,
80+
NO
81+
}
82+
}
83+
}

Digipost.Api.Client.Send/SendDataTransferObjectConverter.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Xml;
55
using Digipost.Api.Client.Common;
6+
using Digipost.Api.Client.Common.Enums;
67
using Digipost.Api.Client.Common.Extensions;
78
using V8;
89

@@ -86,16 +87,16 @@ public static V8.Document ToDataTransferObject(IDocument document)
8687
return documentDto;
8788
}
8889

89-
public static V8.Sms_Notification ToDataTransferObject(ISmsNotification smsNotification)
90+
public static Sms_Notification ToDataTransferObject(ISmsNotification smsNotification)
9091
{
9192
if (smsNotification == null)
9293
return null;
9394

94-
var smsNotificationDto = new V8.Sms_Notification();
95+
var smsNotificationDto = new Sms_Notification();
9596

9697
if (smsNotification.NotifyAtTimes.Count > 0)
9798
{
98-
var timesAsListedTimes = smsNotification.NotifyAtTimes.Select(dateTime => new V8.Listed_Time {Time = dateTime, TimeSpecified = true});
99+
var timesAsListedTimes = smsNotification.NotifyAtTimes.Select(dateTime => new Listed_Time {Time = dateTime, TimeSpecified = true});
99100
foreach (var timesAsListedTime in timesAsListedTimes)
100101
{
101102
smsNotificationDto.At.Add(timesAsListedTime);
@@ -113,7 +114,7 @@ public static V8.Sms_Notification ToDataTransferObject(ISmsNotification smsNotif
113114
return smsNotificationDto;
114115
}
115116

116-
public static IMessageDeliveryResult FromDataTransferObject(V8.Message_Delivery messageDeliveryDto)
117+
public static IMessageDeliveryResult FromDataTransferObject(Message_Delivery messageDeliveryDto)
117118
{
118119
IMessageDeliveryResult messageDeliveryResult = new MessageDeliveryResult
119120
{
@@ -138,7 +139,7 @@ public static IDocument FromDataTransferObject(V8.Document documentDto)
138139
};
139140
}
140141

141-
public static ISmsNotification FromDataTransferObject(V8.Sms_Notification smsNotificationDto)
142+
public static ISmsNotification FromDataTransferObject(Sms_Notification smsNotificationDto)
142143
{
143144
if (smsNotificationDto == null)
144145
return null;
@@ -151,5 +152,47 @@ public static ISmsNotification FromDataTransferObject(V8.Sms_Notification smsNot
151152

152153
return smsNotification;
153154
}
155+
156+
public static DocumentStatus FromDataTransferObject(Document_Status dto)
157+
{
158+
return new DocumentStatus(
159+
dto.Uuid,
160+
dto.Sender_Id,
161+
dto.Created,
162+
dto.Status.ToDeliveryStatus(),
163+
dto.ReadSpecified ? dto.Read.ToRead() : (DocumentStatus.Read?) null,
164+
dto.Channel.ToDeliveryMethod(),
165+
dto.Content_Hash,
166+
dto.DeliveredSpecified ? dto.Delivered : (DateTime?) null,
167+
dto.Is_Primary_DocumentSpecified ? dto.Is_Primary_Document : (bool?) null,
168+
dto.Content_Hash_AlgorithmSpecified ? dto.Content_Hash_Algorithm.ToHashAlgoritm() : (HashAlgoritm?) null
169+
);
170+
}
171+
172+
private static DocumentStatus.DocumentDeliveryStatus ToDeliveryStatus(this Delivery_Status deliveryStatus)
173+
{
174+
switch (deliveryStatus)
175+
{
176+
case Delivery_Status.DELIVERED:
177+
return DocumentStatus.DocumentDeliveryStatus.DELIVERED;
178+
case Delivery_Status.NOT_DELIVERED:
179+
return DocumentStatus.DocumentDeliveryStatus.NOT_DELIVERED;
180+
default:
181+
throw new ArgumentOutOfRangeException();
182+
}
183+
}
184+
185+
private static DocumentStatus.Read ToRead(this Read read)
186+
{
187+
switch (read)
188+
{
189+
case Read.Y:
190+
return DocumentStatus.Read.YES;
191+
case Read.N:
192+
return DocumentStatus.Read.NO;
193+
default:
194+
throw new ArgumentOutOfRangeException();
195+
}
196+
}
154197
}
155198
}

0 commit comments

Comments
 (0)