-
Notifications
You must be signed in to change notification settings - Fork 6
/
tinyurl.cs
82 lines (68 loc) · 1.82 KB
/
tinyurl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using MahTweets.Core;
using MahTweets.Core.Composition;
using MahTweets.Core.Interfaces.Application;
using MahTweets.Core.Interfaces.Plugins;
using MahTweets.Core.Utilities;
namespace MahTweets.UrlShorteners
{
public class TinyUrl : IUrlShortener
{
#region IUrlShortener Members
public bool HasSettings
{
get { return false; }
}
public string Name
{
get { return "TinyURL"; }
}
public string Protocol
{
get { return "tinyurl"; }
}
public BitmapImage Icon
{
get
{
return
ImageUtility.ConvertResourceToBitmap(
"pack://application:,,,/MahTweets.UrlShorteners;component/tinyurl.jpg");
}
}
public Credential Credentials { get; set; }
public string Id
{
get { return Name; }
}
public void Setup()
{
}
public async Task<string> Shorten(String Url)
{
try
{
if (Url.Length <= 30)
{
return Url;
}
var _fetcher = new AsyncWebFetcher();
string text =
await _fetcher.FetchAsync("http://tinyurl.com/api-create.php?url=" + Uri.EscapeDataString(Url));
return text;
}
catch (Exception ex)
{
CompositionManager.Get<IExceptionReporter>().ReportHandledException(ex);
return Url;
}
}
public void ShowSettings()
{
throw new NotImplementedException();
}
#endregion
}
}