hcp 1.4.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +0 -1
  3. data/CHANGELOG.md +75 -0
  4. data/CLAUDE.md +34 -9
  5. data/README.md +99 -125
  6. data/lib/hcp/account.rb +25 -0
  7. data/lib/hcp/answer.rb +3 -11
  8. data/lib/hcp/client.rb +41 -0
  9. data/lib/hcp/collections/estimates.rb +22 -0
  10. data/lib/hcp/collections/jobs.rb +32 -0
  11. data/lib/hcp/collections/leads.rb +25 -0
  12. data/lib/hcp/collections/technicians.rb +23 -0
  13. data/lib/hcp/collections/visits.rb +80 -0
  14. data/lib/hcp/error.rb +1 -1
  15. data/lib/hcp/errors/throttled.rb +4 -0
  16. data/lib/hcp/event.rb +1 -6
  17. data/lib/hcp/resources/business.rb +11 -0
  18. data/lib/hcp/resources/customer.rb +9 -45
  19. data/lib/hcp/resources/estimate.rb +40 -46
  20. data/lib/hcp/resources/job.rb +58 -69
  21. data/lib/hcp/resources/lead.rb +26 -0
  22. data/lib/hcp/resources/line.rb +8 -0
  23. data/lib/hcp/resources/location.rb +7 -0
  24. data/lib/hcp/resources/quote.rb +28 -0
  25. data/lib/hcp/resources/technician.rb +7 -0
  26. data/lib/hcp/resources/visit.rb +45 -0
  27. data/lib/hcp/version.rb +3 -3
  28. data/lib/hcp.rb +22 -41
  29. metadata +30 -28
  30. data/lib/hcp/access.rb +0 -12
  31. data/lib/hcp/concerns/chainable.rb +0 -39
  32. data/lib/hcp/concerns/keyed.rb +0 -14
  33. data/lib/hcp/concerns/named.rb +0 -7
  34. data/lib/hcp/concerns/queryable.rb +0 -41
  35. data/lib/hcp/concerns/scheduled.rb +0 -16
  36. data/lib/hcp/concerns/statused.rb +0 -23
  37. data/lib/hcp/concerns/timestamped.rb +0 -10
  38. data/lib/hcp/errors/not_found.rb +0 -4
  39. data/lib/hcp/errors/too_many_requests.rb +0 -16
  40. data/lib/hcp/filter.rb +0 -36
  41. data/lib/hcp/key.rb +0 -24
  42. data/lib/hcp/lead/pipeline.rb +0 -36
  43. data/lib/hcp/lead.rb +0 -44
  44. data/lib/hcp/relation.rb +0 -76
  45. data/lib/hcp/request.rb +0 -31
  46. data/lib/hcp/resource.rb +0 -58
  47. data/lib/hcp/resources/address.rb +0 -24
  48. data/lib/hcp/resources/booking_window.rb +0 -52
  49. data/lib/hcp/resources/company.rb +0 -42
  50. data/lib/hcp/resources/employee.rb +0 -12
  51. data/lib/hcp/resources/estimate/option.rb +0 -26
  52. data/lib/hcp/resources/job/appointment.rb +0 -22
  53. data/lib/hcp/resources/job/invoice.rb +0 -21
  54. data/lib/hcp/resources/line_item.rb +0 -20
  55. data/lib/hcp/resources/note.rb +0 -6
  56. data/lib/hcp/resources/schedule.rb +0 -21
