Class: Hcp::Lead

Inherits:
Object
  • Object
show all
Includes:
Keyed
Defined in:
lib/hcp/lead.rb

Overview

Somebody who asked a Housecall Pro user for work, before there is a job.

Defined Under Namespace

Classes: Pipeline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, customer_id: nil, key:, company_id:) ⇒ Lead

Returns a new instance of Lead.



8
9
10
11
12
13
# File 'lib/hcp/lead.rb', line 8

def initialize(id: nil, customer_id: nil, key:, company_id:)
  @id = id
  @key = key
  @company_id = company_id
  @customer_id = customer_id
end

Instance Attribute Details

#customer_idObject (readonly)

Returns the value of attribute customer_id.



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

def customer_id
  @customer_id
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Instance Method Details

#create(params = {}) ⇒ Object

Opens the lead on Housecall Pro, and keeps what it filed the lead and customer under.

Parameters:

  • params (Hash) (defaults to: {})

    :name, :email, :phone, :address, :note and :source.



17
18
19
20
21
22
23
24
# File 'lib/hcp/lead.rb', line 17

def create(params = {})
  response = Net::HTTP.post uri, lead_for(params).to_json, headers
  raise Error, response.body unless response.is_a? Net::HTTPSuccess
  body = JSON response.body
  @id, @customer_id = body['id'], body.dig('customer', 'id')
rescue Errno::ECONNREFUSED => error
  raise Error, error
end