/// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            IHttpPostData postData = new HttpPostData();

            if (IsDefault)
            {
                postData.Add("is_default", "true");
            }
            if (string.IsNullOrWhiteSpace(Location) == false)
            {
                postData.Add("location", Location);
            }
            if (string.IsNullOrWhiteSpace(Message) == false)
            {
                postData.Add("message", Message);
            }
            if (string.IsNullOrWhiteSpace(Name) == false)
            {
                postData.Add("name", Name);
            }
            if (string.IsNullOrWhiteSpace(Place) == false)
            {
                postData.Add("place", Place);
            }
            if (Privacy != null && Privacy.Value != FacebookPrivacy.Default)
            {
                postData.Add("privacy", Privacy.ToString());
            }
            return(postData);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpQueryString"/> representing the GET parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            // Both "Title" or "Description" should be specified
            if (string.IsNullOrWhiteSpace(Title))
            {
                throw new PropertyNotSetException("Title");
            }
            if (string.IsNullOrWhiteSpace(Description))
            {
                throw new PropertyNotSetException("Description");
            }

            // Append the options to the POST data (if specified)
            HttpPostData data = new HttpPostData();

            data.Add("title", Title);
            data.Add("description", Description);
            if (!string.IsNullOrWhiteSpace(PrimaryPhotoId))
            {
                data.Add("primary_photo_id ", PrimaryPhotoId);
            }

            // TODO: The "full_result" parameter should be supported as well, but the Flickr API documentation doesn't specify it's type

            return(data);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            IHttpPostData postData = new HttpPostData {
                IsMultipart = !String.IsNullOrWhiteSpace(Source)
            };

            if (!String.IsNullOrWhiteSpace(Source))
            {
                postData.AddFile("source", Source);
            }
            if (!String.IsNullOrWhiteSpace(Url))
            {
                postData.Add("url", Url);
            }
            if (!String.IsNullOrWhiteSpace(Message))
            {
                postData.Add("message", Message);
            }
            if (!String.IsNullOrWhiteSpace(Place))
            {
                postData.Add("place", Place);
            }
            if (NoStory)
            {
                postData.Add("no_story", "true");
            }
            return(postData);
        }
Exemple #4
0
        /// <summary>
        /// Query this method with the provided HTTP POST data
        /// </summary>
        /// <typeparam name="T">The subtype to deserialize (the deserialized type being <see cref="APIResult{T}"/>).</typeparam>
        /// <param name="method">The method to query</param>
        /// <param name="postData">The http POST data</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        /// <returns>The deserialized object</returns>
        private APIResult <T> QueryMethod <T>(APIMethods method, HttpPostData postData, XslCompiledTransform transform)
        {
            // Download
            string url    = GetMethodUrl(method);
            var    result = Util.DownloadAPIResult <T>(url, postData, transform);

            // On failure with a custom method, fallback to CCP
            if (ShouldRetryWithCCP(result))
            {
                return(s_ccpProvider.QueryMethod <T>(method, postData, transform));
            }

            // If the result is a character sheet, we store the result
            if (method == APIMethods.CharacterSheet && !result.HasError)
            {
                SerializableAPICharacterSheet sheet = (SerializableAPICharacterSheet)(Object)result.Result;
                LocalXmlCache.Save(sheet.Name, result.XmlDocument);
            }

            // If the result is a conquerable station list, we store the result
            if (method == APIMethods.ConquerableStationList && !result.HasError)
            {
                LocalXmlCache.Save(method.ToString(), result.XmlDocument);
            }

            // Returns
            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Query a method with the provided arguments for a character messages.
        /// </summary>
        /// <param name="userID">The account's ID</param>
        /// <param name="apiKey">The account's API key</param>
        /// <param name="messageID">The message ID.</param>
        /// <returns></returns>
        public void QueryMethodAsync <T>(APIMethods method, long userID, string apiKey, long characterID, long messageID, QueryCallback <T> callback)
        {
            HttpPostData postData = new HttpPostData(String.Format(
                                                         "userID={0}&apiKey={1}&characterID={2}&ids={3}", userID, apiKey, characterID, messageID));

            QueryMethodAsync <T>(method, postData, RowsetsTransform, callback);
        }
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Meetup OAuth dialog.</param>
        /// <returns>An instance of <see cref="MeetupTokenResponse"/> representing the response.</returns>
        public MeetupTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException("ClientId");
            }
            if (String.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException("ClientSecret");
            }
            if (String.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException("RedirectUri");
            }
            if (String.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException(nameof(authCode));
            }

            // Initialize the query string
            HttpPostData data = new HttpPostData {
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "grant_type", "authorization_code" },
                { "redirect_uri", RedirectUri },
                { "code", authCode }
            };

            // Make the call to the API
            IHttpResponse response = HttpUtils.Http.DoHttpPostRequest("https://secure.meetup.com/oauth2/access", null, data);

            // Parse the response
            return(MeetupTokenResponse.ParseResponse(response));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpPostData"/>.</returns>
        public IHttpPostData GetPostData()
        {
            if (ListId == 0)
            {
                throw new PropertyNotSetException(nameof(ListId));
            }
            if (UserId == 0 && String.IsNullOrWhiteSpace(ScreenName))
            {
                throw new PropertyNotSetException(nameof(UserId));
            }

            IHttpPostData data = new HttpPostData {
                { "list_id", ListId }
            };

            if (UserId > 0)
            {
                data.Add("user_id", UserId);
            }
            if (!String.IsNullOrWhiteSpace(ScreenName))
            {
                data.Add("screen_name", ScreenName);
            }

            return(data);
        }
