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

#create_lead(email = nil, first_name = nil, last_name = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/leadsquared/lead.rb', line 38

def create_lead(email = nil, first_name = nil, last_name = nil)
  url = url_with_service("Lead.Create")
  body = [
    {
      "Attribute": "EmailAddress",
      "Value": email
    },
    {
      "Attribute": "FirstName",
      "Value": first_name
    },
    {
      "Attribute": "LastName",
      "Value": last_name
    }
  ]
  response = connection.post(url, {}, body.to_json)
  parsed_response = handle_response response
  parsed_response["Message"]["Id"]
end

#create_or_update(email = nil, first_name = nil, last_name = nil, phone = nil, search_by = "EmailAddress") ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/leadsquared/lead.rb', line 67

def create_or_update(email = nil, first_name = nil, last_name = nil, phone = nil, search_by = "EmailAddress")
  url = url_with_service("Lead.CreateOrUpdate")
  body = [
    {
      "Attribute": "EmailAddress",
      "Value": email
    },
    {
      "Attribute": "FirstName",
      "Value": first_name
    },
    {
      "Attribute": "LastName",
      "Value": last_name
    },
    {
      "Attribute": "Phone",
      "Value": phone
    },
    {
      "Attribute": "SearchBy",
      "Value": search_by
    }
  ]
  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



59
60
61
62
63
64
65
# File 'lib/leadsquared/lead.rb', line 59

def update_lead(lead_id, values_hash = {})
  url = url_with_service("Lead.Update")
  body = values_hash.map {|key, val| {"Attribute" => key, "Value" => val} }
  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



96
97
98
99
100
101
102
# File 'lib/leadsquared/lead.rb', line 96

def visitor_to_lead(prospect_id, values_hash = {})
  url = url_with_service("Lead.Convert")
  body = values_hash.map {|key, val| {"Attribute" => key, "Value" => val} }
  response = connection.post(url, {leadId: prospect_id}, body.to_json)
  parsed_response = handle_response response
  parsed_response["Status"]
end