Added DeleteFile method to Puush class

This commit is contained in:
Jaex 2017-01-21 10:52:33 +03:00
parent ea149c788b
commit 8ebf9aed1c

View file

@ -28,6 +28,7 @@
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using ShareX.HelpersLib;
namespace ShareX.UploadersLib.FileUploaders
{
@ -57,8 +58,11 @@ public class Puush : FileUploader
public const string PuushResetPasswordURL = PuushURL + "/reset_password";
private const string PuushAPIURL = PuushURL + "/api";
private const string PuushAPILoginURL = PuushAPIURL + "/auth";
private const string PuushAPIAuthenticationURL = PuushAPIURL + "/auth";
private const string PuushAPIUploadURL = PuushAPIURL + "/up";
private const string PuushAPIDeletionURL = PuushAPIURL + "/del";
private const string PuushAPIHistoryURL = PuushAPIURL + "/hist";
private const string PuushAPIThumbnailURL = PuushAPIURL + "/thumb";
public string APIKey { get; set; }
@ -76,9 +80,11 @@ public string Login(string email, string password)
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("e", email);
arguments.Add("p", password);
arguments.Add("z", "ShareX");
arguments.Add("z", UserAgent);
string response = SendRequestMultiPart(PuushAPILoginURL, arguments);
// Successful: status,apikey,expire,usage
// Failed: status
string response = SendRequestMultiPart(PuushAPIAuthenticationURL, arguments);
if (!string.IsNullOrEmpty(response))
{
@ -98,19 +104,47 @@ public string Login(string email, string password)
return null;
}
public bool DeleteFile(string id)
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("k", APIKey);
arguments.Add("i", id);
arguments.Add("z", UserAgent);
// Successful: status\nlist of history items
// Failed: status
string response = SendRequestMultiPart(PuushAPIDeletionURL, arguments);
if (!string.IsNullOrEmpty(response))
{
string[] lines = response.Lines();
if (lines != null && lines.Length > 0)
{
int status;
return int.TryParse(lines[0], out status) && status >= 0;
}
}
return false;
}
public override UploadResult Upload(Stream stream, string fileName)
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("k", APIKey);
arguments.Add("z", "ShareX");
arguments.Add("z", UserAgent);
// Successful: status,url,id,usage
// Failed: status
UploadResult result = SendRequestFile(PuushAPIUploadURL, stream, fileName, "f", arguments);
if (result.IsSuccess)
{
string[] values = result.Response.Split(',');
if (values != null && values.Length > 1)
if (values != null && values.Length > 0)
{
int status;
@ -138,7 +172,7 @@ public override UploadResult Upload(Stream stream, string fileName)
break;
}
}
else
else if (values.Length > 1)
{
result.URL = values[1];
}