Пример #1
0
        public ResponseData(TwitterRequest request, Authentication authentication, dynamic headerResponse, HttpStatusCode statusCode, dynamic apiResponse)
        {
            Command     = request.CommandName;
            HttpMethod  = request.HttpMethod;
            Uri         = authentication.Uri;
            QueryString = authentication.Uri.Query;
            Body        = request.Body;
            Form        = request.Form;
            Status      = statusCode;
            try
            {
                Server             = headerResponse["server"][0];
                ResponseTime       = int.Parse(headerResponse["x-response-time"][0]);
                RateLimit          = int.Parse(headerResponse["x-rate-limit-limit"][0]);
                RateLimitRemaining = int.Parse(headerResponse["x-rate-limit-remaining"][0]);

                DateTime resetTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
                RateLimitReset = resetTime.AddSeconds(int.Parse(headerResponse["x-rate-limit-reset"][0])).ToLocalTime();
            }
            catch
            {
            }
            HeaderResponse = headerResponse;
            ApiResponse    = apiResponse;
            ApiVersion     = request.GetAPIVersion();
        }
Пример #2
0
 // OAuth 2.0 Bearer Token
 public Authentication(
     TwitterRequest request,
     string bearerToken
     )
 {
     HttpMethod = request.HttpMethod.ToString();
     Uri        = request.GetUri();
     AuthHeader = $"Bearer {bearerToken}";
 }
Пример #3
0
        // Basic Authentication
        public Authentication(
            TwitterRequest request,
            string apiKey, string apiSecret
            )
        {
            HttpMethod = request.HttpMethod.ToString();
            Uri        = request.GetUri();
            string basicAuth = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{apiKey}:{apiSecret}"));

            AuthHeader = $"Basic {basicAuth}";
        }
Пример #4
0
        // ----------------------------------------------------------------------------------------
        // Constructors
        // OAuth 1.0a
        public Authentication(
            TwitterRequest request,
            string apiKey, string apiSecret,
            string accessToken, string accessTokenSecret,
            string nonce = null, string timestamp = null)
        {
            _apiKey            = apiKey;
            _apiSecret         = apiSecret;
            _accessToken       = accessToken;
            _accessTokenSecret = accessTokenSecret;

            Nonce     = nonce ?? GetNonce();
            Timestamp = timestamp ?? GetUnixTime();

            SigningKey = $"{Uri.EscapeDataString(_apiSecret)}&{Uri.EscapeDataString(_accessTokenSecret)}";

            HttpMethod = request.HttpMethod.ToString();
            Uri        = request.GetUri();

            string baseUri;

            if (Uri.Query != string.Empty)
            {
                baseUri = Uri.AbsoluteUri.Replace(Uri.Query, null);
            }
            else
            {
                baseUri = Uri.AbsoluteUri;
            }

            SetParameterString();

            SignatureBaseString = $"{HttpMethod}&{Uri.EscapeDataString(baseUri)}&{Uri.EscapeDataString(ParameterString)}";

            SetOAuthSignature();
            SetOAuthHeaderString();
        }