lib/sem4r/ad_group/ad_group.rb in sem4r-0.1.1 vs lib/sem4r/ad_group/ad_group.rb in sem4r-0.1.2

- old
+ new

@@ -94,14 +94,14 @@ new(campaign, &block).save end def self.from_element(campaign, el) new(campaign) do - @id = el.elements["id"].text.strip.to_i - name el.elements["name"].text.strip - status el.elements["status"].text.strip - bids el.elements["bids"] + @id = el.at_xpath("id").text.strip.to_i + name el.at_xpath("name").text.strip + status el.at_xpath("status").text.strip + bids el.at_xpath("bids") end end def save _save @@ -115,12 +115,12 @@ def _save unless @id soap_message = service.ad_group.create(credentials, to_xml("operand")) add_counters( soap_message.counters ) - rval = REXML::XPath.first( soap_message.response, "//mutateResponse/rval") - id = REXML::XPath.match( rval, "value/id" ).first + rval = soap_message.response.xpath("//mutateResponse/rval").first + id = rval.xpath("value/id").first @id = id.text.strip.to_i end end public @@ -179,12 +179,12 @@ private def _ads soap_message = service.ad_group_ad.all(credentials, id) add_counters( soap_message.counters ) - rval = REXML::XPath.first( soap_message.response, "//getResponse/rval") - els = REXML::XPath.match( rval, "entries/ad") + rval = soap_message.response.xpath("//getResponse/rval").first + els = rval.xpath( "entries/ad" ) @ads = els.map do |el| AdGroupAd.from_element( self, el ) end end @@ -196,13 +196,15 @@ xml = unsaved_ads.inject('') do |xml,ad| o = AdGroupAdOperation.new.add(ad) xml + o.to_xml("operations") end + soap_message = service.ad_group_ad.mutate(credentials, xml) add_counters( soap_message.counters ) - els = REXML::XPath.match( soap_message.response, "//mutateResponse/rval/value/ad/id") + els = soap_message.response.xpath("//mutateResponse/rval/value/ad/id") + els.each_with_index do |e,index| id = e.text.strip.to_i unsaved_ads[index].instance_eval{ @id = id } end end @@ -264,12 +266,12 @@ private def _criterions soap_message = service.ad_group_criterion.all(credentials, id) add_counters( soap_message.counters ) - rval = REXML::XPath.first( soap_message.response, "//getResponse/rval") - els = REXML::XPath.match( rval, "entries/criterion") + rval = soap_message.response.xpath("//getResponse/rval").first + els = rval.xpath( "entries/criterion" ) @criterions = els.map do |el| Criterion.from_element( self, el ) end end @@ -285,11 +287,11 @@ o = AdGroupCriterionOperation.new.add(ad) xml + o.to_xml("operations") end soap_message = service.ad_group_criterion.mutate(credentials, xml) add_counters( soap_message.counters ) - els = REXML::XPath.match( soap_message.response, "//mutateResponse/rval/value/criterion/id") + els = soap_message.response.xpath("//mutateResponse/rval/value/criterion/id") els.each_with_index do |e,index| id = e.text.strip.to_i unsaved_criterions[index].criterion.instance_eval{ @id = id } end end @@ -322,11 +324,11 @@ private def _ad_params soap_message = service.ad_param.all(credentials, id) add_counters( soap_message.counters ) - rval = REXML::XPath.first( soap_message.response, "//getResponse/rval") - els = REXML::XPath.match( rval, "entries") + rval = soap_message.response.xpath("//getResponse/rval").first + els = rval.xpath( "entries" ) @ad_params = els.map do |el| AdParam.from_element( self, el ) end end