hcp 0.1.0 → 1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -4
- data/LICENSE.txt +1 -1
- data/README.md +13 -32
- data/lib/hcp/error.rb +3 -0
- data/lib/hcp/lead/pipeline.rb +32 -0
- data/lib/hcp/lead.rb +35 -0
- data/lib/hcp/resource.rb +15 -0
- data/lib/hcp/version.rb +1 -1
- data/lib/hcp.rb +6 -5
- metadata +6 -4
- data/Rakefile +0 -8
- data/sig/hcp.rbs +0 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90d571ad7e7872688843090321835c3f6d8b0c02a5793acee7673575d61e44f3
|
|
4
|
+
data.tar.gz: 78bd3365a5feabeced0e6a94739f091708b94722e509d2447aba4986053dd24c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9dd74a5fda91a8dd80376cea9825bcd4d11db89263679ec6d21ebe382a90c14e3f4ae5a5e438ab43612f492843c26b364a40ed0a83a31389d6809b40700e80ae
|
|
7
|
+
data.tar.gz: ec5410256cfcca4f65ac92aaa0e1988eec68009ae3ae440667f71097dabc9a5e1abceb962cc7c44e3154842837130f17bddf6cf082bba7afd26f46b620fd81d5
|
data/CHANGELOG.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,39 +1,20 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Housecall Pro API Ruby client
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Available methods
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Initialize and create a Lead:
|
|
6
6
|
|
|
7
|
-
|
|
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
|
-
|
|
14
|
+
Change the status of a lead in the pipeline:
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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,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
|
data/lib/hcp/resource.rb
ADDED
data/lib/hcp/version.rb
CHANGED
data/lib/hcp.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'net/http'
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
require 'hcp/error'
|
|
7
|
+
require 'hcp/resource'
|
|
8
|
+
require 'hcp/lead'
|
|
9
|
+
require 'hcp/lead/pipeline'
|
metadata
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hcp
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
-
|
|
7
|
+
- Claudio Baccigalupo
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
@@ -19,10 +19,12 @@ files:
|
|
|
19
19
|
- CHANGELOG.md
|
|
20
20
|
- LICENSE.txt
|
|
21
21
|
- README.md
|
|
22
|
-
- Rakefile
|
|
23
22
|
- lib/hcp.rb
|
|
23
|
+
- lib/hcp/error.rb
|
|
24
|
+
- lib/hcp/lead.rb
|
|
25
|
+
- lib/hcp/lead/pipeline.rb
|
|
26
|
+
- lib/hcp/resource.rb
|
|
24
27
|
- lib/hcp/version.rb
|
|
25
|
-
- sig/hcp.rbs
|
|
26
28
|
homepage: https://github.com/HouseAccountEng/hcp
|
|
27
29
|
licenses:
|
|
28
30
|
- MIT
|
data/Rakefile
DELETED
data/sig/hcp.rbs
DELETED