-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added requisitions endpoints
- Loading branch information
Showing
20 changed files
with
366 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
namespace Nordigen.Net | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Queries; | ||
using Responses; | ||
|
||
public interface IRequisitionsEndpoint | ||
{ | ||
/// <summary> | ||
/// Get details about a specific requisition. | ||
/// </summary> | ||
/// <param name="id">The id of the requisition</param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param> | ||
/// <returns>A list of <see cref="Institution"/> or <see cref="Error"/></returns> | ||
Task<NOneOf<Requisition, Error>> Get(Guid id, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Paginate requisitions. | ||
/// </summary> | ||
/// <param name="command">The Pagination command</param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param> | ||
/// <returns>A list of <see cref="Institution"/> or <see cref="Error"/></returns> | ||
Task<NOneOf<PaginationResult<Requisition>, Error>> Paginate(Paginate<Requisition> command, CancellationToken cancellationToken = default); | ||
|
||
/// <summary> | ||
/// Creates a new requisition | ||
/// </summary> | ||
/// <param name="requisition"> The <see cref="Requisition"/></param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param> | ||
/// <returns></returns> | ||
Task<NOneOf<Requisition, Error>> Post(Requisition requisition, CancellationToken cancellationToken = default); | ||
|
||
|
||
/// <summary> | ||
/// Deletes a requisition. | ||
/// </summary> | ||
/// <param name="id">The id of the requisition</param> | ||
/// <param name="cancellationToken">The <see cref="CancellationToken"/></param> | ||
/// <returns>A list of <see cref="Institution"/> or <see cref="Error"/></returns> | ||
Task<NOneOf<Deleted, Error>> Delete(Guid id, CancellationToken cancellationToken = default); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Nordigen.Net.Internal.Model | ||
{ | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
|
||
public class PaginationResult<T> | ||
{ | ||
[JsonConstructor] | ||
public PaginationResult( | ||
int count, | ||
string next, | ||
string previous, | ||
T[] results | ||
) | ||
{ | ||
Count = count; | ||
Next = next; | ||
Previous = previous; | ||
Results = results; | ||
} | ||
|
||
public int Count { get; } | ||
|
||
public string Next { get; } | ||
|
||
public string Previous { get; } | ||
|
||
public T[] Results { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace Nordigen.Net.Internal.Model | ||
{ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
internal class RequisitionPost | ||
{ | ||
public RequisitionPost( | ||
string redirect, | ||
Guid institutionId, | ||
Guid agreement, | ||
string reference, | ||
string userLanguage, | ||
string ssn, | ||
bool accountSelection | ||
) | ||
{ | ||
this.Redirect = redirect; | ||
this.InstitutionId = institutionId; | ||
this.Agreement = agreement; | ||
this.Reference = reference; | ||
this.UserLanguage = userLanguage; | ||
this.Ssn = ssn; | ||
this.AccountSelection = accountSelection; | ||
} | ||
|
||
[JsonProperty("redirect")] | ||
public string Redirect { get; } | ||
|
||
[JsonProperty("institution_id")] | ||
public Guid InstitutionId { get; } | ||
|
||
[JsonProperty("agreement")] | ||
public Guid Agreement { get; } | ||
|
||
[JsonProperty("reference")] | ||
public string Reference { get; } | ||
|
||
[JsonProperty("user_language")] | ||
public string UserLanguage { get; } | ||
|
||
[JsonProperty("ssn")] | ||
public string Ssn { get; } | ||
|
||
[JsonProperty("account_selection")] | ||
public bool AccountSelection { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace Nordigen.Net.Internal | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Queries; | ||
using Responses; | ||
|
||
public class RequisitionsEndpoint : IRequisitionsEndpoint | ||
{ | ||
private readonly INordigenHttpClient _client; | ||
|
||
internal RequisitionsEndpoint(INordigenHttpClient client) | ||
{ | ||
_client = client; | ||
} | ||
|
||
public Task<NOneOf<Requisition, Error>> Get(Guid id, CancellationToken cancellationToken = default) | ||
{ | ||
return _client.Get<Requisition>($"api/v2/requisitions/{id}/", cancellationToken); | ||
} | ||
|
||
public async Task<NOneOf<Responses.PaginationResult<Requisition>, Error>> Paginate(Paginate<Requisition> command, CancellationToken cancellationToken = default) | ||
{ | ||
var result = await _client.Get<Internal.Model.PaginationResult<Requisition>>($"api/v2/requisitions/?limit={command.Limit}&offset={command.Offset}", cancellationToken); | ||
return result.Match(x => NOneOf<Responses.PaginationResult<Requisition>, Error>.FromT0(new Responses.PaginationResult<Requisition>(x, command.Limit, command.Offset)), _ => _); | ||
} | ||
|
||
public async Task<NOneOf<Requisition, Error>> Post(Requisition requisition, CancellationToken cancellationToken = default) | ||
{ | ||
var model = new Internal.Model.RequisitionPost(requisition.Redirect, requisition.InstitutionId, requisition.Agreement, requisition.Reference, requisition.UserLanguage, requisition.Ssn, requisition.AccountSelection); | ||
return await _client.Post<Internal.Model.RequisitionPost, Requisition>(model, "api/v2/requisitions/", cancellationToken); | ||
} | ||
|
||
public Task<NOneOf<Deleted, Error>> Delete(Guid id, CancellationToken cancellationToken = default) | ||
{ | ||
return _client.Delete($"api/v2/requisitions/{id}/", cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace Nordigen.Net.Queries | ||
{ | ||
public class Paginate<T> | ||
{ | ||
public Paginate(int limit, int offset) | ||
{ | ||
Limit = limit; | ||
Offset = offset; | ||
} | ||
|
||
public int Limit { get; } | ||
|
||
public int Offset { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
|
||
public class Account | ||
{ | ||
[JsonConstructor] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Nordigen.Net.Responses | ||
{ | ||
public struct Deleted | ||
{ | ||
public static Deleted Value | ||
{ | ||
get; | ||
} = new Deleted(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace Nordigen.Net.Responses | ||
{ | ||
public struct End | ||
{ | ||
public static End Value | ||
{ | ||
get; | ||
} = new End(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Nordigen.Net.Responses | ||
{ | ||
using System.Collections.Generic; | ||
using Queries; | ||
|
||
public class PaginationResult<T> | ||
{ | ||
internal PaginationResult(Internal.Model.PaginationResult<T> paginationResult, int limit, int offset) | ||
{ | ||
Result = paginationResult.Results; | ||
var taken = offset + Result.Length; | ||
Next = taken != paginationResult.Count | ||
? (NOneOf<Paginate<T>, End>)new Paginate<T>(limit, taken) | ||
: End.Value; | ||
} | ||
|
||
public T[] Result { get; } | ||
|
||
public NOneOf<Paginate<T>, End> Next { get; } | ||
} | ||
} |
Oops, something went wrong.