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

History and notes #326

Merged
merged 2 commits into from
Apr 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CoreTests/CoreTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
<Compile Include="Integration\Files\Support\File.cs" />
<Compile Include="Integration\Files\Support\FilesTest.cs" />
<Compile Include="Integration\Files\Files\AddFileTest.cs" />
<Compile Include="Integration\HistoryAndNotes\CreateNotes.cs" />
<Compile Include="Integration\HistoryAndNotes\Find.cs" />
<Compile Include="Integration\HistoryAndNotes\HistoryAndNotesTest.cs" />
<Compile Include="Integration\Invoices\Find.cs" />
<Compile Include="Integration\Invoices\InvoicesTest.cs" />
<Compile Include="Integration\Invoices\OnlineInvoiceUrl.cs" />
Expand Down
21 changes: 21 additions & 0 deletions CoreTests/Integration/HistoryAndNotes/CreateNotes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;

namespace CoreTests.Integration.HistoryAndNotes
{
public class CreateNotes : HistoryAndNotesTest
{
[Test]
public void Can_create_notes()
{
const string details = "Details";

Given_a_contact();

Given_a_note_with_these_details(details);

When_I_retrieve_history_and_notes_for_the_contact();

Then_there_is_a_note_with_the_correct_details(details);
}
}
}
17 changes: 17 additions & 0 deletions CoreTests/Integration/HistoryAndNotes/Find.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using NUnit.Framework;

namespace CoreTests.Integration.HistoryAndNotes
{
public class Find : HistoryAndNotesTest
{
[Test]
public void Can_fetch_history_and_notes()
{
Given_a_contact();

When_I_retrieve_history_and_notes_for_the_contact();

Then_there_are_some_history_records();
}
}
}
44 changes: 44 additions & 0 deletions CoreTests/Integration/HistoryAndNotes/HistoryAndNotesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;

namespace CoreTests.Integration.HistoryAndNotes
{
public class HistoryAndNotesTest : ApiWrapperTest
{
private Contact _contact;
private IEnumerable<HistoryRecord> _historyRecords;

protected void Given_a_contact()
{
_contact = Api.Contacts.Create(new Contact { Name = Guid.NewGuid().ToString() });
}

protected void Given_a_note_with_these_details(string details)
{
Api.HistoryAndNotes.CreateNote(HistoryAndNotesEndpointCreateType.Contacts, _contact.Id,
new HistoryRecord
{
Details = details
});
}

protected void When_I_retrieve_history_and_notes_for_the_contact()
{
_historyRecords = Api.HistoryAndNotes.Find(HistoryAndNotesEndpointRetrieveType.Contacts, _contact.Id);
}

protected void Then_there_are_some_history_records()
{
Assert.True(_historyRecords.Any(), "Expected some history records to be returned, but there were none");
}

protected void Then_there_is_a_note_with_the_correct_details(string details)
{
Assert.True(_historyRecords.Any(it => it.Details == details), "Expected a note with the expected details to be returned but it was not");
}
}
}
40 changes: 40 additions & 0 deletions Xero.Api/Core/Endpoints/HistoryAndNotesEndpoint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Types;
using Xero.Api.Core.Request;
using Xero.Api.Core.Response;
using Xero.Api.Infrastructure.Http;

namespace Xero.Api.Core.Endpoints
{
public interface IHistoryAndNotesEndpoint
{
IEnumerable<HistoryRecord> Find(HistoryAndNotesEndpointRetrieveType type, Guid parent);
HistoryRecord CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note);
}

public class HistoryAndNotesEndpoint : IHistoryAndNotesEndpoint
{
private XeroHttpClient Client { get; set; }

public HistoryAndNotesEndpoint(XeroHttpClient client)
{
Client = client;
}

public IEnumerable<HistoryRecord> Find(HistoryAndNotesEndpointRetrieveType type, Guid parent)
{
return Client.Get<HistoryRecord, HistoryRecordsResponse>(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent));
}

public HistoryRecord CreateNote(HistoryAndNotesEndpointCreateType type, Guid parent, HistoryRecord note)
{
var request = new HistoryRecordsRequest {note};

return Client.Put<HistoryRecord, HistoryRecordsResponse>(string.Format("api.xro/2.0/{0}/{1:D}/history", type, parent), request).FirstOrDefault();
}
}
}
1 change: 1 addition & 0 deletions Xero.Api/Core/IXeroCoreApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface IXeroCoreApi
IExpenseClaimsEndpoint ExpenseClaims { get; }
IFilesEndpoint Files { get; }
IFoldersEndpoint Folders { get; }
IHistoryAndNotesEndpoint HistoryAndNotes { get; }
IInboxEndpoint Inbox { get; }
IAssociationsEndpoint Associations { get; }
IInvoicesEndpoint Invoices { get; }
Expand Down
21 changes: 21 additions & 0 deletions Xero.Api/Core/Model/HistoryRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Runtime.Serialization;

