Class: Velocify::Lead

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/velocify/lead.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model

included

Constructor Details

#initialize(body: {}) ⇒ Lead

Returns a new instance of Lead.



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

def initialize body: {}
  @body = body
end

Instance Attribute Details

#agent_idObject

Returns the value of attribute agent_id.



6
7
8
# File 'lib/velocify/lead.rb', line 6

def agent_id
  @agent_id
end

#campaign_idObject

Returns the value of attribute campaign_id.



6
7
8
# File 'lib/velocify/lead.rb', line 6

def campaign_id
  @campaign_id
end

#fieldsObject (readonly)

Returns the value of attribute fields.



5
6
7
# File 'lib/velocify/lead.rb', line 5

def fields
  @fields
end

#status_idObject

Returns the value of attribute status_id.



6
7
8
# File 'lib/velocify/lead.rb', line 6

def status_id
  @status_id
end

Class Method Details

.add(leads:, destruct: false, return_array: false) ⇒ Object

Adds a lead or leads

Parameters:

  • leads (String)

    The string representation of the XML document containing the new leads



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/velocify/lead.rb', line 29

def add leads:, destruct: false, return_array: false
  verify_credentials!

  request do
    destruct_response? destruct
    operation :add_leads
    authenticate? true
    xml AddLeadsPayload.new(leads)
    transform do |resp|
      if return_array
        arrayify resp[:response][:additions][:lead]
      else
        resp
      end
    end
  end
end

.find_all(from:, to:, destruct: false, return_array: false) ⇒ Hash

Retrieves all leads

Parameters:

  • from (String)

    The start date

  • to (String)

    The end date

Returns:

  • (Hash)

    The leads between the ‘from:` and `to:` dates



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/velocify/lead.rb', line 53

def find_all from:, to:, destruct: false, return_array: false
  verify_credentials!

  request do
    destruct_response? destruct
    operation :get_leads
    message from: from, to: to
    authenticate? true
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.find_by_email(email, destruct: false, return_array: false) ⇒ Hash

Retrieves a lead using an email address

Parameters:

  • email (String)

    The email address used to search for a lead

Returns:

  • (Hash)

    The leads having the matching email address



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/velocify/lead.rb', line 76

def find_by_email email, destruct: false, return_array: false
  verify_credentials!

  request do
    destruct_response? destruct
    operation :get_leads_by_email
    authenticate? true
    message email: email
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.find_by_id(id, destruct: false, return_array: false) ⇒ Hash

Retrieves a lead by an id

Parameters:

  • id (String)

    the id of the lead

Returns:

  • (Hash)

    The lead with the matching id



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/velocify/lead.rb', line 122

def find_by_id id, destruct: false, return_array: false
  verify_credentials!
  
  request do
    destruct_response? destruct
    operation :get_lead
    authenticate? true
    message lead_id: id
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.find_by_phone(phone, destruct: false, return_array: false) ⇒ Hash

Retrieves a lead using a phone numebr

Parameters:

  • phone (String)

    The phone number used to search for a lead

Returns:

  • (Hash)

    The leads having the matching phone number



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/velocify/lead.rb', line 99

def find_by_phone phone, destruct: false, return_array: false
  verify_credentials!

  request do
    destruct_response? destruct
    operation :get_leads_by_phone
    message phone: phone.gsub(/[()\- ]/, '')
    authenticate? true
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.find_last_created(destruct: false, return_array: false) ⇒ Object Also known as: last_created



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/velocify/lead.rb', line 140

def find_last_created destruct: false, return_array: false
  verify_credentials!
  
  request do
    destruct_response? destruct
    operation :get_last_created_lead
    authenticate? true
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.find_last_modified(destruct: false, return_array: false) ⇒ Object Also known as: last_modified



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/velocify/lead.rb', line 157

def find_last_modified destruct: false, return_array: false
  verify_credentials!
  
  request do
    destruct_response? destruct
    operation :get_last_modified_lead
    authenticate? true
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.remove(id:, destruct: false, return_array: false) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/velocify/lead.rb', line 174

def remove id:, destruct: false, return_array: false
  verify_credentials!

  request do
    destruct_response? destruct
    operation :remove_lead
    authenticate? true
    message lead_id: id
    transform do |resp|
      if return_array
        arrayify resp[:response][:removals] # also [:lead] ?
      else
        resp
      end
    end
  end
end

.update_field(lead_id:, field_id:, new_value:, destruct: false, return_array: false) ⇒ Hash

Updates a field for a lead

Parameters:

  • lead_id (String)

    The id of the lead to be updated

  • field_id (String)

    The id of the field to be updated

  • new_value (String)

    The new value of the field

Returns:

  • (Hash)

    The response containing the updated lead



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/velocify/lead.rb', line 227

def update_field lead_id:, field_id:, new_value:, destruct: false, return_array: false
  verify_credentials!

  request do
    destruct_response? destruct
    operation :modify_lead_field
    authenticate? true
    message field_id: field_id, lead_id: lead_id, new_value: new_value
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

.update_status(lead_id:, status_id:, destruct: false, return_array: false) ⇒ Hash

Updates the status of a lead.

Use the ‘Velocify::Status.find_all` method to retrieve the id of the status

Parameters:

  • lead_id (String)

    The id of the lead

  • status_id (String)

    The id of the status

Returns:

  • (Hash)

    The response containing the updated lead

See Also:



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/velocify/lead.rb', line 202

def update_status lead_id:, status_id:, destruct: false, return_array: false
  verify_credentials!
  
  request do
    destruct_response? destruct
    operation :modify_lead_status
    authenticate? true
    message lead_id: lead_id, status_id: status_id
    transform do |resp|
      if return_array
        arrayify resp[:leads][:lead]
      else
        resp
      end
    end
  end
end

Instance Method Details

#add_field(id:, value:) ⇒ Object



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

def add_field id:, value:
  @fields = [] if @fields.nil?
  @fields << { id: id, value: value }
end

#agent_id?Boolean

Returns:

  • (Boolean)


19
# File 'lib/velocify/lead.rb', line 19

def agent_id?; !@agent_id.nil?; end

#campaign_id?Boolean

Returns:

  • (Boolean)


17
# File 'lib/velocify/lead.rb', line 17

def campaign_id?; !@campaign_id.nil?; end

#status_id?Boolean

Returns:

  • (Boolean)


21
# File 'lib/velocify/lead.rb', line 21

def status_id?; !@status_id.nil?; end