lib/sem4r/ad_param/ad_param.rb in sem4r-0.1.2 vs lib/sem4r/ad_param/ad_param.rb in sem4r-0.1.3

- old
+ new

@@ -50,29 +50,45 @@ def to_s "#{@id} #{@index} #{@text}" end + # @private + # # adGroupId Id of ad_group This field is required and should not be null. # criterionId The id of the Keyword criterion that this ad parameter applies to. # The keyword must be associated with the same ad_group as this AdParam. # This field is required and should not be null. # insertionText Numeric value or currency value (eg. 15, $99.99) to insert into the ad text # This field is required and should not be null when it is contained # within Operators : SET. The length of this string should be # between 1 and 25, inclusive. # paramIndex - def to_xml(tag) - builder = Builder::XmlMarkup.new - builder.tag!(tag) do |t| - t.adGroupId @ad_group.id - t.criterionId @criterion.id - t.insertionText @text - t.paramIndex @index + def _xml(t) + t.adGroupId @ad_group.id + t.criterionId @criterion.id + t.insertionText @text + t.paramIndex @index + end + + # + # Marshall to xml + # @param [Builder::XmlMarkup] + # + def xml(t, tag = nil) + if tag + t.__send__(tag) { |t| _xml(t) } + else + _xml(t) end end + def to_xml(tag) + xml(Builder::XmlMarkup.new, tag) + end + + def self.from_element(ad_group, el) criterion_id = el.at_xpath("criterionId").text.strip.to_i criterion = ad_group.find_criterion(criterion_id) new(ad_group, criterion) do # ad_param don't have id so use @saved to indicate if readed from xml @@ -83,10 +99,10 @@ end def save return if @saved o = AdParamOperation.new.set( self ) - soap_message = service.ad_param.mutate(credentials, o.to_xml("operations") ) + soap_message = service.ad_param.mutate( credentials, o.to_xml("operations") ) add_counters( soap_message.counters ) # ignore response ad_param doesn't have id @saved = true self end