public Detector(LoginToken token) { this.Token = token; }
public static async Task<uint> CountCreditsAsync(LoginToken token) { token.Validate(); if (token == null) throw new ArgumentNullException("token"); using (HttpClient client = new HttpClient()) { client.SetCopyleaksClient(HttpContentTypes.Json, token); HttpResponseMessage msg = await client.GetAsync(string.Format("{0}/account/count-credits", Resources.ServiceVersion)); if (!msg.IsSuccessStatusCode) { string errorResponse = await msg.Content.ReadAsStringAsync(); BadLoginResponse response = JsonConvert.DeserializeObject<BadLoginResponse>(errorResponse); if (response == null) throw new JsonException("Unable to process server response."); else throw new CommandFailedException(response.Message, msg.StatusCode); } string json = await msg.Content.ReadAsStringAsync(); if (string.IsNullOrEmpty(json)) throw new JsonException("This request could not be processed."); CountCreditsResponse res = JsonConvert.DeserializeObject<CountCreditsResponse>(json); if (token == null) throw new JsonException("Unable to process server response."); return res.Amount; } }