/// <summary>
        /// Completes an asynchronous call to invoke an API method.
        /// </summary>
        /// <param name="asyncResult">The async result from the corresponding BeginCreateAccessToken call.</param>
        /// <returns>The resulting response.</returns>
        public HyvesResponse EndInvokeMethod(IAsyncResult asyncResult)
        {
            if (asyncRequest == null)
            {
                throw new InvalidOperationException("No method is currently being invoked using this request.");
            }

            HyvesResponse response = null;

            try
            {
                HttpWebResponse webResponse = (HttpWebResponse)asyncRequest.EndGetResponse(asyncResult);
                if (webResponse.StatusCode != HttpStatusCode.OK)
                {
                    response = new HyvesResponse(webResponse.StatusCode, asyncMethod);
                }
                else
                {
                    Stream responseStream = webResponse.GetResponseStream();
                    response = new HyvesResponse(responseStream, asyncMethod);
                }
            }
            finally
            {
                asyncRequest = null;
                asyncMethod  = HyvesMethod.Unknown;
            }

            session.LogResponse(response);
            return(response);
        }
        /// <summary>
        /// Creates a request token. This corresponds to the Hyves auth.requesttoken method.
        /// </summary>
        /// <param name="requestTokenSecret">The request token secret to use to sign the request.</param>
        /// <returns>A new requesttoken on success.</returns>
        public string CreateRequestToken(out string tokenSecret, HyvesExpirationType expirationType)
        {
            tokenSecret = string.Empty;
            string          token       = null;
            HttpWebResponse webResponse = null;

            HttpWebRequest webRequest = CreateRequest(null, null, expirationType, session);

            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException we)
            {
                webResponse = (HttpWebResponse)we.Response;
            }

            HyvesResponse requestTokenResponse = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown);

            if (requestTokenResponse.IsError == false)
            {
                Hashtable result = requestTokenResponse.Result as Hashtable;
                if (result != null)
                {
                    token = (string)result["oauth_token"];

                    tokenSecret = (string)result["oauth_token_secret"];
                }
            }

            return(token);
        }
        /// <summary>
        /// Creates a new access token. This corresponds to the Hyves auth.accesstoken method.
        /// </summary>
        /// <param name="requestToken">The request token to use to create the access token.</param>
        /// <param name="requestTokenSecret">The request token secret to use to sign the request.</param>
        /// <param name="tokenSecret"></param>
        /// <param name="userId">The user Id associated with the session.</param>
        /// <param name="expireDate">Date when the created access token expireDate.</param>
        /// <returns>A access token.</returns>
        public string CreateAccessToken(string requestToken, string requestTokenSecret, out string tokenSecret, out string userId, out DateTime expireDate)
        {
            tokenSecret = string.Empty;
            userId      = string.Empty;
            expireDate  = DateTime.Now;

            if (string.IsNullOrEmpty(requestToken))
            {
                throw new ArgumentException("requestToken");
            }

            if (string.IsNullOrEmpty(requestTokenSecret))
            {
                throw new ArgumentException("requestTokenSecret");
            }

            string token = null;

            HttpWebRequest  webRequest  = CreateRequest(requestToken, requestTokenSecret, HyvesExpirationType.Default, session);
            HttpWebResponse webResponse = null;

            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException we)
            {
                webResponse = (HttpWebResponse)we.Response;
            }

            if (webResponse.StatusCode == HttpStatusCode.OK)
            {
                HyvesResponse sessionResponse = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown);
                if (sessionResponse.IsError == false)
                {
                    Hashtable result = sessionResponse.Result as Hashtable;
                    if (result != null)
                    {
                        token       = (string)result["oauth_token"];
                        tokenSecret = (string)result["oauth_token_secret"];
                        userId      = (string)result["userid"];
                        expireDate  = HyvesResponse.CoerceDateTime(result["expiredate"]);
                    }
                }
            }

            return(token);
        }
        /// <summary>
        /// Completes an asynchronous call to create an new access token.
        /// </summary>
        /// <param name="asyncResult">The async result from the corresponding BeginCreateAccessToken call.</param>
        /// <param name="tokenSecret"></param>
        /// <param name="userId">The user Id associated with the access token.</param>
        /// <param name="expireDate">Date when the created access token expireDate.</param>
        /// <returns>A new access token.</returns>
        public string EndCreateAccessToken(IAsyncResult asyncResult, out string tokenSecret, out string userId, out DateTime expireDate)
        {
            tokenSecret = string.Empty;
            userId      = string.Empty;
            expireDate  = DateTime.Now;

            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }

            if (asyncRequest == null)
            {
                throw new InvalidOperationException("No method is currently being invoked using this request.");
            }

            string token = null;

            try
            {
                HttpWebResponse webResponse = (HttpWebResponse)asyncRequest.EndGetResponse(asyncResult);

                if (webResponse.StatusCode == HttpStatusCode.OK)
                {
                    HyvesResponse accessResponse = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown);
                    if (accessResponse.IsError == false)
                    {
                        Hashtable result = accessResponse.Result as Hashtable;
                        if (result != null)
                        {
                            token       = (string)result["oauth_token"];
                            tokenSecret = (string)result["oauth_token_secret"];
                            userId      = (string)result["userid"];
                            expireDate  = HyvesResponse.CoerceDateTime(result["expiredate"]);
                        }
                    }
                }
            }
            finally
            {
                asyncRequest = null;
            }

            return(token);
        }
        /// <summary>
        /// Completes an asynchronous call to create an request token.
        /// </summary>
        /// <param name="asyncResult">The async result from the corresponding BeginCreateRequestToken call.</param>
        /// <param name="requestTokenSecret"></param>
        /// <returns>A new request token on success.</returns>
        public string EndCreateRequestToken(IAsyncResult asyncResult, out string requestTokenSecret)
        {
            requestTokenSecret = string.Empty;

            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            if (asyncRequest == null)
            {
                throw new InvalidOperationException("No method is currently being invoked using this request.");
            }

            string requestToken = null;

            try
            {
                HttpWebResponse webResponse = (HttpWebResponse)asyncRequest.EndGetResponse(asyncResult);

                if (webResponse.StatusCode == HttpStatusCode.OK)
                {
                    HyvesResponse requestTokenResponse = new HyvesResponse(webResponse.GetResponseStream(), HyvesMethod.Unknown);
                    if (requestTokenResponse.IsError == false)
                    {
                        Hashtable result = (Hashtable)requestTokenResponse.Result;

                        requestToken       = (string)result["oauth_token"];
                        requestTokenSecret = (string)result["oauth_token_secret"];
                    }
                }
            }
            finally
            {
                asyncRequest = null;
            }

            return(requestToken);
        }
        /// <summary>
        /// Invokes the specified API method.
        /// </summary>
        /// <param name="method">The name of the API method to invoke.</param>
        /// <param name="method">Indicate if the response must be converted to fancy layout (smilies etc.).</param>
        /// <param name="page">The .</param>
        /// <param name="resultsPerPage">Number of results in the resultset</param>
        /// <returns>The resulting response.</returns>
        public HyvesResponse InvokeMethod(HyvesMethod method, bool useFancyLayout, int page, int resultsPerPage)
        {
            HttpWebRequest webRequest = CreateRequest(method, useFancyLayout, page, resultsPerPage, session, parameters);

            HyvesResponse response = null;

            HttpWebResponse webResponse = null;

            try
            {
                webResponse = (HttpWebResponse)webRequest.GetResponse();
            }
            catch (WebException we)
            {
                webResponse = (HttpWebResponse)we.Response;
            }

            Stream responseStream = webResponse.GetResponseStream();

            response = new HyvesResponse(responseStream, method);

            session.LogResponse(response);
            return(response);
        }
Beispiel #7
0
 internal void LogResponse(HyvesResponse response)
 {
     this.lastResponse = response;
 }