Permalink
Browse files

add ability to sync a lead by its idnum :)

  • Loading branch information...
1 parent 86f871e commit b9e02120a83414cc4bd8150273b35307a0cf3f84 @jeob32 jeob32 committed Apr 3, 2012
Showing with 46 additions and 31 deletions.
  1. +26 −0 lib/marketo/client.rb
  2. +3 −5 lib/marketo/lead_record.rb
  3. +1 −1 marketo.gemspec
  4. +16 −25 spec/marketo/client_spec.rb
View
@@ -111,6 +111,32 @@ def sync_lead_record(lead_record)
end
end
+ def sync_lead_record_on_id(lead_record)
+ idnum = lead_record.idnum
+ raise 'lead record id not set' if idnum.nil?
+
+ begin
+ attributes = []
+ lead_record.each_attribute_pair do |name, value|
+ attributes << {:attr_name => name, :attr_type => 'string', :attr_value => value}
+ end
+
+ attributes << {:attr_name => 'Id', :attr_type => 'string', :attr_value => idnum.to_s}
+
+ response = send_request("ns1:paramsSyncLead", {
+ :return_lead => true,
+ :lead_record =>
+ {
+ :lead_attribute_list => { :attribute => attributes},
+ :id => idnum
+ }})
+ return LeadRecord.from_hash(response[:success_sync_lead][:result][:lead_record])
+ rescue Exception => e
+ @logger.log(e) if @logger
+ return nil
+ end
+ end
+
def add_to_list(list_key, email)
list_operation(list_key, ListOperationType::ADD_TO, email)
end
@@ -3,10 +3,9 @@ module Marketo
# Represents a record of the data known about a lead within marketo
class LeadRecord
def initialize(email, idnum = nil)
- @email = email
@idnum = idnum
@attributes = {}
- set_attribute('Email', @email)
+ set_attribute('Email', email)
end
# hydrates an instance from a savon hash returned form the marketo API
@@ -25,7 +24,7 @@ def idnum
# get the record email
def email
- @email
+ get_attribute('Email')
end
def attributes
@@ -51,8 +50,7 @@ def each_attribute_pair(&block)
def ==(other)
@attributes == other.attributes &&
- @idnum == other.idnum &&
- @email == other.email
+ @idnum == other.idnum
end
end
end
View
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
gem.files = Dir['lib/**/*.rb']
gem.require_path = ['lib']
gem.test_files = Dir['spec/**/*_spec.rb']
- gem.version = "1.2.5"
+ gem.version = "1.3.0"
gem.has_rdoc = true
gem.rdoc_options << '--title' << 'Marketo Client Gem' << '--main' << 'Rapleaf::Marketo::Client'
@@ -148,36 +148,27 @@ module Marketo
}
expect_request(savon_client,
authentication_header,
- equals_matcher({
- :return_lead => true,
- :lead_record => {
- :email => EMAIL,
- :lead_attribute_list =>
- {
- :attribute => [
- {:attr_value => "val1",
- :attr_name => "name1",
- :attr_type => "string"},
- {:attr_value => "val2",
- :attr_name => "name2",
- :attr_type => "string"},
- {:attr_value => EMAIL,
- :attr_name => "Email",
- :attr_type => "string"}
- ]}}}),
+ (Proc.new do |actual|
+ retval = true
+ retval = false unless actual[:return_lead]
+ retval = false unless actual[:lead_record][:email].equal?(EMAIL)
+ retval = false unless actual[:lead_record][:lead_attribute_list][:attribute].size == 5
+ retval = false unless actual[:lead_record][:lead_attribute_list][:attribute].include?({:attr_value => EMAIL, :attr_name => "Email", :attr_type => "string"})
+ retval = false unless actual[:lead_record][:lead_attribute_list][:attribute].include?({:attr_value => "val1", :attr_name => "name1", :attr_type => "string"})
+ retval = false unless actual[:lead_record][:lead_attribute_list][:attribute].include?({:attr_value => "val2", :attr_name => "name2", :attr_type => "string"})
+ retval = false unless actual[:lead_record][:lead_attribute_list][:attribute].include?({:attr_value => "val3", :attr_name => "name3", :attr_type => "string"})
+ retval = false unless actual[:lead_record][:lead_attribute_list][:attribute].include?({:attr_value => "val4", :attr_name => "name4", :attr_type => "string"})
+ retval.should == true
+ end),
'ns1:paramsSyncLead',
response_hash)
- lead_record = LeadRecord.new(EMAIL)
+ lead_record = LeadRecord.new(EMAIL, IDNUM)
lead_record.set_attribute('name1', 'val1')
lead_record.set_attribute('name2', 'val2')
+ lead_record.set_attribute('name3', 'val3')
+ lead_record.set_attribute('name4', 'val4')
- expected_lead_record = LeadRecord.new(EMAIL, IDNUM)
- expected_lead_record.set_attribute('Email', EMAIL)
- expected_lead_record.set_attribute('name1', 'val1')
- expected_lead_record.set_attribute('name2', 'val2')
- expected_lead_record.set_attribute('name3', 'val3')
- expected_lead_record.set_attribute('name4', 'val4')
- client.sync_lead_record(lead_record).should == expected_lead_record
+ client.sync_lead_record(lead_record).should == lead_record
end
it "should have the correct body format on sync_lead" do

0 comments on commit b9e0212

Please sign in to comment.