/// <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); }
internal void InitializeRequest(HttpWebRequest request, HyvesMethod method, bool useFancyLayout, int page, int resultsPerPage, HyvesSession session) { request.Method = "POST"; SetRequestMetadata(request, method, useFancyLayout, page, resultsPerPage, session); InitializeFormRequest(request); }
private static HttpWebRequest CreateRequest(HyvesMethod method, bool useFancyLayout, int page, int resultsPerPage, HyvesSession session, HyvesRequestParameterList parameters) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HyvesHttpUri); parameters.InitializeRequest(request, method, useFancyLayout, page, resultsPerPage, session); return(request); }
/// <summary> /// Starts an asynchronous call to invoke the specified method. /// </summary> /// <param name="method">The name of the API method to invoke.</param> /// <param name="callback">The async callback that is invoked when the request completes.</param> /// <param name="asyncState">The state to associate with the asynchronous call.</param> /// <returns>An async result that represents the asynchronous call.</returns> public IAsyncResult BeginInvokeMethod(HyvesMethod method, AsyncCallback callback, object asyncState) { if (this.asyncRequest != null) { throw new InvalidOperationException("A method is currently being invoked using this request."); } this.asyncMethod = method; this.asyncRequest = CreateRequest(method, this.session, parameters); return(this.asyncRequest.BeginGetResponse(callback, asyncState)); }
private void SetRequestMetadata(HttpWebRequest request, HyvesMethod method, bool useFancyLayout, int page, int resultsPerPage, HyvesSession session) { string url = request.RequestUri.ToString(); this["ha_method"] = EnumHelper.GetDescription(method); this["ha_version"] = session.Version; this["ha_format"] = "json"; this["ha_fancylayout"] = useFancyLayout.ToString().ToLower(); if (page > 0) { this["ha_page"] = page.ToString(); } if (resultsPerPage > 0) { this["ha_resultsperpage"] = resultsPerPage.ToString(); } StringBuilder requestBuilder = new StringBuilder(512); foreach (KeyValuePair <string, string> param in this) { if (requestBuilder.Length != 0) { requestBuilder.Append("&"); } requestBuilder.Append(param.Key); requestBuilder.Append("="); requestBuilder.Append(param.Value); } string timeStamp = oauth.GenerateTimeStamp(); string nonce = this.oauth.GenerateNonce(); if (string.IsNullOrEmpty(session.Token) == false) { this["oauth_token"] = session.Token; } this["oauth_consumer_key"] = session.ConsumerKey; this["oauth_timestamp"] = timeStamp; this["oauth_nonce"] = nonce; this["oauth_version"] = "1.0"; this["oauth_signature_method"] = "HMAC-SHA1"; this["oauth_signature"] = this.oauth.GenerateSignature(new Uri(url), this, session.ConsumerKey, session.ConsumerSecret, session.Token, session.TokenSecret, request.Method, timeStamp, nonce); }
internal HyvesResponse(Stream responseStream, HyvesMethod method) { this.method = method; paginateInformation = null; StreamReader streamReader = new StreamReader(responseStream); this.rawResponse = streamReader.ReadToEnd(); try { JsonReader jsonReader = new JsonReader(new StringReader(this.rawResponse)); object result = jsonReader.ReadValue(); Hashtable jsonObject = result as Hashtable; if (jsonObject != null) { object errorCode = jsonObject["error_code"]; if (errorCode != null) { this.status = (HyvesResponseStatus)(int)errorCode; message = (string)jsonObject["error_message"]; } Hashtable info = jsonObject["info"] as Hashtable; if (info != null) { this.timestampDifference = (int)info["timestamp_difference"]; this.runningMilliseconds = (int)info["running_milliseconds"]; this.paginateInformation = new HyvesPaginateInformation(info); } } if (this.status == HyvesResponseStatus.Succeeded) { this.result = result; } } catch { this.status = HyvesResponseStatus.UnknownError; } }
private static string GetMethods(HyvesMethod hyvesMethod) { StringBuilder methods = new StringBuilder(); // return "albums.addMedia"; // Getting string for all methods if (hyvesMethod == HyvesMethod.All) { Array hyvesMethodValues = Enum.GetValues(typeof(HyvesMethod)); foreach (HyvesMethod method in hyvesMethodValues) { if (method != HyvesMethod.Unknown && method != HyvesMethod.All) { methods.Append(string.Format("{0},", EnumHelper.GetDescription(method))); } } return methods.ToString().Substring(0,methods.Length-1); } // String for one method return EnumHelper.GetDescription(hyvesMethod); }
private static string GetMethods(HyvesMethod hyvesMethod) { //ToDo: fix hyves method to be sync with hyves api 2.0 methods return "albums.getByUser,media.getByAlbum"; StringBuilder methods = new StringBuilder(); // Getting string for all methods if (hyvesMethod == HyvesMethod.All) { Array hyvesMethodValues = Enum.GetValues(typeof(HyvesMethod)); foreach (HyvesMethod method in hyvesMethodValues) { if (method != HyvesMethod.Unknown && method != HyvesMethod.All) { methods.Append(string.Format("{0},", EnumHelper.GetDescription(method))); } } return methods.ToString(); } // String for one method return EnumHelper.GetDescription(hyvesMethod); }
/// <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); }
private static HttpWebRequest CreateRequest(HyvesMethod method, bool useFancyLayout, HyvesSession session, HyvesRequestParameterList parameters) { return CreateRequest(method, useFancyLayout, session, parameters); }
private static HttpWebRequest CreateRequest(HyvesMethod method, HyvesSession session, HyvesRequestParameterList parameters) { return(CreateRequest(method, session, parameters)); }
private static HttpWebRequest CreateRequest(HyvesMethod method, bool useFancyLayout, HyvesSession session, HyvesRequestParameterList parameters) { return(CreateRequest(method, useFancyLayout, session, parameters)); }
internal HyvesResponse(HttpStatusCode errorStatusCode, HyvesMethod method) { status = (HyvesResponseStatus)((uint)HyvesResponseStatus.HttpError | (uint)errorStatusCode); this.method = method; }
internal void InitializeRequest(HttpWebRequest request, HyvesMethod method, bool useFancyLayout, HyvesSession session) { InitializeRequest(request, method, useFancyLayout, -1, -1, session); }
/// <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> /// <returns>The resulting response.</returns> public HyvesResponse InvokeMethod(HyvesMethod method, bool useFancyLayout) { return InvokeMethod(method, useFancyLayout, -1, -1); }
/// <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; }
/// <summary> /// Invokes the specified API method. /// </summary> /// <param name="method">The name of the API method to invoke.</param> /// <returns>The resulting response.</returns> public HyvesResponse InvokeMethod(HyvesMethod method) { return InvokeMethod(method, false); }
internal void InitializeRequest(HttpWebRequest request, HyvesMethod method, int page, int resultsPerPage, HyvesSession session) { InitializeRequest(request, method, false, page, resultsPerPage, session); }
/// <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> /// <returns>The resulting response.</returns> public HyvesResponse InvokeMethod(HyvesMethod method, bool useFancyLayout) { return(InvokeMethod(method, useFancyLayout, -1, -1)); }
/// <summary> /// Starts an asynchronous call to invoke the specified method. /// </summary> /// <param name="method">The name of the API method to invoke.</param> /// <param name="callback">The async callback that is invoked when the request completes.</param> /// <param name="asyncState">The state to associate with the asynchronous call.</param> /// <returns>An async result that represents the asynchronous call.</returns> public IAsyncResult BeginInvokeMethod(HyvesMethod method, AsyncCallback callback, object asyncState) { if (this.asyncRequest != null) { throw new InvalidOperationException("A method is currently being invoked using this request."); } this.asyncMethod = method; this.asyncRequest = CreateRequest(method, this.session, parameters); return this.asyncRequest.BeginGetResponse(callback, asyncState); }
private static HttpWebRequest CreateRequest(HyvesMethod method, HyvesSession session, HyvesRequestParameterList parameters) { return CreateRequest(method, session, parameters); }
/// <summary> /// Invokes the specified API method. /// </summary> /// <param name="method">The name of the API method to invoke.</param> /// <returns>The resulting response.</returns> public HyvesResponse InvokeMethod(HyvesMethod method) { return(InvokeMethod(method, false)); }
private static HttpWebRequest CreateRequest(HyvesMethod method, bool useFancyLayout, int page, int resultsPerPage, HyvesSession session, HyvesRequestParameterList parameters) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(HyvesHttpUri); parameters.InitializeRequest(request, method, useFancyLayout, page, resultsPerPage, session); return request; }
/// <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; }
internal void InitializeRequest(HttpWebRequest request, HyvesMethod method, HyvesSession session) { InitializeRequest(request, method, false, -1, -1, session); }