Class: Rapleaf::Marketo::LeadRecord

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

Overview

Represents a record of the data known about a lead within marketo

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, idnum = nil) ⇒ LeadRecord

Returns a new instance of LeadRecord.



5
6
7
8
9
10
# File 'lib/marketo/lead_record.rb', line 5

def initialize(email, idnum = nil)
  @email      = email
  @idnum      = idnum
  @attributes = {}
  set_attribute('Email', @email)
end

Class Method Details

.from_hash(savon_hash) ⇒ Object

hydrates an instance from a savon hash returned form the marketo API



13
14
15
16
17
18
19
# File 'lib/marketo/lead_record.rb', line 13

def self.from_hash(savon_hash)
  lead_record = LeadRecord.new(savon_hash[:email], savon_hash[:id].to_i)
  savon_hash[:lead_attribute_list][:attribute].each do |attribute|
    lead_record.set_attribute(attribute[:attr_name], attribute[:attr_value])
  end
  lead_record
end

Instance Method Details

#==(other) ⇒ Object



52
53
54
55
56
# File 'lib/marketo/lead_record.rb', line 52

def ==(other)
  @attributes == other.attributes &&
  @idnum == other.idnum &&
  @email == other.email
end

#attributesObject



31
32
33
# File 'lib/marketo/lead_record.rb', line 31

def attributes
  @attributes
end

#each_attribute_pair(&block) ⇒ Object

will yield pairs of |attribute_name, attribute_value|



46
47
48
49
50
# File 'lib/marketo/lead_record.rb', line 46

def each_attribute_pair(&block)
  @attributes.each_pair do |name, value|
    block.call(name, value)
  end
end

#emailObject

get the record email



27
28
29
# File 'lib/marketo/lead_record.rb', line 27

def email
  @email
end

#get_attribute(name) ⇒ Object

get the value for the named attribute



41
42
43
# File 'lib/marketo/lead_record.rb', line 41

def get_attribute(name)
  @attributes[name]
end

#idnumObject

get the record idnum



22
23
24
# File 'lib/marketo/lead_record.rb', line 22

def idnum
  @idnum
end

#set_attribute(name, value) ⇒ Object

update the value of the named attribute



36
37
38
# File 'lib/marketo/lead_record.rb', line 36

def set_attribute(name, value)
  @attributes[name] = value
end