ombu_labs-hubspot 0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +18 -0
- data/app/assets/config/ombu_labs_hubspot_manifest.js +0 -0
- data/app/services/hubspot_service.rb +128 -0
- data/app/workers/contact_hubspot_worker.rb +15 -0
- data/config/routes.rb +2 -0
- data/lib/ombu_labs/hubspot/engine.rb +6 -0
- data/lib/ombu_labs/hubspot/version.rb +5 -0
- data/lib/ombu_labs/hubspot.rb +9 -0
- data/lib/tasks/ombu_labs/hubspot_tasks.rake +4 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c6b1b615b6d1559ceab204ae955d7ca8d813954e5cc3c5392ac927a49808c83e
|
4
|
+
data.tar.gz: 30e136f439b0f62d86f04e9d73659dbda0e76416cb6b5c79682e47de2b3fdd2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a16cff0b4b3bef19658131e526ed442295638a73289275e6d0c9ada25266b592c1af4028a11b027c7a73cb0dbd7415e29f64f4d11399a899f9713210436cc8f9
|
7
|
+
data.tar.gz: 26b968539c6e3810ab21d9cb42307579639a8801317ea0e45252c6cce36f264ed3e3606f2c802e81d9b5eff00a836b8fb4bafe36749d4f8316f1fcda6761d7b7
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2023 Fiona
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# OmbuLabs::Hubspot
|
2
|
+
Source code for OmbuLabs Hubspot integration
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'ombu_labs-hubspot'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install ombu_labs-hubspot
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
4
|
+
load "rails/tasks/engine.rake"
|
5
|
+
|
6
|
+
load "rails/tasks/statistics.rake"
|
7
|
+
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
|
10
|
+
require "rake/testtask"
|
11
|
+
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'test'
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = false
|
16
|
+
end
|
17
|
+
|
18
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'hubspot-api-client'
|
2
|
+
|
3
|
+
class HubspotService
|
4
|
+
attr_reader :contact, :pipeline
|
5
|
+
|
6
|
+
def initialize(contact:)
|
7
|
+
@contact = contact.attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
def save_lead_info
|
11
|
+
return if contact_exists?
|
12
|
+
hubspot_contact = create_contact
|
13
|
+
deal = create_deal
|
14
|
+
company = create_company(contact["email"])
|
15
|
+
create_association({from_name: "contact", to_name: "deal", from_id: hubspot_contact.id, to_id: deal.id, type: "contact_to-deal"})
|
16
|
+
create_association({from_name: "contact", to_name: "company", from_id: hubspot_contact.id, to_id: company.id, type: "contact_to_company"})
|
17
|
+
create_association({from_name: "deal", to_name: "company", from_id: deal.id, to_id: company.id, type: "deal_to_company"})
|
18
|
+
create_association({from_name: "deal", to_name: "contact", from_id: deal.id, to_id: hubspot_contact.id, type: "deal_to_contact"})
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def contact_exists?
|
24
|
+
|
25
|
+
search_api = ::Hubspot::Crm::Contacts::SearchApi.new
|
26
|
+
results = search_api.do_search(contact_search_request, auth_names: "oauth2").results
|
27
|
+
results.present?
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_line_item
|
31
|
+
search_api = ::Hubspot::Crm::LineItems::SearchApi.new
|
32
|
+
search_api.do_search(line_item_search_request, auth_names: "oauth2").results
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_company(company_domain)
|
36
|
+
search_api = ::Hubspot::Crm::Companies::SearchApi.new
|
37
|
+
search_api.do_search(company_search_request(company_domain), auth_names: "oauth2").results.first
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_contact
|
41
|
+
contacts_api = ::Hubspot::Crm::Contacts::BasicApi.new
|
42
|
+
contacts_api.create(properties: contact_properties)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_deal
|
46
|
+
deals_api = ::Hubspot::Crm::Deals::BasicApi.new
|
47
|
+
deals_api.create(properties: deal_properties)
|
48
|
+
end
|
49
|
+
|
50
|
+
def contact_properties
|
51
|
+
{
|
52
|
+
firstname: contact["name"],
|
53
|
+
email: contact["email"],
|
54
|
+
contact_message: contact["message"],
|
55
|
+
request_type: contact["request_type"],
|
56
|
+
utm_campaign: contact["utm_campaign"],
|
57
|
+
utm_medium: contact["utm_medium"],
|
58
|
+
utm_source: contact["utm_source"],
|
59
|
+
gclid: contact["gclid"],
|
60
|
+
in_house_developers: contact["in_house_developers"],
|
61
|
+
starting_at: contact["starting_at"]
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
def deal_properties
|
66
|
+
@pipeline = get_pipeline
|
67
|
+
|
68
|
+
{
|
69
|
+
dealname: contact["name"].capitalize,
|
70
|
+
pipeline: pipeline.id,
|
71
|
+
dealstage: get_cold_stage.id
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_pipeline
|
76
|
+
pipeline_api = ::Hubspot::Crm::Pipelines::PipelinesApi.new
|
77
|
+
pipelines = pipeline_api.get_all("DEAL").results
|
78
|
+
pipelines.find { |pipeline| pipeline.label == ENV["HUBSPOT_PIPELINE_LABEL"] }
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_cold_stage
|
82
|
+
pipeline.stages.find { |stage| stage.label == "Cold" }
|
83
|
+
end
|
84
|
+
|
85
|
+
def contact_search_request
|
86
|
+
filter = ::Hubspot::Crm::Contacts::Filter.new(
|
87
|
+
property_name: "email",
|
88
|
+
operator: "EQ",
|
89
|
+
value: contact["email"]
|
90
|
+
)
|
91
|
+
filter_group = ::Hubspot::Crm::Contacts::FilterGroup.new(filters: [filter])
|
92
|
+
::Hubspot::Crm::Contacts::PublicObjectSearchRequest.new(filter_groups: [filter_group])
|
93
|
+
end
|
94
|
+
|
95
|
+
def company_search_request(company_domain)
|
96
|
+
filter = ::Hubspot::Crm::Companies::Filter.new(
|
97
|
+
property_name: "domain",
|
98
|
+
operator: "EQ",
|
99
|
+
value: company_domain
|
100
|
+
)
|
101
|
+
filter_group = ::Hubspot::Crm::LineItems::FilterGroup.new(filters: [filter])
|
102
|
+
::Hubspot::Crm::LineItems::PublicObjectSearchRequest.new(filter_groups: [filter_group])
|
103
|
+
end
|
104
|
+
|
105
|
+
def create_association(properties)
|
106
|
+
connection = ::Hubspot::Crm::Associations::BatchApi.new
|
107
|
+
connection.create(
|
108
|
+
properties[:from_name], properties[:to_name],
|
109
|
+
batch_input_public_association: {
|
110
|
+
inputs: [
|
111
|
+
{from: {id: properties[:from_id]}, to: {id: properties[:to_id]}, type: properties[:type]}
|
112
|
+
]
|
113
|
+
}
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def create_company(email)
|
118
|
+
company_domain = email.split("@").last
|
119
|
+
existing_company = get_company(company_domain)
|
120
|
+
return existing_company if existing_company.present?
|
121
|
+
company_name = company_domain.split(".").first
|
122
|
+
company = ::Hubspot::Crm::Companies::BasicApi.new
|
123
|
+
company.create(properties: {
|
124
|
+
domain: company_domain,
|
125
|
+
name: company_name.capitalize
|
126
|
+
})
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ContactHubspotWorker
|
2
|
+
include Sidekiq::Worker
|
3
|
+
|
4
|
+
def perform(contact_id)
|
5
|
+
return unless (contact = Contact.find(contact_id))
|
6
|
+
|
7
|
+
if contact.hubspot_notified_at.blank?
|
8
|
+
HubspotService.new(contact: contact).save_lead_info
|
9
|
+
contact.update_column :hubspot_notified_at, Time.current
|
10
|
+
Sidekiq.logger.info "Hubspot sync complete (#{contact.email})"
|
11
|
+
else
|
12
|
+
Sidekiq.logger.info "Skipping hubspot sync (#{contact.email})"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/config/routes.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ombu_labs-hubspot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fiona
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '6.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hubspot-api-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 11.1.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 11.1.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sidekiq
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
description: Knows how to send a new contact information to Hubspot
|
56
|
+
email:
|
57
|
+
- fiona@ombulabs.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- app/assets/config/ombu_labs_hubspot_manifest.js
|
66
|
+
- app/services/hubspot_service.rb
|
67
|
+
- app/workers/contact_hubspot_worker.rb
|
68
|
+
- config/routes.rb
|
69
|
+
- lib/ombu_labs/hubspot.rb
|
70
|
+
- lib/ombu_labs/hubspot/engine.rb
|
71
|
+
- lib/ombu_labs/hubspot/version.rb
|
72
|
+
- lib/tasks/ombu_labs/hubspot_tasks.rake
|
73
|
+
homepage: https://github.com/fastruby/ombu_labs-hubspot
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
allowed_push_host: https://rubygems.org
|
78
|
+
homepage_uri: https://github.com/fastruby/ombu_labs-hubspot
|
79
|
+
source_code_uri: https://github.com/fastruby/ombu_labs-hubspot
|
80
|
+
changelog_uri: https://github.com/fastruby/ombu_labs-hubspot
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.1.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: A gem to send notifications to hubspot
|
100
|
+
test_files: []
|