-
Notifications
You must be signed in to change notification settings - Fork 3
/
TicketAPIClient.cs
46 lines (40 loc) · 1.32 KB
/
TicketAPIClient.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
namespace HelpDeskBot.Util
{
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using System.Web.Configuration;
public class Ticket
{
public string Category { get; set; }
public string Severity { get; set; }
public string Description { get; set; }
}
public class TicketAPIClient
{
public async Task<int> PostTicketAsync(string category, string severity, string description)
{
try
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(WebConfigurationManager.AppSettings["TicketsAPIBaseUrl"]);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var ticket = new Ticket
{
Category = category,
Severity = severity,
Description = description
};
var response = await client.PostAsJsonAsync("api/tickets", ticket);
return await response.Content.ReadAsAsync<int>();
}
}
catch
{
return -1;
}
}
}
}