/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetRecommendationsResponse response = new GetRecommendationsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("itemList", targetDepth)) { var unmarshaller = new ListUnmarshaller <PredictedItem, PredictedItemUnmarshaller>(PredictedItemUnmarshaller.Instance); response.ItemList = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("recommendationId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RecommendationId = unmarshaller.Unmarshall(context); continue; } } return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetRecommendationsResponse response = new GetRecommendationsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("anomalies", targetDepth)) { var unmarshaller = new ListUnmarshaller <Anomaly, AnomalyUnmarshaller>(AnomalyUnmarshaller.Instance); response.Anomalies = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("profileEndTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.ProfileEndTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("profileStartTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.ProfileStartTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("profilingGroupName", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ProfilingGroupName = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("recommendations", targetDepth)) { var unmarshaller = new ListUnmarshaller <Recommendation, RecommendationUnmarshaller>(RecommendationUnmarshaller.Instance); response.Recommendations = unmarshaller.Unmarshall(context); continue; } } return(response); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { GetRecommendationsResponse response = new GetRecommendationsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("recommendations", targetDepth)) { var unmarshaller = new ListUnmarshaller <RecommendationData, RecommendationDataUnmarshaller>(RecommendationDataUnmarshaller.Instance); response.Recommendations = unmarshaller.Unmarshall(context); continue; } } return(response); }
public async Task <ActionResult> Create([Bind(Include = "Id, Artist, Tempo, Energy, Danceability, Mode")] RecommendationBasis basis) { if (ModelState.IsValid) { var client = new SpotifyApiClient(); var response = await client.SearchArtistsAsync(basis.Artist); var artists = response.Artists; GetRecommendationsResponse recommendations = null; if (artists.Total > 0) { var artist = artists.Items[0]; var energy = basis.Energy * 0.01f; var danceability = 0.0f; var mode = 0; if (basis.Danceability) { danceability = 1.0f; } if (basis.Mode) { mode = 1; } recommendations = await client.GetRecommendationsAsync(artist.Id, basis.Tempo, energy, danceability, mode); } else { recommendations = await client.GetRecommendationsAsync("0OdUWJ0sBjDrqHygGUXeCF"); } return(View("Details", recommendations.Tracks)); } return(View(basis)); }