Esempio n. 1
0
        /// <inheritdoc />
        public async Task <T> MakeRequestAsync <T>(
            string methodName,
            VTopeParams @params,
            CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (string.IsNullOrWhiteSpace(methodName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(methodName));
            }

            if (@params == null)
            {
                throw new ArgumentNullException(nameof(@params));
            }

            var url     = $"https://vto.pe/botcontrol/{methodName}";
            var payload = SerializeObject(Authorize(@params));
            var content = GetContent(payload);

            _logger?.LogDebug($"POST request: {url}{Environment.NewLine}{payload}");

            var response = await PostAsync(url, content, cancellationToken).ConfigureAwait(false);

            var json      = response.ToJObject();
            var formatted = json.ToString(Formatting.Indented);

            _logger?.LogDebug($"POST response: {url}{Environment.NewLine}{formatted}");

            return(json.ToObject <T>());
        }
Esempio n. 2
0
 /// <summary>
 ///     Authorizes the bot. Required for each request.
 /// </summary>
 private VTopeParams Authorize(VTopeParams @params)
 {
     if (@params == null)
     {
         throw new ArgumentNullException(nameof(@params));
     }
     if ([email protected]("user"))
     {
         @params.Add("user", User);
     }
     if ([email protected]("key"))
     {
         @params.Add("key", Key);
     }
     return(@params);
 }
Esempio n. 3
0
        public void Constructor_With_Parameters()
        {
            // Act
            var dictionary = new Dictionary <string, object>
            {
                { "param1", 123 }
            };

            // Arrange
            var arg = new VTopeParams(dictionary);

            // Assert
            Assert.NotNull(arg);
            Assert.True(arg.ContainsKey("param1"));
            Assert.True(arg.ContainsValue(123));
        }