Skip to content

Commit ac4c53a

Browse files
author
Kevin Hellemun
committed
Merge branch 'release/0.12.4'
2 parents 73384a7 + 5b8a824 commit ac4c53a

File tree

159 files changed

+7176
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

159 files changed

+7176
-89
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,4 @@ bunq.conf
266266
bunq-test.conf
267267
config.json
268268
.idea/.idea.BunqSdk/.idea/preferred-vcs.xml
269+
.idea/.idea.BunqSdk/.idea/indexLayout.xml

.idea/.idea.BunqSdk/.idea/contentModel.xml

+329
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.BunqSdk/riderModule.iml

+4-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

BunqSdk.Tests/Model/Generated/Object/NotificationUrlTest.cs

+28-12
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ public class NotificationUrlTest : BunqSdkTestBase
1818
private const string GET_PAYMENT = "Payment";
1919
private const string GET_BUNQ_ME_TAB = "BunqMeTab";
2020
private const string GET_CHAT_MESSAGE_ANNOUNCEMENT = "ChatMessageAnnouncement";
21+
private const string GET_CHAT_MESSAGE = "ChatMessage";
2122
private const string GET_DRAFT_PAYMENT = "DraftPayment";
2223
private const string GET_MASTER_CARD_ACTION = "MasterCardAction";
2324
private const string GET_MONETARY_ACCOUNT_BANK = "MonetaryAccountBank";
25+
private const string GET_MONETARY_ACCOUNT = "MonetaryAccount";
2426
private const string GET_PAYMENT_BATCH = "PaymentBatch";
2527
private const string GET_REQUEST_INQUIRY = "RequestInquiry";
2628
private const string GET_REQUEST_RESPONSE = "RequestResponse";
@@ -58,23 +60,33 @@ public class NotificationUrlTest : BunqSdkTestBase
5860

5961
private void ExecuteNotificationUrlTest(
6062
string expectedJsonFileName,
61-
Type classNameExpected,
62-
string referencedObjectPropertyName
63-
) {
63+
Type classTypeExpected,
64+
string referencedObjectPropertyName,
65+
string subClassObjectPropertyName = null,
66+
Type subClassTypeExpected = null)
67+
{
6468
var jsonString = ReadJsonFromFile(expectedJsonFileName);
65-
var notificationUrl = BunqModel.CreateFromJsonString<NotificationUrl>(jsonString);
69+
var notificationUrl = NotificationUrl.CreateFromJsonString(jsonString);
6670

6771
Assert.NotNull(notificationUrl);
6872
Assert.NotNull(notificationUrl.Object);
6973

70-
var model = notificationUrl.Object.GetType().GetProperty(referencedObjectPropertyName).GetValue(
71-
notificationUrl.Object);
74+
var model = notificationUrl.Object.GetType()
75+
.GetProperty(referencedObjectPropertyName)
76+
.GetValue(notificationUrl.Object);
7277
var referencedModel = notificationUrl.Object.GetReferencedObject();
7378

7479
Assert.NotNull(model);
7580
Assert.NotNull(referencedModel);
76-
Assert.IsType(classNameExpected, referencedModel);
77-
Assert.Equal(classNameExpected, referencedModel.GetType());
81+
Assert.IsType(classTypeExpected, referencedModel);
82+
83+
if (subClassObjectPropertyName == null || subClassTypeExpected == null) return;
84+
var subClass = referencedModel.GetType()
85+
.GetProperty(subClassObjectPropertyName)
86+
.GetValue(referencedModel);
87+
88+
Assert.NotNull(subClass);
89+
Assert.IsType(subClassTypeExpected, subClass);
7890
}
7991

8092
private static string ReadJsonFromFile(string fileName)
@@ -113,8 +125,10 @@ public void TestChatMessageAnnouncementModel()
113125
{
114126
ExecuteNotificationUrlTest(
115127
JSON_PATH_CHAT_MESSAGE_ANNOUNCEMENT_MODEL,
116-
typeof(ChatMessageAnnouncement),
117-
GET_CHAT_MESSAGE_ANNOUNCEMENT
128+
typeof(ChatMessage),
129+
GET_CHAT_MESSAGE,
130+
GET_CHAT_MESSAGE_ANNOUNCEMENT,
131+
typeof(ChatMessageAnnouncement)
118132
);
119133
}
120134

@@ -143,8 +157,10 @@ public void TestMonetaryAccountBankModel()
143157
{
144158
ExecuteNotificationUrlTest(
145159
JSON_PATH_MONETARY_ACCOUNT_BANK_MODEL,
146-
typeof(MonetaryAccountBank),
147-
GET_MONETARY_ACCOUNT_BANK
160+
typeof(MonetaryAccount),
161+
GET_MONETARY_ACCOUNT,
162+
GET_MONETARY_ACCOUNT_BANK,
163+
typeof(MonetaryAccountBank)
148164
);
149165
}
150166

