public void Verify(string apiKey) { try { var verificationRequest = new Verification(); verificationRequest.ApiKey = apiKey; var client = new ProwlClient(); _logger.Debug("Verifying API Key: {0}", apiKey); var verificationResult = client.SendVerification(verificationRequest); if (!string.IsNullOrWhiteSpace(verificationResult.ErrorMessage) && verificationResult.ResultCode != "200") { throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid"); } } catch (Exception ex) { _logger.DebugException(ex.Message, ex); _logger.Warn("Invalid API Key: {0}", apiKey); throw new InvalidApiKeyException("API Key: " + apiKey + " is invalid"); } }
public void BuildDictionaryForVerification_should_build_correct_dictionary() { Verification v = new Verification() { ApiKey = "1234567890123456789012345678901234567890", ProviderKey = "9012345678901234567890123456789012345678" }; Dictionary<string, string> resultDict = new RequestBuilderHelper().BuildDictionaryForVerification(v); Assert.Equal(v.ApiKey, resultDict["apikey"]); Assert.Equal(v.ProviderKey, resultDict["providerkey"]); }
public virtual bool Verify(string apiKey) { try { var verificationRequest = new Verification(); verificationRequest.ApiKey = apiKey; var client = new ProwlClient(); Logger.Trace("Verifying API Key: {0}", apiKey); var verificationResult = client.SendVerification(verificationRequest); if (String.IsNullOrWhiteSpace(verificationResult.ErrorMessage) && verificationResult.ResultCode == "200") return true; } catch (Exception ex) { Logger.TraceException(ex.Message, ex); Logger.Warn("Invalid API Key: {0}", apiKey); } return false; }