Class: Leadsquared::Lead

Inherits:
ApiConnection show all
Defined in:
lib/leadsquared/lead.rb

Constant Summary collapse

SERVICE =
'/v2/LeadManagement.svc/'.freeze

Instance Attribute Summary

Attributes inherited from ApiConnection

#connection

Instance Method Summary collapse

Constructor Details

#initializeLead

Returns a new instance of Lead.



8
9
10
# File 'lib/leadsquared/lead.rb', line 8

def initialize
  super(SERVICE)
end

Instance Method Details

#capture_lead(values_hash = {}) ⇒ Object



86
87
88
89
90
91
92
# 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 = {}) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# 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 = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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) ⇒ Object



25
26
27
28
29
30
# 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) ⇒ Object



18
19
20
21
22
23
# 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_dataObject



12
13
14
15
16
# File 'lib/leadsquared/lead.rb', line 12

def 
  url = url_with_service("LeadsMetaData.Get")
  response = connection.get(url, {})
  handle_response response
end

#quick_search(key) ⇒ Object



32
33
34
35
36
# File 'lib/leadsquared/lead.rb', line 32

def quick_search(key)
  url = url_with_service("Leads.GetByQuickSearch")
  response = connection.get(url, {key: key})
  handle_response response
end

#update_lead(lead_id, values_hash = {}) ⇒ Object



52
53
54
55
56
57
58
# 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 = {}) ⇒ Object



78
79
80
81
82
83
84
# 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