Email Validation C# Code Snippet

EV3Response result = null;
string mainURL = "https://trial.serviceobjects.com/ev3/web.svc/json/ValidateEmailInfo?" + "EmailAddress=" + email + "&AllowCorrections=" + allowcorrections + "&Timeout=" + timeout + "&LicenseKey=" + licenseKey;
string backupURL = "https://trial.serviceobjects.com/ev3/web.svc/json/ValidateEmailInfo?" + "EmailAddress=" + email + "&AllowCorrections=" + allowcorrections + "&Timeout=" + timeout + "&LicenseKey=" + licenseKey;
try
{
    HttpWebRequest request = WebRequest.Create(mainURL) as HttpWebRequest;
    request.Timeout = 5000;//timeout for get operation
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        if (response.StatusCode != HttpStatusCode.OK)
        {
            throw new Exception(String.Format("Server error (HTTP {0}: {1}).",response.StatusCode,response.StatusDescription));
        }
        //parse response
        DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(EV3Response));
        object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
        result = objResponse as EV3Response;
    }
}
catch (Exception e)
{   //ERROR IN MAIN URL - USING BACKUP
    HttpWebRequest request = WebRequest.Create(backupURL) as HttpWebRequest;
    request.Timeout = 5000;//timeout for get operation
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
    {
        if (response.StatusCode != HttpStatusCode.OK)
        {
            throw new Exception(String.Format("Server error (HTTP {0}: {1}).",response.StatusCode,response.StatusDescription));
        }
        //parse response
        DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(EV3Response));
        object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
        result = objResponse as EV3Response;
    }
}

Email Validation 3 Java Code Snippet

ValidateEmailResponse.Error error = null;
ValidateEmailResponse.ValidateEmailInfo info = null;
try {
  
    String email = request.getParameter("iEmail");
    String allowcorrections = request.getParameter("iAllowCorrections");
    String timeout = request.getParameter("iTimeout");
    String licenseKey = request.getParameter("iKey");
  
    EV3RestClient EV3Client = new EV3RestClient();
    ValidateEmailResponse result = EV3Client.ValidateEmailResponse(email, allowcorrections, timeout, licenseKey);
    if (result != null) {
        error = result.error;
        info = result.ValidateEmailInfo;
    }

Email Validation 3 PHP Code Snippet

// variable cleanup before generating url
$Email = trim($Email);
$AllowCorrections = trim($AllowCorrections);
$Timeout = trim($Timeout);
$LicenseKey = trim($LicenseKey);
  
  
$URL = "https://trial.serviceobjects.com/ev3/web.svc/json/ValidateEmailInfo?EmailAddress=".urlencode($Email)."&AllowCorrections=".urlencode($AllowCorrections)."&Timeout=".urlencode($Timeout)."&LicenseKey=".urlencode($LicenseKey);
  
//use backup url once given purchased license key
$backupURL = "https://trial.serviceobjects.com/ev3/web.svc/json/ValidateEmailInfo?EmailAddress=".urlencode($Email)."&AllowCorrections=".urlencode($AllowCorrections)."&Timeout=".urlencode($Timeout)."&LicenseKey=".urlencode($LicenseKey);
  
  
    // Get cURL resource
    $curl = curl_init();
    curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $URL, CURLOPT_USERAGENT => 'Service Objects Email Validation 3'));
    curl_setopt($curl, CURLOPT_TIMEOUT, 50); //timeout in seconds
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
      
    // Close request to clear up some resources
    if($resp == false)
    {
        echo "IN back up block";
        curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $backupURL, CURLOPT_USERAGENT => 'Service Objects Email Validation 3'));
        curl_setopt($curl, CURLOPT_TIMEOUT, 50); //timeout in seconds
        // Send the request & save response to $resp
        $resp = curl_exec($curl);
        if($resp == false)
        {
            echo "<b> Both rest calls failed </b>";
            curl_close($curl);
            return;
        }
      
      
    }
curl_close($curl);

Email Validation 3 RoR Code Snippet

#This sets the default timeout for HTTParty get operation. This must be set in order to use the gem
    default_timeout = 10
  
    licensekey = @request.licensekey
    timeout = @request.timeout
    allowcorrections = @request.allowcorrections
    email = @request.email
    #Checks the users input and sets values equal to an underscore if the user entered nil.
    #These can be changed to whatever your application might need.
    email = "" if @request.email == nil
    timeout = "" if @request.timeout == nil
    allowcorrections = "" if @request.allowcorrections == nil
    licensekey = "" if @request.licensekey == nil
  
   #Set Primary and Backup URLs as needed
    primaryURL = URI.encode("https://trial.serviceobjects.com/ev3/web.svc/json/ValidateEmailAddress?EmailAddress=" + email + "&AllowCorrections=" + allowcorrections + "&Timeout=" + timeout + "&LicenseKey=" + licensekey )
    backupURL = URI.encode("https://trial.serviceobjects.com/ev3/web.svc/json/ValidateEmailAddress?EmailAddress=" + email + "&AllowCorrections=" + allowcorrections + "&Timeout=" + timeout + "&LicenseKey=" + licensekey )
     
   #These are set to access the hash that is returned
    @validateemailresponse = "ValidateEmailResponse"
    @validateemailinfo = "ValidateEmailInfo"
    @error = "Error"
  
    #Begins the call the RESTful web service
    begin
      response = HTTParty.get(primaryURL, timeout: default_timeout)
      #processes the response to display to the screen
        
      #Passes the response from HTTParty and the hash key values to this method
      processresults(response)
     rescue StandardError => e
          begin
          #uses the backupURl in the event that the service encountered an error
          response = HTTParty.get(backupURL, timeout: default_timeout)
          
        #processes the response returned from using the backupURL
         processresults(response)
  
        #If the backup url railed this will raise an error and display the
        #error message returned from the HTTParty gem.
          rescue StandardError => error
          end
    end
