/// <summary> /// Notifies a subscriber that a post has already happened. /// </summary> /// <param name="arguments">Arguments for the call</param> internal static void OnAfterPost(ServicePostEventArgs arguments) { if (AfterPost != null) { AfterPost(Service.Instance, arguments); } }
/// <summary> /// Notifies subscribers that a post is about to happen. /// </summary> /// <param name="arguments">Arguments for the call</param> internal static void OnBeforePost(ServicePostEventArgs arguments) { if (BeforePost != null) { BeforePost(Service.Instance, arguments); } }
/// <summary> /// Uploads a document into Scribd asynchronously. /// </summary> /// <param name="request"></param> internal void PostFileUploadRequest(Request request) { // Set up our Event arguments for subscribers. ServicePostEventArgs _args = new ServicePostEventArgs(request.RESTCall, request.MethodName); // Give subscribers a chance to stop this before it gets ugly. OnBeforePost(_args); if (!_args.Cancel) { // Ensure we have the min. necessary params. if (string.IsNullOrEmpty(Service.APIKey)) { OnErrorOccurred(10000, Properties.Resources.ERR_NO_APIKEY); return; } else if (Service.SecretKeyBytes == null) { OnErrorOccurred(10001, Properties.Resources.ERR_NO_SECRETKEY); return; } if (!request.SpecifiedUser) { // Hook up our current user. request.User = InternalUser; } try { // Set up our client to call API using (WebClient _client = new WebClient()) { // Set up the proxy, if available. if (Service.WebProxy != null) { _client.Proxy = Service.WebProxy; } // Special case - need to upload multi-part POST if (request.MethodName == "docs.upload" || request.MethodName == "docs.uploadThumb") { // Get our filename from the request, then dump it! // (Scribd doesn't like passing the literal "file" param.) string _fileName = request.Parameters["file"]; request.Parameters.Remove("file"); // Make that call. _client.UploadProgressChanged += new UploadProgressChangedEventHandler(_client_UploadProgressChanged); _client.UploadFileCompleted += new UploadFileCompletedEventHandler(_client_UploadFileCompleted); _client.UploadFileAsync(new Uri(request.RESTCall), "POST", _fileName); } else { return; } } } catch (Exception ex) { // Something unexpected? OnErrorOccurred(666, ex.Message, ex); } finally { OnAfterPost(_args); } } return; }
/// <summary> /// Send a request to Scribd /// </summary> /// <param name="request">The request data</param> /// <returns><see cref="T:Scribd.Net.Response"/></returns> internal Response PostRequest(Request request) { // Get started Response _result = null; // Set up our Event arguments for subscribers. ServicePostEventArgs _args = new ServicePostEventArgs(request.RESTCall, request.MethodName); // Give subscribers a chance to stop this before it gets ugly. OnBeforePost(_args); if (!_args.Cancel) { // Ensure we have the min. necessary params. if (string.IsNullOrEmpty(Service.APIKey)) { OnErrorOccurred(10000, Properties.Resources.ERR_NO_APIKEY); return _result; } else if (Service.SecretKeyBytes == null) { OnErrorOccurred(10001, Properties.Resources.ERR_NO_SECRETKEY); return _result; } if (!request.SpecifiedUser) { // Hook up our current user. request.User = InternalUser; } try { // Set up our client to call API using (WebClient _client = new WebClient()) { _client.Headers.Add("user-agent", Service.UserAgent); // Set up the proxy, if available. if (Service.WebProxy != null) { _client.Proxy = Service.WebProxy; } // Make the call and get the response. string _xml = string.Empty; // Special case - need to upload multi-part POST if (request.MethodName == "docs.upload") { // Get our filename from the request, then dump it! // (Scribd doesn't like passing the literal "file" param.) string _fileName = request.Parameters["file"]; request.Parameters.Remove("file"); byte[] _resp = FileUploader(_fileName, request.RESTCall, string.Empty); // Get the response _xml = System.Text.Encoding.Default.GetString(_resp); } else { _xml = _client.DownloadString(request.ToString()); } // Load up the resultant XML _result = new Response(_xml); // Are we cool? if (_result.Status != "ok") { foreach (int _code in _result.ErrorList.Keys) { // Let the subscribers know, cuz they care. OnErrorOccurred(_code, _result.ErrorList[_code]); } } // Append the response to the AfterPost event. _args.ResponseXML = _result.InnerXml; } } catch (Exception ex) { // Something unexpected? OnErrorOccurred(666, ex.Message, ex); } finally { OnAfterPost(_args); } } // Load up response here ... return _result; }
/// <summary> /// Send a request to Scribd /// </summary> /// <param name="request">The request data</param> /// <returns><see cref="T:Scribd.Net.Response"/></returns> internal Response PostRequest(Request request) { // Get started Response _result = null; // Set up our Event arguments for subscribers. ServicePostEventArgs _args = new ServicePostEventArgs(request.RESTCall, request.MethodName); // Give subscribers a chance to stop this before it gets ugly. OnBeforePost(_args); if (!_args.Cancel) { // Ensure we have the min. necessary params. if (string.IsNullOrEmpty(Service.APIKey)) { OnErrorOccurred(10000, Properties.Resources.ERR_NO_APIKEY); return(_result); } else if (Service.SecretKeyBytes == null) { OnErrorOccurred(10001, Properties.Resources.ERR_NO_SECRETKEY); return(_result); } if (!request.SpecifiedUser) { // Hook up our current user. request.User = InternalUser; } try { // Set up our client to call API using (WebClient _client = new WebClient()) { _client.Headers.Add("user-agent", Service.UserAgent); // Set up the proxy, if available. if (Service.WebProxy != null) { _client.Proxy = Service.WebProxy; } // Make the call and get the response. string _xml = string.Empty; // Special case - need to upload multi-part POST if (request.MethodName == "docs.upload") { // Get our filename from the request, then dump it! // (Scribd doesn't like passing the literal "file" param.) string _fileName = request.Parameters["file"]; request.Parameters.Remove("file"); byte[] _resp = FileUploader(_fileName, request.RESTCall, string.Empty); // Get the response _xml = System.Text.Encoding.Default.GetString(_resp); } else { _xml = _client.DownloadString(request.ToString()); } // Load up the resultant XML _result = new Response(_xml); // Are we cool? if (_result.Status != "ok") { foreach (int _code in _result.ErrorList.Keys) { // Let the subscribers know, cuz they care. OnErrorOccurred(_code, _result.ErrorList[_code]); } } // Append the response to the AfterPost event. _args.ResponseXML = _result.InnerXml; } } catch (Exception ex) { // Something unexpected? OnErrorOccurred(666, ex.Message, ex); } finally { OnAfterPost(_args); } } // Load up response here ... return(_result); }