Skip to content

Commit

Permalink
Merge branch 'add_lookup_field' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisztian Szabo committed Mar 24, 2015
2 parents 630cad0 + 49778b8 commit fe658f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mkto_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def create_leads(leads, action = 'createOnly', partition = nil)
def upsert_leads(leads, lookupField = :email, action = 'createOrUpdate')
post(
action: action,
lookupField: sym.to_s,
lookupField: lookupField.to_s,
input: leads
)
end
Expand Down
9 changes: 7 additions & 2 deletions spec/mkto_rest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ def set_create_leads_stub_request(leads, hostname, token, options = nil)
}
url = "https://#{hostname}/rest/v1/leads.json"
# taken from dev.marekto.com
preferred_action = options && options.include?(:action) ? options[:action] : 'createOnly'
req_body = {
'action' => 'createOnly',
'input' => []
'action' => preferred_action
}

req_body['lookupField'] = 'email' if options && options.include?(:upsert)

req_body['input'] = []

if options
req_body['partitionName'] = options[:partition] if options[:partition]
req_body['lookupField'] = options[:lookupField] if options[:lookupField]
Expand Down
10 changes: 10 additions & 0 deletions spec/mkto_rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@
end
let(:partition) { 'bizdev' }


describe '#upsert_leads' do
let(:updated_leads) { authenticated_client.upsert_leads(sample_leads) }

it 'inserts or updates the given leads' do
set_create_leads_stub_request(sample_leads, hostname, token, action: 'createOrUpdate', upsert: true)
updated_leads
end
end

it 'can be updated by id' do
set_update_lead_stub_request(:id, 1, { 'someFieldX' => 'new_value' }, hostname, token)
lead1.update({ 'someFieldX' => 'new_value' }, :id)
Expand Down

0 comments on commit fe658f8

Please sign in to comment.