class MarketoAPI::Lead
An object representing a Marketo Lead
record.
Attributes
The attributes for the Lead
.
The Marketo ID. This value cannot be set by consumers.
The proxy object for this class.
The types for the Lead
attributes.
Public Class Methods
Creates a new Lead
key hash suitable for use in a number of Marketo API calls.
# File lib/marketo_api/lead.rb, line 235 def key(key, value) { leadKey: { keyType: key_type(key), keyValue: value } } end
:method: values
Returns the attribute values.
# File lib/marketo_api/lead.rb, line 87 def initialize(options = {}) @id = options[:id] @attributes = {} @types = {} @foreign = {} self[:Email] = options[:email] self.proxy = options[:proxy] yield self if block_given? end
Private Class Methods
# File lib/marketo_api/lead.rb, line 245 def key_type(key) key = key.to_sym res = if KEY_TYPES.include? key key else NAMED_KEYS[key] end raise ArgumentError, "Invalid key #{key}" unless res res end
Public Instance Methods
# File lib/marketo_api/lead.rb, line 257 def ==(other) id == other.id && cookie == other.cookie && foreign == other.foreign && attributes == other.attributes && types == other.types end
Looks up the provided attribute.
# File lib/marketo_api/lead.rb, line 39
:method: []=(hash, value)
Looks up the provided attribute.
# File lib/marketo_api/lead.rb, line 103 def []=(key, value) @attributes[key] = value @types[key] ||= infer_value_type(value) end
Iterates over the attributes.
# File lib/marketo_api/lead.rb, line 46
Iterates over the attribute keys.
# File lib/marketo_api/lead.rb, line 60
Iterates over the attributes.
# File lib/marketo_api/lead.rb, line 53
Iterates over the attribute values.
# File lib/marketo_api/lead.rb, line 67
:attr_reader: email
# File lib/marketo_api/lead.rb, line 141 def email self[:Email] end
:attr_writer: email
# File lib/marketo_api/lead.rb, line 146 def email=(value) self[:Email] = value end
Sets or returns the foreign system type and person ID.
# File lib/marketo_api/lead.rb, line 135 def foreign(type = nil, id = nil) @foreign = { type: type.to_sym, id: id } if type and id @foreign end
# File lib/marketo_api/lead.rb, line 262 def inspect "#<#{self.class} id=#{id} cookie=#{cookie} foreign=#{foreign.inspect} attributes=#{attributes.inspect} types=#{types.inspect}>" end
Returns the attribute keys.
# File lib/marketo_api/lead.rb, line 74
Returns a lead key structure suitable for use with MarketoAPI::Leads#get
.
# File lib/marketo_api/lead.rb, line 188 def params_for_get self.class.key(:IDNUM, id) end
Returns the parameters required for use with MarketoAPI::Leads#sync
.
# File lib/marketo_api/lead.rb, line 193 def params_for_sync { returnLead: true, marketoCookie: cookie, leadRecord: { Email: email, Id: id, ForeignSysPersonId: foreign[:id], ForeignSysType: foreign[:type], leadAttributeList: { attribute: attributes.map { |key, value| { attrName: key.to_s, attrType: types[key], attrValue: value } } } }.delete_if(&MarketoAPI::MINIMIZE_HASH) }.delete_if(&MarketoAPI::MINIMIZE_HASH) end
:attr_writer:
Assign a proxy object. Once set, the proxy cannot be unset, but it can be changed.
# File lib/marketo_api/lead.rb, line 114 def proxy=(value) @proxy = case value when nil defined?(@proxy) && @proxy when MarketoAPI::Leads value when MarketoAPI::ClientProxy value.instance_variable_get(:@client).leads when MarketoAPI::Client value.leads else raise ArgumentError, "Invalid proxy type" end end
Performs a Lead
sync and returns the new Lead
object, or nil
if the sync failed.
Raises an ArgumentError if a proxy has not been configured with Lead#proxy=
.
# File lib/marketo_api/lead.rb, line 155 def sync raise ArgumentError, "No proxy configured" unless proxy proxy.sync(self) end
Performs a Lead
sync and updates this Lead
object in-place, or nil
if the sync failed.
Raises an ArgumentError if a proxy has not been configured with Lead#proxy=
.
# File lib/marketo_api/lead.rb, line 165 def sync! if lead = sync @id = lead.id @cookie = lead.cookie @foreign = lead.foreign @proxy = lead.proxy removed = self.keys - lead.keys lead.each_pair { |k, v| @attributes[k] = v @types[k] = lead.types[k] } removed.each { |k| @attributes.delete(k) @types.delete(k) } self end end
Private Instance Methods
# File lib/marketo_api/lead.rb, line 267 def infer_value_type(value) case value when Integer 'integer' when Time, DateTime 'datetime' else 'string' end end