Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SessionServerConverter, bump up to 0.9.2.0-beta [#7] #8

Merged
merged 1 commit into from
Aug 18, 2017
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
4 changes: 2 additions & 2 deletions BunqSdk/BunqSdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageId>Bunq.Sdk</PackageId>
</PropertyGroup>
<PropertyGroup>
<VersionPrefix>0.9.1.0</VersionPrefix>
<VersionPrefix>0.9.2.0</VersionPrefix>
<VersionSuffix>beta</VersionSuffix>
</PropertyGroup>
<PropertyGroup>
Expand All @@ -34,4 +34,4 @@
<Content Include="../README.md" />
<Content Include="../.gitignore" />
</ItemGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion BunqSdk/Http/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ApiClient
/// Values for the default headers
/// </summary>
private const string CACHE_CONTROL_NONE = "no-cache";
private const string USER_AGENT_BUNQ = "bunq-sdk-csharp/0.9.0.1-beta";
private const string USER_AGENT_BUNQ = "bunq-sdk-csharp/0.9.2.0-beta";
private const string LANGUAGE_EN_US = "en_US";
private const string REGION_NL_NL = "nl_NL";
private const string GEOLOCATION_ZERO = "0 0 0 0 NL";
Expand Down
15 changes: 7 additions & 8 deletions BunqSdk/Json/SessionServerConverter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Bunq.Sdk.Model;
using Bunq.Sdk.Model.Generated;
using Newtonsoft.Json;
Expand All @@ -26,19 +25,19 @@ public class SessionServerConverter : JsonConverter
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
var jObjects = JArray.Load(reader).ToObject<List<JObject>>();
var id = GetByIndexAndFieldName(jObjects, INDEX_ID, FIELD_ID).ToObject<Id>();
var token = GetByIndexAndFieldName(jObjects, INDEX_TOKEN, FIELD_TOKEN).ToObject<SessionToken>();
var jObjects = JArray.Load(reader);
var id = FetchObject<Id>(jObjects[INDEX_ID], FIELD_ID);
var token = FetchObject<SessionToken>(jObjects[INDEX_TOKEN], FIELD_TOKEN);
var userBody = jObjects[INDEX_USER];

return userBody[FIELD_USER_COMPANY] == null
? new SessionServer(id, token, userBody.GetValue(FIELD_USER_PERSON).ToObject<UserPerson>())
: new SessionServer(id, token, userBody.GetValue(FIELD_USER_COMPANY).ToObject<UserCompany>());
? new SessionServer(id, token, FetchObject<UserPerson>(userBody, FIELD_USER_PERSON))
: new SessionServer(id, token, FetchObject<UserCompany>(userBody, FIELD_USER_COMPANY));
}

private static JToken GetByIndexAndFieldName(IReadOnlyList<JObject> jObjects, int index, string fieldName)
private static T FetchObject<T>(JToken jToken, string fieldName)
{
return jObjects[index].GetValue(fieldName);
return jToken[fieldName].ToObject<T>();
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
Expand Down