From 2bf12846018431dd0641e56fc7d289aa5f38cb3b Mon Sep 17 00:00:00 2001 From: Jaex Date: Wed, 29 Jan 2014 15:57:41 +0200 Subject: [PATCH] Added upaste.me text uploader --- ShareX/UploadTask.cs | 3 + UploadersLib/ApiKeys/ApiKeys.cs | 1 + UploadersLib/ApiKeys/ApiKeysConfig.cs | 3 + UploadersLib/Enums.cs | 2 + UploadersLib/TextUploaders/Upaste.cs | 97 +++++++++++++++++++++++++++ UploadersLib/UploadersLib.csproj | 1 + 6 files changed, 107 insertions(+) create mode 100644 UploadersLib/TextUploaders/Upaste.cs diff --git a/ShareX/UploadTask.cs b/ShareX/UploadTask.cs index c592c34b2..984b2ce29 100644 --- a/ShareX/UploadTask.cs +++ b/ShareX/UploadTask.cs @@ -672,6 +672,9 @@ public UploadResult UploadText(Stream stream, string fileName) ? new Gist(Program.UploadersConfig.GistPublishPublic) : new Gist(Program.UploadersConfig.GistPublishPublic, Program.UploadersConfig.GistOAuth2Info); break; + case TextDestination.Upaste: + textUploader = new Upaste(ApiKeys.UpasteKey); + break; case TextDestination.CustomTextUploader: if (Program.UploadersConfig.CustomUploadersList.IsValidIndex(Program.UploadersConfig.CustomTextUploaderSelected)) { diff --git a/UploadersLib/ApiKeys/ApiKeys.cs b/UploadersLib/ApiKeys/ApiKeys.cs index bb0535cdf..b3b647f89 100644 --- a/UploadersLib/ApiKeys/ApiKeys.cs +++ b/UploadersLib/ApiKeys/ApiKeys.cs @@ -64,6 +64,7 @@ public static class ApiKeys public const string PastebinCaKey = "KxTofLKQThSBZ63Gpa7hYLlMdyQlMD6u"; public const string GistId = "badfa7b5e0a67e31da88"; public const string GistSecret = "a538eff39300680f43d123a59ab9c1d9d4763640"; + public const string UpasteKey = "67941cA40Ca76625c6Fa96e59b98be9f"; // URL Shorteners public const string BitlyClientID = "0bf9726bea922ab7d5760a913d6749b441e5176a"; diff --git a/UploadersLib/ApiKeys/ApiKeysConfig.cs b/UploadersLib/ApiKeys/ApiKeysConfig.cs index 36ed942db..b38c17ab6 100644 --- a/UploadersLib/ApiKeys/ApiKeysConfig.cs +++ b/UploadersLib/ApiKeys/ApiKeysConfig.cs @@ -124,6 +124,9 @@ public class UploadersAPIKeys [Category("Pastebin"), DefaultValue(ApiKeys.PastebinCaKey), Description("Pastebin Consumer Secret")] public string PastebinCaKey { get; set; } + [Category("Upaste"), DefaultValue(ApiKeys.UpasteKey), Description("Upaste Key")] + public string UpasteKey { get; set; } + #endregion Text Uploaders #region URL Shorteners diff --git a/UploadersLib/Enums.cs b/UploadersLib/Enums.cs index 8afbbc708..dde0e4ca3 100644 --- a/UploadersLib/Enums.cs +++ b/UploadersLib/Enums.cs @@ -77,6 +77,8 @@ public enum TextDestination Paste_ee, [Description("gist.github.com")] Gist, + [Description("upaste.me")] + Upaste, [Description("Custom text uploader")] CustomTextUploader, [Description("File uploader")] diff --git a/UploadersLib/TextUploaders/Upaste.cs b/UploadersLib/TextUploaders/Upaste.cs new file mode 100644 index 000000000..eea8b1428 --- /dev/null +++ b/UploadersLib/TextUploaders/Upaste.cs @@ -0,0 +1,97 @@ +#region License Information (GPL v3) + +/* + ShareX - A program that allows you to take screenshots and share any file type + Copyright (C) 2008-2014 ShareX Developers + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + Optionally you can also view the license at . +*/ + +#endregion License Information (GPL v3) + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; + +namespace UploadersLib.TextUploaders +{ + public sealed class Upaste : TextUploader + { + private const string APIURL = "http://upaste.me/api"; + + public string APIKey { get; private set; } + + public Upaste(string apiKey) + { + APIKey = apiKey; + } + + public override UploadResult UploadText(string text, string fileName) + { + UploadResult ur = new UploadResult(); + + if (!string.IsNullOrEmpty(text)) + { + Dictionary arguments = new Dictionary(); + arguments.Add("api_key", APIKey); + arguments.Add("paste", text); + //arguments.Add("syntax", ""); + //arguments.Add("name", ""); + arguments.Add("privacy", "1"); // 0 public 1 private + arguments.Add("expire", "n"); + arguments.Add("json", "true"); + + ur.Response = SendPostRequest(APIURL, arguments); + + if (!string.IsNullOrEmpty(ur.Response)) + { + UpasteResponse response = JsonConvert.DeserializeObject(ur.Response); + + if (response != null) + { + if (response.status.Equals("success", StringComparison.InvariantCultureIgnoreCase)) + { + ur.URL = response.paste.link; + } + else + { + Errors.Add(response.error); + } + } + } + } + + return ur; + } + + public class UpastePaste + { + public string id { get; set; } + public string link { get; set; } + public string raw { get; set; } + public string download { get; set; } + } + + public class UpasteResponse + { + public UpastePaste paste { get; set; } + public int errorcode { get; set; } + public string error { get; set; } + public string status { get; set; } + } + } +} \ No newline at end of file diff --git a/UploadersLib/UploadersLib.csproj b/UploadersLib/UploadersLib.csproj index f2d564106..d60b52b2f 100644 --- a/UploadersLib/UploadersLib.csproj +++ b/UploadersLib/UploadersLib.csproj @@ -189,6 +189,7 @@ UploadersConfigForm.cs + Form