/// <summary> /// Авторизация /// </summary> /// <param name="storage">Хранилище</param> /// <param name="token">Токен авторизации</param> /// <returns></returns> public async Task AuthorizeAsync(AuthStorage storage, string token) { if (string.IsNullOrEmpty(token)) { throw new Exception("Задан пустой токен авторизации."); } storage.Token = token; // Пытаемся получить информацию о пользователе YResponse <YAccountResult> authInfo = await GetUserAuthAsync(storage); // Если не авторизован, то авторизуем if (string.IsNullOrEmpty(authInfo.Result.Account.Uid)) { throw new Exception("Пользователь незалогинен."); } // Флаг авторизации storage.IsAuthorized = true; //var authUserDetails = await GetUserAuthDetailsAsync(storage); //var authUser = authUserDetails.User; storage.User = authInfo.Result.Account; }
public void GetMetadataForDownload_ValidData_True() { Fixture.Track.Should().NotBe(null); downloadInfo = Fixture.API.Track.GetMetadataForDownload(Fixture.Storage, Fixture.Track.GetKey().ToString()); downloadInfo.Result.Count.Should().BePositive(); }
public void GetStationTracks_ValidData_True() { Fixture.Station.Should().NotBeNull(); Fixture.Station.Result.Count.Should().BeGreaterThan(0); YResponse <YStationSequence> sequence = Fixture.API.Radio.GetStationTracks(Fixture.Storage, Fixture.Station.Result.First()); sequence.Result.Sequence.Count.Should().BeGreaterThan(0); }
public void SetStationSettings2_ValidData_True() { Fixture.Station.Should().NotBeNull(); Fixture.Station.Result.Count.Should().BeGreaterThan(0); YResponse <string> response = Fixture.API.Radio.SetStationSettings2(Fixture.Storage, Fixture.Station.Result.First(), new YStationSettings2 { Language = "any", Diversity = "default", MoodEnergy = "all" }); response.Result.Should().Be("ok"); }
public override async Task <FyResult> GetAsync() { Result = null; var queryStringParameters = new Dictionary <string, object>(); // If there are definitions for 'StartDate' or 'FinishDate' then use it as arguments. if (StartDate != null || FinishDate != null) { // Set default timestamp for 'StartDate' when it is not defined. if (StartDate == null) { StartDate = YUtils.DefaultDateTime; } // Set current datetime for' FinishDate' when it is not defined. if (FinishDate == null) { FinishDate = DateTime.Now; } // Validate the Start/Finish interval. if (StartDate > FinishDate) { throw new ArgumentOutOfRangeException("StartDate", "The StartDate can not be greater than FinishDate."); } var period1 = YUtils.GetTimestampFromDateTime(StartDate.Value); var period2 = YUtils.GetTimestampFromDateTime(FinishDate.Value); // YahooFinance expect two parameters called 'period1' and 'period1' as timeStamps values. queryStringParameters.Add(nameof(period1), period1); queryStringParameters.Add(nameof(period2), period2); } else { // When there is no definition for Start/Finish dates. // We can must use the Period property which is available on the enumerator YPeriod. // Get the valida format for periods. var range = YUtils.GetPeriod(Period); // Use the range parameter. queryStringParameters.Add(nameof(range), range); } // Add the interval based on Interval property. var interval = YUtils.GetInterval(Interval == Interval.ThirtyMinutes ? Interval.FifteenMinutes : Interval); // Use the interval parameter. queryStringParameters.Add(nameof(interval), interval); // queryStringParameters.Add("includePrePost", false); var events = new List <string>(); if (Dividends) { events.Add("div"); } if (Splits) { events.Add("splits"); } if (events.Any()) { queryStringParameters.Add("events", string.Join(",", events)); } // build the queryString parameters. var queryString = string.Join("&", queryStringParameters.Select(x => $"{x.Key}={x.Value}")); // Build the 'url' to request. var url = $"{YUtils.BaseUrl}/v8/finance/chart/{Symbol}?{queryString}"; // Make a http get request to the url. var http = new HttpClient(); var response = await http.GetAsync(url); var responseBody = await response.Content.ReadAsStringAsync(); YResponse yResponse = null; if (!string.IsNullOrWhiteSpace(responseBody)) { yResponse = JsonConvert.DeserializeObject <YResponse>(responseBody); } if (!response.IsSuccessStatusCode || yResponse == null) { var error = yResponse?.chart?.error; string code = "Fynance.Yahoo"; string message = "This result was not possible to get from Yahoo Finance."; if (error != null) { code = error.code; message = error.description; } throw new FynanceException(code, message) { Symbol = this.Symbol, Period = this.Period, Interval = this.Interval, StatusCode = response.StatusCode }; } try { Result = yResponse.GetResult(this.TimeZone); } catch (Exception ex) { throw new FynanceException("Fynance.Yahoo", "An error occurred while trying to fetch the results. Please, check the InnerException for more details.", ex); } return(Result); }
public void Podcasts_ValidData_True() { YResponse <YPlaylist> response = Fixture.API.Playlist.Podcasts(Fixture.Storage); response.Should().NotBeNull(); }
public void Missed_ValidData_True() { YResponse <YPlaylist> response = Fixture.API.Playlist.Missed(Fixture.Storage); response.Should().NotBeNull(); }
public void OfTheDay_ValidData_True() { YResponse <YPlaylist> response = Fixture.API.Playlist.OfTheDay(Fixture.Storage); response.Should().NotBeNull(); }
public void Suggest_ValidData_True() { YResponse <YSearchSuggest> suggest = Fixture.API.Search.Suggest(Fixture.Storage, artist); suggest.Result.Suggestions.Count.Should().BeGreaterThan(0); }
public void Video_ValidData_True() { YResponse <YSearch> response = Fixture.API.Search.Videos(Fixture.Storage, track); response.Result.Videos.Total.Should().BeGreaterThan(0); }
public void Playlist_ValidData_True() { YResponse <YSearch> response = Fixture.API.Search.Playlist(Fixture.Storage, playlist); response.Result.Playlists.Total.Should().BeGreaterThan(0); }
public void Albums_ValidData_True() { YResponse <YSearch> response = Fixture.API.Search.Albums(Fixture.Storage, album); response.Result.Albums.Total.Should().BeGreaterThan(0); }
public void GetStations_ValidData_True() { YResponse <List <YStation> > stations = Fixture.API.Radio.GetStations(Fixture.Storage); stations.Result.Count.Should().BeGreaterThan(0); }
public void GetStationsDashboard_ValidData_True() { YResponse <YStationsDashboard> stations = Fixture.API.Radio.GetStationsDashboard(Fixture.Storage); stations.Result.Stations.Count.Should().BeGreaterThan(0); }