/// <summary> /// JToken Constructor /// </summary> /// <param name="token"></param> public Artist(JToken token) { /* Simple Fields */ Uri = token.Value <string>("uri") ?? string.Empty; Popularity = token.Value <int?>("popularity") ?? 0; Name = token.Value <string>("name") ?? string.Empty; Id = token.Value <string>("id") ?? string.Empty; Href = token.Value <string>("href") ?? string.Empty; /* Complex Fields */ JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* Followers */ JToken follower = token.Value <JToken>("followers"); if (follower != null) { Followers = new Followers(follower); } /* Images */ JArray images = token.Value <JArray>("images"); if (images != null) { List <Image> ims = new List <Image>(); foreach (JObject jobj in images.Values <JObject>()) { Image i = new Image(jobj); ims.Add(i); } Images = ims.ToArray(); } /* Genres */ JArray genres = token.Value <JArray>("genres"); if (genres != null) { List <string> gens = new List <string>(); foreach (JValue jv in genres) { string s = jv.ToString(); gens.Add(s); } Genres = gens.ToArray(); } }
/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> public TrackLink(JToken token) { Href = token.Value <string>("href") ?? string.Empty; Id = token.Value <string>("id") ?? string.Empty; Uri = token.Value <string>("uri") ?? string.Empty; JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } }
/// <summary> /// JToken Constructor /// </summary> /// <param name="token"></param> public Context(JToken token) { Type = token.Value <string>("type") ?? string.Empty; Uri = token.Value <string>("uri") ?? string.Empty; Href = token.Value <string>("href") ?? string.Empty; /* External Urls*/ JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } }
/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> internal User(JToken token) { /* Simple fields */ Birthdate = token.Value <string>("birthdate") ?? string.Empty; Country = token.Value <string>("country") ?? string.Empty; DisplayName = token.Value <string>("display_name") ?? string.Empty; Email = token.Value <string>("email") ?? string.Empty; Product = token.Value <string>("product") ?? string.Empty; Href = token.Value <string>("href") ?? string.Empty; Id = token.Value <string>("id") ?? string.Empty; Uri = token.Value <string>("uri") ?? string.Empty; /* External Urls*/ JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* Followers */ JToken follower = token.Value <JToken>("followers"); if (follower != null) { Followers = new Followers(follower); } /* Images */ JArray images = token.Value <JArray>("images"); if (images != null) { List <Image> ims = new List <Image>(); foreach (JObject jobj in images.Values <JObject>()) { Image i = new Image(jobj); ims.Add(i); } Images = ims.ToArray(); } }
/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> public Track(JToken token) { /* Simple Fields */ Disc_Number = token.Value <int?>("disc_number ") ?? 1; Duration_Ms = token.Value <long?>("duration_ms") ?? 0; Explicit = token.Value <bool?>("explicit") ?? false; Href = token.Value <string>("href") ?? string.Empty; Is_Playable = token.Value <bool?>("is_playable") ?? false; Id = token.Value <string>("id") ?? string.Empty; Name = token.Value <string>("name") ?? string.Empty; Popularity = token.Value <int?>("popularity") ?? 0; Preview_Url = token.Value <string>("preview_url") ?? string.Empty; Track_Number = token.Value <int?>("track_number") ?? 1; Uri = token.Value <string>("uri") ?? string.Empty; /*Complex Fields */ /* Available Markets */ JArray markets = token.Value <JArray>("available_markets"); if (markets != null) { this.Available_Markets = markets.Values <string>().ToArray(); } /* Album */ JObject album = token.Value <JObject>("album"); if (album != null) { this.Album = new Album(album); } /* Artists */ JArray artists = token.Value <JArray>("artists"); if (artists != null) { List <Artist> arts = new List <Artist>(); foreach (JObject jobj in artists) { arts.Add(new Artist(jobj)); } Artists = arts.ToArray(); } JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* External Ids */ JObject extids = token.Value <JObject>("external_ids"); if (extids != null) { foreach (JProperty x in extids.Properties()) { External_Ids.Add(x.Name, x.Value <JToken>().ToString()); } } /* Linked From */ JObject linked = token.Value <JObject>("linked_from"); if (linked != null) { Linked_From = new TrackLink(linked); } }
/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> public Playlist(JToken token) { /* Simple fields */ Collaborative = token.Value <bool?>("collaborative") ?? false; Description = token.Value <string>("description") ?? string.Empty; Href = token.Value <string>("href") ?? string.Empty; Id = token.Value <string>("id") ?? string.Empty; Name = token.Value <string>("name") ?? string.Empty; Public = token.Value <bool?>("public") ?? true; Snapshot_Id = token.Value <string>("snapshot_id") ?? string.Empty; Uri = token.Value <string>("uri") ?? string.Empty; /* External URLS handling */ JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* Follower Handling */ JObject follower = token.Value <JObject>("followers"); if (follower != null) { Followers = new Followers(follower); } /* Image Handling */ JArray images = token.Value <JArray>("images"); if (images != null) { List <Image> ims = new List <Image>(); foreach (JObject jobj in images.Values <JObject>()) { Image i = new Image(jobj); ims.Add(i); } Images = ims.ToArray(); } /* Owner Handling */ JToken owner = token.Value <JToken>("owner"); if (owner != null && owner.HasValues) { Owner = new User(owner); } /* Track Handling */ JObject tracks = token.Value <JObject>("tracks"); Total = tracks.Value <int?>("total") ?? -1; IEnumerable <JToken> trackValues = tracks.Values().ToList(); // >2 properties means its really full of tracks if (tracks.Values().Count() > 2) { //TODO handle tracks //Paging a bitch, yo } }
/// <summary> /// JToken constructor /// </summary> /// <param name="token"></param> public Album(JToken token) { /* simple fields */ Album_Type = token.Value <string>("album_type") ?? string.Empty; Href = token.Value <string>("href") ?? string.Empty; Id = token.Value <string>("id") ?? string.Empty; Label = token.Value <string>("label") ?? string.Empty; Name = token.Value <string>("name") ?? string.Empty; Popularity = token.Value <int?>("popularity") ?? 0; Release_Date = token.Value <string>("release_date") ?? string.Empty; Release_Date_Precision = token.Value <string>("release_date_precision") ?? string.Empty; Uri = token.Value <string>("uri") ?? string.Empty; /* complex fields */ JObject exturls = token.Value <JObject>("external_urls"); if (exturls != null) { foreach (JProperty x in exturls.Properties()) { External_Urls.Add(x.Name, x.Value <JToken>().ToString()); } } /* External Ids */ JObject extids = token.Value <JObject>("external_ids"); if (extids != null) { foreach (JProperty x in extids.Properties()) { External_Ids.Add(x.Name, x.Value <JToken>().ToString()); } } /* Images */ JArray images = token.Value <JArray>("images"); if (images != null) { List <Image> ims = new List <Image>(); foreach (JObject jobj in images.Values <JObject>()) { Image i = new Image(jobj); ims.Add(i); } Images = ims.ToArray(); } /* Genres */ JArray genres = token.Value <JArray>("genres"); if (genres != null) { List <string> gens = new List <string>(); foreach (JValue jv in genres) { string s = jv.ToString(); gens.Add(s); } Genres = gens.ToArray(); } /* Copyrights */ JArray copyrights = token.Value <JArray>("copyright"); if (copyrights != null) { List <Copyright> cps = new List <Copyright>(); foreach (JObject jobj in copyrights.Values <JObject>()) { Copyright i = new Copyright(jobj); cps.Add(i); } Copyrights = cps.ToArray(); } /* Available Markets */ JArray markets = token.Value <JArray>("available_markets"); if (markets != null) { this.Available_Markets = markets.Values <string>().ToArray(); } /* Artists */ JArray artists = token.Value <JArray>("artists"); if (artists != null) { List <Artist> arts = new List <Artist>(); foreach (JObject jobj in artists) { arts.Add(new Artist(jobj)); } Artists = arts.ToArray(); } //tracks JToken paging = token.Value <JToken>("tracks"); if (paging != null) { Tracks = new Paging <Track>(paging); } }