Class: Hcp::Event

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

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.



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

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.



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

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.



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

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.



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

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.



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

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

#estimate_idString

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

Returns:

  • (String)

    unique identifier of the estimate in a :job_created event.



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

def estimate_id = @params.dig :job, :original_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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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