public async Task <InstaMedia> GetMediaByCodeAsync(string postCode) { string mediaUrl = $"{InstaApiConstants.INSTAGRAM_URL}{InstaApiConstants.P_SUFFIX}{postCode}{InstaApiConstants.GET_ALL_POSTFIX}"; var stream = await _httpClient.GetStreamAsync(mediaUrl); InstaResponseMedia mediaResponse; using (var reader = new StreamReader(stream)) { var json = reader.ReadToEnd(); var root = JObject.Parse(json); var mediaObject = root["media"]; mediaResponse = JsonConvert.DeserializeObject <InstaResponseMedia>(mediaObject.ToString()); } var converter = ConvertersFabric.GetSingleMediaConverter(mediaResponse); return(converter.Convert()); }
public async Task <IResult <InstaMedia> > GetMediaByCodeAsync(string mediaCode) { ValidateUser(); var mediaUri = UriCreator.GetMediaUri(mediaCode); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, mediaUri, _deviceInfo); var response = await _httpClient.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode == HttpStatusCode.OK) { var mediaResponse = JsonConvert.DeserializeObject <InstaMediaListResponse>(json, new InstaMediaListDataConverter()); if (mediaResponse.Medias?.Count != 1) { string errorMessage = $"Got wrong media count for request with media id={mediaCode}"; _logger.Write(errorMessage); return(Result.Fail <InstaMedia>(errorMessage)); } var converter = ConvertersFabric.GetSingleMediaConverter(mediaResponse.Medias.FirstOrDefault()); return(Result.Success(converter.Convert())); } return(Result.Fail(GetBadStatusFromJsonString(json).Message, (InstaMedia)null)); }