Class: Adapi::CampaignTarget
Overview
Constant Summary collapse
- ATTRIBUTES =
[ :campaign_id, :targets ]
Constants inherited from Api
Api::API_EXCEPTIONS, Api::LOGGER
Instance Attribute Summary
Attributes inherited from Api
#adwords, #id, #params, #service, #status, #version, #xsi_type
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(params = {}) ⇒ CampaignTarget
constructor
A new instance of CampaignTarget.
- #set ⇒ Object (also: #create)
Methods inherited from Api
#[], #[]=, #check_for_errors, create, #mutate, #new?, #persisted?, #store_errors, to_micro_units, #to_param, update
Constructor Details
#initialize(params = {}) ⇒ CampaignTarget
Returns a new instance of CampaignTarget.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/adapi/campaign_target.rb', line 22 def initialize(params = {}) params[:service_name] = :CampaignTargetService @xsi_type = 'CampaignTarget' ATTRIBUTES.each do |param_name| self.send "#{param_name}=", params[param_name] end super(params) end |
Class Method Details
.create_targets(target_type, target_data) ⇒ Object
Obsolete. Transforms our own high-level target parameters to google low-level
76 77 78 |
# File 'lib/adapi/campaign_target.rb', line 76 def self.create_targets(target_type, target_data) nil end |
.find(params = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/adapi/campaign_target.rb', line 56 def self.find(params = {}) params.symbolize_keys! if params[:conditions] params[:campaign_id] = params[:campaign_id] || params[:conditions][:campaign_id] end raise ArgumentError, "Campaing ID is required" unless params[:campaign_id] selector = { :campaign_ids => [ params[:campaign_id].to_i ] } response = CampaignTarget.new.service.get(selector) response = (response and response[:entries]) ? response[:entries] : [] response end |
Instance Method Details
#attributes ⇒ Object
18 19 20 |
# File 'lib/adapi/campaign_target.rb', line 18 def attributes super.merge Hash[ ATTRIBUTES.map { |k| [k, self.send(k)] } ] end |
#set ⇒ Object Also known as: create
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/adapi/campaign_target.rb', line 34 def set # transform our own high-level target parameters to google low-level # target parameters operations = [] @targets.each_pair do |targetting_type, targetting_settings| operations << { :operator => 'SET', :operand => { :xsi_type => "#{targetting_type.to_s.capitalize}TargetList", :campaign_id => @campaign_id, :targets => CampaignTarget::create_targets(targetting_type, targetting_settings) } } end response = self.mutate(operations) (response and response[:value]) ? true : false end |