Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit 155a773

Browse files
authored
Merge branch 'master' into cis-settings
2 parents 275435c + 99bc60c commit 155a773

13 files changed

+211
-1
lines changed

CoreTests/CoreTests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
<Compile Include="Integration\Files\Support\File.cs" />
111111
<Compile Include="Integration\Files\Support\FilesTest.cs" />
112112
<Compile Include="Integration\Files\Files\AddFileTest.cs" />
113+
<Compile Include="Integration\HistoryAndNotes\CreateNotes.cs" />
114+
<Compile Include="Integration\HistoryAndNotes\Find.cs" />
115+
<Compile Include="Integration\HistoryAndNotes\HistoryAndNotesTest.cs" />
113116
<Compile Include="Integration\Invoices\Find.cs" />
114117
<Compile Include="Integration\Invoices\InvoicesTest.cs" />
115118
<Compile Include="Integration\Invoices\OnlineInvoiceUrl.cs" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
3+
namespace CoreTests.Integration.HistoryAndNotes
4+
{
5+
public class CreateNotes : HistoryAndNotesTest
6+
{
7+
[Test]
8+
public void Can_create_notes()
9+
{
10+
const string details = "Details";
11+
12+
Given_a_contact();
13+
14+
Given_a_note_with_these_details(details);
15+
16+
When_I_retrieve_history_and_notes_for_the_contact();
17+
18+
Then_there_is_a_note_with_the_correct_details(details);
19+
}
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using NUnit.Framework;
2+
3+
namespace CoreTests.Integration.HistoryAndNotes
4+
{
5+
public class Find : HistoryAndNotesTest
6+
{
7+
[Test]
8+
public void Can_fetch_history_and_notes()
9+
{
10+
Given_a_contact();
11+
12+
When_I_retrieve_history_and_notes_for_the_contact();
13+
14+
Then_there_are_some_history_records();
15+
}
16+
}
17+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NUnit.Framework;
5+
using Xero.Api.Core.Model;
6+
using Xero.Api.Core.Model.Types;
7+
8+
namespace CoreTests.Integration.HistoryAndNotes
9+
{
10+
public class HistoryAndNotesTest : ApiWrapperTest
11+
{
12+
private Contact _contact;
13+
private IEnumerable<HistoryRecord> _historyRecords;
14+
15+
protected void Given_a_contact()
16+
{
17+
_contact = Api.Contacts.Create(new Contact { Name = Guid.NewGuid().ToString() });
18+
}
19+
20+
protected void Given_a_note_with_these_details(string details)
21+
{
22+
Api.HistoryAndNotes.CreateNote(HistoryAndNotesEndpointCreateType.Contacts, _contact.Id,
23+
new HistoryRecord
24+
{
25+
Details = details
26+
});
27+
}
28+
29+
protected void When_I_retrieve_history_and_notes_for_the_contact()
30+
{
31+
_historyRecords = Api.HistoryAndNotes.Find(HistoryAndNotesEndpointRetrieveType.Contacts, _contact.Id);
32+
}
33+
34+
protected void Then_there_are_some_history_records()
35+
{
36+
Assert.True(_historyRecords.Any(), "Expected some history records to be returned, but there were none");
37+
}
38+
39+
protected void Then_there_is_a_note_with_the_correct_details(string details)
40+
{
41+
Assert.True(_historyRecords.Any(it => it.Details == details), "Expected a note with the expected details to be returned but it was not");
42+
}
43+
}
44+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using Xero.Api.Core.Model;
6+
using Xero.Api.Core.Model.Types;
7+
using Xero.Api.Core.Request;
8+
using Xero.Api.Core.Response;
9+
using Xero.Api.Infrastructure.Http;
10+
11+
namespace Xero.Api.Core.Endpoints
12+
{
13+
public interface IHistoryAndNotesEndpoint
14+
{
15+
IEnumerable<HistoryRecord> Find(HistoryAndNotesEndpointRetrieveType type, Guid parent);
16+
HistoryRecord CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note);
17+
}
18+
19+
public class HistoryAndNotesEndpoint : IHistoryAndNotesEndpoint
20+
{
21+
private XeroHttpClient Client { get; set; }
22+
23+
public HistoryAndNotesEndpoint(XeroHttpClient client)
24+
{
25+
Client = client;
26+
}
27+
28+
public IEnumerable<HistoryRecord> Find(HistoryAndNotesEndpointRetrieveType type, Guid parent)
29+
{
30+
return Client.Get<HistoryRecord, HistoryRecordsResponse>(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent));
31+
}
32+
33+
public HistoryRecord CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note)
34+
{
35+
var request = new HistoryRecordsRequest {note};
36+
37+
return Client.Put<HistoryRecord, HistoryRecordsResponse>(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent), request).FirstOrDefault();
38+
}
39+
}
40+
}