Exemple #8
0
        /// <summary>
        /// Asynchrnoneously queries this method with the provided HTTP POST data
        /// </summary>
        /// <typeparam name="T">The subtype to deserialize (the deserialized type being <see cref="APIResult{T}"/>).</typeparam>
        /// <param name="method">The method to query</param>
        /// <param name="postData">The http POST data</param>
        /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        private void QueryMethodAsync <T>(APIMethods method, HttpPostData postData, XslCompiledTransform transform, QueryCallback <T> callback)
        {
            // Check callback not null
            if (callback == null)
            {
                throw new ArgumentNullException("The callback cannot be null.", "callback");
            }

            // Lazy download
            string url = GetMethodUrl(method);

            Util.DownloadAPIResultAsync <T>(url, postData, transform, (result) =>
            {
                // On failure with a custom method, fallback to CCP
                if (ShouldRetryWithCCP(result))
                {
                    result = s_ccpProvider.QueryMethod <T>(method, postData, transform);
                }

                // If the result is a character sheet, we store the result
                if (method == APIMethods.CharacterSheet && !result.HasError)
                {
                    SerializableAPICharacter sheet = (SerializableAPICharacter)(Object)result.Result;
                    LocalXmlCache.Save(sheet.Name, result.XmlDocument);
                }

                // Invokes the callback
                callback(result);
            });
        }
        /// <summary>
        /// Writes the value to the specified <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">The stream the value should be written to.</param>
        /// <param name="boundary">The multipart boundary.</param>
        /// <param name="newLine">The characters used to indicate a new line.</param>
        /// <param name="isLast">Whether the value is the last in the request body.</param>
        public void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast)
        {
            HttpPostData.Write(stream, "--" + boundary + newLine);
            HttpPostData.Write(stream, "Content-Disposition: form-data; name=\"" + Name + "\"" + newLine);
            HttpPostData.Write(stream, newLine);

            HttpPostData.Write(stream, Value);

            HttpPostData.Write(stream, newLine);
            HttpPostData.Write(stream, "--" + boundary + (isLast ? "--" : "") + newLine);
        }
