예제 #1
0
        public async Task GetToken_FailedRequest_ReturnsNone()
        {
            _jsonConnection.PostAsync <GetTokenRequest.TokenData>(null, null)
            .ReturnsForAnyArgs(new FailedRequest(HttpStatusCode.NotFound, "NotFound"));

            var result = await _token.GetToken(_jsonConnection, _aniListConfiguration, _resultContext);

            result.IsRight.Should().BeFalse();
        }
        public async Task <Option <string> > GetTokenAsync()
        {
            if (_hasToken)
            {
                _log.Debug($"Using existing token '{_token}'");
                return(_token);
            }

            var request = new LoginRequest(_apiKey);

            var response = await _jsonConnection.PostAsync(request, Option <string> .None);

            return(response.Match(
                       r =>
            {
                _hasToken = true;
                _token = r.Data.Token;

                _log.Debug($"Got new token '{_token}'");
                return _token;
            },
                       fr =>
            {
                _log.Debug("Failed to get a new token");
                return Option <string> .None;
            }));
        }
예제 #3
0
        public Task <Either <ProcessFailedResult, IEnumerable <AniListSeriesData> > > FindSeriesAsync(string title,
                                                                                                      ProcessResultContext resultContext)
        {
            var token = _aniListToken.GetToken(_jsonConnection, _anilistConfiguration, resultContext);

            var request = new FindSeriesRequest(title);

            return(token.Map(e => e.MapLeft(FailedRequest.ToFailedResult(resultContext)))
                   .BindAsync(t =>
            {
                return _jsonConnection.PostAsync(request, t)
                .MapAsync(r => r.Data.Data.Page.Media)
                .Map(e => e.MapLeft(FailedRequest.ToFailedResult(resultContext)));
            }));
        }
        private Task <Either <FailedRequest, string> > RequestToken(IJsonConnection jsonConnection,
                                                                    IAnilistConfiguration anilistConfiguration)
        {
            var response = jsonConnection
                           .PostAsync(new GetTokenRequest(362, "NSjmeTEekFlV9OZuZo9iR0BERNe3KS83iaIiI7EQ",
                                                          "http://localhost:8096/web/configurationpage?name=AniMetadata",
                                                          anilistConfiguration.AuthorisationCode), Option <string> .None);

            var token = response.MapAsync(r =>
            {
                anilistConfiguration.AccessToken = r.Data.AccessToken;
                return(r.Data.AccessToken);
            });

            return(token);
        }