Class: Markety::Lead

Inherits:
Object
  • Object
show all
Defined in:
lib/markety/lead.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email: nil, idnum: nil, foreign_sys_person_id: nil) ⇒ Lead

Returns a new instance of Lead.



7
8
9
10
11
12
13
# File 'lib/markety/lead.rb', line 7

def initialize(email:nil, idnum:nil, foreign_sys_person_id:nil)
  @idnum      = idnum
  @foreign_sys_person_id = foreign_sys_person_id
  @email = email
  @attributes = {}
  @types      = {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/markety/lead.rb', line 4

def attributes
  @attributes
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/markety/lead.rb', line 5

def email
  @email
end

#foreign_sys_person_idObject

Returns the value of attribute foreign_sys_person_id.



5
6
7
# File 'lib/markety/lead.rb', line 5

def foreign_sys_person_id
  @foreign_sys_person_id
end

#idnumObject (readonly)

Returns the value of attribute idnum.



4
5
6
# File 'lib/markety/lead.rb', line 4

def idnum
  @idnum
end

#typesObject (readonly)

Returns the value of attribute types.



4
5
6
# File 'lib/markety/lead.rb', line 4

def types
  @types
end

Class Method Details

.from_hash(savon_hash) ⇒ Object

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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/markety/lead.rb', line 24

def self.from_hash(savon_hash)
  lead = Lead.new(email: savon_hash[:email], idnum:savon_hash[:id].to_i)

  unless savon_hash[:lead_attribute_list].nil?
    if savon_hash[:lead_attribute_list][:attribute].kind_of? Hash
      attributes = [savon_hash[:lead_attribute_list][:attribute]]
    else
      attributes = savon_hash[:lead_attribute_list][:attribute]
    end

    attributes.each do |attribute|
      lead.set_attribute(attribute[:attr_name], attribute[:attr_value], attribute[:attr_type])
    end
  end

  lead
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/markety/lead.rb', line 15

def ==(other)
  other.is_a?(Lead) &&
  @attributes==other.send(:attributes) &&
  @idnum==other.idnum &&
  @email==other.email &&
  @foreign_sys_person_id==other.foreign_sys_person_id
end

#get_attribute(name) ⇒ Object

get the value for the named attribute



50
51
52
# File 'lib/markety/lead.rb', line 50

def get_attribute(name)
  @attributes[name]
end

#get_attribute_type(name) ⇒ Object

get the type of the named attribute



55
56
57
# File 'lib/markety/lead.rb', line 55

def get_attribute_type(name)
  @types[name]
end

#set_attribute(name, value, type = "string") ⇒ Object

update the value of the named attribute



44
45
46
47
# File 'lib/markety/lead.rb', line 44

def set_attribute(name, value, type = "string")
  @attributes[name] = value
  @types[name] = type
end

#synchronisation_hashObject



59
60
61
# File 'lib/markety/lead.rb', line 59

def synchronisation_hash
  keys_hash.merge({"leadAttributeList" => {"attribute" => attributes_soap_array}})
end