Module: Sem4r

Defined in:
lib/sem4r/base.rb,
lib/sem4r/account.rb,
lib/sem4r/adwords.rb,
lib/sem4r/profile.rb,
lib/sem4r/service.rb,
lib/sem4r/version.rb,
lib/sem4r/operation.rb,
lib/sem4r/extensions.rb,
lib/sem4r/credentials.rb,
lib/sem4r/sem4r_error.rb,
lib/sem4r/sem4r_templates.rb,
lib/sem4r/sem4r_utilities.rb,
lib/sem4r/ad_group/ad_group.rb,
lib/sem4r/ad_param/ad_param.rb,
lib/sem4r/campaign/campaign.rb,
lib/sem4r/info/info_service.rb,
lib/sem4r/v13_report/report.rb,
lib/sem4r/info/info_selector.rb,
lib/sem4r/geo_location/address.rb,
lib/sem4r/v13_report/report_job.rb,
lib/sem4r/ad_group/ad_group_bids.rb,
lib/sem4r/ad_group_ad/ad_group_ad.rb,
lib/sem4r/ad_group/mobile_ad_image.rb,
lib/sem4r/ad_group/ad_group_service.rb,
lib/sem4r/ad_param/ad_param_service.rb,
lib/sem4r/campaign/campaign_service.rb,
lib/sem4r/v13_report/report_service.rb,
lib/sem4r/ad_param/ad_param_operation.rb,
lib/sem4r/info/info_account_extension.rb,
lib/sem4r/v13_account/account_service.rb,
lib/sem4r/v13_account/billing_address.rb,
lib/sem4r/ad_group_ad/ad_group_text_ad.rb,
lib/sem4r/ad_group_criterion/criterion.rb,
lib/sem4r/targeting_idea/targeting_idea.rb,
lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb,
lib/sem4r/bulk_mutate_job/job_operations.rb,
lib/sem4r/report_definition/report_field.rb,
lib/sem4r/ad_group_ad/ad_group_ad_service.rb,
lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb,
lib/sem4r/geo_location/geo_location_service.rb,
lib/sem4r/ad_group_ad/ad_group_ad_operations.rb,
lib/sem4r/geo_location/geo_location_selector.rb,
lib/sem4r/campaign/campaign_account_extension.rb,
lib/sem4r/report_definition/report_definition.rb,
lib/sem4r/v13_report/report_account_extension.rb,
lib/sem4r/ad_group_criterion/criterion_keyword.rb,
lib/sem4r/ad_group_criterion/ad_group_criterion.rb,
lib/sem4r/targeting_idea/targeting_idea_service.rb,
lib/sem4r/v13_account/account_account_extension.rb,
lib/sem4r/ad_group_criterion/criterion_placement.rb,
lib/sem4r/targeting_idea/targeting_idea_selector.rb,
lib/sem4r/bulk_mutate_job/bulk_mutate_job_service.rb,
lib/sem4r/bulk_mutate_job/bulk_mutate_job_selector.rb,
lib/sem4r/ad_group_criterion/ad_group_criterion_bids.rb,
lib/sem4r/geo_location/geo_location_account_extension.rb,
lib/sem4r/report_definition/report_definition_service.rb,
lib/sem4r/report_definition/report_definition_selector.rb,
lib/sem4r/ad_group_criterion/ad_group_criterion_service.rb,
lib/sem4r/report_definition/report_definition_operation.rb,
lib/sem4r/targeting_idea/targeting_idea_account_extension.rb,
lib/sem4r/ad_group_criterion/ad_group_criterion_operations.rb,
lib/sem4r/bulk_mutate_job/bulk_mutate_job_account_extension.rb,
lib/sem4r/report_definition/report_definition_account_extension.rb

Overview


