Code Samples

This page contains a number of small code samples. These samples demonstrate the process of connecting to our server, using our API, and testing a comment.

These samples do not contain error checking, but may be useful starting points for future development.

Perl Sample

The following sample uses the RPC::XML library, (simple XML-RPC introduction), to make a test.


#!/usr/bin/perl

use strict;
use warnings;

require RPC::XML;
require RPC::XML::Client;

my $client = RPC::XML::Client->new('http://test.blogspam.net:8888/');

#
#  The comment we're testing.  In the perl XML-RPC mapping
# a struct is a hash.  Makes sense.
#
my %params = ( ip      => "192.168.1.1",
               comment => "You suck"
             );

my $res = $client->send_request('testComment', \%params);

print "Response: " . $res->value . "\n";


[Download this sample]

Python Sample

The following sample, contributed by Muntasir Azam Khan, uses the Python scripting language to submit a comment for testing:


#! /usr/bin/python

from xmlrpclib import ServerProxy, Error

if __name__=='__main__':
        server=ServerProxy('http://test.blogspam.net:8888/')

        comment_details={
                        'ip':'1.2.3.4',
                        'email':'pvsnpnutter@nutters.com',
                        'name':'nutcase',
                        'comment':'you suck'
                        }
        try:
                print server.testComment(comment_details)
        except Error, v:
                print v

[Download this sample]

Ruby Sample

The following sample uses Ruby, and the xmlrpc module, to submit a comment for testing:


#!/usr/bin/ruby1.8

# Use the RPC client
require "xmlrpc/client"

# Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( "test.blogspam.net", "/", 8888 )

# The comment we're testing
message = { "ip"      => "1.2.3.4",
            "email"   => "foo@example.com",
            "name"    => "Some Spammer",
            "comment" => "you suck" }

# Now call the test method
result = server.call( "testComment", message )

# Show the result
print "Result: #{result}\n"

[Download this sample]