Add LnkU URL Shortener

This commit is contained in:
Daniel McAssey 2015-07-20 15:51:34 +01:00
parent b7c4005ea9
commit 843a07566b
9 changed files with 117 additions and 4 deletions

View file

@ -154,6 +154,8 @@ public enum UrlShortenerType
NLCM,
[Description("adf.ly")]
AdFly,
[Description("lnku.co")]
LnkU,
CustomURLShortener // Localized
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -95,6 +95,7 @@ private void FormSettings()
AddIconToTab(tpImageShack, Resources.ImageShack);
AddIconToTab(tpImgur, Resources.Imgur);
AddIconToTab(tpJira, Resources.jira);
AddIconToTab(tpLnkU, Resources.LnkU);
AddIconToTab(tpMediaFire, Resources.MediaFire);
AddIconToTab(tpMega, Resources.Mega);
AddIconToTab(tpMinus, Resources.Minus);
@ -582,6 +583,10 @@ public void LoadSettings(UploadersConfig uploadersConfig)
txtAdflyAPIKEY.Text = Config.AdFlyAPIKEY;
txtAdflyAPIUID.Text = Config.AdFlyAPIUID;
// lnku.co
txtLnkUAPIKEY.Text = Config.LnkUAPIKEY;
#endregion URL Shorteners
#region Other Services
@ -2133,13 +2138,21 @@ private void llAdflyLink_LinkClicked(object sender, LinkLabelLinkClickedEventArg
#endregion adf.ly
#endregion URL Shorteners
#region LnkU.co
#region Other Uploaders
private void txtLnkUAPIKEY_TextChanged(object sender, EventArgs e)
{
Config.LnkUAPIKEY = txtLnkUAPIKEY.Text;
}
#endregion
#region Twitter
#endregion URL Shorteners
private void btnTwitterAdd_Click(object sender, EventArgs e)
#region Other Uploaders
#region Twitter
private void btnTwitterAdd_Click(object sender, EventArgs e)
{
OAuthInfo oauth = new OAuthInfo();
Config.TwitterOAuthInfoList.Add(oauth);

View file

@ -421,6 +421,16 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>
internal static System.Drawing.Icon LnkU {
get {
object obj = ResourceManager.GetObject("LnkU", resourceCulture);
return ((System.Drawing.Icon)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View file

@ -461,4 +461,7 @@ Created folders:</value>
<data name="Hubic" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\hubic.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="LnkU" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Favicons\LnkU.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -289,6 +289,7 @@
<Compile Include="URLShorteners\CustomURLShortener.cs" />
<Compile Include="URLShorteners\GoogleURLShortener.cs" />
<Compile Include="URLShorteners\IsgdURLShortener.cs" />
<Compile Include="URLShorteners\LnkUURLShortener.cs" />
<Compile Include="URLShorteners\NlcmURLShortener.cs" />
<Compile Include="URLShorteners\TinyURLShortener.cs" />
<Compile Include="URLShorteners\TurlURLShortener.cs" />
@ -745,6 +746,10 @@
<ItemGroup>
<None Include="Favicons\Up1.ico" />
</ItemGroup>
<ItemGroup>
<Content Include="Favicons\LnkU.ico" />
<None Include="Resources\LnkU.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>

View file

@ -0,0 +1,69 @@
#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 Newtonsoft.Json;
using System.Collections.Generic;
namespace ShareX.UploadersLib.URLShorteners
{
public sealed class LnkUURLShortener : URLShortener
{
private const string API_ENDPOINT = "https://api-ssl.bitly.com/";
public string API_KEY { get; set; }
public override UploadResult ShortenURL(string url)
{
UploadResult result = new UploadResult { URL = url };
Dictionary<string, string> args = new Dictionary<string, string>();
args.Add("apikey", API_KEY);
args.Add("action" , "shorten");
args.Add("url", url);
string response = SendRequest(HttpMethod.GET, API_ENDPOINT, args);
if (!string.IsNullOrEmpty(response))
{
LnkUURLShortenerResponse jsonResponse = JsonConvert.DeserializeObject<LnkUURLShortenerResponse>(response);
if (jsonResponse != null)
{
result.ShortenedURL = jsonResponse.shorturl;
}
}
return result;
}
}
public class LnkUURLShortenerResponse
{
public string shortcode { get; set; }
public string site { get; set; }
public string shorturl { get; set; }
public string fullurl { get; set; }
public string title { get; set; }
}
}

View file

@ -275,6 +275,9 @@ public class UploadersConfig : SettingsBase<UploadersConfig>
public string AdFlyAPIKEY = String.Empty;
public string AdFlyAPIUID = String.Empty;
// lnku.co
public string LnkUAPIKEY = string.Empty;
#endregion URL shorteners
#region URL sharing services
@ -428,6 +431,8 @@ public bool IsValid(UrlShortenerType destination)
return !string.IsNullOrEmpty(YourlsAPIURL) && (!string.IsNullOrEmpty(YourlsSignature) || (!string.IsNullOrEmpty(YourlsUsername) && !string.IsNullOrEmpty(YourlsPassword)));
case UrlShortenerType.AdFly:
return !string.IsNullOrEmpty(AdFlyAPIKEY) && !string.IsNullOrEmpty(AdFlyAPIUID);
case UrlShortenerType.LnkU:
return !string.IsNullOrEmpty(LnkUAPIKEY);
case UrlShortenerType.CustomURLShortener:
return CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomURLShortenerSelected);
}

View file

@ -1075,6 +1075,12 @@ public UploadResult ShortenURL(string url)
APIUID = Program.UploadersConfig.AdFlyAPIUID
};
break;
case UrlShortenerType.LnkU:
urlShortener = new LnkUURLShortener
{
API_KEY = Program.UploadersConfig.LnkUAPIKEY
};
break;
case UrlShortenerType.CustomURLShortener:
CustomUploaderItem customUploader = GetCustomUploader(Program.UploadersConfig.CustomURLShortenerSelected);
if (customUploader != null)