Пример #1
0
        protected async Task <TransIpResponse> ParseResponse(HttpResponseMessage response, TransIpResponse output = null)
        {
            if (output == null)
            {
                output = new TransIpResponse();
            }
            output.Success = response.IsSuccessStatusCode;
            output.Payload = await response.Content.ReadAsStringAsync();

            if (!output.Success)
            {
                try
                {
                    var error = JsonConvert.DeserializeObject <TransIpError>(output.Payload);
                    output.Payload = error.Error;
                }
                catch { }
            }
            if (response.Headers.Contains("X-Rate-Limit-Remaining"))
            {
                output.RateLimitRemaining = int.Parse(response.Headers.GetValues("X-Rate-Limit-Remaining").FirstOrDefault());
            }
            if (response.Headers.Contains("X-Rate-Limit-Reset"))
            {
                output.RateLimitReset = _epoch.AddSeconds(double.Parse(response.Headers.GetValues("X-Rate-Limit-Reset").FirstOrDefault()));
            }
            return(output);
        }
Пример #2
0
        private async Task <string> GetToken()
        {
            var request = new AuthenticationRequest()
            {
                Login          = _login,
                Nonce          = Guid.NewGuid().ToString().Substring(0, 32),
                ExpirationTime = "30 minutes",
                GlobalKey      = true,
                ReadOnly       = false
            };
            var body    = JsonConvert.SerializeObject(request);
            var content = new StringContent(body);

            content.Headers.Add("Signature", Sign(body));
            var client = await base.GetClient();

            var response = await client.PostAsync("auth", content);

            var result = await ParseResponse(response);

            var typedResult = new TransIpResponse <AuthenticationResponse>(result);

            return(typedResult.PayloadTyped.Token);
        }