-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTags.cs
More file actions
63 lines (57 loc) · 2.01 KB
/
Tags.cs
File metadata and controls
63 lines (57 loc) · 2.01 KB
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
using Birko.SuperFaktura.Request.Tags;
using Birko.SuperFaktura.Response;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Birko.SuperFaktura
{
public class Tags
{
private readonly AbstractSuperFaktura superFaktura;
public Tags(AbstractSuperFaktura superFaktura)
{
this.superFaktura = superFaktura;
}
public async Task<Dictionary<int, string>> List()
{
var result = await superFaktura.Get("tags/index.json").ConfigureAwait(false);
try
{
return superFaktura.DeserializeResult<Dictionary<int, string>>(result);
}
catch (Exceptions.ParseException ex)
{
try
{
var deserialized = superFaktura.DeserializeResult<string[]>(result);
var data = new Dictionary<int, string>();
int i = 1;
foreach (var tag in deserialized)
{
data.Add(i, tag);
i++;
}
return data;
}
catch
{
throw ex;
}
}
}
public async Task<Response.Tag.Tag> Add(Tag tag)
{
var result = await superFaktura.Post("tags/add", tag).ConfigureAwait(false);
return superFaktura.DeserializeResult<Response.Tag.Tag>(result);
}
public async Task<Response.Tag.Tag> Edit(int id, Tag tag)
{
var result = await superFaktura.Post($"tags/edit/{id}", tag).ConfigureAwait(false);
return superFaktura.DeserializeResult<Response.Tag.Tag>(result);
}
public async Task<ErrorMessageResponse> Delete(int id)
{
var result = await superFaktura.Get($"tags/delete/{id}").ConfigureAwait(false);
return superFaktura.DeserializeResult<ErrorMessageResponse>(result);
}
}
}