From e26ccf51f87351d45e2bbca94c585a76acbb0d9f Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Thu, 7 Oct 2021 08:52:19 +0200 Subject: [PATCH] parse faction for vouchers --- RedeemVoucherEntry.cs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/RedeemVoucherEntry.cs b/RedeemVoucherEntry.cs index 4a6aff3..f76e2e7 100644 --- a/RedeemVoucherEntry.cs +++ b/RedeemVoucherEntry.cs @@ -1,13 +1,33 @@ -namespace EDJournal { +using Newtonsoft.Json.Linq; +using System.Collections.Generic; + +namespace EDJournal { public class RedeemVoucherEntry : Entry { - private int amount = 0; - private string type = null; protected override void Initialise() { - amount = JSON.Value("Amount"); - type = JSON.Value("Type"); + Amount = JSON.Value("Amount"); + Type = JSON.Value("Type"); + + /* according to API, there should be a Factions structure */ + JToken factions = JSON.GetValue("Factions"); + if (factions != null) { + foreach (JObject faction in factions.Children()) { + string faction_name = faction.Value("Faction"); + if (faction_name == null || faction_name.Length <= 0) { + continue; + } + Factions.Add(faction_name); + } + } + + /* but there also might be just a Faction entry */ + string single_faction = JSON.Value("Faction"); + if (single_faction != null) { + Factions.Add(single_faction); + } } - public int Amount => amount; - public string Type => type; + public int Amount { get; set; } = 0; + public string Type { get; set; } = "Bounty"; + public List Factions { get; set; } = new List(); } }