HTTP-API/SELECT
select - Getting data by ID or Message Token
Beginning with bounceHammer 2.4.0, HTTP-API(select) is for getting data from a database by specifying ID or
Message Token.
The purpose of this API(select) is to get data from other host or network
via HTTP. For Example, at web site (low page traffic), The result of email address
verification will be displayed at each user's page.
In The Case of Mass Email Delivery
If you want to get many records for verifying email addresses before mass email delivery, you may use datadumper command instead of this API.
How to use API(select)
A URL for getting data via API(select) is the following format:
http://Hostname (bounceHammer is running)/CGI script name of API/select/Message Token or ID .
Example implementation with Perl and Python
Perl
The following code shows an easy example of implementation with Perl.
The code is not include error handling. In this section,
the following code use JSON::Syck module because bounceHammer's HTTP-API output data
as JSON format.
#!/usr/local/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use JSON::Syck;
use Digest::MD5;
my $addresser = q{sender01@example.jp};
my $recipient = q{user01@example.org};
my $queryhost = q{http://apitest.bouncehammer.jp/index.cgi/query/};
my $mesgtoken = Digest::MD5::md5_hex(sprintf("\x02%s\x1e%s\x03",$addresser,$recipient));
my $useragent = new LWP::UserAgent();
my $response = $useragent->request( HTTP::Request->new( GET => $queryhost.$mesgtoken ));
my $metadata = JSON::Syck::Load($response->content()) || [];
foreach my $j ( @$metadata )
{
printf( "%s: %s\n", $j->{recipient}, $j->{reason} );
}
Python
The following code shows an easy example of implementation with Python.
The code is not include error handling. In this section, the following code use simplejson module
because bounceHammer's HTTP-API output data as JSON format.
#!/usr/bin/python
# coding: utf-8
import urllib2
import simplejson
import md5
addresser = 'sender01@example.jp'
recipient = 'user01@example.org'
mesgtoken = md5.new('\x02%s\x1e%s\x03' % (addresser,recipient))
queryhost = 'http://apitest.bouncehammer.jp/index.cgi/query/'
response = urllib2.urlopen( queryhost + mesgtoken.hexdigest() )
metadata = simplejson.load(response)
for j in metadata:
print j['recipient'] + ': ' + j['reason']
If you use Ruby or PHP, you can find sample scripts: request-to-api.{rb,php} in Ruby(1.9) and PHP in bounceHammer's source distribution/examples directory .
No TrackBacks
TrackBack URL: http://bouncehammer.jp/cgi-bin/mt/mt-tb.cgi/136

Leave a comment