public Task SendGiftRequestEmailAsync(string productKey, string recipientEmail) { if (productKey == null) { throw new ArgumentNullException(nameof(productKey)); } if (recipientEmail == null) { throw new ArgumentNullException(nameof(productKey)); } return(Task.Run(() => { DrmClient.EnsureLoggedIn(false); var resp = Rest.DoPost("Product/Gift/Request", new { SessionKey = DrmClient.SessionKey, ProductKeyToGift = productKey, EmailAddressToGiftTo = recipientEmail }); if (resp.Message == "user_not_found") { throw new AccountDetailsIncorrectException("user_not_found"); } if (resp.Message == "product_key_not_found") { throw new ProductKeyNotFoundException(); } })); }
public Task <bool> RedeemAsync(string productKey) { if (!DrmClient._initialized) { throw new NotInitializedException(); } if (productKey == null) { throw new ArgumentNullException(nameof(productKey)); } return(Task.Run(() => { DrmClient.EnsureLoggedIn(); var resp = Rest.DoPost("Product/Redeem", new { SessionKey = DrmClient.SessionKey, ProductKey = productKey }); if (resp.Message == "product_key_not_found") { throw new ProductKeyNotFoundException(); } if (resp.Message == "product_key_already_redeemed") { throw new ProductKeyAlreadyRedeemedException(); } return true; })); }
public Task <string> GetServerTokenAsync() { return(Task.Run(() => { DrmClient.EnsureLoggedIn(false); var resp = Rest.DoPost <GetServerTokenResponse>("Token/Get", new { SessionKey = DrmClient.SessionKey }); return resp.Data.Token; })); }
public static Model <T> DoGet <T>(string address) { address = UrlBase + address; try { var req = WebRequest.Create(address); req.Method = "GET"; using (var response = (HttpWebResponse)req.GetResponse()) { if (response.StatusCode == HttpStatusCode.RequestTimeout) { DrmClient.EnsureInitialized(); DrmClient.Offline = true; throw new Exceptions.UnableToAccessAccountServerException(); } if (response.StatusCode != HttpStatusCode.OK) { throw new Exceptions.AccountServerException(); } var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); DrmClient.EnsureInitialized(); DrmClient.Offline = false; var resp = JsonConvert.DeserializeObject <Model <T> >(responseString); if (resp.Message == "invalid_request" || resp.Message == "unknown_error") { throw new Exceptions.AccountServerException(); } return(resp); } } catch (Exception ex) { throw new Exceptions.AccountServerException(ex); } }