-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPrintNodeChildAccount.cs
More file actions
120 lines (102 loc) · 4.15 KB
/
PrintNodeChildAccount.cs
File metadata and controls
120 lines (102 loc) · 4.15 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json;
using PrintNodeNet.Http;
namespace PrintNodeNet
{
public sealed class PrintNodeChildAccount
{
/// <summary>
/// Assigned by API. Any value submitted here will be ignored.
/// </summary>
[JsonProperty("id")]
public long? Id { get; set; }
/// <summary>
/// The child account user's first name
/// </summary>
[JsonProperty("firstname")]
public string FirstName { get; set; }
/// <summary>
/// The child account user's last name
/// </summary>
[JsonProperty("lastname")]
public string LastName { get; set; }
/// <summary>
/// A valid email address. This must be unique and would normally be the email address of your customer.
/// This email is for actions like account password resets, informing customers of new versions of the
/// client, etc. Your email will never be shared with any third party or used for marketing purposes.
/// </summary>
[JsonProperty("email")]
public string Email { get; set; }
/// <summary>
/// The password should be plain text. It will be encoded in the PrintNode database and cannot be
/// retrieved, only reset.
/// </summary>
[JsonProperty("password")]
public string Password { get; set; }
/// <summary>
/// OPTIONAL
///
/// A unique reference which you can use as a method to identify an account.
/// </summary>
[JsonProperty("creatorRef")]
public string CreatorRef { get; set; }
/// <summary>
/// OPTIONAL
///
/// A array of named API Keys you wish to create for this account.
/// </summary>
[JsonProperty("ApiKeys")]
public string[] ApiKeys { get; set; }
/// <summary>
/// OPTIONAL
///
/// A array of tag names and values to be associated with an account.
/// </summary>
[JsonProperty("Tags")]
public Dictionary<string, string> Tags { get; set; }
public async Task<PrintNodeChildAccount> CreateAsync(PrintNodeRequestOptions options = null)
{
var response = await PrintNodeApiHelper.Post("/account", new
{
Account = this,
ApiKeys,
Tags
}, options);
return JsonConvert.DeserializeObject<PrintNodeChildAccount>(response, new PrintNodeChildAccountCreationResponseConverter());
}
public static async Task<string> GetKeyAsync(string clientId, PrintNodeRequestOptions options = null)
{
var response = await PrintNodeApiHelper.Get($"/client/key/{clientId}?version=4.7.1&edition=printnode", options);
return JsonConvert.DeserializeObject<string>(response);
}
public static async Task<bool> Exists(PrintNodeRequestOptions options = null)
{
try
{
var response = await PrintNodeApiHelper.Get("/whoami", options);
return !string.IsNullOrEmpty(response);
}
catch
{
return false;
}
}
public async Task<PrintNodeChildAccount> UpdateAsync(PrintNodeRequestOptions options = null)
{
var response = await PrintNodeApiHelper.Patch("/account", this, options, new Dictionary<string, string>
{
{ "X-Child-Account-By-Id", Id.ToString() }
});
return JsonConvert.DeserializeObject<PrintNodeChildAccount>(response);
}
public static async Task<bool> DeleteAsync(long id, PrintNodeRequestOptions options = null)
{
var response = await PrintNodeApiHelper.Delete("/account", options, new Dictionary<string, string>
{
{ "X-Child-Account-By-Id", id.ToString() }
});
return JsonConvert.DeserializeObject<bool>(response);
}
}
}