#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 System.Collections.Generic;
using System.ComponentModel;
namespace UploadersLib.TextUploaders
{
public sealed class Pastebin_ca : TextUploader
{
private const string APIURL = "http://pastebin.ca/quiet-paste.php";
private string APIKey;
private PastebinCaSettings settings;
public Pastebin_ca(string apiKey)
{
APIKey = apiKey;
settings = new PastebinCaSettings();
}
public Pastebin_ca(string apiKey, PastebinCaSettings settings)
{
APIKey = apiKey;
this.settings = settings;
}
public override UploadResult UploadText(string text, string fileName)
{
UploadResult ur = new UploadResult();
if (!string.IsNullOrEmpty(text))
{
Dictionary arguments = new Dictionary();
arguments.Add("api", APIKey);
arguments.Add("content", text);
arguments.Add("description", settings.Description);
if (settings.Encrypt)
{
arguments.Add("encrypt", "true");
}
arguments.Add("encryptpw", settings.EncryptPassword);
arguments.Add("expiry", settings.ExpireTime);
arguments.Add("name", settings.Author);
arguments.Add("s", "Submit Post");
arguments.Add("tags", settings.Tags);
arguments.Add("type", settings.TextFormat);
ur.Response = SendRequest(HttpMethod.POST, APIURL, arguments);
if (!string.IsNullOrEmpty(ur.Response))
{
if (ur.Response.StartsWith("SUCCESS:"))
{
ur.URL = "http://pastebin.ca/" + ur.Response.Substring(8);
}
else if (ur.Response.StartsWith("FAIL:"))
{
Errors.Add(ur.Response.Substring(5));
}
}
}
return ur;
}
}
public class PastebinCaSettings
{
/// name
[Description("Name / Title")]
public string Author { get; set; }
/// description
[Description("Description / Question")]
public string Description { get; set; }
/// tags
[Description("Tags (space separated, optional)")]
public string Tags { get; set; }
/// type
[Description("Content Type"), DefaultValue("1")]
public string TextFormat { get; set; }
/// expiry
[Description("Expire this post in ..."), DefaultValue("1 month")]
public string ExpireTime { get; set; }
/// encrypt
[Description("Encrypt this paste")]
public bool Encrypt { get; set; }
/// encryptpw
public string EncryptPassword { get; set; }
public PastebinCaSettings()
{
Author = string.Empty;
Description = string.Empty;
Tags = string.Empty;
TextFormat = "1";
ExpireTime = "1 month";
Encrypt = false;
EncryptPassword = string.Empty;
}
}
}