diff --git a/UploadersLib/FileUploaders/Box.cs b/UploadersLib/FileUploaders/Box.cs index 4b7acdd98..c8ff74822 100644 --- a/UploadersLib/FileUploaders/Box.cs +++ b/UploadersLib/FileUploaders/Box.cs @@ -195,7 +195,7 @@ public override UploadResult Upload(Stream stream, string fileName) Dictionary args = new Dictionary(); args.Add("parent_id", FolderID); - UploadResult result = UploadData(stream, "https://upload.box.com/api/2.0/files/content", fileName, "filename", args, headers: GetAuthHeaders()); + UploadResult result = UploadData(stream, "https://upload.box.com/api/2.0/files/content", fileName, "filename", args, GetAuthHeaders()); if (result.IsSuccess) { diff --git a/UploadersLib/FileUploaders/Copy.cs b/UploadersLib/FileUploaders/Copy.cs index 1f26646c2..840bc4eaf 100644 --- a/UploadersLib/FileUploaders/Copy.cs +++ b/UploadersLib/FileUploaders/Copy.cs @@ -91,7 +91,7 @@ public CopyAccountInfo GetAccountInfo() { string query = OAuthManager.GenerateQuery(URLAccountInfo, null, HttpMethod.GET, AuthInfo); - string response = SendRequest(HttpMethod.GET, query, null, ResponseType.Text, APIHeaders); + string response = SendRequest(HttpMethod.GET, query, null, APIHeaders, responseType: ResponseType.Text); if (!string.IsNullOrEmpty(response)) { @@ -143,7 +143,7 @@ public UploadResult UploadFile(Stream stream, string path, string fileName) string query = OAuthManager.GenerateQuery(url, args, HttpMethod.POST, AuthInfo); // There's a 1GB and 5 hour(max time for a single upload) limit to all uploads through the API. - UploadResult result = UploadData(stream, query, fileName, "file", null, null, APIHeaders); + UploadResult result = UploadData(stream, query, fileName, "file", headers: APIHeaders); if (result.IsSuccess) { diff --git a/UploadersLib/FileUploaders/Dropbox.cs b/UploadersLib/FileUploaders/Dropbox.cs index e951d3e67..f29f7bb74 100644 --- a/UploadersLib/FileUploaders/Dropbox.cs +++ b/UploadersLib/FileUploaders/Dropbox.cs @@ -216,7 +216,7 @@ public DropboxContentInfo GetMetadata(string path, bool list) Dictionary args = new Dictionary(); args.Add("list", list ? "true" : "false"); - string response = SendRequest(HttpMethod.GET, url, args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.GET, url, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { @@ -243,7 +243,7 @@ public string CreateShareableLink(string path, DropboxURLType urlType) Dictionary args = new Dictionary(); args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false"); - string response = SendRequest(HttpMethod.POST, url, args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.POST, url, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { @@ -287,7 +287,7 @@ public DropboxContentInfo Copy(string from_path, string to_path) args.Add("from_path", from_path); args.Add("to_path", to_path); - string response = SendRequest(HttpMethod.POST, URLCopy, args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.POST, URLCopy, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { @@ -309,7 +309,7 @@ public DropboxContentInfo CreateFolder(string path) args.Add("root", Root); args.Add("path", path); - string response = SendRequest(HttpMethod.POST, URLCreateFolder, args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.POST, URLCreateFolder, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { @@ -331,7 +331,7 @@ public DropboxContentInfo Delete(string path) args.Add("root", Root); args.Add("path", path); - string response = SendRequest(HttpMethod.POST, URLDelete, args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.POST, URLDelete, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { @@ -354,7 +354,7 @@ public DropboxContentInfo Move(string from_path, string to_path) args.Add("from_path", from_path); args.Add("to_path", to_path); - string response = SendRequest(HttpMethod.POST, URLMove, args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.POST, URLMove, args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { diff --git a/UploadersLib/FileUploaders/GoogleDrive.cs b/UploadersLib/FileUploaders/GoogleDrive.cs index ca34ac2e0..82a0823f6 100644 --- a/UploadersLib/FileUploaders/GoogleDrive.cs +++ b/UploadersLib/FileUploaders/GoogleDrive.cs @@ -161,7 +161,7 @@ private void SetMetadata(string fileID, string title, string parentID = null) string json = JsonConvert.SerializeObject(metadata); - string response = SendRequestJSON(url, json, headers: GetAuthHeaders(), method: HttpMethod.PUT); + string response = SendRequestJSON(url, json, GetAuthHeaders(), method: HttpMethod.PUT); } private void SetPermissions(string fileID, GoogleDrivePermissionRole role, GoogleDrivePermissionType type, string value, bool withLink) @@ -176,7 +176,7 @@ private void SetPermissions(string fileID, GoogleDrivePermissionRole role, Googl withLink = withLink.ToString() }); - string response = SendRequestJSON(url, json, headers: GetAuthHeaders()); + string response = SendRequestJSON(url, json, GetAuthHeaders()); } public List GetFolders(bool trashed = false, bool writer = true) @@ -198,7 +198,7 @@ public List GetFolders(bool trashed = false, bool writer = true Dictionary args = new Dictionary(); args.Add("q", query); - string response = SendRequest(HttpMethod.GET, "https://www.googleapis.com/drive/v2/files", args, headers: GetAuthHeaders()); + string response = SendRequest(HttpMethod.GET, "https://www.googleapis.com/drive/v2/files", args, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { @@ -217,7 +217,7 @@ public override UploadResult Upload(Stream stream, string fileName) { if (!CheckAuthorization()) return null; - UploadResult result = UploadData(stream, "https://www.googleapis.com/upload/drive/v2/files", fileName, "file", headers: GetAuthHeaders()); + UploadResult result = UploadData(stream, "https://www.googleapis.com/upload/drive/v2/files", fileName, headers: GetAuthHeaders()); if (!string.IsNullOrEmpty(result.Response)) { diff --git a/UploadersLib/FileUploaders/Hostr.cs b/UploadersLib/FileUploaders/Hostr.cs index 385910acc..555a9066f 100644 --- a/UploadersLib/FileUploaders/Hostr.cs +++ b/UploadersLib/FileUploaders/Hostr.cs @@ -48,7 +48,7 @@ public override UploadResult Upload(Stream stream, string fileName) if (!string.IsNullOrEmpty(Email) && !string.IsNullOrEmpty(Password)) { NameValueCollection headers = CreateAuthenticationHeader(Email, Password); - result = UploadData(stream, "https://api.hostr.co/file", fileName, "file", null, null, headers); + result = UploadData(stream, "https://api.hostr.co/file", fileName, headers: headers); if (result.IsSuccess) { diff --git a/UploadersLib/FileUploaders/Jira.cs b/UploadersLib/FileUploaders/Jira.cs index 4a0332320..ca60e3756 100644 --- a/UploadersLib/FileUploaders/Jira.cs +++ b/UploadersLib/FileUploaders/Jira.cs @@ -216,7 +216,7 @@ public override UploadResult Upload(Stream stream, string fileName) NameValueCollection headers = new NameValueCollection(); headers.Set("X-Atlassian-Token", "nocheck"); - UploadResult res = UploadData(stream, query, fileName, "file", null, null, headers); + UploadResult res = UploadData(stream, query, fileName, headers: headers); if (res.Response.Contains("errorMessages")) { res.Errors.Add(res.Response); diff --git a/UploadersLib/FileUploaders/OwnCloud.cs b/UploadersLib/FileUploaders/OwnCloud.cs index 468559e1d..fd1a0ebfc 100644 --- a/UploadersLib/FileUploaders/OwnCloud.cs +++ b/UploadersLib/FileUploaders/OwnCloud.cs @@ -60,7 +60,7 @@ public string ShareFile(string path) string url = URLHelpers.CombineURL(Host, "ocs/v1.php/apps/files_sharing/api/v1/shares"); NameValueCollection headers = CreateAuthenticationHeader(Username, Password); - string response = SendRequest(HttpMethod.GET, url, args, headers: headers); + string response = SendRequest(HttpMethod.GET, url, args, headers); if (!string.IsNullOrEmpty(response)) { diff --git a/UploadersLib/FileUploaders/Pushbullet.cs b/UploadersLib/FileUploaders/Pushbullet.cs index c7d4807ff..ee77035d0 100644 --- a/UploadersLib/FileUploaders/Pushbullet.cs +++ b/UploadersLib/FileUploaders/Pushbullet.cs @@ -52,7 +52,7 @@ public UploadResult PushFile(Stream stream, string fileName) args.Add("device_iden", Config.CurrentDevice.Key); args.Add("type", "file"); - UploadResult result = UploadData(stream, "https://api.pushbullet.com/api/pushes", fileName, arguments: args, headers: headers); + UploadResult result = UploadData(stream, "https://api.pushbullet.com/api/pushes", fileName, "file", args, headers); PushbulletResponsePush push = JsonConvert.DeserializeObject(result.Response); @@ -74,7 +74,7 @@ private string Push(string pushType, string valueType, string value, string titl args.Add("title", title); args.Add(valueType, value); - string response = SendRequest(HttpMethod.POST, "https://api.pushbullet.com/api/pushes", args, headers: headers); + string response = SendRequest(HttpMethod.POST, "https://api.pushbullet.com/api/pushes", args, headers); PushbulletResponsePush push = JsonConvert.DeserializeObject(response); diff --git a/UploadersLib/ImageUploaders/Imgur_v3.cs b/UploadersLib/ImageUploaders/Imgur_v3.cs index 810430740..d11e43890 100644 --- a/UploadersLib/ImageUploaders/Imgur_v3.cs +++ b/UploadersLib/ImageUploaders/Imgur_v3.cs @@ -198,7 +198,7 @@ public override UploadResult Upload(Stream stream, string fileName) headers.Add("Authorization", "Client-ID " + AuthInfo.Client_ID); } - UploadResult result = UploadData(stream, "https://api.imgur.com/3/image", fileName, "image", args, headers: headers); + UploadResult result = UploadData(stream, "https://api.imgur.com/3/image", fileName, "image", args, headers); if (!string.IsNullOrEmpty(result.Response)) { diff --git a/UploadersLib/ImageUploaders/Picasa.cs b/UploadersLib/ImageUploaders/Picasa.cs index 64fdd2840..5dfce89aa 100644 --- a/UploadersLib/ImageUploaders/Picasa.cs +++ b/UploadersLib/ImageUploaders/Picasa.cs @@ -180,7 +180,7 @@ public override UploadResult Upload(Stream stream, string fileName) NameValueCollection headers = GetAuthHeaders(); headers.Add("Slug", URLHelpers.URLEncode(fileName)); - ur.Response = SendRequestStream(url, stream, contentType, headers: headers); + ur.Response = SendRequestStream(url, stream, contentType, headers); XDocument xd = XDocument.Parse(ur.Response); diff --git a/UploadersLib/TextUploaders/CustomTextUploader.cs b/UploadersLib/TextUploaders/CustomTextUploader.cs index 6caba4983..d75b96078 100644 --- a/UploadersLib/TextUploaders/CustomTextUploader.cs +++ b/UploadersLib/TextUploaders/CustomTextUploader.cs @@ -56,7 +56,7 @@ public override UploadResult UploadText(string text, string fileName) { if (string.IsNullOrEmpty(customUploader.FileFormName)) { - result.Response = SendRequest(HttpMethod.POST, customUploader.RequestURL, args, customUploader.ResponseType); + result.Response = SendRequest(HttpMethod.POST, customUploader.RequestURL, args, responseType: customUploader.ResponseType); } else { @@ -69,7 +69,7 @@ public override UploadResult UploadText(string text, string fileName) } else if (customUploader.RequestType == CustomUploaderRequestType.GET) { - result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, customUploader.ResponseType); + result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, responseType: customUploader.ResponseType); } customUploader.ParseResponse(result); diff --git a/UploadersLib/TextUploaders/Gist.cs b/UploadersLib/TextUploaders/Gist.cs index 899b9f7a0..f2b987808 100644 --- a/UploadersLib/TextUploaders/Gist.cs +++ b/UploadersLib/TextUploaders/Gist.cs @@ -76,7 +76,7 @@ public bool GetAccessToken(string code) WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Accept", "application/json"); - string response = SendRequest(HttpMethod.POST, "https://github.com/login/oauth/access_token", args, headers: headers); + string response = SendRequest(HttpMethod.POST, "https://github.com/login/oauth/access_token", args, headers); if (!string.IsNullOrEmpty(response)) { diff --git a/UploadersLib/TextUploaders/Paste2.cs b/UploadersLib/TextUploaders/Paste2.cs index 280d056f8..eae5ed79c 100644 --- a/UploadersLib/TextUploaders/Paste2.cs +++ b/UploadersLib/TextUploaders/Paste2.cs @@ -55,7 +55,7 @@ public override UploadResult UploadText(string text, string fileName) arguments.Add("lang", settings.TextFormat); arguments.Add("parent", "0"); - ur.URL = SendRequest(HttpMethod.POST, APIURL, arguments, ResponseType.RedirectionURL); + ur.URL = SendRequest(HttpMethod.POST, APIURL, arguments, responseType: ResponseType.RedirectionURL); } return ur; diff --git a/UploadersLib/TextUploaders/Pastee.cs b/UploadersLib/TextUploaders/Pastee.cs index 627c38a0a..79a73580a 100644 --- a/UploadersLib/TextUploaders/Pastee.cs +++ b/UploadersLib/TextUploaders/Pastee.cs @@ -56,7 +56,7 @@ public override UploadResult UploadText(string text, string fileName) arguments.Add("key", Key); } - ur.URL = SendRequest(HttpMethod.POST, "https://pastee.org/submit", arguments, ResponseType.RedirectionURL); + ur.URL = SendRequest(HttpMethod.POST, "https://pastee.org/submit", arguments, responseType: ResponseType.RedirectionURL); } return ur; diff --git a/UploadersLib/TextUploaders/Slexy.cs b/UploadersLib/TextUploaders/Slexy.cs index 7754c522a..cb55572d6 100644 --- a/UploadersLib/TextUploaders/Slexy.cs +++ b/UploadersLib/TextUploaders/Slexy.cs @@ -63,7 +63,7 @@ public override UploadResult UploadText(string text, string fileName) arguments.Add("tabbing", "true"); arguments.Add("tabtype", "real"); - ur.URL = SendRequest(HttpMethod.POST, APIURL, arguments, ResponseType.RedirectionURL); + ur.URL = SendRequest(HttpMethod.POST, APIURL, arguments, responseType: ResponseType.RedirectionURL); } return ur; diff --git a/UploadersLib/URLShorteners/CustomURLShortener.cs b/UploadersLib/URLShorteners/CustomURLShortener.cs index a99013b73..b2b19103a 100644 --- a/UploadersLib/URLShorteners/CustomURLShortener.cs +++ b/UploadersLib/URLShorteners/CustomURLShortener.cs @@ -54,11 +54,11 @@ public override UploadResult ShortenURL(string url) if (customUploader.RequestType == CustomUploaderRequestType.POST) { - result.Response = SendRequest(HttpMethod.POST, customUploader.RequestURL, args, customUploader.ResponseType); + result.Response = SendRequest(HttpMethod.POST, customUploader.RequestURL, args, responseType: customUploader.ResponseType); } else if (customUploader.RequestType == CustomUploaderRequestType.GET) { - result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, customUploader.ResponseType); + result.Response = SendRequest(HttpMethod.GET, customUploader.RequestURL, args, responseType: customUploader.ResponseType); } customUploader.ParseResponse(result, true); diff --git a/UploadersLib/Uploader.cs b/UploadersLib/Uploader.cs index 36e1ce919..6869b3e80 100644 --- a/UploadersLib/Uploader.cs +++ b/UploadersLib/Uploader.cs @@ -114,8 +114,8 @@ public virtual void StopUpload() } } - protected string SendRequest(HttpMethod method, string url, Dictionary arguments = null, ResponseType responseType = ResponseType.Text, - NameValueCollection headers = null, CookieCollection cookies = null) + protected string SendRequest(HttpMethod method, string url, Dictionary arguments = null, NameValueCollection headers = null, + CookieCollection cookies = null, ResponseType responseType = ResponseType.Text) { HttpWebResponse response = null; @@ -141,20 +141,20 @@ protected string SendRequest(HttpMethod method, string url, Dictionary arguments = null, ResponseType responseType = ResponseType.Text, - NameValueCollection headers = null, CookieCollection cookies = null) + protected string SendRequest(HttpMethod method, string url, string content, Dictionary arguments = null, NameValueCollection headers = null, + CookieCollection cookies = null, ResponseType responseType = ResponseType.Text) { byte[] data = Encoding.UTF8.GetBytes(content); using (MemoryStream ms = new MemoryStream()) { ms.Write(data, 0, data.Length); - return SendRequest(method, url, ms, arguments, responseType, headers, cookies); + return SendRequest(method, url, ms, arguments, headers, cookies, responseType); } } - protected string SendRequest(HttpMethod method, string url, Stream content, Dictionary arguments = null, ResponseType responseType = ResponseType.Text, - NameValueCollection headers = null, CookieCollection cookies = null) + protected string SendRequest(HttpMethod method, string url, Stream content, Dictionary arguments = null, NameValueCollection headers = null, + CookieCollection cookies = null, ResponseType responseType = ResponseType.Text) { using (HttpWebResponse response = GetResponse(method, url, arguments, headers, cookies, content)) { @@ -219,7 +219,7 @@ private HttpWebResponse GetResponse(HttpMethod method, string url, Dictionary arguments, NameValueCollection headers = null, CookieCollection cookies = null, HttpMethod method = HttpMethod.POST) + private HttpWebResponse SendRequestMultiPart(string url, Dictionary arguments, NameValueCollection headers = null, + CookieCollection cookies = null, HttpMethod method = HttpMethod.POST) { string boundary = CreateBoundary(); byte[] data = MakeInputContent(boundary, arguments); @@ -247,12 +249,12 @@ private HttpWebResponse SendRequestMultiPart(string url, Dictionary arguments = null, CookieCollection cookies = null, NameValueCollection headers = null, - ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.POST) + protected UploadResult UploadData(Stream dataStream, string url, string fileName, string fileFormName = "file", Dictionary arguments = null, + NameValueCollection headers = null, CookieCollection cookies = null, ResponseType responseType = ResponseType.Text, HttpMethod method = HttpMethod.POST) { UploadResult result = new UploadResult();