Skip to content

Commit 51ea0c2

Browse files
author
Kevin Hellemun
committed
Refactored core models.
1 parent 1513bde commit 51ea0c2

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

BunqSdk/Model/Core/BunqModel.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Text;
4+
using Bunq.Sdk.Context;
45
using Bunq.Sdk.Http;
56
using Bunq.Sdk.Json;
67
using Newtonsoft.Json.Linq;
@@ -13,6 +14,7 @@ public abstract class BunqModel
1314
/// Field constants.
1415
/// </summary>
1516
private const string FIELD_RESPONSE = "Response";
17+
1618
private const string FIELD_ID = "Id";
1719
private const string FIELD_UUID = "Uuid";
1820
private const string FIELD_PAGINATION = "Pagination";
@@ -95,7 +97,7 @@ protected static BunqResponse<T> FromJson<T>(BunqResponseRaw responseRaw)
9597
public static T CreateFromJsonString<T>(string json)
9698
{
9799
var modelValue = BunqJsonConvert.DeserializeObject<T>(json);
98-
100+
99101
return modelValue;
100102
}
101103

@@ -148,5 +150,20 @@ public override string ToString()
148150
}
149151

150152
public abstract bool IsAllFieldNull();
153+
154+
protected static ApiContext GetApiContext()
155+
{
156+
return BunqContext.ApiContext;
157+
}
158+
159+
protected static int DetermineUserId()
160+
{
161+
return BunqContext.UserContext.UserId;
162+
}
163+
164+
protected static int DetermineMonetaryAccountId(int? monetaryAccountId = null)
165+
{
166+
return monetaryAccountId ?? BunqContext.UserContext.PrimaryMonetaryAccountBank.Id.Value;
167+
}
151168
}
152-
}
169+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System.Collections.Generic;
2+
using System.Text;
3+
using Bunq.Sdk.Context;
4+
using Bunq.Sdk.Http;
5+
using Bunq.Sdk.Json;
6+
using Bunq.Sdk.Model.Generated.Endpoint;
7+
8+
namespace Bunq.Sdk.Model.Core
9+
{
10+
public class DeviceServerInternal : DeviceServer
11+
{
12+
/// <summary>
13+
/// Create a new DeviceServer providing the installation token in the header and signing the request with the
14+
/// private part of the key you used to create the installation. The API Key that you are using will be bound to
15+
/// the IP address of the DeviceServer which you have created.<br/><br/>Using a Wildcard API Key gives you the
16+
/// freedom to make API calls even if the IP address has changed after the POST device-server.<br/><br/>Find out
17+
/// more at this link <a href="https://bunq.com/en/apikey-dynamic-ip"
18+
/// target="_blank">https://bunq.com/en/apikey-dynamic-ip</a>.
19+
/// </summary>
20+
public static BunqResponse<int> Create(ApiContext apiContext, string description, string secret, List<string> permittedIps = null,
21+
IDictionary<string, string> customHeaders = null)
22+
{
23+
if (customHeaders == null) customHeaders = new Dictionary<string, string>();
24+
25+
var apiClient = new ApiClient(apiContext);
26+
27+
var requestMap = new Dictionary<string, object>
28+
{
29+
{FIELD_DESCRIPTION, description},
30+
{FIELD_SECRET, secret},
31+
{FIELD_PERMITTED_IPS, permittedIps},
32+
};
33+
34+
var requestBytes = Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(requestMap));
35+
var responseRaw = apiClient.Post(ENDPOINT_URL_CREATE, requestBytes, customHeaders);
36+
37+
return ProcessForId(responseRaw);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)