Class: MarketoAPI::Leads

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

Overview

Implements Lead operations for Marketo.

Instance Method Summary collapse

Methods inherited from ClientProxy

inherited, #initialize

Constructor Details

This class inherits a constructor from MarketoAPI::ClientProxy

Instance Method Details

#activity(lead_key, options = {}) ⇒ Object

:nodoc:

Raises:

  • (NotImplementedError)


97
98
99
# File 'lib/marketo_api/leads.rb', line 97

def activity(lead_key, options = {}) #:nodoc:
  raise NotImplementedError
end

#changes(start_position, options = {}) ⇒ Object

:nodoc:

Raises:

  • (NotImplementedError)


101
102
103
# File 'lib/marketo_api/leads.rb', line 101

def changes(start_position, options = {}) #:nodoc:
  raise NotImplementedError
end

#get(type_or_key, value = nil) ⇒ Object

Implements href="http://developers.marketo.com/documentation/soap/getlead/">, returning a MarketoAPI::Lead object.

:call-seq:

get(lead_key) -> Lead
get(key_type, key_value) -> Lead


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/marketo_api/leads.rb', line 24

def get(type_or_key, value = nil)
  key = case type_or_key
        when Hash
          if lk = type_or_key[:leadKey]
            if MarketoAPI::Lead.send(:key_type, lk[:keyType])
              type_or_key
            end
          end
        when MarketoAPI::Lead
          transform_param(__method__, type_or_key)
        else
          MarketoAPI::Lead.key(type_or_key, value)
        end

  unless key
    raise ArgumentError, "#{type_or_key} is not a valid lead key"
  end
  extract_from_response(call(:get_lead, key), :lead_record_list) { |record|
    MarketoAPI::Lead.from_soap_hash(record[:lead_record]) do |lead|
      lead.proxy = self
    end
  }
end

#get_multiple(selector) ⇒ Object

:nodoc:

Raises:

  • (NotImplementedError)


64
65
66
# File 'lib/marketo_api/leads.rb', line 64

def get_multiple(selector) #:nodoc:
  raise NotImplementedError
end

#merge(winning_key, losing_keys) ⇒ Object

:nodoc:

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/marketo_api/leads.rb', line 93

def merge(winning_key, losing_keys) #:nodoc:
  raise NotImplementedError
end

#nameObject

:method: get_by_salesforce_opportunity_id :call-seq: get_by_salesforce_opportunity_id(salesforce_opportunity_id)

Gets the Lead by the provided SFDC Opportunity ID.



166
167
168
169
170
# File 'lib/marketo_api/leads.rb', line 166

MarketoAPI::Lead::NAMED_KEYS.each_pair { |name, key|
  define_method(:"get_by_#{name}") do |value|
    get(key, value)
  end
}

#new(options = {}, &block) ⇒ Object

Creates a new lead with a proxy to this Leads instance.

:call-seq:

new -> Lead
new { |lead| ... } -> Lead
new(options) -> Lead
new(options) { |lead| ... } -> Lead


13
14
15
# File 'lib/marketo_api/leads.rb', line 13

def new(options = {}, &block)
  MarketoAPI::Lead.new(options.merge(proxy: self), &block)
end

#sync(lead_record) ⇒ Object

Implements href="http://developers.marketo.com/documentation/soap/synclead/">, returning a MarketoAPI::Lead object.

:call-seq:

sync(Lead) -> Lead


54
55
56
57
58
59
60
61
62
# File 'lib/marketo_api/leads.rb', line 54

def sync(lead_record)
  extract_from_response(
    call(:sync_lead, transform_param(__method__, lead_record)),
  ) { |record|
    MarketoAPI::Lead.from_soap_hash(record[:lead_record]) do |lead|
      lead.proxy = self
    end
  }
end

#sync_multiple(leads, options = { dedup_enabled: true }) ⇒ Object

Implements href="http://developers.marketo.com/documentation/soap/syncmultipleleads/">, returning an array of MarketoAPI::Lead objects.

May optionally disable de-duplication by passing dedup_enabled: false.

:call-seq:

sync_multiple(leads) -> array of Lead
sync_multiple(leads, dedup_enabled: false) -> array of Lead


78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/marketo_api/leads.rb', line 78

def sync_multiple(leads, options = { dedup_enabled: true })
  response = call(
    :sync_multiple_leads,
    dedupEnabled:   options[:dedup_enabled],
    leadRecordList: transform_param_list(:sync, leads)
  )
  extract_from_response(response, :lead_record_list) do |list|
    list.each do |record|
      MarketoAPI::Lead.from_soap_hash(record[:lead_record]) do |lead|
        lead.proxy = self
      end
    end
  end
end