public static async Task <PrintNodeComputer> GetAsync(long id, PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/computers/" + id, clientContext); var list = JsonConvert.DeserializeObject <List <PrintNodeComputer> >(response); return(list.FirstOrDefault()); }
public static async Task <IEnumerable <PrintNodePrinter> > ListAsync(PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/printers", clientContext); var list = JsonConvert.DeserializeObject <List <PrintNodePrinter> >(response); // Set clientContext on each printer object; list.ForEach(p => p.ClientContext = clientContext); return(list); }
public static async Task <PrintNodePrinter> GetAsync(long id, PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/printers/" + id, clientContext); var list = JsonConvert.DeserializeObject <List <PrintNodePrinter> >(response); // Set clientContext on each printer object; list.ForEach(p => p.ClientContext = clientContext); return(list.FirstOrDefault()); }
public static async Task <bool> Exists(PrintNodeDelegatedClientContext clientContext = null) { try { var response = await ApiHelper.Get("/whoami", clientContext); return(!string.IsNullOrEmpty(response)); } catch { return(false); } }
internal static async Task <string> Get(string relativeUri, PrintNodeDelegatedClientContext clientContext = null) { using (var http = BuildHttpClient(clientContext: clientContext)) { var result = await http.GetAsync(BaseUri + relativeUri, CancellationToken.None); if (!result.IsSuccessStatusCode) { throw new Exception(result.StatusCode.ToString()); } return(await result.Content.ReadAsStringAsync()); } }
public static async Task <IEnumerable <PrintNodeComputer> > ListAsync(PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/computers", clientContext); return(JsonConvert.DeserializeObject <List <PrintNodeComputer> >(response)); }
public static async Task <IEnumerable <IEnumerable <PrintNodePrintJobState> > > ListAsync(PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/printjobs/states", clientContext); return(JsonConvert.DeserializeObject <IEnumerable <IEnumerable <PrintNodePrintJobState> > >(response)); }
public static async Task <IEnumerable <PrintNodePrintJob> > ListForPrinterAsync(int printerId, PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/printers/" + printerId + "/printjobs"); var list = JsonConvert.DeserializeObject <List <PrintNodePrintJob> >(response); // Set clientContext on each job object; list.ForEach(j => j.ClientContext = clientContext); return(list); }
public static async Task <PrintNodeScale> GetAsync(long computerId, string deviceName, PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/computer/" + computerId + "/scales/" + deviceName, clientContext); return(JsonConvert.DeserializeObject <PrintNodeScale>(response)); }
public static async Task <IEnumerable <PrintNodeScale> > ListForComputerAsync(long computerId, PrintNodeDelegatedClientContext clientContext = null) { var response = await ApiHelper.Get("/computer/" + computerId + "/scales", clientContext); return(JsonConvert.DeserializeObject <List <PrintNodeScale> >(response)); }
private static HttpClient BuildHttpClient(Dictionary <string, string> headers = null, PrintNodeDelegatedClientContext clientContext = null) { headers = headers ?? new Dictionary <string, string>(); var http = new HttpClient(); http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(PrintNodeConfiguration.GetApiKey()))); http.DefaultRequestHeaders.Add("Accept-Version", "~3"); var context = clientContext; if (context != null) { var headerName = ""; switch (context.AuthenticationMode) { case PrintNodeDelegatedClientContextAuthenticationMode.Id: headerName = "X-Child-Account-By-Id"; break; case PrintNodeDelegatedClientContextAuthenticationMode.Email: headerName = "X-Child-Account-By-Email"; break; case PrintNodeDelegatedClientContextAuthenticationMode.CreatorRef: headerName = "X-Child-Account-By-CreatorRef"; break; } http.DefaultRequestHeaders.Add(headerName, context.AuthenticationValue); } foreach (var kv in headers) { http.DefaultRequestHeaders.Add(kv.Key, kv.Value); } return(http); }
internal static async Task <string> Post <T>(string relativeUri, T parameters, PrintNodeDelegatedClientContext clientContext = null) { using (var http = BuildHttpClient(clientContext: clientContext)) { var json = JsonConvert.SerializeObject(parameters, DefaultSerializationSettings); var response = await http.PostAsync(BaseUri + relativeUri, new StringContent(json, Encoding.UTF8, "application/json"), CancellationToken.None); if (!response.IsSuccessStatusCode) { throw new PrintNodeException(response); } return(await response.Content.ReadAsStringAsync()); } }