Class: Hcp::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/hcp/event.rb

Overview

What Housecall Pro sent a webhook to say, read without reaching the network.

Constant Summary collapse

SIGNATURE_HEADER =
'Api-Signature'
TIMESTAMP_HEADER =
'Api-Timestamp'

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Event

Returns a new instance of Event.

Parameters:

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

    the payload for an event webhook.



11
12
13
# File 'lib/hcp/event.rb', line 11

def initialize(params = {})
  @params = params
end

Instance Method Details

#completed_atTime

Returns time when the job was completed a :job_completed event.

Returns:

  • (Time)

    time when the job was completed a :job_completed event.



40
# File 'lib/hcp/event.rb', line 40

def completed_at = Time.iso8601(@params.dig :job, :work_timestamps, :completed_at)

#conversion_idString

Returns the latest conversion ID, can be an estimate ID or a job ID.

Returns:

  • (String)

    the latest conversion ID, can be an estimate ID or a job ID.



34
# File 'lib/hcp/event.rb', line 34

def conversion_id = conversion['id']

#conversion_typeSymbol

Returns the latest conversion type, can be :estimate or :job.

Returns:

  • (Symbol)

    the latest conversion type, can be :estimate or :job.



31
# File 'lib/hcp/event.rb', line 31

def conversion_type = conversion['type'].downcase.to_sym

#customer_idString

Returns unique identifier of the customer in a :lead_converted or :job_created event.

Returns:

  • (String)

    unique identifier of the customer in a :lead_converted or :job_created event.



22
# File 'lib/hcp/event.rb', line 22

def customer_id = @params.dig resource_type, :customer, :id

#estimate_idString

Returns unique estimate identifier in a :job_created of :estimate_sent event.

Returns:

  • (String)

    unique estimate identifier in a :job_created of :estimate_sent event.



28
# File 'lib/hcp/event.rb', line 28

def estimate_id = @params.dig(:job, :original_estimate_id) || @params.dig(:estimate, :id)

#invoice_amountBigDecimal

Returns dollar amount of the invoice in an :invoice_sent event.

Returns:

  • (BigDecimal)

    dollar amount of the invoice in an :invoice_sent event.



49
# File 'lib/hcp/event.rb', line 49

def invoice_amount = BigDecimal(@params.dig :invoice, :amount) / 100.0

#invoice_idString

Returns unique identifier of the invoice in an :invoice_sent event.

Returns:

  • (String)

    unique identifier of the invoice in an :invoice_sent event.



43
# File 'lib/hcp/event.rb', line 43

def invoice_id = @params.dig :invoice, :id

#invoice_job_idString

Returns unique identifier of the job in an :invoice_sent event.

Returns:

  • (String)

    unique identifier of the job in an :invoice_sent event.



46
# File 'lib/hcp/event.rb', line 46

def invoice_job_id = @params.dig :invoice, :job_id

#job_idString

Returns unique identifier of the job in a :job_created/scheduled/completed event.

Returns:

  • (String)

    unique identifier of the job in a :job_created/scheduled/completed event.



25
# File 'lib/hcp/event.rb', line 25

def job_id = @params.dig :job, :id

#lead_idString

Returns unique identifier of the lead in a :lead_converted event.

Returns:

  • (String)

    unique identifier of the lead in a :lead_converted event.



19
# File 'lib/hcp/event.rb', line 19

def lead_id = @params.dig :lead, :id

#scheduled_atTime

Returns time when the job is scheduled a :job_scheduled event.

Returns:

  • (Time)

    time when the job is scheduled a :job_scheduled event.



37
# File 'lib/hcp/event.rb', line 37

def scheduled_at = Time.iso8601(@params.dig :job, :schedule, :scheduled_start)

#typeSymbol

Returns the type of event, e.g.: :lead_converted, :job_created, :invoice_sent.

Returns:

  • (Symbol)

    the type of event, e.g.: :lead_converted, :job_created, :invoice_sent.



16
# File 'lib/hcp/event.rb', line 16

def type = @params.fetch(:event, '').gsub('.', '_').to_sym