Exemple #10
0
        private static void L_OnDataReceived(HttpPostData data)
        {
            Console.WriteLine($"Query string: {data.Query}");
            foreach (var header in data.Headers)
            {
                Console.WriteLine($"Header: {header.Name} Value: {header.Value}");
            }

            Console.WriteLine($"Data: {Encoding.UTF8.GetString(data.Message)}");
            Console.WriteLine();
        }
Exemple #11
0
        public void SetPostData()
        {
            IHttpPostData data = new HttpPostData {
                { "hello", "there" }
            };

            IHttpRequest request = HttpRequest
                                   .New()
                                   .SetPostData(data);

            Assert.AreEqual("hello=there", request.PostData.ToString());
        }
Exemple #12
0
        /// <summary>
        /// Asynchronously downloads a JSON object from a JSON stream.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">The URL.</param>
        /// <param name="token">The ESI token.</param>
        /// <param name="acceptEncoded">if set to <c>true</c> [accept encoded].</param>
        /// <param name="postData">The post data.</param>
        /// <returns></returns>
        public static async Task <JsonResult <T> > DownloadJsonAsync <T>(Uri url, string token,
                                                                         bool acceptEncoded = false, string postData = null, string postContentType = null)
            where T : class
        {
            // Create POST data body
            HttpPostData content = null;

            if (postData != null)
            {
                content = new HttpPostData(postData, contentType: postContentType);
            }
            JsonResult <T> result;

            try
            {
                DownloadResult <T> asyncResult = await HttpWebClientService.DownloadStreamAsync <T>(
                    url, ParseJSONObject <T>, acceptEncoded, content, token);

                var error = asyncResult.Error;
                T   data;

                // Was there an HTTP error?
                if (error != null)
                {
                    result = new JsonResult <T>(error);
                }
                else if ((data = asyncResult.Result) == default(T))
                {
                    // This will become a json error
                    result = new JsonResult <T>(new InvalidOperationException("null JSON response"));
                }
                else
                {
                    result = new JsonResult <T>(asyncResult.ResponseCode, data)
                    {
                        CurrentTime = asyncResult.ServerTime
                    }
                };
            }
            catch (InvalidOperationException e)
            {
                result = new JsonResult <T>(e);
                ExceptionHandler.LogException(e, true);
            }
            catch (InvalidDataContractException e)
            {
                result = new JsonResult <T>(e);
                ExceptionHandler.LogException(e, true);
            }

            return(result);
        }
        /// <summary>
        /// Writes the value to the specified <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">The stream the value should be written to.</param>
        /// <param name="boundary">The multipart boundary.</param>
        /// <param name="newLine">The characters used to indicate a new line.</param>
        /// <param name="isLast">Whether the value is the last in the request body.</param>
        public void WriteToMultipartStream(Stream stream, string boundary, string newLine, bool isLast)
        {
            HttpPostData.Write(stream, "--" + boundary + newLine);
            HttpPostData.Write(stream, "Content-Disposition: form-data; name=\"" + Name + "\"; filename=\"" + FileName + "\"" + newLine);
            HttpPostData.Write(stream, "Content-Type: " + ContentType + newLine);
            HttpPostData.Write(stream, newLine);

            stream.Write(Data, 0, Data.Length);

            HttpPostData.Write(stream, newLine);
            HttpPostData.Write(stream, newLine);
            HttpPostData.Write(stream, "--" + boundary + (isLast ? "--" : "") + newLine);
        }
Exemple #14
0
        /// <returns>An instance of <see cref="HttpResponse"/> representing the raw response.</returns>
        protected virtual IHttpResponse GetAccessTokenResponse(string verifier)
        {
            // Some error checking
            if (string.IsNullOrWhiteSpace(AccessTokenUrl))
            {
                throw new PropertyNotSetException(nameof(AccessTokenUrl));
            }

            // Initialize the POST data
            IHttpPostData postData = new HttpPostData();

            postData.Add("oauth_verifier", verifier);

            // Make the call to the API/provider
            return(Post(AccessTokenUrl, null, postData));
        }