namespace Xero.Api.Core.Model
{
[DataContract(Namespace = "")]
public sealed class HistoryRecord
{
[DataMember]
public string Changes { get; set; }

[DataMember(Name = "DateUTC")]
public DateTime DateUtc { get; set; }

[DataMember]
public string User { get; set; }

[DataMember]
public string Details { get; set; }
}
}
11 changes: 11 additions & 0 deletions Xero.Api/Core/Model/Types/HistoryAndNotesEndpointCreateType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Xero.Api.Core.Model.Types
{
public enum HistoryAndNotesEndpointCreateType
{
BankTransactions,
Contacts,
CreditNotes,
Invoices,
PurchaseOrders
}
}
18 changes: 18 additions & 0 deletions Xero.Api/Core/Model/Types/HistoryAndNotesEndpointRetrieveType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Xero.Api.Core.Model.Types
{
public enum HistoryAndNotesEndpointRetrieveType
{
BankTransactions,
BankTransfers,
Contacts,
CreditNotes,
ExpenseClaims,
Invoices,
Items,
ManualJournals,
Payments,
PurchaseOrders,
Receipts,
RepeatingInvoices
}
}
11 changes: 11 additions & 0 deletions Xero.Api/Core/Request/HistoryRecordsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Runtime.Serialization;
using Xero.Api.Common;
using Xero.Api.Core.Model;

namespace Xero.Api.Core.Request
{
[CollectionDataContract(Namespace = "", Name = "HistoryRecords")]
public class HistoryRecordsRequest : XeroRequest<HistoryRecord>
{
}
}
16 changes: 16 additions & 0 deletions Xero.Api/Core/Response/HistoryRecordsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Xero.Api.Common;
using Xero.Api.Core.Model;

namespace Xero.Api.Core.Response
{
public class HistoryRecordsResponse : XeroResponse<HistoryRecord>
{
public List<HistoryRecord> HistoryRecords { get; set; }

public override IList<HistoryRecord> Values
{
get { return HistoryRecords; }
}
}
}
3 changes: 2 additions & 1 deletion Xero.Api/Core/XeroCoreApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Xero.Api.Core.Endpoints;
using Xero.Api.Core.Model;
using Xero.Api.Core.Model.Setup;
using Xero.Api.Core.Response;
using Xero.Api.Infrastructure.Interfaces;
using Xero.Api.Infrastructure.RateLimiter;
using Xero.Api.Serialization;
Expand Down Expand Up @@ -52,6 +51,7 @@ public XeroCoreApi(string baseUri, IAuthenticator auth, IConsumer consumer, IUse
public IExpenseClaimsEndpoint ExpenseClaims { get; private set; }
public IFilesEndpoint Files { get; private set; }
public IFoldersEndpoint Folders { get; private set; }
public IHistoryAndNotesEndpoint HistoryAndNotes { get; private set; }
public IInboxEndpoint Inbox { get; private set; }
public IAssociationsEndpoint Associations { get; private set; }
public IInvoicesEndpoint Invoices { get; private set; }
Expand Down Expand Up @@ -91,6 +91,7 @@ private void Connect()
ExpenseClaims = new ExpenseClaimsEndpoint(Client);
Files = new FilesEndpoint(Client);
Folders = new FoldersEndpoint(Client);
HistoryAndNotes = new HistoryAndNotesEndpoint(Client);
Inbox = new InboxEndpoint(Client);
Associations = new AssociationsEndpoint(Client);
Invoices = new InvoicesEndpoint(Client);
Expand Down
6 changes: 6 additions & 0 deletions Xero.Api/Xero.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
<Compile Include="Core\Endpoints\Base\IXeroUpdateEndpoint.cs" />
<Compile Include="Core\Endpoints\ContactGroupEndpoint.cs" />
<Compile Include="Core\Endpoints\FoldersEndpoint.cs" />
<Compile Include="Core\Endpoints\HistoryAndNotesEndpoint.cs" />
<Compile Include="Core\Endpoints\InboxEndpoint.cs" />
<Compile Include="Core\Endpoints\LinkedTransactionsEndpoint.cs" />
<Compile Include="Core\Model\EnumExtensions.cs" />
<Compile Include="Core\Model\HistoryRecord.cs" />
<Compile Include="Core\Model\OnlineInvoice.cs" />
<Compile Include="Core\IXeroCoreApi.cs" />
<Compile Include="Core\Endpoints\PurchaseOrdersEndpoint.cs" />
Expand All @@ -71,11 +73,14 @@
<Compile Include="Core\Model\Status\PurchaseOrderStatus.cs" />
<Compile Include="Core\Model\Status\TrackingOptionStatus.cs" />
<Compile Include="Core\Model\Types\BankAccountType.cs" />
<Compile Include="Core\Model\Types\HistoryAndNotesEndpointCreateType.cs" />
<Compile Include="Core\Model\Types\HistoryAndNotesEndpointRetrieveType.cs" />
<Compile Include="Core\Model\Types\LinkedTransactionType.cs" />
<Compile Include="Core\Model\Types\ObjectGroupType.cs" />
<Compile Include="Core\Model\Types\ObjectType.cs" />
<Compile Include="Core\Model\Types\SourceType.cs" />
<Compile Include="Core\Request\CurrenciesRequest.cs" />
<Compile Include="Core\Request\HistoryRecordsRequest.cs" />
<Compile Include="Core\Request\LinkedTransactionsRequest.cs" />
<Compile Include="Core\Request\OnlineInvoicesRequest.cs" />
<Compile Include="Core\Request\PurchaseOrdersRequest.cs" />
Expand All @@ -94,6 +99,7 @@
<Compile Include="Core\Model\Types\OverpaymentType.cs" />
<Compile Include="Common\CoreData.cs" />
<Compile Include="Core\Model\Status\ValidationStatus.cs" />
<Compile Include="Core\Response\HistoryRecordsResponse.cs" />
<Compile Include="Core\Response\LinkedTransactionsResponse.cs" />
<Compile Include="Core\Response\OnlineInvoicesResponse.cs" />
<Compile Include="Core\Response\OverpaymentsResponse.cs" />
Expand Down