Class: Velocify::AddLeadsPayload

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/velocify/payload.rb

Instance Method Summary collapse

Constructor Details

#initialize(leads) ⇒ AddLeadsPayload

Creates a new request to add leads

Parameters:

  • leads (Array<Lead>)

    A list of leads to be added



24
25
26
27
# File 'lib/velocify/payload.rb', line 24

def initialize leads
  @leads = leads
  @credentials = {}
end

Instance Method Details

#authenticate(username:, password:) ⇒ Hash

Stores credentials for making an authenticated request

Parameters:

  • username (String)
  • password (String)

Returns:

  • (Hash)


34
35
36
# File 'lib/velocify/payload.rb', line 34

def authenticate username:, password:
  @credentials = Hash[:username, username, :password, password]
end

#renderString

Returns The XML payload to send to Velocify’s AddLeads operation.

Returns:

  • (String)

    The XML payload to send to Velocify’s AddLeads operation



39
40
41
42
43
44
45
46
# File 'lib/velocify/payload.rb', line 39

def render
  relative_path = File.join '..', '..', 'templates', 'add_leads.xml.erb'
  current_dir = File.dirname(__FILE__)
  path = File.expand_path relative_path, current_dir
  template = File.read(path)
  xml_str = ERB.new(template).result binding
  { xml: xml_str.gsub(/[\n\t]*/, '').gsub(/[ ]{2,}/, '') }
end