BunqSdk/BunqSdk.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<PackageId>Bunq.Sdk</PackageId>
1111
</PropertyGroup>
1212
<PropertyGroup>
13-
<VersionPrefix>0.12.3.0</VersionPrefix>
13+
<VersionPrefix>0.12.4.0</VersionPrefix>
1414
<VersionSuffix>beta</VersionSuffix>
1515
</PropertyGroup>
1616
<PropertyGroup>

BunqSdk/Http/ApiClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class ApiClient
5454
/// Values for the default headers
5555
/// </summary>
5656
private const string CACHE_CONTROL_NONE = "no-cache";
57-
private const string USER_AGENT_BUNQ = "bunq-sdk-csharp/0.12.0.0-beta";
57+
private const string USER_AGENT_BUNQ = "bunq-sdk-csharp/0.12.4.0-beta";
5858
private const string LANGUAGE_EN_US = "en_US";
5959
private const string REGION_NL_NL = "nl_NL";
6060
private const string GEOLOCATION_ZERO = "0 0 0 0 NL";

BunqSdk/Json/AnchorObjectConverter.cs

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using Bunq.Sdk.Model.Core;
5+
using Newtonsoft.Json;
6+
using Newtonsoft.Json.Linq;
7+
8+
namespace Bunq.Sdk.Json
9+
{
10+
public class AnchorObjectConverter: JsonConverter
11+
{
12+
private const string FORMAT_DATE = "yyyy-MM-dd HH:mm:ss.ffffff";
13+
14+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
15+
{
16+
new JsonSerializer().Serialize(writer, value);
17+
}
18+
19+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
20+
{
21+
var jsonSerializer = JsonSerializer.CreateDefault(
22+
new JsonSerializerSettings
23+
{
24+
ContractResolver = new BunqContractResolver(new List<Type> {typeof(IAnchorObjectInterface)}),
25+
DateFormatString = FORMAT_DATE,
26+
FloatParseHandling = FloatParseHandling.Decimal,
27+
Formatting = Formatting.Indented,
28+
NullValueHandling = NullValueHandling.Ignore,
29+
}
30+
);
31+
32+
JToken token = JObject.Load(reader);
33+
var model = (IAnchorObjectInterface) jsonSerializer.Deserialize(token.CreateReader(), objectType);
34+
35+
if (!model.IsAllFieldNull()) return model;
36+
37+
var fields = objectType.GetProperties();
38+
39+
foreach (var field in fields)
40+
{
41+
var fieldType = field.PropertyType;
42+
43+
if (!typeof(BunqModel).IsAssignableFrom(fieldType))
44+
{
45+
continue;
46+
}
47+
48+
var fieldContent = (BunqModel) jsonSerializer.Deserialize(token.CreateReader(), fieldType);
49+
50+
field.SetValue(model, fieldContent.IsAllFieldNull() ? null : fieldContent);
51+
}
52+
53+
return model;
54+
}
55+
56+
public override bool CanConvert(Type objectType)
57+
{
58+
return typeof(IAnchorObjectInterface).IsAssignableFrom(objectType);
59+
}
60+
}
61+
}

BunqSdk/Json/BunqContractResolver.cs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Reflection;
34
using Bunq.Sdk.Context;
45
using Bunq.Sdk.Http;
56
using Bunq.Sdk.Model.Core;
7+
using Bunq.Sdk.Model.Generated.Endpoint;
68
using Bunq.Sdk.Model.Generated.Object;
79
using Newtonsoft.Json;
10+
using Newtonsoft.Json.Converters;
811
using Newtonsoft.Json.Serialization;
912

