private static object HydrateCompactObject(TargetObjectType type, JToken item) { try { if (item != null) { switch (type) { case TargetObjectType.Badge: return(Badge.ParseJson(item)); case TargetObjectType.Checkin: return(Checkin.ParseJson(item)); case TargetObjectType.Special: // VenueId, if null, must be parsed out of the // notification or else it will throw. FYI. return(CompactSpecial.ParseJson(item, null)); case TargetObjectType.Tip: return(Tip.ParseJson(item)); case TargetObjectType.Url: Uri uri = Json.TryGetUriProperty(item, "url"); return(uri); case TargetObjectType.User: return(CompactUser.ParseJson(item)); case TargetObjectType.Venue: return(CompactVenue.ParseJson(item)); default: break; } } } catch (Exception) { } return(null); }
protected override object DeserializeCore(JObject json, Type objectType, LoadContext context) { try { var b = new UserBadges(context); var sets = json["sets"]; if (sets != null) { /* * type: "all" * name: "all badges" * image: { * prefix: "http://foursquare.com/img/badge/" * sizes: [ * 24 * 32 * 48 * 64 * ] * name: "/allbadges.png" * */ // TODO: V2: support icons for groups var listOfGroups = new List <BadgeGroup>(); var badgesInGroups = new Dictionary <BadgeGroup, Dictionary <string, bool> >(); var groups = sets["groups"]; foreach (var group in groups) { BadgeGroup bbgg = new BadgeGroup(); bbgg.Name = Json.TryGetJsonProperty(group, "name"); bbgg.Type = Json.TryGetJsonProperty(group, "type"); // TODO: FUTURE: V2 badge group image support here var items = group["items"]; if (items != null) { var contained = new Dictionary <string, bool>(); foreach (string s in items) { contained[s] = true; } badgesInGroups[bbgg] = contained; listOfGroups.Add(bbgg); } } //BadgeGroup all = lbg.Where(z => z.Type == "all").FirstOrDefault(); var badges = json["badges"]; if (badges != null) { foreach (var bb in badges) { var item = bb.First(); string key = Json.TryGetJsonProperty(item, "id"); if (!string.IsNullOrEmpty(key)) { var thisBadget = badges[key]; Badge badge = Badge.ParseJson(thisBadget); foreach (var c in badgesInGroups) { var badgeGroup = c.Key; var contained = c.Value; if (contained.ContainsKey(key)) { badgeGroup.Add(badge); } } } } } // TODO: P0 SHIP: TESTING NEEDED: If they have zero badges, which group will we have - probably not the right one! // NOTE: V2: For now I only want the first group. var tempList = new List <BadgeGroup>(1); tempList.Add(listOfGroups[0]); b.Groups = tempList; // listOfGroups; } b.IsLoadComplete = true; return(b); } catch (Exception e) { throw new UserIntendedException( "There was a problem trying to read the list of friends.", e); } }