end
  private
    def processresults(response) 
    #Processes Error Response from rest Client   
    #Processes Valid response from rest client 
   end

Email Validation 3 Python Code Snippet

mEmailAddress =  EmailAddress.get()
if mEmailAddress is None or  mEmailAddress == "":
     mEmailAddress = " "
mAllowCorrections =  AllowCorrections.get()
if mAllowCorrections is None or  mAllowCorrections == "":
     mAllowCorrections = " "
mTimeout =  Timeout.get()
if mTimeout is None or  mTimeout == "":
     mTimeout = " "
mLicenseKey = LicenseKey.get()
if mLicenseKey is None or mLicenseKey == "":
    mLicenseKey = " "
#Set the primary and backup URL as needed.
primaryURL = 'https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?'
backupURL = 'https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?'
#The
 Requests package allows the user to format the path parameters like so
instead of having to manually insert them into the URL
inputs = {'EmailAddress': mEmailAddress, 'AllowCorrections': mAllowCorrections, 'Timeout': mTimeout, 'LicenseKey': mLicenseKey}
try:
    result = requests.get(primaryURL, params=inputs)
    #Parses the XML response from the service into a python dictionary type
    outputs = xmltodict.parse(result.content)
    #checks the output for Errors and displays the info accordingly
    if 'Error' in outputs['ValidateEmailResponse']:
        #loops through the response from the service and prints the values to the screen.
        for key, value in outputs['ValidateEmailResponse']['Error'].iteritems():
            Label(swin.window, text=str(key) + " : " + str(value)).pack()
    else:
        for key, value in outputs['ValidateEmailResponse']['ValidateEmailInfo'].iteritems():
            Label(swin.window, text=str(key) + " : " + str(value)).pack()

Email Validation 3 ColdFusion Code Snippet

<!--Makes Request to web service --->
<cfIf isDefined("form.Action") AND Action neq ""  >
    <cftry>
        <cfset primaryURL = "https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?EmailAddress=#EmailAddress#&AllowCorrections=#AllowCorrections#&Timeout=#Timeout#&LicenseKey=#LicenseKey#">
        <cfhttp url="#primaryURL#" method="get" result="response">
        <cfset outputs = XmlParse(response.FileContent)>
    <cfcatch >
        <cftry>
            <cfset backupURL = "https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?EmailAddress=#EmailAddress#&AllowCorrections=#AllowCorrections#&Timeout=#Timeout#&LicenseKey=#LicenseKey#">
            <cfhttp url="#backupURL#" method="get" result="response">
            <cfset outputs = XmlParse(outputs.FileContent)>              
            <cfcatch >
                <cfoutput >
                    The Following Error Occured: #response.StatusCode#
                </cfoutput>
            </cfcatch>
        </cftry>
    </cfcatch>
    </cftry>
</cfif>

Email Validation 3 VB Code Snippet

email = Me.EmailAddress.Text
licensekey = Me.LicenseKey.Text
allowcorrections = Me.AllowCorrections.Text
timeout = Me.Timeout.Text
Try
    'encodes the URLs for the get Call. Set the primary and back urls as necessary
    Dim primaryurl As String = "https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?EmailAddress=" & email + "&AllowCorrections=" + allowcorrections + "&Timeout=" + timeout + "&LicenseKey=" & licensekey
    Dim backupurl As String = "https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?EmailAddress=" & email + "&AllowCorrections=" + allowcorrections + "&Timeout=" + timeout + "&LicenseKey=" & licensekey
    Dim wsresponse As EV3Response.ValidateEmailResponse = httpGet(primaryurl)
  
    'checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured.
    If wsresponse Is Nothing OrElse (wsresponse.[Error] IsNot Nothing AndAlso wsresponse.[Error].TypeCode = "3") Then
        wsresponse = httpGet(backupurl)
    End If
    If wsresponse.[Error] IsNot Nothing Then
        ProcessErrorResponse(wsresponse.[Error])
    Else
        ProcessSuccessfulResponse(wsresponse)
    End If
Catch ex As Exception
    'Displays the relevant error mesasge if both backup and primary urls failed.
    resultsLabel.Text = ex.Message
    resultsLabel.Visible = True
End Try

Email Validation 3 TSQL Code Snippet

--If a production key is purchased, this will execute the failover
IF @isLiveKey = 1
BEGIN
    SET @sUrl = 'https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?EmailAddress=' + @email + '&AllowCorrections=' + @allowcorrections + '&Timeout=' + @timeout + '&LicenseKey=' + @key
    EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
    EXEC sp_OAMethod @obj, 'Open', NULL, 'Get', @sUrl, false
    EXEC sp_OAMethod @obj, 'send'
    EXEC sp_OAGetProperty @obj, 'responseText', @response OUT
              
    --Checks the Response for a fatal error or if null.
    IF @response IS NULL
    BEGIN
        SET @sBackupUrl = 'https://trial.serviceobjects.com/ev3/web.svc/xml/ValidateEmailAddress?EmailAddress=' + @email + '&AllowCorrections=' + @allowcorrections + '&Timeout=' + @timeout + '&LicenseKey=' + @key
        EXEC sp_OACreate 'MSXML2.ServerXMLHttp', @obj OUT
        EXEC sp_OAMethod @obj, 'Open', NULL, 'Get', @sBackupUrl, false
        EXEC sp_OAMethod @obj, 'send'
        EXEC sp_OAGetProperty @obj, 'responseText', @response OUT
    END
END