Class: Adapi::AdParam
Constant Summary collapse
- ATTRIBUTES =
[ :ad_group_id, :criterion_id, :insertion_text, :param_index ]
Constants inherited from Api
Adapi::Api::API_EXCEPTIONS, Adapi::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
- #create ⇒ Object
-
#initialize(params = {}) ⇒ AdParam
constructor
A new instance of AdParam.
Methods inherited from Api
#[], #[]=, #check_for_errors, create, #mutate, #new?, #persisted?, #store_errors, to_micro_units, #to_param, update
Constructor Details
#initialize(params = {}) ⇒ AdParam
Returns a new instance of AdParam.
16 17 18 19 20 21 22 23 24 |
# File 'lib/adapi/ad_param.rb', line 16 def initialize(params = {}) params[:service_name] = :AdParamService ATTRIBUTES.each do |param_name| self.send "#{param_name}=", params[param_name] end super(params) end |
Class Method Details
.find(params = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/adapi/ad_param.rb', line 54 def self.find(params = {}) params.symbolize_keys! predicates = [ :ad_group_id, :criterion_id ].map do |param_name| if params[param_name] value = Array.try_convert(params[param_name]) ? params_param_name : [params[param_name]] {:field => param_name.to_s.camelcase, :operator => 'IN', :values => value } end end.compact selector = { :fields => ['AdGroupId', 'CriterionId', 'InsertionText', 'ParamIndex'], :predicates => predicates } response = AdParam.new.service.get(selector) response = (response and response[:entries]) ? response[:entries] : [] response.map! do |ad_params_data| AdParam.new(ad_params_data) end response end |
Instance Method Details
#attributes ⇒ Object
12 13 14 |
# File 'lib/adapi/ad_param.rb', line 12 def attributes super.merge Hash[ ATTRIBUTES.map { |k| [k, self.send(k)] } ] end |
#create ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/adapi/ad_param.rb', line 26 def create operation = { :operator => 'SET', :operand => self.attributes } begin response = @service.mutate([operation]) #rescue AdsCommon::Errors::HttpError => e #self.errors.add(:base, e.message) ## traps any exceptions raised by AdWords API #rescue AdwordsApi::Errors::ApiException => e # # return PolicyViolations so they can be sent again # e.errors.each do |error| # if (error[:api_error_type] == 'PolicyViolationError') && error[:is_exemptable] # self.errors.add(error[:api_error_type], error[:key]) # else # # otherwise, just report the errors # self.errors.add( "[#{self.xsi_type.underscore}]", "#{error[:error_string]} @ #{error[:field_path]}") # end # end end response end |