Class: Rapleaf::Marketo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/marketo/client.rb

Overview

The client for talking to marketo

based on the SOAP wsdl file: http://app.marketo.com/soap/mktows/1_4?WSDL

Usage:

client = Rapleaf::Marketo.new_client(<access_key>, <secret_key>)

get_lead_by_email:

lead_record = client.get_lead_by_email(‘[email protected]’)

puts lead_record.idnum

puts lead_record.get_attribute(‘FirstName’)

puts lead_record.get_attribute(‘LastName’)

sync_lead: (update)

lead_record = client.sync_lead(‘[email protected]’, ‘Joe’, ‘Smith’, ‘Company 1’, ‘415 911’)

sync_lead_record: (update with custom fields)

lead_record = Rapleaf::Marketo::LeadRecord.new(‘[email protected]’)

lead_record.set_attribute(‘FirstName’, ‘harry’)

lead_record.set_attribute(‘LastName’, ‘smith’)

lead_record.set_attribute(‘Email’, ‘[email protected]’)

lead_record.set_attribute(‘Company’, ‘Rapleaf’)

lead_record.set_attribute(‘MobilePhone’, ‘123 456’)

response = client.sync_lead_record(lead_record)

Instance Method Summary collapse

Constructor Details

#initialize(savon_client, authentication_header) ⇒ Client

This constructor is used internally, create your client with *Rapleaf::Marketo.new_client(<access_key>, <secret_key>)*



58
59
60
61
# File 'lib/marketo/client.rb', line 58

def initialize(savon_client, authentication_header)
  @client = savon_client
  @header = authentication_header
end

Instance Method Details

#add_to_list(list_key, email) ⇒ Object



143
144
145
# File 'lib/marketo/client.rb', line 143

def add_to_list(list_key, email)
  list_operation(list_key, ListOperationType::ADD_TO, email)
end

#get_lead_by_email(email) ⇒ Object



70
71
72
# File 'lib/marketo/client.rb', line 70

def get_lead_by_email(email)
  get_lead(LeadKey.new(LeadKeyType::EMAIL, email))
end

#get_lead_by_idnum(idnum) ⇒ Object



65
66
67
# File 'lib/marketo/client.rb', line 65

def get_lead_by_idnum(idnum)
  get_lead(LeadKey.new(LeadKeyType::IDNUM, idnum))
end

#is_member_of_list?(list_key, email) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/marketo/client.rb', line 151

def is_member_of_list?(list_key, email)
  list_operation(list_key, ListOperationType::IS_MEMBER_OF, email)
end

#remove_from_list(list_key, email) ⇒ Object



147
148
149
# File 'lib/marketo/client.rb', line 147

def remove_from_list(list_key, email)
  list_operation(list_key, ListOperationType::REMOVE_FROM, email)
end

#set_logger(logger) ⇒ Object



74
75
76
# File 'lib/marketo/client.rb', line 74

def set_logger(logger)
  @logger = logger
end

#sync_lead(email, first, last, company, mobile) ⇒ Object

create (if new) or update (if existing) a lead

  • email - email address of lead

  • first - first name of lead

  • last - surname/last name of lead

  • company - company the lead is associated with

  • mobile - mobile/cell phone number

returns the LeadRecord instance on success otherwise nil



87
88
89
90
91
92
93
94
95
# File 'lib/marketo/client.rb', line 87

def sync_lead(email, first, last, company, mobile)
  lead_record = LeadRecord.new(email)
  lead_record.set_attribute('FirstName', first)
  lead_record.set_attribute('LastName', last)
  lead_record.set_attribute('Email', email)
  lead_record.set_attribute('Company', company)
  lead_record.set_attribute('MobilePhone', mobile)
  sync_lead_record(lead_record)
end

#sync_lead_record(lead_record) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/marketo/client.rb', line 97

def sync_lead_record(lead_record)
  begin
    attributes = []
    lead_record.each_attribute_pair do |name, value|
      attributes << {:attr_name => name, :attr_type => 'string', :attr_value => value}
    end

    response = send_request("ns1:paramsSyncLead", {
        :return_lead => true,
        :lead_record =>
            {:email               => lead_record.email,
             :lead_attribute_list => {
                 :attribute => attributes}}})
    return LeadRecord.from_hash(response[:success_sync_lead][:result][:lead_record])
  rescue Exception => e
    @logger.log(e) if @logger
    return nil
  end
end

#sync_multi_lead_records(lead_records) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/marketo/client.rb', line 117

def sync_multi_lead_records(lead_records)
  send_records = []
  begin
    lead_records.each do |lead_record|
      attributes = []
      lead_record.each_attribute_pair do |name, value|
        attributes << {:attr_name => name, :attr_type => 'string', :attr_value => value}
      end
      
      send_records << {
        "Email" => lead_record.email, 
        :lead_attribute_list => { :attribute => attributes }
      }
    end
    
    response = send_request("ns1:paramsSyncMultipleLeads", {
          :lead_record_list => { :lead_record => send_records }}) # an array of lead records
    
    return response
  rescue Exception => e
    @logger.log(e) if @logger
    return @client.http
    #return nil
  end
end