-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPrintNodePrinter.cs
77 lines (58 loc) · 2.71 KB
/
PrintNodePrinter.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PrintNodeNet.Http;
using PrintNodeNet.Util;
namespace PrintNodeNet
{
public sealed class PrintNodePrinter
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("computer")]
public PrintNodeComputer Computer { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("capabilities")]
public PrintNodePrinterCapabilities Capabilities { get; set; }
[JsonProperty("default")]
public string Default { get; set; }
[JsonProperty("createTimeStamp")]
public DateTime CreateTimeStamp { get; set; }
[JsonProperty("state")]
public string State { get; set; }
public static async Task<IEnumerable<PrintNodePrinter>> ListAsync(PrintNodeRequestOptions options = null)
{
var response = await PrintNodeApiHelper.Get("/printers", options);
return JsonConvert.DeserializeObject<List<PrintNodePrinter>>(response);
}
public static async Task<PrintNodePrinter> GetAsync(long id, PrintNodeRequestOptions options = null)
{
var response = await PrintNodeApiHelper.Get($"/printers/{id}", options);
var list = JsonConvert.DeserializeObject<List<PrintNodePrinter>>(response);
return list.FirstOrDefault();
}
/// <summary>
/// Static method to retrieve a set of printers from the PrintNode API.
/// </summary>
/// <param name="printerSet">The list of ids of the printers.</param>
/// <param name="options">The request options (allows API key modification).</param>
/// <returns>The list of <seealso cref="PrintNodePrinter"/> matching to the given ids.</returns>
public static async Task<IEnumerable<PrintNodePrinter>> GetSetAsync(IEnumerable<long> printerSet, PrintNodeRequestOptions options = null)
{
string ids = new SetBuilder(printerSet).Build();
var response = await PrintNodeApiHelper.Get($"/printers/{ids}", options);
return JsonConvert.DeserializeObject<List<PrintNodePrinter>>(response);
}
public async Task<long> AddPrintJob(PrintNodePrintJob job, PrintNodeRequestOptions options = null)
{
job.PrinterId = Id;
var response = await PrintNodeApiHelper.Post("/printjobs", job, options);
return JsonConvert.DeserializeObject<long>(response);
}
}
}