class Leadsquared::Lead

Constants

SERVICE

Public Class Methods

new() click to toggle source
Calls superclass method Leadsquared::ApiConnection::new
# File lib/leadsquared/lead.rb, line 8
def initialize
  super(SERVICE)
end

Public Instance Methods

capture_lead(values_hash = {}) click to toggle source
# File lib/leadsquared/lead.rb, line 86
def capture_lead(values_hash = {})
  url = url_with_service('Lead.Capture')
  body = build_attributes values_hash
  response = connection.post(url, body.to_json)
  parsed_response = handle_response response
  parsed_response['Status']
end
create_lead(email, values_hash = {}) click to toggle source
# File lib/leadsquared/lead.rb, line 38
def create_lead(email, values_hash = {})
  url = url_with_service("Lead.Create")
  body = [
    {
      "Attribute": "EmailAddress",
      "Value": email
    }
  ]
  body += build_attributes values_hash
  response = connection.post(url, {}, body.to_json)
  parsed_response = handle_response response
  parsed_response["Message"]["Id"]
end
create_or_update(email, values_hash = {}) click to toggle source
# File lib/leadsquared/lead.rb, line 60
def create_or_update(email, values_hash = {})
  url = url_with_service("Lead.CreateOrUpdate")
  body = [
    {
      "Attribute": "EmailAddress",
      "Value": email
    },
    {
      "Attribute": "SearchBy",
      "Value": "EmailAddress"
    }
  ]
  body += build_attributes values_hash
  response = connection.post(url, {}, body.to_json)
  parsed_response = handle_response response
  parsed_response["Message"]["Id"]
end
get_lead_by_email(email) click to toggle source
# File lib/leadsquared/lead.rb, line 25
def get_lead_by_email(email)
  url = url_with_service("Leads.GetByEmailaddress")
  response = connection.get(url, { emailaddress: email })
  parsed_response = handle_response response
  parsed_response.first
end
get_lead_by_id(lead_id) click to toggle source
# File lib/leadsquared/lead.rb, line 18
def get_lead_by_id(lead_id)
  url = url_with_service("Leads.GetById")
  response = connection.get(url, { id: lead_id })
  parsed_response = handle_response response
  parsed_response.first
end
get_meta_data() click to toggle source
# File lib/leadsquared/lead.rb, line 12
def get_meta_data
  url = url_with_service("LeadsMetaData.Get")
  response = connection.get(url, {})
  handle_response response
end
update_lead(lead_id, values_hash = {}) click to toggle source
# File lib/leadsquared/lead.rb, line 52
def update_lead(lead_id, values_hash = {})
  url = url_with_service("Lead.Update")
  body = build_attributes values_hash
  response = connection.post(url, {leadId: lead_id}, body.to_json)
  parsed_response = handle_response response
  parsed_response["Status"]
end
visitor_to_lead(prospect_id, values_hash = {}) click to toggle source
# File lib/leadsquared/lead.rb, line 78
def visitor_to_lead(prospect_id, values_hash = {})
  url = url_with_service('Lead.Convert')
  body = build_attributes values_hash
  response = connection.post(url, {leadId: prospect_id}, body.to_json)
  parsed_response = handle_response response
  parsed_response["Status"]
end

Private Instance Methods

build_attributes(values_hash) click to toggle source
# File lib/leadsquared/lead.rb, line 96
def build_attributes(values_hash)
  values_hash.map { |key, val| { 'Attribute' => key, 'Value' => val } }
end