Create Things.TrafficSnapshot and Things.TrafficDailySnapshot, add them to Things.Traffic, and handle deserialization
Previous ticket: https://github.com/sirkris/Reddit.NET/issues/42
Now that we know what the different numbers mean in the JSON return of GET /r/subreddit/about/traffic, it's time to update Things.Traffic and create a couple new types to accommodate this data. This could prove a bit more challenging than most, since the API returns these numbers as an unlabeled array. I'd recommend creating one or two new converters in Models.Converters to handle this.
Ideally, I'd like Things.Traffic to look something like this:
using Newtonsoft.Json;
using Reddit.Models.Converters;
using System;
using System.Collections.Generic;
namespace Reddit.Things
{
[Serializable]
public class Traffic
{
[JsonProperty("day")]
[JsonConverter(typeof(TrafficDailyConvert))]
public List<TrafficDailySnapshot> Day;
[JsonProperty("hour")]
[JsonConverter(typeof(TrafficConvert))]
public List<TrafficSnapshot> Hour;
[JsonProperty("month")]
[JsonConverter(typeof(TrafficConvert))]
public List<TrafficSnapshot> Month;
}
}
Things.TrafficSnapshot:
using Newtonsoft.Json;
using Reddit.Models.Converters;
using System;
namespace Reddit.Things
{
[Serializable]
public class TrafficSnapshot
{
[JsonProperty(Order = 1)]
[JsonConverter(typeof(TimestampConvert))]
public DateTime Timestamp;
[JsonProperty(Order = 2)]
public int Uniques;
[JsonProperty(Order = 3)]
public int PageViews;
public TrafficSnapshot(DateTime timestamp, int uniques, int pageViews)
{
Timestamp = timestamp;
Uniques = uniques;
PageViews = pageViews;
}
public TrafficSnapshot() { }
}
}
Things.TrafficDailySnapshot:
using Newtonsoft.Json;
using System;
namespace Reddit.Things
{
[Serializable]
public class TrafficDailySnapshot : TrafficSnapshot
{
[JsonProperty(Order = 4)]
public int Subscriptions;
public TrafficDailySnapshot(DateTime timestamp, int uniques, int pageViews, int subscriptions)
: base(timestamp, uniques, pageViews)
{
Subscriptions = subscriptions;
}
public TrafficDailySnapshot() { }
}
}
That's just a rough mockup but should give you a general idea as to what we're looking for here. I didn't test any of that code so your mileage may vary.