hcp 0.1.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c1c564302b41ae3bae64611780cd75bd3547bb4b85b96e4820a868c913a1769
4
- data.tar.gz: 55ea615bb079c1618cf9112d8a44673df5f143058a270453fbe519ae5ed873cb
3
+ metadata.gz: 2c507e653633d17395829ab18ff34b44313aa37c8e19286aecad3096adae8848
4
+ data.tar.gz: 3677c714fefd88238ff2ebee783f2d6ba6141bf6a2aa37d994a43b7cd0b292e5
5
5
  SHA512:
6
- metadata.gz: 2f61c290fa12ea7acaeccc160eeeebc59a9cfb806111ab6b6a8310d8b73b678d232ab5028e86fbb85e0475b4dc0ad34b2c190f8a1845ecfdf323fb7b8dba91f9
7
- data.tar.gz: 33a705767166474ecf31a1710d51a837332f554db980fef6e9ce5fad6c30ee54cafecac849a6e4e376323a77f701d9d185ebdb6ba9328bc278dad42a388d1f71
6
+ metadata.gz: 34f585b624bec1d61839a69a6c2678bad38e8b24bd02605e5fb47aa11fc5fdff5c31cd8e2aab802daa75f943a72cf9c7f39ac97fafa5d15dd52b0efb52ef42d6
7
+ data.tar.gz: a498b1a75b5f8170837a99661c265800eccaec5d3384c626f5bbbd086373488afbc063172876e04c15abb7c520418aa51e7c6fb3ef2c5ac28d580bcc1795304c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
- ## [Unreleased]
1
+ ## [1.1.0] - 2026-05-27
2
2
 
3
- ## [0.1.0] - 2026-03-24
3
+ - [New] Add Hcp::Event
4
4
 