Xero.Api/Core/IXeroCoreApi.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public interface IXeroCoreApi
2222
IExpenseClaimsEndpoint ExpenseClaims { get; }
2323
IFilesEndpoint Files { get; }
2424
IFoldersEndpoint Folders { get; }
25+
IHistoryAndNotesEndpoint HistoryAndNotes { get; }
2526
IInboxEndpoint Inbox { get; }
2627
IAssociationsEndpoint Associations { get; }
2728
IInvoicesEndpoint Invoices { get; }

Xero.Api/Core/Model/HistoryRecord.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
4+
namespace Xero.Api.Core.Model
5+
{
6+
[DataContract(Namespace = "")]
7+
public sealed class HistoryRecord
8+
{
9+
[DataMember]
10+
public string Changes { get; set; }
11+
12+
[DataMember(Name = "DateUTC")]
13+
public DateTime DateUtc { get; set; }
14+
15+
[DataMember]
16+
public string User { get; set; }
17+
18+
[DataMember]
19+
public string Details { get; set; }
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Xero.Api.Core.Model.Types
2+
{
3+
public enum HistoryAndNotesEndpointCreateType
4+
{
5+
BankTransactions,
6+
Contacts,
7+
CreditNotes,
8+
Invoices,
9+
PurchaseOrders
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Xero.Api.Core.Model.Types
2+
{
3+
public enum HistoryAndNotesEndpointRetrieveType
4+
{
5+
BankTransactions,
6+
BankTransfers,
7+
Contacts,
8+
CreditNotes,
9+
ExpenseClaims,
10+
Invoices,
11+
Items,
12+
ManualJournals,
13+
Payments,
14+
PurchaseOrders,
15+
Receipts,
16+
RepeatingInvoices
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Runtime.Serialization;
2+
using Xero.Api.Common;
3+
using Xero.Api.Core.Model;
4+
5+
namespace Xero.Api.Core.Request
6+
{
7+
[CollectionDataContract(Namespace = "", Name = "HistoryRecords")]
8+
public class HistoryRecordsRequest : XeroRequest<HistoryRecord>
9+
{
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Collections.Generic;
2+
using Xero.Api.Common;
3+
using Xero.Api.Core.Model;
4+
5+
namespace Xero.Api.Core.Response
6+
{
7+
public class HistoryRecordsResponse : XeroResponse<HistoryRecord>
8+
{
9+
public List<HistoryRecord> HistoryRecords { get; set; }
10+
11+
public override IList<HistoryRecord> Values
12+
{
13+
get { return HistoryRecords; }
14+
}
15+
}
16+
}

Xero.Api/Core/XeroCoreApi.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Xero.Api.Core.Endpoints;
55
using Xero.Api.Core.Model;
66
using Xero.Api.Core.Model.Setup;
7-
using Xero.Api.Core.Response;
87
using Xero.Api.Infrastructure.Interfaces;
98
using Xero.Api.Infrastructure.RateLimiter;
109
using Xero.Api.Serialization;
@@ -50,6 +49,7 @@ public XeroCoreApi(string baseUri, IAuthenticator auth, IConsumer consumer, IUse
5049
public IExpenseClaimsEndpoint ExpenseClaims { get; private set; }
5150
public IFilesEndpoint Files { get; private set; }
5251
public IFoldersEndpoint Folders { get; private set; }
52+
public IHistoryAndNotesEndpoint HistoryAndNotes { get; private set; }
5353
public IInboxEndpoint Inbox { get; private set; }
5454
public IAssociationsEndpoint Associations { get; private set; }
5555
public IInvoicesEndpoint Invoices { get; private set; }
@@ -90,6 +90,7 @@ private void Connect()
9090
ExpenseClaims = new ExpenseClaimsEndpoint(Client);
9191
Files = new FilesEndpoint(Client);
9292
Folders = new FoldersEndpoint(Client);
93+
HistoryAndNotes = new HistoryAndNotesEndpoint(Client);
9394
Inbox = new InboxEndpoint(Client);
9495
Associations = new AssociationsEndpoint(Client);
9596
Invoices = new InvoicesEndpoint(Client);

Xero.Api/Xero.Api.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@
5757
<Compile Include="Core\Endpoints\Base\IXeroUpdateEndpoint.cs" />
5858
<Compile Include="Core\Endpoints\ContactGroupEndpoint.cs" />
5959
<Compile Include="Core\Endpoints\FoldersEndpoint.cs" />
60+
<Compile Include="Core\Endpoints\HistoryAndNotesEndpoint.cs" />
6061
<Compile Include="Core\Endpoints\InboxEndpoint.cs" />
6162
<Compile Include="Core\Endpoints\LinkedTransactionsEndpoint.cs" />
6263
<Compile Include="Core\Model\ContactCisSetting.cs" />
6364
<Compile Include="Core\Model\EnumExtensions.cs" />
65+
<Compile Include="Core\Model\HistoryRecord.cs" />
6466
<Compile Include="Core\Model\OnlineInvoice.cs" />
6567
<Compile Include="Core\IXeroCoreApi.cs" />
6668
<Compile Include="Core\Endpoints\PurchaseOrdersEndpoint.cs" />
@@ -73,11 +75,14 @@
7375
<Compile Include="Core\Model\Status\PurchaseOrderStatus.cs" />
7476
<Compile Include="Core\Model\Status\TrackingOptionStatus.cs" />
7577
<Compile Include="Core\Model\Types\BankAccountType.cs" />
78+
<Compile Include="Core\Model\Types\HistoryAndNotesEndpointCreateType.cs" />
79+
<Compile Include="Core\Model\Types\HistoryAndNotesEndpointRetrieveType.cs" />
7680
<Compile Include="Core\Model\Types\LinkedTransactionType.cs" />
7781
<Compile Include="Core\Model\Types\ObjectGroupType.cs" />
7882
<Compile Include="Core\Model\Types\ObjectType.cs" />
7983
<Compile Include="Core\Model\Types\SourceType.cs" />
8084
<Compile Include="Core\Request\CurrenciesRequest.cs" />
85+
<Compile Include="Core\Request\HistoryRecordsRequest.cs" />
8186
<Compile Include="Core\Request\LinkedTransactionsRequest.cs" />
8287
<Compile Include="Core\Request\OnlineInvoicesRequest.cs" />
8388
<Compile Include="Core\Request\PurchaseOrdersRequest.cs" />
@@ -97,6 +102,7 @@
97102
<Compile Include="Common\CoreData.cs" />
98103
<Compile Include="Core\Model\Status\ValidationStatus.cs" />
99104
<Compile Include="Core\Response\ContactCisSettingsResponse.cs" />
105+
<Compile Include="Core\Response\HistoryRecordsResponse.cs" />
100106
<Compile Include="Core\Response\LinkedTransactionsResponse.cs" />
101107
<Compile Include="Core\Response\OnlineInvoicesResponse.cs" />
102108
<Compile Include="Core\Response\OrganisationCisSettingsResponse.cs" />

0 commit comments

Comments
 (0)