**
I am currently testing some code from google adwords ruby api.
class CampaignController < ApplicationController
PAGE_SIZE = 50
def index()
@selected_account = selected_account
if @selected_account
response = request_campaigns_list()
if response
@campaigns = Campaign.get_campaigns_list(response)
@campaign_count = response[:total_num_entries]
end
end
end
private
def request_campaigns_list()
api = get_adwords_api()
service = api.service(:CampaignService, get_api_version())
selector = {
:fields => ['Id', 'Name', 'Status'],
:ordering => [{:field => 'Id', :sort_order => 'ASCENDING'}],
:paging => {:start_index => 0, :number_results => PAGE_SIZE}
}
result = nil
begin
result = service.get(selector)
rescue AdwordsApi::Errors::ApiException => e
logger.fatal("Exception occurred: %s\n%s" % [e.to_s, e.message])
flash.now[:alert] =
'API request failed with an error, see logs for details'
end
return result
endend
class Campaign
attr_reader :id
attr_reader :name
attr_reader :status
def initialize(api_campaign)
@id = api_campaign[:id]
@name = api_campaign[:name]
@status = api_campaign[:status]
end
def self.get_campaigns_list(response)
result = {}
if response[:entries]
response[:entries].each do |api_campaign|
campaign = Campaign.new(api_campaign)
result[campaign.id] = campaign
end
end
return result
endend
What I want to do is take the value of @campaign_count (from the
controller) and save it in a db. I tried adding the code for inserting the
value in the db, but it says that I'm missing few parameters. I want to
save this value because I want to display it in application.html.erb, or
otherwise I will have to request data from the api every time I load a page.
Campaign.create(:total_campaigns => 2)
Thank you.
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.