From 38f7d44fe79eda0e49acd8c97b822fde98f6880f Mon Sep 17 00:00:00 2001 From: rodkings Date: Thu, 23 Apr 2015 00:37:36 -0600 Subject: [PATCH 1/4] update UserActivityFeed --- .../Responses/Feeds/UserActivityFeed.cs | 257 ++++++++---------- 1 file changed, 107 insertions(+), 150 deletions(-) diff --git a/src/Untappd.Net/Responses/Feeds/UserActivityFeed.cs b/src/Untappd.Net/Responses/Feeds/UserActivityFeed.cs index fdf6253..d03a1d9 100644 --- a/src/Untappd.Net/Responses/Feeds/UserActivityFeed.cs +++ b/src/Untappd.Net/Responses/Feeds/UserActivityFeed.cs @@ -214,72 +214,116 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public int BreweryActive { get; set; } } - public class User2 - { - - [JsonProperty("uid")] - public int Uid { get; set; } - - [JsonProperty("user_name")] - public string UserName { get; set; } - - [JsonProperty("first_name")] - public string FirstName { get; set; } - - [JsonProperty("last_name")] - public string LastName { get; set; } - - [JsonProperty("bio")] - public string Bio { get; set; } - - [JsonProperty("location")] - public string Location { get; set; } - - [JsonProperty("relationship")] - public string Relationship { get; set; } - - [JsonProperty("is_supporter")] - public int IsSupporter { get; set; } - - [JsonProperty("user_avatar")] - public string UserAvatar { get; set; } - - [JsonProperty("user_link")] - public string UserLink { get; set; } - - [JsonProperty("account_type")] - public string AccountType { get; set; } - - [JsonProperty("brewery_details")] - public IList BreweryDetails { get; set; } - } - public class Item2 { - [JsonProperty("user")] - public User2 User { get; set; } + [JsonProperty("category_name")] + public string CategoryName { get; set; } - [JsonProperty("checkin_id")] - public int CheckinId { get; set; } + [JsonProperty("category_id")] + public string CategoryId { get; set; } - [JsonProperty("comment_id")] - public int CommentId { get; set; } + [JsonProperty("is_primary")] + public bool IsPrimary { get; set; } + } - [JsonProperty("comment_owner")] - public bool CommentOwner { get; set; } + public class Categories + { - [JsonProperty("comment_editor")] - public bool CommentEditor { get; set; } + [JsonProperty("count")] + public int Count { get; set; } - [JsonProperty("comment")] - public string Comment { get; set; } + [JsonProperty("items")] + public IList Items { get; set; } + } - [JsonProperty("created_at")] - public string CreatedAt { get; set; } + public class Location2 + { - [JsonProperty("comment_source")] - public string CommentSource { get; set; } + [JsonProperty("venue_address")] + public string VenueAddress { get; set; } + + [JsonProperty("venue_city")] + public string VenueCity { get; set; } + + [JsonProperty("venue_state")] + public string VenueState { get; set; } + + [JsonProperty("venue_country")] + public string VenueCountry { get; set; } + + [JsonProperty("lat")] + public double Lat { get; set; } + + [JsonProperty("lng")] + public double Lng { get; set; } + } + + public class Contact3 + { + + [JsonProperty("twitter")] + public string Twitter { get; set; } + + [JsonProperty("venue_url")] + public string VenueUrl { get; set; } + } + + public class Foursquare + { + + [JsonProperty("foursquare_id")] + public string FoursquareId { get; set; } + + [JsonProperty("foursquare_url")] + public string FoursquareUrl { get; set; } + } + + public class VenueIcon + { + + [JsonProperty("sm")] + public string Sm { get; set; } + + [JsonProperty("md")] + public string Md { get; set; } + + [JsonProperty("lg")] + public string Lg { get; set; } + } + + public class Venue + { + + [JsonProperty("venue_id")] + public int VenueId { get; set; } + + [JsonProperty("venue_name")] + public string VenueName { get; set; } + + [JsonProperty("primary_category")] + public string PrimaryCategory { get; set; } + + [JsonProperty("parent_category_id")] + public string ParentCategoryId { get; set; } + + [JsonProperty("categories")] + public Categories Categories { get; set; } + + [JsonProperty("location")] + public Location2 Location { get; set; } + + [JsonProperty("contact")] + public Contact3 Contact { get; set; } + + [JsonProperty("public_venue")] + public bool PublicVenue { get; set; } + + [JsonProperty("foursquare")] + public Foursquare Foursquare { get; set; } + + [JsonProperty("venue_icon")] + public VenueIcon VenueIcon { get; set; } } public class Comments @@ -292,60 +336,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public int Count { get; set; } [JsonProperty("items")] - public IList Items { get; set; } - } - - public class User3 - { - - [JsonProperty("uid")] - public int Uid { get; set; } - - [JsonProperty("user_name")] - public string UserName { get; set; } - - [JsonProperty("first_name")] - public string FirstName { get; set; } - - [JsonProperty("last_name")] - public string LastName { get; set; } - - [JsonProperty("bio")] - public string Bio { get; set; } - - [JsonProperty("location")] - public string Location { get; set; } - - [JsonProperty("user_avatar")] - public string UserAvatar { get; set; } - - [JsonProperty("user_link")] - public string UserLink { get; set; } - - [JsonProperty("account_type")] - public string AccountType { get; set; } - - [JsonProperty("brewery_details")] - public IList BreweryDetails { get; set; } - } - - public class Item3 - { - - [JsonProperty("uid")] - public int Uid { get; set; } - - [JsonProperty("user")] - public User3 User { get; set; } - - [JsonProperty("like_id")] - public int LikeId { get; set; } - - [JsonProperty("like_owner")] - public bool LikeOwner { get; set; } - - [JsonProperty("created_at")] - public string CreatedAt { get; set; } + public IList Items { get; set; } } public class Toasts @@ -361,7 +352,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public bool AuthToast { get; set; } [JsonProperty("items")] - public IList Items { get; set; } + public IList Items { get; set; } } public class Photo @@ -380,7 +371,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public string PhotoImgOg { get; set; } } - public class Item4 + public class Item3 { [JsonProperty("photo_id")] @@ -397,7 +388,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public int Count { get; set; } [JsonProperty("items")] - public IList Items { get; set; } + public IList Items { get; set; } } public class Source @@ -410,41 +401,6 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public string AppWebsite { get; set; } } - public class BadgeImage - { - - [JsonProperty("sm")] - public string Sm { get; set; } - - [JsonProperty("md")] - public string Md { get; set; } - - [JsonProperty("lg")] - public string Lg { get; set; } - } - - public class Item5 - { - - [JsonProperty("badge_id")] - public int BadgeId { get; set; } - - [JsonProperty("user_badge_id")] - public int UserBadgeId { get; set; } - - [JsonProperty("badge_name")] - public string BadgeName { get; set; } - - [JsonProperty("badge_description")] - public string BadgeDescription { get; set; } - - [JsonProperty("created_at")] - public string CreatedAt { get; set; } - - [JsonProperty("badge_image")] - public BadgeImage BadgeImage { get; set; } - } - public class Badges { @@ -452,7 +408,7 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public int Count { get; set; } [JsonProperty("items")] - public IList Items { get; set; } + public IList Items { get; set; } } public class Item @@ -480,7 +436,8 @@ namespace Untappd.Net.Responses.Feeds.UserActivityFeed public Brewery Brewery { get; set; } [JsonProperty("venue")] - public object Venue { get; set; } + [JsonConverter(typeof(SingleObjectArrayConverter))] + public Venue Venue { get; set; } [JsonProperty("comments")] public Comments Comments { get; set; } From 37c43b95f4e57ecb2e6f10529d010eef4039dd98 Mon Sep 17 00:00:00 2001 From: rodkings Date: Thu, 23 Apr 2015 00:44:09 -0600 Subject: [PATCH 2/4] added generic constraint --- src/Untappd.Net/SingleObjectArrayConverter.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Untappd.Net/SingleObjectArrayConverter.cs b/src/Untappd.Net/SingleObjectArrayConverter.cs index b3c349e..2f2c189 100644 --- a/src/Untappd.Net/SingleObjectArrayConverter.cs +++ b/src/Untappd.Net/SingleObjectArrayConverter.cs @@ -11,6 +11,7 @@ namespace Untappd.Net /// /// internal class SingleObjectArrayConverter : JsonConverter + where T : new() { public override bool CanConvert(Type objectType) { @@ -29,7 +30,7 @@ namespace Untappd.Net else if (reader.TokenType == JsonToken.StartArray) { reader.Read(); - retval = null; + retval = new T(); } return retval; From c05c5889984802d8520a185fd6219168992b553c Mon Sep 17 00:00:00 2001 From: rodkings Date: Sun, 26 Apr 2015 11:37:39 -0600 Subject: [PATCH 3/4] small change UserBadges --- src/Untappd.Net/Responses/UserBadges.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Untappd.Net/Responses/UserBadges.cs b/src/Untappd.Net/Responses/UserBadges.cs index 7ba02ff..423ccdc 100644 --- a/src/Untappd.Net/Responses/UserBadges.cs +++ b/src/Untappd.Net/Responses/UserBadges.cs @@ -173,7 +173,7 @@ namespace Untappd.Net.Responses.UserBadges /// [JsonProperty(PropertyName = "levels")] [JsonConverter(typeof(SingleObjectArrayConverter))] - public object Levels { get; set; } + public Levels Levels { get; set; } [JsonProperty("badge_pack")] public int BadgePack { get; set; } From fe555f4fff461f271f9e0bdde267ee8e34b187ae Mon Sep 17 00:00:00 2001 From: rodkings Date: Sun, 26 Apr 2015 11:52:18 -0600 Subject: [PATCH 4/4] Auth Creds with one parameter --- .../Client/TestAuthenticatedUntappdCredentials.cs | 4 ++-- src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs | 5 +---- src/Untappd.Net/Client/AuthenticatedUntappdCredentials.cs | 3 +-- src/Untappd.Net/Client/UntappdCredentials.cs | 4 ++++ src/Untappd.Net/SingleObjectArrayConverter.cs | 7 ++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Untappd.Net.UnitTests/Client/TestAuthenticatedUntappdCredentials.cs b/src/Untappd.Net.UnitTests/Client/TestAuthenticatedUntappdCredentials.cs index 6cb0242..9209952 100644 --- a/src/Untappd.Net.UnitTests/Client/TestAuthenticatedUntappdCredentials.cs +++ b/src/Untappd.Net.UnitTests/Client/TestAuthenticatedUntappdCredentials.cs @@ -11,13 +11,13 @@ namespace Untappd.Net.UnitTests.Client [ExpectedException(typeof(ArgumentNullException))] public void ExpectException() { - var t = new AuthenticatedUntappdCredentials(null, "d", "d"); + var t = new AuthenticatedUntappdCredentials(null); } [Test] public void ExpectValid() { var token = "awesome"; - var t = new AuthenticatedUntappdCredentials(token, "d", "d"); + var t = new AuthenticatedUntappdCredentials(token); Assert.AreEqual(token, "awesome"); token = "newString"; //Make sure the reference is not copied over diff --git a/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs b/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs index bd9da1e..1486e1f 100644 --- a/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs +++ b/src/Untappd.Net.UnitTests/Responses/TestDeserializer.cs @@ -29,10 +29,7 @@ namespace Untappd.Net.UnitTests [Ignore] public void GetActualJsonRequest() { - var credentials = new AuthenticatedUntappdCredentials( - "", - "", - ""); + var credentials = new AuthenticatedUntappdCredentials(""); Dictionary parameters = new Dictionary(); parameters.Add("q", "wild rose"); diff --git a/src/Untappd.Net/Client/AuthenticatedUntappdCredentials.cs b/src/Untappd.Net/Client/AuthenticatedUntappdCredentials.cs index a0f5b41..4a0eb55 100644 --- a/src/Untappd.Net/Client/AuthenticatedUntappdCredentials.cs +++ b/src/Untappd.Net/Client/AuthenticatedUntappdCredentials.cs @@ -11,8 +11,7 @@ namespace Untappd.Net.Client /// /// /// - public AuthenticatedUntappdCredentials(string accessToken, string clientId, string clientSecret) - :base(clientId, clientSecret) + public AuthenticatedUntappdCredentials(string accessToken) { if (string.IsNullOrWhiteSpace(accessToken)) { diff --git a/src/Untappd.Net/Client/UntappdCredentials.cs b/src/Untappd.Net/Client/UntappdCredentials.cs index 23e5390..73b6a73 100644 --- a/src/Untappd.Net/Client/UntappdCredentials.cs +++ b/src/Untappd.Net/Client/UntappdCredentials.cs @@ -7,6 +7,10 @@ namespace Untappd.Net.Client public string ClientId { get; private set; } public string ClientSecret { get; private set; } + protected UntappdCredentials() + { + } + /// /// UnAuthenticated request. Pass your API id and secret /// diff --git a/src/Untappd.Net/SingleObjectArrayConverter.cs b/src/Untappd.Net/SingleObjectArrayConverter.cs index c10bae2..cbfc17e 100644 --- a/src/Untappd.Net/SingleObjectArrayConverter.cs +++ b/src/Untappd.Net/SingleObjectArrayConverter.cs @@ -28,11 +28,12 @@ namespace Untappd.Net { case JsonToken.StartObject: var instance = (T)serializer.Deserialize(reader, typeof(T)); - retval = instance; + retval = instance; break; case JsonToken.StartArray: - reader.Read(); - retval = new T(); + reader.Read(); + retval = new T(); + break; } return retval;