SEM Development

December 13, 2005

Making web service APIs behave the same

Filed under: Tips & Tricks — Bob @ 5:18 pm

YSM and Google’s account management APIs look incredibly different but do, essentially, the same thing. That is, allow you to manage your SEM campaigns through a web service. Ask Jeeves has a sponsored listings product with an API for larger advertisers and MSN will soon be releasing it sponsored search product. So, how are you going to keep a similar programming interface across all of these products? I’ll tell you how I’m doing it.

Essentially, these web services boil down to a CRUD (Create, Retrieve, Update, Destroy) service for your search advertising campaigns. So, why not create a class that does all of these things for each part of a campaign?

Firstly, I want to express the way of handling CRUD that is the most intuitive to me. I use four methods in all of my classes. There are:

new() or new(ID):
Instantiates an empty object or tries to instantiate a populated object if an ID is supplied. Dies if the ID does not exist.

exists(ID):
Instantiates an object with the ID supplied or returns false.

remove():
Deletes the object.

save():
Creates the object if none exists yet or updates it if it already exists.

For Google, I’ve written 5 classes:

  • Account
  • Campaign
  • AdGroup
  • Creative
  • Keyword

For YSM, there are only 3 classes:

  • Account
  • Category
  • Listing

This allows for code that looks kind of like this (in Perl, by the way):

#Get the ad group
my @ags = Google::AdGroup->getAll;
my $ag = pop @ags;


#Make the keyword
my $kw = new Google::Keyword;
$kw->maxCpc(40000); #microns, remember
$kw->text('somethin');
$kw->destinationUrl('http://www.example.com');


#Save the keyword in the ad group
$ag->addKeyword($kw);

More intuitive, don’t you think?

2 Responses to “Making web service APIs behave the same”

  1. SEM Development » “Forking” with POE Says:

    [...] ne at the same time. This works incredibly well for my saveAll and getAll functions in my Net objects. Now I can just spray a bunch of keywords at these functions, they’ll split the keywords into the [...]

  2. SEM Development » Regression tests and web service APIs Says:

    [...] e red box is supposed to represent a Criterion object.  I’ve talked about how I create an object representation of the API services before.  Of course there are more objects but they’re [...]

Leave a Reply