Class: MarketoAPI::Campaigns

Inherits:
ClientProxy show all
Defined in:
lib/marketo_api/campaigns.rb

Overview

Implements Campaign-related calls for Marketo.

Sources

Campaigns have a source, which the Marketo SOAP API provides as MKTOWS and SALES. MarketoAPI provides these values as the friendlier values marketo and sales, but accepts the standard Maketo SOAP API enumeration values.

Instance Method Summary collapse

Methods inherited from ClientProxy

inherited, #initialize

Constructor Details

This class inherits a constructor from MarketoAPI::ClientProxy

Instance Method Details

#for_source(source, name = nil, exact_name = nil) ⇒ Object

Implements href="http://developers.marketo.com/documentation/soap/getcampaignsforsource/">.

If possible, prefer the generated methods #for_marketo and #for_sales.

:call-seq:

for_source(source)
for_source(source, name)
for_source(source, name, exact_name)


37
38
39
40
41
42
43
44
45
46
# File 'lib/marketo_api/campaigns.rb', line 37

def for_source(source, name = nil, exact_name = nil)
  call(
    :get_campaigns_for_source,
    {
      source:      resolve_source(source),
      name:        name,
      exactName:   exact_name
    }.delete_if(&MarketoAPI::MINIMIZE_HASH)
  )
end

#request(options = {}) ⇒ Object

Implements href="http://developers.marketo.com/documentation/soap/requestcampaign/">.

Parameters

source

Required. The source of the campaign.

leads

Required. An array of Lead objects or lead keys. If both leads and lead are provided, they will be merged.

lead

An alias for leads.

campaign_id

The campaign ID to request for the lead or leads. Required if campaign_name or program_name are not provided.

campaign_name

The campaign name to request for the lead or leads. Required if campaign_id or program_name are not provided.

program_name

The program name to request for the lead or leads. Required if campaign_id or campaign_name are not provided, or if program_tokens are provided.

program_tokens

An array of program tokens in the form: { attrib: { name: name, value: value } } This will be made easier to manage in the future.

If possible, prefer #request_marketo and #request_sales.

:call-seq:

request(options)


98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/marketo_api/campaigns.rb', line 98

def request(options = {})
  source = options.fetch(:source) { :MKTOWS }
  leads = MarketoAPI.array(options.delete(:leads)) +
    MarketoAPI.array(options.delete(:lead))
  if leads.empty?
    raise ArgumentError, ':lead or :leads must be provided'
  end

  valid_id = options.has_key?(:campaign_id) ||
    options.has_key?(:campaign_name) || options.has_key?(:program_name)
  unless valid_id
    raise ArgumentError,
      ':campaign_id, :campaign_name, or :program_name must be provided'
  end

  if options.has_key?(:campaign_id) && options.has_key?(:campaign_name)
    raise ArgumentError,
      ':campaign_id and :campaign_name are mutually exclusive'
  end

  if (tokens = options.delete(:program_tokens)) && !tokens.empty?
    if !options[:program_name]
      raise KeyError,
        ':program_name must be provided when using :program_tokens'
    end
  end

  REQUEST_PARAM_XF.each { |o, n| options[n] = options.delete(o) }

  call(
    :RequestCampaign,
    options.merge(
      source:           resolve_source(source),
      leadList:         transform_param_list(:get, leads),
      programTokenList: tokens
    ).delete_if(&MarketoAPI::MINIMIZE_HASH)
  )
end

#schedule(program_name, campaign_name, options = {}) ⇒ Object

Implements href="http://developers.marketo.com/documentation/soap/schedulecampaign/">.

Optional Parameters

run_at

The time to run the scheduled campaign.

program_tokens

An array of program tokens in the form: { attrib: { name: name, value: value } } This will be made easier to manage in the future.

source must be marketo or sales or the equivalent enumerated values from the SOAP environment (MKTOWS or SALES).

:call-seq:

schedule(program_name, campaign_name, options = {})


170
171
172
173
174
175
176
177
178
179
180
# File 'lib/marketo_api/campaigns.rb', line 170

def schedule(program_name, campaign_name, options = {})
  call(
    :ScheduleCampaign,
    {
      programName:      program_name,
      campaignName:     campaign_name,
      campaignRunAt:    options[:run_at],
      programTokenList: options[:program_tokens]
    }.delete_if(&MarketoAPI::MINIMIZE_HASH)
  )
end