5
- - Initial release
5
+ ## [1.0.0] - 2026-05-15
6
+
7
+ - Initial release: Lead and Lead::Pipeline classes
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2026 claudiob
3
+ Copyright (c) 2026 HouseAccount
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,39 +1,20 @@
1
- # Hcp
1
+ # The Housecall Pro API Ruby client
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ ## Available methods
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hcp`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ Initialize and create a Lead:
6
6
 
7
- ## Installation
7
+ ```ruby
8
+ lead = Hcp::Lead.new key:, company_id:
9
+ lead.create name: 'Alice', phone: '8008008000', email: 'alice@example.com',
10
+ address: { street: '7111 Melrose Ave', city: 'Los Angeles', state: 'CA', zip: '90046' },
11
+ note: 'Very interested in buying', source: 'The Lead Generator'
12
+ ````
8
13
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
14
+ Change the status of a lead in the pipeline:
10
15
 
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
- ```
16
-
17
- If bundler is not being used to manage dependencies, install the gem by executing:
18
-
19
- ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ ```ruby
17
+ pipeline = Hcp::Lead::Pipeline.new id:, key:, company_id:
18
+ pipeline.update status_name: 'Won'
21
19
  ```
22
20
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hcp.
36
-
37
- ## License
38
-
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/lib/hcp/error.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Hcp
2
+ Error = Class.new StandardError
3
+ end
data/lib/hcp/event.rb ADDED
@@ -0,0 +1,58 @@
1
+ module Hcp
2
+ class Event
3
+ # @see https://docs.housecallpro.com/docs/housecall-public-api/46e9e1be07621-webhooks
4
+ SIGNATURE_HEADER = 'Api-Signature'
5
+
6
+ # @see https://docs.housecallpro.com/docs/housecall-public-api/46e9e1be07621-webhooks
7
+ TIMESTAMP_HEADER = 'Api-Timestamp'
8
+
9
+ # @param params [Hash] the payload for an event webhook.
10
+ def initialize(params = {})
11
+ @params = params
12
+ end
13
+
14
+ # @return [Symbol] the type of event, e.g.: :lead_converted, :job_created, :invoice_sent.
15
+ def type = @params[:event].gsub('.', '_').to_sym
16
+
17
+ # @return [String] unique identifier of the lead in a :lead_converted event.
18
+ def lead_id = @params.dig :lead, :id
19
+
20
+ # @return [String] unique identifier of the customer in a :lead_converted or :job_created event.
21
+ def customer_id = @params.dig resource_type, :customer, :id
22
+
23
+ # @return [String] unique identifier of the job in a :job_created/scheduled/completed event.
24
+ def job_id = @params.dig :job, :id
25
+
26
+ # @return [String] unique identifier of the estimate in a :job_created event.
27
+ def estimate_id = @params.dig :job, :original_estimate_id
28
+
29
+ # @return [Symbol] the latest conversion type, can be :estimate or :job.
30
+ def conversion_type = conversion['type'].downcase.to_sym
31
+
32
+ # @return [String] the latest conversion ID, can be an estimate ID or a job ID.
33
+ def conversion_id = conversion['id']
34
+
35
+ # @return [Time] time when the job is scheduled a :job_scheduled event.
36
+ def scheduled_at = Time.iso8601(@params.dig :job, :schedule, :scheduled_start)
37
+
38
+ # @return [Time] time when the job was completed a :job_completed event.
39
+ def completed_at = Time.iso8601(@params.dig :job, :work_timestamps, :completed_at)
40
+
41
+ # @return [String] unique identifier of the invoice in an :invoice_sent event.
42
+ def invoice_id = @params.dig :invoice, :id
43
+
44
+ # @return [String] unique identifier of the job in an :invoice_sent event.
45
+ def invoice_job_id = @params.dig :invoice, :job_id
46
+
47
+ # @return [BigDecimal] dollar amount of the invoice in an :invoice_sent event.
48
+ def invoice_amount = BigDecimal(@params.dig :invoice, :amount) / 100.0
49
+
50
+ private
51
+
52
+ # @return [Hash] the latest conversion, applies to 'lead.converted' events.
53
+ def conversion = @params.dig(:lead, :conversions).last
54
+
55
+ # @return [Symbol] the type of resource affected by the event, can be :lead or :job.
56
+ def resource_type = @params[:event].split('.').first.to_sym
57
+ end
58
+ end
@@ -0,0 +1,32 @@
1
+ module Hcp
2
+ class Lead::Pipeline < Resource
3
+ def initialize(id: nil, key:, company_id:)
4
+ @id = id
5
+ @key = key
6
+ @company_id = company_id
7
+ end
8
+
9
+ def update(status_name:)
10
+ status = find_status_by name: status_name
11
+ raise Error, "Status #{status_name} not found for lead #{@id}" unless status
12
+
13
+ payload = { resource_type: 'lead', resource_id: @id, status_id: status['id'] }.to_json
14
+ Net::HTTP.put uri, payload, headers
15
+ rescue Errno::ECONNREFUSED => error
16
+ raise Error, error
17
+ end
18
+
19
+ private
20
+
21
+ def find_status_by(name:)
22
+ body = JSON Net::HTTP.get(uri, headers)
23
+ body['statuses'].find { |status| status['name'] == name } || unknown_status(name: name)
24
+ end
25
+
26
+ def unknown_status(name:)
27
+ raise Error, "Status #{name} not found for lead #{@id}"
28
+ end
29
+
30
+ def uri = URI 'https://api.housecallpro.com/pipeline/statuses?resource_type=lead'
31
+ end
32
+ end
data/lib/hcp/lead.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Hcp
2
+ class Lead < Resource
3
+ attr_reader :customer_id
4
+
5
+ def initialize(id: nil, customer_id: nil, key:, company_id:)
6
+ @id = id
7
+ @key = key
8
+ @company_id = company_id
9
+ @customer_id = customer_id
10
+ end
11
+
12
+ def create(params = {})
13
+ body = JSON Net::HTTP.post(uri, lead_for(params).to_json, headers).body
14
+ @id, @customer_id = body['id'], body.dig('customer', 'id')
15
+ rescue Errno::ECONNREFUSED => error
16
+ raise Error, error
17
+ end
18
+
19
+ def lead_for(params = {})
20
+ {
21
+ customer: customer_for(params), address: params[:address],
22
+ lead_source: params[:source], note: params[:note]
23
+ }.compact_blank
24
+ end
25
+
26
+ def customer_for(params = {})
27
+ {
28
+ first_name: params[:name], email: params[:email],
29
+ mobile_number: params[:phone], lead_source: params[:source],
30
+ }.compact_blank
31
+ end
32
+
33
+ def uri = URI 'https://api.housecallpro.com/leads'
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module Hcp
2
+ class Resource
3
+ attr_reader :id
4
+
5
+ private
6
+
7
+ def headers
8
+ {
9
+ 'Authorization' => "Token #{@key}",
10
+ 'Content-Type' => 'application/json',
11
+ 'X-Company-Id' => @company_id,
12
+ }.compact
13
+ end
14
+ end
15
+ end
data/lib/hcp/version.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Ruby client for the Housecall Pro API.
3
4
  module Hcp
4
- VERSION = "0.1.0"
5
+ # Current version of the gem.
6
+ VERSION = '1.1.0'
5
7
  end
data/lib/hcp.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "hcp/version"
3
+ require 'json'
4
+ require 'net/http'
4
5
 
5
- module Hcp
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
6
+ require 'hcp/error'
7
+ require 'hcp/resource'
8
+ require 'hcp/lead'
9
+ require 'hcp/lead/pipeline'
10
+
11
+ require 'hcp/event'
metadata CHANGED
@@ -1,14 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hcp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - claudiob
7
+ - Claudio Baccigalupo
8
8
  bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies: []
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
12
26
  description: Housecall Pro API
13
27
  email:
14
28
  - claudiob@users.noreply.github.com
@@ -19,17 +33,20 @@ files:
19
33
  - CHANGELOG.md
20
34
  - LICENSE.txt
21
35
  - README.md
22
- - Rakefile
23
36
  - lib/hcp.rb
37
+ - lib/hcp/error.rb
38
+ - lib/hcp/event.rb
39
+ - lib/hcp/lead.rb
40
+ - lib/hcp/lead/pipeline.rb
41
+ - lib/hcp/resource.rb
24
42
  - lib/hcp/version.rb
25
- - sig/hcp.rbs
26
- homepage: https://github.com/HouseAccountEng/hcp
43
+ homepage: https://github.com/claudiob/hcp
27
44
  licenses:
28
45
  - MIT
29
46
  metadata:
30
- homepage_uri: https://github.com/HouseAccountEng/hcp
31
- source_code_uri: https://github.com/HouseAccountEng/hcp
32
- changelog_uri: https://github.com/HouseAccountEng/hcp
47
+ homepage_uri: https://github.com/claudiob/hcp
48
+ source_code_uri: https://github.com/claudiob/hcp
49
+ changelog_uri: https://github.com/claudiob/hcp
33
50
  rdoc_options: []
34
51
  require_paths:
35
52
  - lib
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
data/sig/hcp.rbs DELETED
@@ -1,4 +0,0 @@
1
- module Hcp
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end