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