Exemple #15
0
        /// <summary>
        /// Exchanges the specified authorization <paramref name="code"/> for a short-lived access token.
        /// </summary>
        /// <param name="code">The authorization code.</param>
        /// <returns>An instance of <see cref="InstagramShortLivedTokenResponse"/> representing the API response.</returns>
        /// <see>
        ///     <cref>https://developers.facebook.com/docs/instagram-basic-display-api/reference/oauth-access-token</cref>
        /// </see>
        public InstagramShortLivedTokenResponse GetAccessTokenFromAuthCode(string code)
        {
            // Initialize the POST data
            IHttpPostData post = new HttpPostData {
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "code", code },
                { "grant_type", "authorization_code" },
                { "redirect_uri", RedirectUri }
            };

            // Make a POST request to the API
            IHttpResponse response = HttpUtils.Requests.Post("https://api.instagram.com/oauth/access_token", post);

            // Wrap the raw response
            return(new InstagramShortLivedTokenResponse(response));
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpPostData"/>.</returns>
        public IHttpPostData GetPostData()
        {
            if (String.IsNullOrWhiteSpace(Name))
            {
                throw new ArgumentNullException(nameof(Name));
            }

            IHttpPostData data = new HttpPostData();

            data.Set("name", Name);
            data.Set("mode", StringUtils.ToCamelCase(Mode));
            if (!String.IsNullOrWhiteSpace(Description))
            {
                data.Add("description", Description);
            }

            return(data);
        }
Exemple #17
0
        /// <summary>
        /// Synchronously download an XML and deserializes it into the specified type
        /// </summary>
        /// <typeparam name="T">The inner type to deserialize</typeparam>
        /// <param name="url">The url to query</param>
        /// <param name="postData">The HTTP POST data to send, may be null.</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        internal static APIResult <T> DownloadAPIResult <T>(string url, HttpPostData postData, XslCompiledTransform transform)
        {
            APIResult <T> result = new APIResult <T>(APIErrors.Http, "Time out on querying " + url);

            // Query async and wait.
            using (var wait = new EventWaitHandle(false, EventResetMode.AutoReset))
            {
                EveClient.HttpWebService.DownloadXmlAsync(url, postData, (asyncResult, userState) =>
                {
                    try
                    {
                        // Was there an HTTP error ??
                        if (asyncResult.Error != null)
                        {
                            result = new APIResult <T>(asyncResult.Error);
                        }
                        // No http error, let's try to deserialize
                        else
                        {
                            result = DeserializeAPIResultCore <T>(transform, asyncResult.Result);
                        }
                    }
                    catch (Exception e)
                    {
                        ExceptionHandler.LogException(e, true);
                        result = new APIResult <T>(APIErrors.Http, e.Message);
                    }
                    finally
                    {
                        // We got the result, so we resume the calling thread
                        wait.Set();
                    }
                },
                                                          null);

                // Wait for the completion of the backgound thread.
                wait.WaitOne();
            }

            // Returns
            return(result);
        }
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Vimeo OAuth dialog.</param>
        /// <returns>An instance of <see cref="VimeoTokenResponse"/> representing the response.</returns>
        public VimeoTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (string.IsNullOrWhiteSpace(ClientId))
            {
                throw new PropertyNotSetException(nameof(ClientId));
            }
            if (string.IsNullOrWhiteSpace(ClientSecret))
            {
                throw new PropertyNotSetException(nameof(ClientSecret));
            }
            if (string.IsNullOrWhiteSpace(RedirectUri))
            {
                throw new PropertyNotSetException(nameof(RedirectUri));
            }
            if (string.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException(nameof(authCode));
            }

            // Initialize the POST data
            IHttpPostData data = new HttpPostData();

            data.Add("grant_type", "authorization_code");
            data.Add("code", authCode);
            data.Add("redirect_uri", RedirectUri);

            // Initialize the request
            IHttpRequest request = new HttpRequest {
                Method        = HttpMethod.Post,
                Url           = "https://api.vimeo.com/oauth/access_token",
                PostData      = data,
                Authorization = "basic " + SecurityUtils.Base64Encode(ClientId + ":" + ClientSecret)
            };

            // Make the call to the API
            IHttpResponse response = request.GetResponse();

            // Parse the response
            return(new VimeoTokenResponse(response));
        }