data/lib/hcp/resource.rb DELETED
@@ -1,58 +0,0 @@
1
- module Hcp
2
- # A record as Housecall Pro answered it.
3
- class Resource
4
- class << self
5
- # Declares a reader for what Housecall Pro answers under a name.
6
- # @!macro [attach] attribute
7
- # @!method $1
8
- # @return [String, nil] the $1, as Housecall Pro answers it.
9
- def attribute(name, key = name) = define_method(name) { @node[key.to_s] }
10
-
11
- # Declares a reader for a moment Housecall Pro stamps.
12
- # @!macro [attach] timestamp
13
- # @!method $1
14
- # @return [Time, nil] the moment Housecall Pro answers as $1.
15
- def timestamp(name, key = name) = define_method(name) { time key.to_s }
16
-
17
- # Declares a reader for a sum Housecall Pro counts in cents.
18
- # @!macro [attach] amount
19
- # @!method $1
20
- # @return [BigDecimal, nil] the $1, which Housecall Pro counts in cents.
21
- def amount(name, key = name) = define_method(name) { money key.to_s }
22
- end
23
-
24
- # @param node [Hash] the record as Housecall Pro answered it.
25
- # @param company_id [String, nil] the location it was read as.
26
- def initialize(node: {}, company_id: nil)
27
- @node = node
28
- @company_id = company_id
29
- end
30
-
31
- # @return [String] the ID Housecall Pro files the record under.
32
- def id = @node['id']
33
-
34
- private
35
-
36
- # Built from the record's own path rather than its class, so a nested collection sits
37
- # under its parent however deep Housecall Pro put it.
38
- def nested(type, segment)
39
- Relation.new type: type, path: "#{path}/#{segment}", company_id: @company_id
40
- end
41
-
42
- def path = "#{self.class.path}/#{id}"
43
-
44
- def time(*keys)
45
- value = @node.dig(*keys)
46
- Time.iso8601 value if value.present?
47
- end
48
-
49
- # Housecall Pro counts money in cents, and a caller reads it in dollars.
50
- def money(key) = (BigDecimal(@node[key].to_s) / 100 if @node[key])
51
-
52
- def record(type, key) = (type.new node: @node[key], company_id: @company_id if @node[key])
53
-
54
- def records(type, key)
55
- Array(@node[key]).map { |node| type.new node: node, company_id: @company_id }
56
- end
57
- end
58
- end
@@ -1,24 +0,0 @@
1
- module Hcp
2
- # Where a customer is billed, or where the work happens.
3
- class Address < Resource
4
- # What Housecall Pro calls a page of a customer's addresses.
5
- def self.key = 'addresses'
6
-
7
- attribute :street
8
- attribute :street_line_2
9
- attribute :city
10
- attribute :state
11
- attribute :zip
12
- attribute :country
13
-
14
- # Housecall Pro answers these as numbers under a customer and as strings under the company.
15
- # @return [Float, nil] how far north the address is, where Housecall Pro placed it.
16
- def latitude = @node['latitude']&.to_f
17
-
18
- # @return [Float, nil] how far east the address is, where Housecall Pro placed it.
19
- def longitude = @node['longitude']&.to_f
20
-
21
- # @return [Symbol, nil] :billing or :service.
22
- def type = @node['type']&.to_sym
23
- end
24
- end
@@ -1,52 +0,0 @@
1
- module Hcp
2
- # A slot the account's online booking settings leave open for work to be booked into.
3
- class BookingWindow < Resource
4
- # How Housecall Pro writes the moment a range is looked at from.
5
- STAMP = '%Y-%m-%dT%H:%M:%S'
6
-
7
- class << self
8
- # Where Housecall Pro keeps them.
9
- def path = 'company/schedule_availability/booking_windows'
10
-
11
- # What Housecall Pro calls a list of them.
12
- def key = 'booking_windows'
13
-
14
- # Housecall Pro answers these whole rather than a page at a time, so they are read in one
15
- # request rather than walked, and there is no list left to narrow, order or cut.
16
- # @param starts_at [Date, Time, nil] where to look from; the next day holding a free
17
- # window where left out.
18
- # @param days [Integer, nil] how many days of the schedule to look at; seven where left out.
19
- # @param minutes [Integer, nil] how wide to cut each window; the service's own duration,
20
- # or thirty minutes, where left out.
21
- # @param service_id [String, nil] the service whose assigned pros to look at.
22
- # @param price_form_id [String, nil] the price form whose assigned pros to look at.
23
- # @param employee_ids [Array<String>, nil] the pros to look at, rather than all of them.
24
- # @param company_id [String, nil] the location to read as, where the account has several.
25
- # @return [Array<BookingWindow>] every window in the range, free and taken alike.
26
- def all(starts_at: nil, days: nil, minutes: nil, service_id: nil, price_form_id: nil,
27
- employee_ids: nil, company_id: nil)
28
- params = { start_date: stamp(starts_at), show_for_days: days, service_id: service_id,
29
- service_duration: minutes, price_form_id: price_form_id, employee_ids: employee_ids, }
30
- read(params, company_id).fetch(key).
31
- map { |node| new node: node, company_id: company_id }
32
- end
33
-
34
- private
35
-
36
- def stamp(value) = value&.strftime(STAMP)
37
-
38
- def read(params, company_id)
39
- Request.new(path: path, params: params, company_id: company_id).body
40
- end
41
- end
42
-
43
- # @return [Time, nil] when the window opens.
44
- timestamp :starts_at, :start_time
45
-
46
- # @return [Time, nil] when the window closes.
47
- timestamp :ends_at, :end_time
48
-
49
- # @return [Boolean] whether the account is free to take work in the window.
50
- def available? = @node['available']
51
- end
52
- end
@@ -1,42 +0,0 @@
1
- module Hcp
2
- # The account a key belongs to, and the settings every job it holds is booked under.
3
- class Company < Resource
4
- # Where Housecall Pro keeps it.
5
- def self.path = 'company'
6
-
7
- # The only company a key can read is its own, so there is no list and no ID to find one by.
8
- # @param company_id [String, nil] the location to read as, where the account has several.
9
- # @return [Company] the account, as the location it was read as.
10
- def self.current(company_id: nil)
11
- node = Request.new(path: path, company_id: company_id).body
12
- new node: node, company_id: company_id
13
- end
14
-
15
- attribute :name
16
- attribute :website
17
- attribute :time_zone
18
-
19
- # @return [String, nil] where the account's logo is served from.
20
- attribute :logo_url
21
-
22
- # @return [String, nil] the number the account is reached on.
23
- attribute :phone, :phone_number
24
-
25
- # @return [String, nil] the address a customer's reply goes to.
26
- attribute :support_email
27
-
28
- # @return [Integer, nil] how many minutes wide the window a customer is given is, by default.
29
- attribute :arrival_window, :default_arrival_window
30
-
31
- # @return [Address, nil] where the account is run from.
32
- def address = record Address, 'address'
33
-
34
- # @return [Array<String>] the ZIP codes the account will travel to.
35
- def zip_codes = Array(@node.dig('service_areas_data', 'zip_codes'))
36
-
37
- # Itself first, then every location under it at any depth, in the order Housecall Pro
38
- # lists them: a single company is its own one location, and a franchise reads flat.
39
- # @return [Array<Company>] the locations whose IDs `company_id:` takes, this one included.
40
- def locations = [ self, *records(Company, 'locations').flat_map(&:locations) ]
41
- end
42
- end
@@ -1,12 +0,0 @@
1
- module Hcp
2
- # A pro on a Housecall Pro account.
3
- class Employee < Resource
4
- include Named, Timestamped
5
-
6
- attribute :email
7
- attribute :role
8
-
9
- # @return [String, nil] the number the pro is reached on.
10
- attribute :phone, :mobile_number
11
- end
12
- end
@@ -1,26 +0,0 @@
1
- module Hcp
2
- # One of the things a customer was offered on an estimate, priced on its own.
3
- class Estimate::Option < Resource
4
- include Timestamped
5
-
6
- attribute :name
7
- attribute :option_number
8
-
9
- # @return [String, nil] whether the customer has answered, and how.
10
- attribute :approval_status
11
-
12
- # @return [String, nil] where Housecall Pro files the option in its own workflow.
13
- attribute :status
14
-
15
- # @return [String, nil] what the pro said when they sent it.
16
- attribute :message_from_pro
17
-
18
- amount :total_amount
19
-
20
- # @return [Array<String>] what the option is tagged with.
21
- def tags = Array(@node['tags'])
22
-
23
- # @return [Array<Note>] what the pros wrote on the option.
24
- def notes = records Note, 'notes'
25
- end
26
- end
@@ -1,22 +0,0 @@
1
- module Hcp
2
- # One visit a job is booked for, where the work takes more than a single trip.
3
- class Job::Appointment < Resource
4
- # What Housecall Pro calls a list of them.
5
- def self.key = 'appointments'
6
-
7
- # @return [Time, nil] when the visit is booked to start.
8
- timestamp :starts_at, :start_time
9
-
10
- # @return [Time, nil] when the visit is booked to end.
11
- timestamp :ends_at, :end_time
12
-
13
- # @return [Integer, nil] how many minutes wide the arrival window is.
14
- attribute :arrival_window, :arrival_window_minutes
15
-
16
- # @return [Boolean] whether the visit is booked for a day rather than for a time.
17
- def anytime? = @node['anytime']
18
-
19
- # @return [Array<String>] the IDs of the pros sent on the visit.
20
- def dispatched_employee_ids = Array(@node['dispatched_employees_ids'])
21
- end
22
- end
@@ -1,21 +0,0 @@
1
- module Hcp
2
- # A bill raised for a job.
3
- class Job::Invoice < Resource
4
- # What Housecall Pro calls a list of them.
5
- def self.key = 'invoices'
6
-
7
- attribute :invoice_number
8
-
9
- # @return [String, nil] where Housecall Pro files the invoice in its own workflow.
10
- attribute :status
11
-
12
- amount :amount
13
- amount :due_amount
14
-
15
- # @return [Time, nil] when the invoice was sent.
16
- timestamp :sent_at
17
-
18
- # @return [Time, nil] when the invoice was paid.
19
- timestamp :paid_at
20
- end
21
- end
@@ -1,20 +0,0 @@
1
- module Hcp
2
- # One line of what a job or an estimate option comes to.
3
- class LineItem < Resource
4
- # Housecall Pro answers a job's line items under `data` rather than under their own name.
5
- def self.key = 'data'
6
-
7
- attribute :name
8
- attribute :description
9
-
10
- # @return [Float, nil] how many of it, to two decimal places.
11
- attribute :quantity
12
-
13
- amount :unit_price
14
- amount :unit_cost
15
- amount :amount
16
-
17
- # @return [Symbol, nil] :materials, :labor, or one of the gratuities and discounts.
18
- def kind = @node['kind']&.tr(' ', '_')&.to_sym
19
- end
20
- end
@@ -1,6 +0,0 @@
1
- module Hcp
2
- # Something a pro wrote on a job or on an estimate option.
3
- class Note < Resource
4
- attribute :content
5
- end
6
- end
@@ -1,21 +0,0 @@
1
- module Hcp
2
- # When work is booked for, and how long a window the customer was given.
3
- class Schedule < Resource
4
- # @return [Time, nil] when the work is booked to start.
5
- timestamp :starts_at, :scheduled_start
6
-
7
- # @return [Time, nil] when the work is booked to end.
8
- timestamp :ends_at, :scheduled_end
9
-
10
- # @return [String, nil] the IANA zone to show a customer a time in.
11
- attribute :time_zone
12
-
13
- # @return [Integer, nil] how many minutes wide the arrival window is.
14
- attribute :arrival_window
15
-
16
- # Housecall Pro leaves these out unless a list was asked to bring them back, so a job read
17
- # without `includes(:appointments)` has none of them rather than none at all.
18
- # @return [Array<Job::Appointment>] the visits the work is booked for.
19
- def appointments = records Job::Appointment, 'appointments'
20
- end
21
- end