Prev | Current Page 369 | Next

David Berube

"Practical Reporting with Ruby and Rails"


You can create this database with the following command:
mysqladmin create text_ad_data
Listing 13-2. Google AdWords Database Loader (google_adwords_loader.rb)
require 'hpricot'
require 'active_record'
class AdResult < ActiveRecord::Base
end
ActiveRecord::Base.establish_connection(
:adapter=>'mysql',
:database=>'text_ad_performance',
:host=>'your_mysql_host_here',
:username=>'your_mysql_username_here',
:password=>'your_mysql_password_here')
unless AdResult.table_exists?
first_row = rows.first # We'll use this row as a model
# to create the database schema
field_override_types = {
'imps'=>:integer,
'clicks'=>:integer,
'ctr'=>:float,
'cpc'=>:integer,
'cost'=>:integer
}
ActiveRecord::Schema.define do
create_table :ad_results do |t|
first_row.attributes.each do |attribute_name, value|
if field_override_types.include?(attribute_name)
t.column attribute_name, field_override_types[attribute_name]
else
t.column attribute_name, :text, :length=>25
end
end
CHAPTER 13 n TRACKING YOUR ADS WITH GOOGLE ADWORDS 268
end
end
end
hpricot_doc = Hpricot.


Pages:
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
Prawo filmowe naprawa komputerów Warszawa spa nad morzem koszule korporacyjne Rowy noclegi