Exemple #19
0
        /// <summary>
        /// Asynchronously download an object from an XML stream.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">The url to download from</param>
        /// <param name="postData">The http POST data to pass with the url. May be null.</param>
        /// <param name="callback">A callback invoked on the UI thread</param>
        /// <returns></returns>
        public static void DownloadXMLAsync <T>(string url, HttpPostData postData, DownloadCallback <T> callback)
            where T : class
        {
            EveClient.HttpWebService.DownloadXmlAsync(url, postData,

                                                      // Callback
                                                      (asyncResult, userState) =>
            {
                T result            = null;
                string errorMessage = "";

                // Was there an HTTP error ??
                if (asyncResult.Error != null)
                {
                    errorMessage = asyncResult.Error.Message;
                }
                // No http error, let's try to deserialize
                else
                {
                    try
                    {
                        // Deserialize
                        using (XmlNodeReader reader = new XmlNodeReader(asyncResult.Result))
                        {
                            XmlSerializer xs = new XmlSerializer(typeof(T));
                            result           = (T)xs.Deserialize(reader);
                        }
                    }
                    // An error occured during the deserialization
                    catch (InvalidOperationException exc)
                    {
                        ExceptionHandler.LogException(exc, true);
                        errorMessage = (exc.InnerException == null ? exc.Message : exc.InnerException.Message);
                    }
                }

                // We got the result, let's invoke the callback on this actor
                Dispatcher.Invoke(() => callback.Invoke(result, errorMessage));
            },
                                                      null);
        }
