public async Task <List <StreamLabsDonationIntermediate> > Get()
        {
            var accessToken = _getSettingRepository.Get <string>("StreamLabsAccessToken");

            if (string.IsNullOrWhiteSpace(accessToken))
            {
                return(null);
            }

            var lastDonationId = _getSettingRepository.Get <string>("LatestDonationId");

            if (string.IsNullOrWhiteSpace(lastDonationId))
            {
                lastDonationId = string.Empty;
            }

            var client = new HttpClient();

            var donationsResponse =
                await client.GetAsync(
                    $"https://streamlabs.com/api/v1.0/donations?access_token={accessToken}&after={lastDonationId}&currency={_configService.Get<string>("DonationCurrency")}&limit=100");

            if (!donationsResponse.IsSuccessStatusCode)
            {
                return(null);
            }

            var donationsJsonString = await donationsResponse.Content.ReadAsStringAsync();

            var donations = JsonConvert.DeserializeObject <StreamLabsDonationsIntermediate>(donationsJsonString);

            return(donations.StreamLabsDonations.ToList());
        }
        public async void Refresh()
        {
            var refreshToken = _getSettingRepository.Get <string>("StreamLabsRefreshToken");

            if (string.IsNullOrWhiteSpace(refreshToken))
            {
                return;
            }

            var vals = new Dictionary <string, string>
            {
                { "grant_type", "refresh_token" },
                { "client_id", _secretService.GetSecret <string>("StreamLabsClientId") },
                { "client_secret", _secretService.GetSecret <string>("StreamLabsClientSecret") },
                { "redirect_uri", "localhost" },
                { "refresh_token", refreshToken }
            };

            var encodedContent   = new FormUrlEncodedContent(vals);
            var client           = new HttpClient();
            var getTokenResponse = await client.PostAsync("https://streamlabs.com/api/v1.0/token", encodedContent);

            var tokenJsonString = await getTokenResponse.Content.ReadAsStringAsync();

            var tokenModel = JsonConvert.DeserializeObject <StreamLabsTokenIntermediate>(tokenJsonString);

            _setOrCreateSettingRepository.Set("StreamLabsAccessToken", tokenModel.Token);
            _setOrCreateSettingRepository.Set("StreamLabsRefreshToken", tokenModel.RefreshToken);
        }
示例#3
0
        public PlaylistState GetPlaylistState()
        {
            var state = _getSettingRepository.Get <string>("PlaylistStatus");

            return(string.IsNullOrWhiteSpace(state) ? PlaylistState.VeryClosed : Enum.Parse <PlaylistState>(state));
        }
示例#4
0
        public bool InProgress()
        {
            var gameInProgress = _getSettingRepository.Get <bool>(SettingsKeys.GuessingGameStateSettingKey);

            return(gameInProgress);
        }