hubspot_client 0.1.0.beta1 → 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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +5 -1
- data/CHANGELOG.md +28 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +56 -2
- data/hubspot_client.gemspec +2 -2
- data/lib/hubspot_client/client/communication_preference.rb +39 -0
- data/lib/hubspot_client/client/contact.rb +15 -5
- data/lib/hubspot_client/model/communication_preference.rb +11 -0
- data/lib/hubspot_client/model/company.rb +8 -1
- data/lib/hubspot_client/model/contact.rb +28 -1
- data/lib/hubspot_client/version.rb +1 -1
- data/lib/hubspot_client.rb +6 -4
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64366ba11cb24670e4a304a5a16307402736fe0f941f725535f148a37329afdc
|
4
|
+
data.tar.gz: d134c5b394c90e1b86d7cc716b20196289ba3c3c1b7768793d5d15fdca86ff0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be8964ed3c42cc2e01481da815de2d7f068ff1a4359f092ec1c89a864c761aa51c91cc6c79511004c685bcab19da1a8b7a81d0ec4cdf17b7ccc95de8fdb72b8
|
7
|
+
data.tar.gz: b27567094d0c0cfe0166ee7ae13b0c99012b2f127cddb62d5f703916b17e32864257a39892109360625c528239ddbc0961fbc3df369be1c89c1ded0e0ab6e906
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
## 0.1.0 (2022-11-30)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
* add method for contact model to set communication preferences
|
5
|
+
* added communication preference client
|
6
|
+
|
7
|
+
### Breaking Changes
|
8
|
+
None
|
9
|
+
|
10
|
+
## 0.1.0.beta2 (2022-11-28)
|
11
|
+
|
12
|
+
### Features
|
13
|
+
* Add associate company to contact logic
|
14
|
+
* Update README to make it more understanble
|
15
|
+
|
16
|
+
### Breaking Changes
|
17
|
+
None
|
18
|
+
|
19
|
+
## 0.1.0.beta1 (2022-11-25)
|
20
|
+
|
21
|
+
### Features
|
22
|
+
* Add Company Model and Client
|
23
|
+
* Add primary_company method to Contact model
|
24
|
+
* Add Properties Client
|
25
|
+
* Add Matrix for RSpec tests and support for the moment Ruby 3.0 and 3.1
|
26
|
+
|
27
|
+
## Breaking Changes
|
28
|
+
None
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
You need to configure the `
|
24
|
+
You need to configure the `hubspot_client` first:
|
25
25
|
``` ruby
|
26
26
|
HubspotClient.configure do |config|
|
27
27
|
config.access_token = 'PRIVATE_APP_ACCESS_TOKEN'
|
@@ -38,6 +38,7 @@ The idea is that the models behave like an ActiveRecord Model.
|
|
38
38
|
|
39
39
|
#### find
|
40
40
|
You can find by `hubspot_id` or `email`
|
41
|
+
|
41
42
|
```ruby
|
42
43
|
HubspotClient::Model::Contact.find(hubspot_id: '1337')
|
43
44
|
=> #<HubspotClient::Model::Contact createdate="2022-11-11T11:57:15.901Z", email="vader@example.com", firstname="Darth", hs_object_id="1337", lastmodifieddate="2022-11-17T13:31:00.526Z", lastname="Vader">
|
@@ -46,9 +47,62 @@ HubspotClient::Model::Contact.find(email: 'vader@example.com')
|
|
46
47
|
=> #<HubspotClient::Model::Contact createdate="2022-11-11T11:57:15.901Z", email="vader@example.com", firstname="Darth", hs_object_id="1337", lastmodifieddate="2022-11-17T13:31:00.526Z", lastname="Vader">
|
47
48
|
```
|
48
49
|
|
50
|
+
#### Associate_primary_company
|
51
|
+
|
52
|
+
Successfull Request
|
53
|
+
```ruby
|
54
|
+
hubspot_contact = HubspotClient::Model::Contact.find(hubspot_id: '1337')
|
55
|
+
=> #<HubspotClient::Model::Contact createdate="2022-11-11T11:57:15.901Z", email="vader@example.com", firstname="Darth", hs_object_id="1337", lastmodifieddate="2022-11-17T13:31:00.526Z", lastname="Vader">
|
56
|
+
|
57
|
+
hubspot_contact.associate_primary_company(6582942445)
|
58
|
+
=> true
|
59
|
+
```
|
60
|
+
|
49
61
|
### Company
|
50
62
|
|
51
|
-
[Hubspot-
|
63
|
+
Here you can find the [Hubspot-Companies-API-Documentation](https://developers.hubspot.com/docs/api/crm/companies)
|
64
|
+
|
65
|
+
#### find
|
66
|
+
|
67
|
+
Find a company be `hubspot_id`
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
HubspotClient::Model::Company.find(hubspot_id: '6614067165')
|
71
|
+
=> #<HubspotClient::Model::Company address="Todesternstraße 1", city="Todestern", createdate="2022-11-28T13:45:40.989Z", hs_lastmodifieddate="2022-11-28T13:45:44.933Z", hs_object_id="6614067165", name="Todesternverwaltungs GmbH", phone="0152123456789", zip="1337">
|
72
|
+
```
|
73
|
+
|
74
|
+
#### create
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
example_properties = { name: 'Todesternverwaltungs GmbH',
|
78
|
+
phone: '0152123456789',
|
79
|
+
address: 'Todesternstraße 1',
|
80
|
+
city: 'Todestern',
|
81
|
+
zip: '1337' }
|
82
|
+
|
83
|
+
HubspotClient::Model::Company.create(example_properties)
|
84
|
+
=> #<HubspotClient::Model::Company address="Todesternstraße 1", city="Todestern", createdate="2022-11-28T13:45:40.989Z", hs_lastmodifieddate="2022-11-28T13:45:40.989Z", hs_object_id="6614067165", hs_pipeline="companies-lifecycle-pipeline", lifecyclestage="lead", name="Todesternverwaltungs GmbH", phone="0152123456789", zip="1337">
|
85
|
+
```
|
86
|
+
|
87
|
+
#### update
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
hubspot_company = HubspotClient::Model::Company.find(hubspot_id: '6614067165')
|
91
|
+
|
92
|
+
# You can change the attribute like so:
|
93
|
+
hubspot_company.name = 'Blubber'
|
94
|
+
|
95
|
+
# or like so:
|
96
|
+
hubspot_company.assign_attributes(name: 'Blubber')
|
97
|
+
|
98
|
+
# then you can run:
|
99
|
+
hubspot_company.update
|
100
|
+
|
101
|
+
# you can also do it directly in the update method:
|
102
|
+
hubspot_company.update({ name: 'Blubber' })
|
103
|
+
```
|
104
|
+
|
105
|
+
|
52
106
|
|
53
107
|
### Subscription-Preferences
|
54
108
|
|
data/hubspot_client.gemspec
CHANGED
@@ -7,8 +7,8 @@ require 'hubspot_client/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'hubspot_client'
|
9
9
|
spec.version = HubspotClient::VERSION
|
10
|
-
spec.authors = %w[Garllon]
|
11
|
-
spec.email = [
|
10
|
+
spec.authors = %w[Garllon romankonz]
|
11
|
+
spec.email = %w[garllon@protonmail.com roman@konz.me]
|
12
12
|
|
13
13
|
spec.summary = 'Hubspot client'
|
14
14
|
spec.description = 'Hubspot client to handle CRM objects.'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HubspotClient
|
4
|
+
module Client
|
5
|
+
class SubscriptionNotSuccessful < StandardError; end
|
6
|
+
class FetchDefinitionsNotSuccessful < StandardError; end
|
7
|
+
|
8
|
+
class CommunicationPreference
|
9
|
+
include HTTParty
|
10
|
+
base_uri 'https://api.hubapi.com'
|
11
|
+
|
12
|
+
BASE_PATH = '/communication-preferences/v3'
|
13
|
+
|
14
|
+
def definitions
|
15
|
+
response = self.class.get("#{BASE_PATH}/definitions",
|
16
|
+
headers: headers)
|
17
|
+
|
18
|
+
return response if response.code == 200
|
19
|
+
|
20
|
+
raise FetchDefinitionsNotSuccessful
|
21
|
+
end
|
22
|
+
|
23
|
+
def subscribe(properties)
|
24
|
+
response = self.class.post("#{BASE_PATH}/subscribe",
|
25
|
+
body: properties.to_json,
|
26
|
+
headers: headers)
|
27
|
+
|
28
|
+
return response if response.code == 200
|
29
|
+
|
30
|
+
raise SubscriptionNotSuccessful
|
31
|
+
end
|
32
|
+
|
33
|
+
def headers
|
34
|
+
{ Authorization: "Bearer #{HubspotClient.configuration.access_token}",
|
35
|
+
'Content-Type': 'application/json' }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -5,27 +5,28 @@ module HubspotClient
|
|
5
5
|
class ContactNotFound < StandardError; end
|
6
6
|
class ContactNotCreated < StandardError; end
|
7
7
|
class ContactNotUpdated < StandardError; end
|
8
|
+
class AssociationError < StandardError; end
|
8
9
|
|
9
10
|
class Contact
|
10
11
|
include HTTParty
|
11
12
|
base_uri 'https://api.hubapi.com'
|
12
13
|
|
13
|
-
|
14
|
+
BASE_PATH_V3 = '/crm/v3/objects/contacts'
|
14
15
|
FIND_PROPERTIES = %w[firstname lastname email phone lifecyclestage associatedcompanyid].freeze
|
15
16
|
|
16
17
|
def find_by_email(email)
|
17
18
|
query_params = find_query_params({ idProperty: 'email' })
|
18
|
-
find_by("#{
|
19
|
+
find_by("#{BASE_PATH_V3}/#{email}?#{query_params}")
|
19
20
|
end
|
20
21
|
|
21
22
|
def find_by_id(hubspot_id)
|
22
23
|
query_params = find_query_params
|
23
24
|
|
24
|
-
find_by("#{
|
25
|
+
find_by("#{BASE_PATH_V3}/#{hubspot_id}?#{query_params}")
|
25
26
|
end
|
26
27
|
|
27
28
|
def create(properties)
|
28
|
-
response = self.class.post(
|
29
|
+
response = self.class.post(BASE_PATH_V3,
|
29
30
|
body: { properties: properties }.to_json,
|
30
31
|
headers: headers)
|
31
32
|
|
@@ -35,7 +36,7 @@ module HubspotClient
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def update(hubspot_id, properties)
|
38
|
-
response = self.class.patch("#{
|
39
|
+
response = self.class.patch("#{BASE_PATH_V3}/#{hubspot_id}",
|
39
40
|
body: { properties: properties }.to_json,
|
40
41
|
headers: headers)
|
41
42
|
|
@@ -44,6 +45,15 @@ module HubspotClient
|
|
44
45
|
raise ContactNotUpdated, 'Hubspot could not update'
|
45
46
|
end
|
46
47
|
|
48
|
+
def associate_with(hubspot_id, to_object_type, to_object_type_id, association_type = '1')
|
49
|
+
path = "#{BASE_PATH_V3}/#{hubspot_id}/associations/#{to_object_type}/#{to_object_type_id}/#{association_type}"
|
50
|
+
response = self.class.put(path, headers: headers)
|
51
|
+
|
52
|
+
return response if response.code == 200
|
53
|
+
|
54
|
+
raise AssociationError, response
|
55
|
+
end
|
56
|
+
|
47
57
|
private
|
48
58
|
|
49
59
|
def find_by(path)
|
@@ -20,7 +20,8 @@ module HubspotClient
|
|
20
20
|
new(response['properties'])
|
21
21
|
end
|
22
22
|
|
23
|
-
def update
|
23
|
+
def update(new_properties = {})
|
24
|
+
assign_attributes(new_properties)
|
24
25
|
properties = to_h.slice(*UPDATABLE_PROPERTIES)
|
25
26
|
response = Client::Company.new.update(hs_object_id, properties)
|
26
27
|
|
@@ -37,6 +38,12 @@ module HubspotClient
|
|
37
38
|
|
38
39
|
self
|
39
40
|
end
|
41
|
+
|
42
|
+
def assign_attributes(attributes)
|
43
|
+
attributes.each do |attribute, value|
|
44
|
+
self[attribute] = value
|
45
|
+
end
|
46
|
+
end
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -26,7 +26,8 @@ module HubspotClient
|
|
26
26
|
new(response['properties'])
|
27
27
|
end
|
28
28
|
|
29
|
-
def update
|
29
|
+
def update(new_properties = {})
|
30
|
+
assign_attributes(new_properties)
|
30
31
|
properties = to_h.slice(*UPDATABLE_PROPERTIES)
|
31
32
|
response = Client::Contact.new.update(hs_object_id, properties)
|
32
33
|
|
@@ -44,9 +45,35 @@ module HubspotClient
|
|
44
45
|
self
|
45
46
|
end
|
46
47
|
|
48
|
+
def create_communication_subscription(subscription_id:, legal_basis: nil, legal_basis_explanation: nil)
|
49
|
+
properties = {
|
50
|
+
emailAddress: email,
|
51
|
+
subscriptionId: subscription_id
|
52
|
+
}
|
53
|
+
|
54
|
+
properties[:legalBasis] = legal_basis if legal_basis
|
55
|
+
properties[:legalBasisExplanation] = legal_basis_explanation if legal_basis_explanation
|
56
|
+
|
57
|
+
Client::CommunicationPreference.new.subscribe(properties)
|
58
|
+
end
|
59
|
+
|
47
60
|
def primary_company
|
48
61
|
@primary_company ||= Company.find(hubspot_id: associatedcompanyid)
|
49
62
|
end
|
63
|
+
|
64
|
+
def associate_primary_company(hubspot_id)
|
65
|
+
response = Client::Contact.new.associate_with(hs_object_id, 'companies', hubspot_id)
|
66
|
+
|
67
|
+
return true if response.code == 200
|
68
|
+
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def assign_attributes(attributes)
|
73
|
+
attributes.each do |attribute, value|
|
74
|
+
self[attribute] = value
|
75
|
+
end
|
76
|
+
end
|
50
77
|
end
|
51
78
|
end
|
52
79
|
end
|
data/lib/hubspot_client.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'httparty'
|
4
|
-
require 'hubspot_client/
|
5
|
-
require 'hubspot_client/configuration'
|
6
|
-
require 'hubspot_client/client/contact'
|
4
|
+
require 'hubspot_client/client/communication_preference'
|
7
5
|
require 'hubspot_client/client/company'
|
6
|
+
require 'hubspot_client/client/contact'
|
8
7
|
require 'hubspot_client/client/properties'
|
9
|
-
require 'hubspot_client/
|
8
|
+
require 'hubspot_client/configuration'
|
9
|
+
require 'hubspot_client/model/communication_preference'
|
10
10
|
require 'hubspot_client/model/company'
|
11
|
+
require 'hubspot_client/model/contact'
|
12
|
+
require 'hubspot_client/version'
|
11
13
|
|
12
14
|
module HubspotClient
|
13
15
|
class << self
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubspot_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garllon
|
8
|
+
- romankonz
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
12
|
+
date: 2022-11-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: httparty
|
@@ -145,6 +146,7 @@ dependencies:
|
|
145
146
|
description: Hubspot client to handle CRM objects.
|
146
147
|
email:
|
147
148
|
- garllon@protonmail.com
|
149
|
+
- roman@konz.me
|
148
150
|
executables: []
|
149
151
|
extensions: []
|
150
152
|
extra_rdoc_files: []
|
@@ -152,16 +154,19 @@ files:
|
|
152
154
|
- ".github/workflows/rspec_and_rubocop.yml"
|
153
155
|
- ".gitignore"
|
154
156
|
- ".rubocop.yml"
|
157
|
+
- CHANGELOG.md
|
155
158
|
- Gemfile
|
156
159
|
- Gemfile.lock
|
157
160
|
- README.md
|
158
161
|
- bin/console
|
159
162
|
- hubspot_client.gemspec
|
160
163
|
- lib/hubspot_client.rb
|
164
|
+
- lib/hubspot_client/client/communication_preference.rb
|
161
165
|
- lib/hubspot_client/client/company.rb
|
162
166
|
- lib/hubspot_client/client/contact.rb
|
163
167
|
- lib/hubspot_client/client/properties.rb
|
164
168
|
- lib/hubspot_client/configuration.rb
|
169
|
+
- lib/hubspot_client/model/communication_preference.rb
|
165
170
|
- lib/hubspot_client/model/company.rb
|
166
171
|
- lib/hubspot_client/model/contact.rb
|
167
172
|
- lib/hubspot_client/version.rb
|
@@ -183,11 +188,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
183
188
|
version: 3.0.0
|
184
189
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
190
|
requirements:
|
186
|
-
- - "
|
191
|
+
- - ">="
|
187
192
|
- !ruby/object:Gem::Version
|
188
|
-
version:
|
193
|
+
version: '0'
|
189
194
|
requirements: []
|
190
|
-
rubygems_version: 3.3.
|
195
|
+
rubygems_version: 3.3.22
|
191
196
|
signing_key:
|
192
197
|
specification_version: 4
|
193
198
|
summary: Hubspot client
|