Exemple #20
0
        /// <summary>
        /// Asynchronously download an XML and deserializes it into the specified type
        /// </summary>
        /// <typeparam name="T">The inner type to deserialize</typeparam>
        /// <param name="url">The url to query</param>
        /// <param name="postData">The HTTP POST data to send, may be null.</param>
        /// <param name="transform">The XSL transform to apply, may be null.</param>
        /// <param name="callback">The callback to call once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        internal static void DownloadAPIResultAsync <T>(string url, HttpPostData postData, XslCompiledTransform transform, QueryCallback <T> callback)
        {
            EveClient.HttpWebService.DownloadXmlAsync(url, postData, (asyncResult, userState) =>
            {
                APIResult <T> result;

                // Was there an HTTP error ?
                if (asyncResult.Error != null)
                {
                    result = new APIResult <T>(asyncResult.Error);
                }
                // No http error, let's try to deserialize
                else
                {
                    result = DeserializeAPIResultCore <T>(transform, asyncResult.Result);
                }

                // We got the result, let's invoke the callback on this actor
                Dispatcher.Invoke(() => callback.Invoke(result));
            },
                                                      null);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        /// <returns>An instance of <see cref="IHttpPostData"/>.</returns>
        public IHttpPostData GetPostData()
        {
            // Validate required properties
            if (String.IsNullOrWhiteSpace(Status))
            {
                throw new PropertyNotSetException(nameof(Status));
            }

            // Initialize a new instance with required parameters
            IHttpPostData data = new HttpPostData();

            data.Set("status", Status);

            // Append optional parameters to be POST data
            if (ReplyTo > 0)
            {
                data.Add("in_reply_to_status_id", ReplyTo);
            }
            if (IsPossiblySensitive)
            {
                data.Add("possibly_sensitive", "true");
            }
            if (Math.Abs(Latitude) > Double.Epsilon && Math.Abs(Longitude) > Double.Epsilon)
            {
                data.Add("lat", Latitude);
                data.Add("long", Longitude);
            }
            if (PlaceId != null)
            {
                data.Add("place_id", PlaceId);
            }
            if (DisplayCoordinates)
            {
                data.Add("display_coordinates", "true");
            }

            return(data);
        }
        /// <summary>
        /// Gets an instance of <see cref="IHttpPostData"/> representing the POST parameters.
        /// </summary>
        public IHttpPostData GetPostData()
        {
            IHttpPostData postData = new HttpPostData();

            if (string.IsNullOrWhiteSpace(Message) == false)
            {
                postData.Add("message", Message);
            }
            if (string.IsNullOrWhiteSpace(Link) == false)
            {
                postData.Add("link", Link);
            }
            if (string.IsNullOrWhiteSpace(Picture) == false)
            {
                postData.Add("picture", Picture);
            }
            if (string.IsNullOrWhiteSpace(Name) == false)
            {
                postData.Add("name", Name);
            }
            if (string.IsNullOrWhiteSpace(Caption) == false)
            {
                postData.Add("caption", Caption);
            }
            if (string.IsNullOrWhiteSpace(Description) == false)
            {
                postData.Add("description", Description);
            }
            if (string.IsNullOrWhiteSpace(Place) == false)
            {
                postData.Add("place", Place);
            }
            if (Tags != null && Tags.Length > 0)
            {
                postData.Add("tags", string.Join(",", Tags));
            }
            return(postData);
        }
Exemple #23
0
        /// <summary>
        /// Exchanges the specified authorization code for an access token.
        /// </summary>
        /// <param name="authCode">The authorization code received from the Mailchimp OAuth dialog.</param>
        /// <returns>An access token based on the specified <paramref name="authCode"/>.</returns>
        public MailchimpTokenResponse GetAccessTokenFromAuthCode(string authCode)
        {
            // Some validation
            if (String.IsNullOrWhiteSpace(authCode))
            {
                throw new ArgumentNullException(nameof(authCode));
            }

            // Initialize the query string
            IHttpPostData query = new HttpPostData {
                { "grant_type", "authorization_code" },
                { "client_id", ClientId },
                { "client_secret", ClientSecret },
                { "redirect_uri", RedirectUri },
                { "code", authCode }
            };

            // Make the call to the API
            IHttpResponse response = HttpUtils.Http.DoHttpPostRequest("https://login.mailchimp.com/oauth2/token", null, query);

            // Parse the response
            return(MailchimpTokenResponse.ParseResponse(response));
        }
Exemple #24
0
        public void GenerateSignature()
        {
            // These are not real tokens, but randomly generated GUIDs
            const string a = "45b998c8-3ee3-4cb0-86c8-ef4ef81e52fe";
            const string b = "afee51a6-6aca-49a2-9d3e-084b4d372a97";
            const string c = "401fdd6d-4708-4174-ad2e-29c6ea054ec6";
            const string d = "3642df43-fc23-469e-9d5b-4bee66b5fc4b";

            const string timestamp = "1568285417";
            const string nonce     = "a random value";

            OAuthClient client = new OAuthClient {
                ConsumerKey    = a,
                ConsumerSecret = b,
                Token          = c,
                TokenSecret    = d,
                AutoReset      = false,
                Nonce          = nonce,
                Timestamp      = timestamp
            };

            HttpQueryString query = new HttpQueryString {
                { "hello", "world" }
            };

            HttpPostData post = new HttpPostData {
                { "alpha", "bravo" }
            };

            string signature = client.GenerateSignature(HttpMethod.Post, "https://example.org/", query, post);

            Assert.AreEqual("hcmLTxgZgsZuTh9ywU68PFGZLL0=", signature);

            string header = client.GenerateHeaderString(signature);

            Assert.AreEqual("OAuth realm=\"\",oauth_consumer_key=\"45b998c8-3ee3-4cb0-86c8-ef4ef81e52fe\",oauth_nonce=\"a%20random%20value\",oauth_signature=\"hcmLTxgZgsZuTh9ywU68PFGZLL0%3D\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1568285417\",oauth_token=\"401fdd6d-4708-4174-ad2e-29c6ea054ec6\",oauth_version=\"1.0\"", header);
        }
Exemple #25
0
        /// <summary>
        /// Query the characters list for the provided account.
        /// </summary>
        /// <param name="userID">The account's ID</param>
        /// <param name="apiKey">The account's API key</param>
        public APIResult <SerializableAPICharacters> QueryCharactersList(long userID, string apiKey)
        {
            HttpPostData postData = new HttpPostData(String.Format("userID={0}&apiKey={1}", userID, apiKey));

            return(QueryMethod <SerializableAPICharacters>(APIMethods.CharacterList, postData, RowsetsTransform));
        }
Exemple #26
0
        /// <summary>
        /// Query a method with the provided arguments for a character.
        /// </summary>
        /// <typeparam name="T">The type of the deserialization object.</typeparam>
        /// <param name="method"></param>
        /// <param name="userID"></param>
        /// <param name="apiKey"></param>
        /// <param name="charID"></param>
        /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        public void QueryMethodAsync <T>(APIMethods method, long userID, string apiKey, long charID, QueryCallback <T> callback)
        {
            HttpPostData postData = new HttpPostData("userID=" + userID + "&apiKey=" + apiKey + "&characterID=" + charID.ToString());

            QueryMethodAsync <T>(method, postData, RowsetsTransform, callback);
        }
Exemple #27
0
        /// <summary>
        /// Query the account balance for a character. Requires full api key. Used to test whether a key is a full or limited one.
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="apiKey"></param>
        /// <param name="charID"></param>
        /// <returns></returns>
        public APIResult <SerializableAPIAccountBalance> QueryCharacterAccountBalance(long userID, string apiKey, long charID)
        {
            HttpPostData postData = new HttpPostData(String.Format("userID={0}&apiKey={1}&characterID={2}", userID, apiKey, charID));

            return(QueryMethod <SerializableAPIAccountBalance>(APIMethods.CharacterAccountBalance, postData, RowsetsTransform));
        }
Exemple #28
0
        /// <summary>
        /// Query the status for the provided account. Requires full api key.
        /// </summary>
        /// <param name="userID">The account's ID</param>
        /// <param name="apiKey">The account's API key</param>
        public APIResult <SerializableAPIAccountStatus> QueryAccountStatus(long userID, string apiKey)
        {
            HttpPostData postData = new HttpPostData(String.Format("userID={0}&apiKey={1}", userID, apiKey));

            return(QueryMethod <SerializableAPIAccountStatus>(APIMethods.AccountStatus, postData, RowsetsTransform));
        }
Exemple #29
0
        /// <summary>
        /// Query the character name from the provided list of IDs.
        /// </summary>
        public APIResult <SerializableAPICharacterName> QueryCharacterName(string IDs)
        {
            HttpPostData postData = new HttpPostData(String.Format("ids={0}", IDs));

            return(QueryMethod <SerializableAPICharacterName>(APIMethods.CharacterName, postData, RowsetsTransform));
        }
Exemple #30
0
        /// <summary>
        /// Query a method with the provided arguments for an account.
        /// </summary>
        /// <typeparam name="T">The type of the deserialization object.</typeparam>
        /// <param name="method"></param>
        /// <param name="userID"></param>
        /// <param name="apiKey"></param>
        /// <param name="callback">The callback to invoke once the query has been completed. It will be done on the data actor (see <see cref="DataObject.CommonActor"/>).</param>
        public void QueryMethodAsync <T>(APIMethods method, long userID, string apiKey, QueryCallback <T> callback)
        {
            HttpPostData postData = new HttpPostData(String.Format("userID={0}&apiKey={1}", userID, apiKey));

            QueryMethodAsync <T>(method, postData, RowsetsTransform, callback);
        }