Copyright © 2009-2010 Sem4r [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Defined Under Namespace

Modules: AccountAccountExtension, AccountCampaignExtension, AccountInfoExtension, BulkMutateJobAccountExtension, CoreExtensions, GeoLocationAccountExtension, ReportAccountExtension, ReportDefinitionAccountExtension, TargetingIdeaExtension Classes: Account, AccountService, AdGroup, AdGroupAd, AdGroupAdOperation, AdGroupAdService, AdGroupBids, AdGroupCriterion, AdGroupCriterionBids, AdGroupCriterionOperation, AdGroupCriterionService, AdGroupMobileAd, AdGroupService, AdGroupTextAd, AdParam, AdParamOperation, AdParamService, Address, Adwords, Base, BiddableAdGroupCriterion, BillingAddress, BudgetOptimizerAdGroupBids, BudgetOptimizerAdGroupCriterionBids, BulkMutateJob, BulkMutateJobSelector, BulkMutateJobService, Campaign, CampaignService, ConversionOptimizerAdGroupBids, ConversionOptimizerAdGroupCriterionBids, CountryTargetSearchParameter, Credentials, Criterion, CriterionKeyword, CriterionPlacement, ExcludedKeywordSearchParameter, GeoLocationSelector, GeoLocationService, InfoSelector, InfoService, JobOperation, KeywordMatchTypeSearchParameter, ManualCPCAdGroupBids, ManualCPCAdGroupCriterionBids, ManualCPMAdGroupBids, ManualCPMAdGroupCriterionBids, MobileAdImage, NegativeAdGroupCriterion, NgramGroupsSearchParameter, Operation, Profile, RelatedToKeywordSearchParameter, Report, ReportDefinition, ReportDefinitionOperation, ReportDefinitionSelector, ReportDefinitionService, ReportField, ReportJob, ReportService, Sem4rError, Service, TIdeaTypeAttribute, TKeywordAttribute, TMonthlySearchVolumeAttribute, TargetingIdea, TargetingIdeaSelector, TargetingIdeaService

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pretty_print_xml_with_nokogiri(xml) ⇒ Object



106
107
108
109
110
111
# File 'lib/sem4r/sem4r_utilities.rb', line 106

def self.pretty_print_xml_with_nokogiri(xml)
  doc  = Nokogiri::XML(xml)
  xslt = Nokogiri::XSLT(@_nokogiri_xsl)
  out  = xslt.transform(doc).root.to_xml # using root omit the xml declaration
  # out.gsub(/<\?xml version.rb=('|")1.0('|") encoding=('|")UTF-8('|")\?>/, "")
end

.pretty_print_xml_with_rexml(xml) ⇒ Object

def pretty_xml(xml)

normalized = Class.new(REXML::Formatters::Pretty) do
  def write_text(node, output)
    super(node.to_s.strip, output)
  end
end
normalized.new(0, false).write(xml, xml_pretty='')
xml_pretty

end



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sem4r/sem4r_utilities.rb', line 37

def self.pretty_print_xml_with_rexml(xml)
  # TODO: using nokogiri also for pretty print xml ?
  require 'rexml/document'
  begin
    xml_document = REXML::Document.new(xml)
    f            = REXML::Formatters::Pretty.new
    out          = String.new
    f.write(xml_document, out)
    # remove xml directive
    out.gsub("<?xml version.rb='1.0' encoding='UTF-8'?>", "")
  rescue
    #    rescue RuntimeError
    puts "----------------------------------"
    puts xml
    puts "----------------------------------"
    raise
  end
  out
end

Instance Method Details

#template_bulk_mutate_job(campaign, adgroup) ⇒ Object

create an example mutate job useful for test, example, etc



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sem4r/sem4r_templates.rb', line 51

def template_bulk_mutate_job(campaign, adgroup)
  # TextAd
  text_ad1                    = AdGroupTextAd.new(adgroup)
  text_ad1.headline           = "Cruise to Mars Sector 1"
  text_ad1.description1       = "Visit the Red Planet in style."
  text_ad1.description2       = "Low-gravity fun for everyone!"
  text_ad1.url                = "http://www.example.com"
  text_ad1.display_url        = "www.example.com"

  # TextAd
  text_ad2                    = AdGroupTextAd.new(adgroup)
  text_ad2.headline           = "Cruise to Mars Sector 2"
  text_ad2.description1       = "Visit the Red Planet in style."
  text_ad2.description2       = "Low-gravity fun for everyone!"
  text_ad2.url                = "http://www.example.com"
  text_ad2.display_url        = "www.example.com"


  bulk_mutate_job             = BulkMutateJob.new
  bulk_mutate_job.campaign_id = campaign.id
  bulk_mutate_job.add_operation AdGroupAdOperation.add text_ad1
  bulk_mutate_job.add_operation AdGroupAdOperation.add text_ad2

  bulk_mutate_job
end

#template_campaign_and_ad_group(account) ⇒ Object

create an example mutate job useful for test, example, etc



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/sem4r/sem4r_templates.rb', line 31

def template_campaign_and_ad_group()
   = .client_accounts.first

  campaign       = Campaign.create() do
    name "campaign #{Time.now.strftime('%m%d-%H%M%S')}"
  end

  ad_group       = campaign.ad_group do
    name "adgroup #{Time.now.strftime('%m%d-%H%M%S')}"
  end

  puts "created campaign '#{campaign.name}' with id '#{campaign.id}'"
  puts "created adgroup '#{ad_group.name}' with id '#{ad_group.id}'"
  [campaign, ad_group]
end