Class: Hcp::Lead::Pipeline

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

Overview

Where a Housecall Pro user files a lead while they are still chasing it.

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, key:, company_id:) ⇒ Pipeline

Returns a new instance of Pipeline.



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

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

Instance Method Details

#update(status_name:) ⇒ Object

Moves the lead to the status going by this name.

Parameters:

  • status_name (String)

    the status as the account names it, such as 'Won'.



14
15
16
17
18
19
20
21
# File 'lib/hcp/lead/pipeline.rb', line 14

def update(status_name:)
  status = find_status_by name: status_name
  payload = { resource_type: 'lead', resource_id: @id, status_id: status['id'] }.to_json
  response = Net::HTTP.put uri, payload, headers
  raise Error, response.body unless response.is_a? Net::HTTPSuccess
rescue Errno::ECONNREFUSED => error
  raise Error, error
end