hubspot_client 0.1.0.beta1 → 0.1.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +1 -1
- data/README.md +55 -1
- data/lib/hubspot_client/client/contact.rb +15 -5
- data/lib/hubspot_client/model/company.rb +8 -1
- data/lib/hubspot_client/model/contact.rb +16 -1
- data/lib/hubspot_client/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bc3a880bcae828da2e0ae5b37c4027339352b7294868caeb3b87395be557897
|
4
|
+
data.tar.gz: 78a1a367a7a052726fa95f4d792ffdcb1d619ba58cfde4a3f3f1842277aedb41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5d4d5cd7dae89474741e4a985452b2a7aaf15681ba97b61a4fe8ddf8a52d5ecebd0267a6c4304470e65b5a20c35cf52a46c3f4aa66cb86febe0c313d5534914
|
7
|
+
data.tar.gz: 965e6fbd91337cc4f22c88ed74b4ca02ffc1a5fd3dacc8dbd9b0a3efc7254c288fa06efc840827fb453372b389f9cf35fd66398c15f276e3103ec863a820a221
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## 0.1.0.beta2 (2022-11-28)
|
2
|
+
|
3
|
+
### Features
|
4
|
+
* Add associate company to contact logic
|
5
|
+
* Update README to make it more understanble
|
6
|
+
|
7
|
+
### Breaking Changes
|
8
|
+
None
|
9
|
+
|
10
|
+
## 0.1.0.beta1 (2022-11-25)
|
11
|
+
|
12
|
+
### Features
|
13
|
+
* Add Company Model and Client
|
14
|
+
* Add primary_company method to Contact model
|
15
|
+
* Add Properties Client
|
16
|
+
* Add Matrix for RSpec tests and support for the moment Ruby 3.0 and 3.1
|
17
|
+
|
18
|
+
## Breaking Changes
|
19
|
+
None
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -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
|
|
@@ -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
|
|
@@ -47,6 +48,20 @@ module HubspotClient
|
|
47
48
|
def primary_company
|
48
49
|
@primary_company ||= Company.find(hubspot_id: associatedcompanyid)
|
49
50
|
end
|
51
|
+
|
52
|
+
def associate_primary_company(hubspot_id)
|
53
|
+
response = Client::Contact.new.associate_with(hs_object_id, 'companies', hubspot_id)
|
54
|
+
|
55
|
+
return true if response.code == 200
|
56
|
+
|
57
|
+
false
|
58
|
+
end
|
59
|
+
|
60
|
+
def assign_attributes(attributes)
|
61
|
+
attributes.each do |attribute, value|
|
62
|
+
self[attribute] = value
|
63
|
+
end
|
64
|
+
end
|
50
65
|
end
|
51
66
|
end
|
52
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.beta2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garllon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- ".github/workflows/rspec_and_rubocop.yml"
|
153
153
|
- ".gitignore"
|
154
154
|
- ".rubocop.yml"
|
155
|
+
- CHANGELOG.md
|
155
156
|
- Gemfile
|
156
157
|
- Gemfile.lock
|
157
158
|
- README.md
|
@@ -187,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
188
|
- !ruby/object:Gem::Version
|
188
189
|
version: 1.3.1
|
189
190
|
requirements: []
|
190
|
-
rubygems_version: 3.3.
|
191
|
+
rubygems_version: 3.3.22
|
191
192
|
signing_key:
|
192
193
|
specification_version: 4
|
193
194
|
summary: Hubspot client
|