1013
namespace Bunq.Sdk.Json
@@ -14,9 +17,9 @@ namespace Bunq.Sdk.Json
1417
/// </summary>
1518
public class BunqContractResolver : DefaultContractResolver
1619
{
17-
private readonly Dictionary<Type, JsonConverter> converterRegistry = new Dictionary<Type, JsonConverter>();
20+
protected readonly Dictionary<Type, JsonConverter> converterRegistry = new Dictionary<Type, JsonConverter>();
1821

19-
public BunqContractResolver()
22+
public BunqContractResolver(IReadOnlyCollection<Type> typesToExclude=null)
2023
{
2124
RegisterConverter(typeof(ApiEnvironmentType), new ApiEnvironmentTypeConverter());
2225
RegisterConverter(typeof(Geolocation), new GeolocationConverter());
@@ -28,6 +31,17 @@ public BunqContractResolver()
2831
RegisterConverter(typeof(double?), new NonIntegerNumberConverter());
2932
RegisterConverter(typeof(float?), new NonIntegerNumberConverter());
3033
RegisterConverter(typeof(Pagination), new PaginationConverter());
34+
RegisterConverter(typeof(IAnchorObjectInterface), new AnchorObjectConverter());
35+
36+
if (typesToExclude == null)
37+
{
38+
return;
39+
}
40+
41+
foreach (var type in typesToExclude)
42+
{
43+
converterRegistry.Remove(type);
44+
}
3145
}
3246

3347
private void RegisterConverter(Type objectType, JsonConverter converter)
@@ -50,6 +64,13 @@ protected override JsonContract CreateContract(Type objectType)
5064

5165
private JsonConverter GetCustomConverterOrNull(Type objectType)
5266
{
67+
if (typeof(IAnchorObjectInterface).IsAssignableFrom(objectType))
68+
{
69+
return converterRegistry.ContainsKey(typeof(IAnchorObjectInterface))
70+
? converterRegistry[typeof(IAnchorObjectInterface)]
71+
: null;
72+
}
73+
5374
return converterRegistry.ContainsKey(objectType) ? converterRegistry[objectType] : null;
5475
}
5576
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Bunq.Sdk.Model.Core
2+
{
3+
public interface IAnchorObjectInterface
4+
{
5+
bool IsAllFieldNull();
6+
7+
BunqModel GetReferencedObject();
8+
}
9+
}

BunqSdk/Model/Core/BunqModel.cs

+2
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,7 @@ public override string ToString()
146146
{
147147
return BunqJsonConvert.SerializeObject(this);
148148
}
149+
150+
public abstract bool IsAllFieldNull();
149151
}
150152
}

BunqSdk/Model/Core/Installation.cs

+20
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,25 @@ public string GetPublicKeyServerString()
6565
{
6666
return publicKeyServer.ServerPublicKey;
6767
}
68+
69+
public override bool IsAllFieldNull()
70+
{
71+
if (this.SessionToken != null)
72+
{
73+
return false;
74+
}
75+
76+
if (this.id != null)
77+
{
78+
return false;
79+
}
80+
81+
if (this.publicKeyServer != null)
82+
{
83+
return false;
84+
}
85+
86+
return true;
87+
}
6888
}
6989
}

BunqSdk/Model/Core/SessionServer.cs

+25
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,30 @@ private static byte[] GenerateRequestBodyBytes(string apiKey)
6161

6262
return Encoding.UTF8.GetBytes(BunqJsonConvert.SerializeObject(sessionServerRequestBody));
6363
}
64+
65+
public override bool IsAllFieldNull()
66+
{
67+
if (this.Id != null)
68+
{
69+
return false;
70+
}
71+
72+
if (this.SessionToken != null)
73+
{
74+
return false;
75+
}
76+
77+
if (this.UserCompany != null)
78+
{
79+
return false;
80+
}
81+
82+
if (this.UserPerson != null)
83+
{
84+
return false;
85+
}
86+
87+
return true;
88+
}
6489
}
6590
}

BunqSdk/Model/Generated/Endpoint/AttachmentConversationContent.cs

+15
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,20 @@ public static BunqResponse<byte[]> List(ApiContext apiContext, int userId, int c
3737

3838
return new BunqResponse<byte[]>(responseRaw.BodyBytes, responseRaw.Headers);
3939
}
40+
41+
42+
/// <summary>
43+
/// </summary>
44+
public override bool IsAllFieldNull()
45+
{
46+
return true;
47+
}
48+
49+
/// <summary>
50+
/// </summary>
51+
public static AttachmentConversationContent CreateFromJsonString(string json)
52+
{
53+
return BunqModel.CreateFromJsonString<AttachmentConversationContent>(json);
54+
}
4055
}
4156
}

BunqSdk/Model/Generated/Endpoint/AttachmentMonetaryAccount.cs

+25
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,30 @@ public static BunqResponse<int> Create(ApiContext apiContext, byte[] requestByte
5353

5454
return ProcessForId(responseRaw);
5555
}
56+
57+
58+
/// <summary>
59+
/// </summary>
60+
public override bool IsAllFieldNull()
61+
{
62+
if (this.Attachment != null)
63+
{
64+
return false;
65+
}
66+
67+
if (this.Id != null)
68+
{
69+
return false;
70+
}
71+
72+
return true;
73+
}
74+
75+
/// <summary>
76+
/// </summary>
77+
public static AttachmentMonetaryAccount CreateFromJsonString(string json)
78+
{
79+
return BunqModel.CreateFromJsonString<AttachmentMonetaryAccount>(json);
80+
}
5681
}
5782
}

0 commit comments

Comments
 (0)