Added v.gd url shortener, Updated is.gd API usage

This commit is contained in:
Jaex 2015-02-24 07:59:07 +02:00
parent 2db840ef3d
commit ea80f46acc
5 changed files with 55 additions and 3 deletions

View file

@ -136,6 +136,8 @@ public enum UrlShortenerType
Google,
[Description("is.gd")]
ISGD,
[Description("v.gd")]
VGD,
[Description("tinyurl.com")]
TINYURL,
[Description("turl.ca")]

View file

@ -281,6 +281,7 @@
<Compile Include="URLShorteners\TinyURLShortener.cs" />
<Compile Include="URLShorteners\TurlURLShortener.cs" />
<Compile Include="FileUploaders\MediaCrushUploader.cs" />
<Compile Include="URLShorteners\VgdURLShortener.cs" />
<Compile Include="URLShorteners\YourlsURLShortener.cs" />
</ItemGroup>
<ItemGroup>

View file

@ -23,12 +23,15 @@ You should have received a copy of the GNU General Public License
#endregion License Information (GPL v3)
using System;
using System.Collections.Generic;
namespace ShareX.UploadersLib.URLShorteners
{
public sealed class IsgdURLShortener : URLShortener
public class IsgdURLShortener : URLShortener
{
protected virtual string APIURL { get { return "http://is.gd/create.php"; } }
public override UploadResult ShortenURL(string url)
{
UploadResult result = new UploadResult { URL = url };
@ -36,9 +39,15 @@ public override UploadResult ShortenURL(string url)
if (!string.IsNullOrEmpty(url))
{
Dictionary<string, string> arguments = new Dictionary<string, string>();
arguments.Add("longurl", url);
arguments.Add("format", "simple");
arguments.Add("url", url);
result.Response = result.ShortenedURL = SendRequest(HttpMethod.GET, "http://is.gd/api.php", arguments);
result.Response = SendRequest(HttpMethod.GET, APIURL, arguments);
if (!result.Response.StartsWith("Error:", StringComparison.InvariantCultureIgnoreCase))
{
result.ShortenedURL = result.Response;
}
}
return result;

View file

@ -0,0 +1,37 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright © 2007-2015 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 <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShareX.UploadersLib.URLShorteners
{
public class VgdURLShortener : IsgdURLShortener
{
protected override string APIURL { get { return "http://v.gd/create.php"; } }
}
}

View file

@ -1030,6 +1030,9 @@ public UploadResult ShortenURL(string url)
case UrlShortenerType.ISGD:
urlShortener = new IsgdURLShortener();
break;
case UrlShortenerType.VGD:
urlShortener = new VgdURLShortener();
break;
case UrlShortenerType.TINYURL:
urlShortener = new TinyURLShortener();
break;