Class: Hcp::Event
- Inherits:
-
Object
- Object
- Hcp::Event
- 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
-
#completed_at ⇒ Time
Time when the job was completed a :job_completed event.
-
#conversion_id ⇒ String
The latest conversion ID, can be an estimate ID or a job ID.
-
#conversion_type ⇒ Symbol
The latest conversion type, can be :estimate or :job.
-
#customer_id ⇒ String
Unique identifier of the customer in a :lead_converted or :job_created event.
-
#estimate_id ⇒ String
Unique estimate identifier in a :job_created of :estimate_sent event.
-
#initialize(params = {}) ⇒ Event
constructor
A new instance of Event.
-
#invoice_amount ⇒ BigDecimal
Dollar amount of the invoice in an :invoice_sent event.
-
#invoice_id ⇒ String
Unique identifier of the invoice in an :invoice_sent event.
-
#invoice_job_id ⇒ String
Unique identifier of the job in an :invoice_sent event.
-
#job_id ⇒ String
Unique identifier of the job in a :job_created/scheduled/completed event.
-
#lead_id ⇒ String
Unique identifier of the lead in a :lead_converted event.
-
#scheduled_at ⇒ Time
Time when the job is scheduled a :job_scheduled event.
-
#type ⇒ Symbol
The type of event, e.g.: :lead_converted, :job_created, :invoice_sent.
Constructor Details
#initialize(params = {}) ⇒ Event
Returns a new instance of Event.
11 12 13 |
# File 'lib/hcp/event.rb', line 11 def initialize(params = {}) @params = params end |
Instance Method Details
#completed_at ⇒ Time
Returns 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_id ⇒ String
Returns 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_type ⇒ Symbol
Returns 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_id ⇒ String
Returns 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_id ⇒ String
Returns 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_amount ⇒ BigDecimal
Returns 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_id ⇒ String
Returns 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_id ⇒ String
Returns 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_id ⇒ String
Returns 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_id ⇒ String
Returns 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_at ⇒ Time
Returns 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) |
#type ⇒ Symbol
Returns 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 |