Create a new campaign

The idea underline sem4r is to have the code readible as much as possible.
The code for the creation of campaign looks like more natural1
than a bunch of arrays and hashes.

Account exposes the method create_campaign than take a block.
The block specifies the campaign name, and the adgroups contained into the campaign.
The adgroup take a block that specified the criterion contained into the adgroup.

campaign = account.create_campaign do
  name "new campaign #{Time.now}"
  adgroup do
    name "new adgroup #{Time.now}"
    keyword do
      text       "keyword"
      match      "BROAD"
    end
    placement do
      url "www.example.com"
    end
  end
end

The criterion can be keyword or placement.

Putting all together:

 1 require 'rubygems'
 2 require 'sem4r'
 3 include Sem4r
 4 
 5 adwords = Adwords.sandbox(
 6   :email => "<myaccount>@gmail.com",
 7   :password => "secret",
 8   :developer_token => "<myaccount>@gmail.com++EUR")
 9 
10 account = adwords.account.client_accounts
11 
12 campaign = account.create_campaign do
13   name "new campaign #{Time.now}"
14 
15   adgroup do
16     name "new adgroup #{Time.now}"
17     keyword do
18       text       "keyword"
19       match      "BROAD"
20     end
21     placement do
22       url "www.example.com"
23     end
24   end
25 end
26 
27 campaign.p_adgroups(true)

You can find the example code (eventually updated) on github

1 IMHO

Sem4r version 0.0.4 released

Released version 0.0.4 on gemcutter.

Fixed some bug on ruby 1.8. Now it works on ruby 1.8, 1.9 under windows
and linux.

sem4r hello world!

To install sem4r, you need Ruby and know how ruby gem works.
If you are reading this probabily you know it already. Anyway in the sidebar
there are links to learn more about Ruby.

To install sem4r, you can type:

gem install sem4r

To access adwords sandbox you need:

  • gmail account (i.e. myaccount @gmail.com)
  • password (your gmail password)
  • developer token (i.e. myaccount @gmail.com++EUR)

To connect sem4r to sandbox environment:

require 'rubygems'
require 'sem4r'
include Sem4r

adwords = Adwords.sandbox(
  :email => "<myaccount>@gmail.com",
  :password => "secret",
  :developer_token => "<myaccount>@gmail.com++EUR")

You can list all client accounts:

adwords.account.p_client_accounts

Putting all together:

1 require 'rubygems'
2 require 'sem4r'
3 include Sem4r
4 
5 adwords = Adwords.sandbox(
6   :email => "<myaccount>@gmail.com",
7   :password => "secret",
8   :developer_token => "<myaccount>@gmail.com++EUR")
9 adwords.account.p_client_accounts

The output look like this1:

myaccount@gmail.com - client_1+myaccount@gmail.com
myaccount@gmail.com - client_2+myaccount@gmail.com
myaccount@gmail.com - client_3+myaccount@gmail.com
myaccount@gmail.com - client_4+myaccount@gmail.com
myaccount@gmail.com - client_5+myaccount@gmail.com

You can find the code on github

1 the real accout name was replaced with myaccount

Sem4r version 0.0.3 released

Released version 0.0.3 on gemcutter. Added spec some tests and more examples.

Why sem4r

Sem4r is an adwords client library. The Google AdWords Api
is a webservice soap protocol. From the official site:

The Google AdWords API lets developers build applications that interact directly
with the AdWords platform. With these applications, advertisers and third
parties can more efficiently and creatively manage their large or complex
AdWords accounts and campaigns.

I used for some time adwords api for my job in PHP and sometime in Java.
Further I like to experiment in my spare time new languages, and
I found the wonderful Ruby language.

I have tryed the adwords4r, the official library by Google.
And I don’t like it. In my opinion is not rubyish and reveals
to much of the underlying lower level api.

At the best of my knowledge, the official adwords4r library
doesn’t work with Ruby 1.9, because it uses soap4r.
The soap4r library is not supported by ruby 1.9.

The library objectives are:

  • works with ruby 1.8 and 1.9
  • works under linux and windows
  • reduces external dependencies (soap4r,…)
  • implements a consistent model to hide the low level api call
  • be rubyish :-)

My personal objectives are:

  • Finding spare time to dedicate to this project
    (it is the hard thing, and i am not sure to achieve it)
  • Learning more about Ruby
  • Learning Ruby metaprogramming techniques1
  • Writing an (useful) library into a niche so I can write at my
    own pace without to many competitors :-P. I don’t have a lot of time, so I use my spare time.
  • Use English (I’m to lazy to learn it so I force myself to use it writing documentation)
  • Learning to manage a little open source project.
    (Write test, write documentation, and so on).

1 I have bought the wonderful book Metaprogramming Ruby published
by “The Pragmatic Programmer”