/
PushoverPoster.cs
60 lines (53 loc) · 1.87 KB
/
PushoverPoster.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
using System;
using System.Collections.Specialized;
using System.Net;
namespace SendPushoverNotification
{
public class PushoverPoster
{
private string _title;
private string _url;
private string _message;
private readonly ConsoleHelper _consoleHelper;
public PushoverPoster(string title, string url, string message)
{
_message = message;
_title = title;
_url = url;
_consoleHelper = new ConsoleHelper();
}
public bool Post()
{
var parameters = CreatePostParameters();
using (var client = new WebClient())
{
if (Configuration.NetworkProxy.UseNetworkProxy)
{
client.Proxy = GetProxy();
}
client.UploadValues(Configuration.Pushover.Url, parameters);
}
return true;
}
private NameValueCollection CreatePostParameters()
{
var parameters = new NameValueCollection
{
{"token", Configuration.Pushover.Token},
{"user", Configuration.Pushover.User},
{"message", _message},
{"url", _url},
{"title", _title}
};
return parameters;
}
private IWebProxy GetProxy()
{
var credential = new NetworkCredential(Environment.UserName,
_consoleHelper.GetPasswordFromConsoleInput().ToString(),
Environment.UserDomainName);
var webProxyAddress = string.Concat(Configuration.NetworkProxy.Server, ":", Configuration.NetworkProxy.Port);
return new WebProxy(webProxyAddress, false, null, credential);
}
}
}