hubspot_client 0.1.0.beta2 → 0.2.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: 6bc3a880bcae828da2e0ae5b37c4027339352b7294868caeb3b87395be557897
4
- data.tar.gz: 78a1a367a7a052726fa95f4d792ffdcb1d619ba58cfde4a3f3f1842277aedb41
3
+ metadata.gz: 29ef10cf9b14d327f1d9990684aca8cfe7c7988cbf26cb4420c20bc14c18d237
4
+ data.tar.gz: fded388fb01ad2b338ba0ba32631553d24e72612fa0866644c9d95725b91542d
5
5
  SHA512:
6
- metadata.gz: c5d4d5cd7dae89474741e4a985452b2a7aaf15681ba97b61a4fe8ddf8a52d5ecebd0267a6c4304470e65b5a20c35cf52a46c3f4aa66cb86febe0c313d5534914
7
- data.tar.gz: 965e6fbd91337cc4f22c88ed74b4ca02ffc1a5fd3dacc8dbd9b0a3efc7254c288fa06efc840827fb453372b389f9cf35fd66398c15f276e3103ec863a820a221
6
+ metadata.gz: e5b1458f89a50a95e1323b984329b10b47a992e05b8f1a662935ada633d019e111043de8e4ec31c453fb61f8421bca05be70c63d32629f556ac216b49e60d383
7
+ data.tar.gz: 512dfc4ba03b80366059709c74ea09559c5e925c339dbdc556b4a24efd0d81db9cedd99ff90c308890c5e1b7fce83c2aeb034ed1a1d69f9cf58e4565f8879774
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .env
2
2
  .idea/
3
+ .ruby-version
data/.rubocop.yml CHANGED
@@ -4,4 +4,8 @@ Layout/LineLength:
4
4
  Max: 120
5
5
 
6
6
  Style/Documentation:
7
- Enabled: false
7
+ Enabled: false
8
+
9
+ Metrics/ModuleLength:
10
+ Exclude:
11
+ # - 'spec/hubspot_client/model/contact_spec.rb'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
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
+
1
10
  ## 0.1.0.beta2 (2022-11-28)
2
11
 
3
12
  ### Features
data/Gemfile CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- # Specify your gem's dependencies in graphql_connector.gemspec
5
+ # Specify your gem's dependencies in hubspot_client.gemspec
6
6
  gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hubspot_client (0.1.0.beta2)
4
+ hubspot_client (0.2.0)
5
5
  httparty (~> 0.20.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,7 +1,13 @@
1
1
 
2
2
  # HubspotClient
3
3
 
4
- An simple Hubspot Client. We only like to support the CRm features for the moment. Maybe we do more.
4
+ A Hubspot Client. Currently we only support the following CRM Parts:
5
+ * Contact
6
+ * Company
7
+ * Properties
8
+
9
+ Also:
10
+ * Communication Preferences
5
11
 
6
12
  ## Installation
7
13
 
@@ -21,7 +27,7 @@ Or install it yourself as:
21
27
 
22
28
  ## Usage
23
29
 
24
- You need to configure the `graphql_connector` first:
30
+ You need to configure the `hubspot_client` first:
25
31
  ``` ruby
26
32
  HubspotClient.configure do |config|
27
33
  config.access_token = 'PRIVATE_APP_ACCESS_TOKEN'
@@ -30,9 +36,10 @@ end
30
36
 
31
37
  ## Models
32
38
 
33
- The idea is that the models behave like an ActiveRecord Model.
39
+ The following models exists and should be mainly used. However you can also use the clients itself,
40
+ if you like, but you need to understand the code by yourself.
34
41
 
35
- ### Contact - HubspotClient::Model::Contact
42
+ ### Contact
36
43
 
37
44
  [Hubspot- API](https://developers.hubspot.com/docs/api/crm/contacts)
38
45
 
@@ -47,9 +54,8 @@ HubspotClient::Model::Contact.find(email: 'vader@example.com')
47
54
  => #<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">
48
55
  ```
49
56
 
50
- #### Associate_primary_company
57
+ #### associate_primary_company
51
58
 
52
- Successfull Request
53
59
  ```ruby
54
60
  hubspot_contact = HubspotClient::Model::Contact.find(hubspot_id: '1337')
55
61
  => #<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">
@@ -104,7 +110,7 @@ hubspot_company.update({ name: 'Blubber' })
104
110
 
105
111
 
106
112
 
107
- ### Subscription-Preferences
113
+ ### Communication-Preference
108
114
 
109
115
  [Hubspot- API](https://developers.hubspot.com/docs/api/marketing-api/subscriptions-preferences)
110
116
 
@@ -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 = ['garllon@protonmail.com']
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 < ClientBaseError; end
6
+ class FetchDefinitionsNotSuccessful < ClientBaseError; 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, response
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, response
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
@@ -2,9 +2,9 @@
2
2
 
3
3
  module HubspotClient
4
4
  module Client
5
- class CompanyNotFound < StandardError; end
6
- class CompanyNotCreated < StandardError; end
7
- class CompanyNotUpdated < StandardError; end
5
+ class CompanyNotFound < ClientBaseError; end
6
+ class CompanyNotCreated < ClientBaseError; end
7
+ class CompanyNotUpdated < ClientBaseError; end
8
8
 
9
9
  class Company
10
10
  include HTTParty
@@ -18,7 +18,7 @@ module HubspotClient
18
18
  headers: headers)
19
19
  return response if response.code == 200
20
20
 
21
- raise CompanyNotFound, 'Hubspot Company Not Found'
21
+ raise CompanyNotFound, response
22
22
  end
23
23
 
24
24
  def create(properties)
@@ -28,7 +28,7 @@ module HubspotClient
28
28
 
29
29
  return response if response.code == 201
30
30
 
31
- raise CompanyNotCreated, 'Hubspot could not Create'
31
+ raise CompanyNotCreated, response
32
32
  end
33
33
 
34
34
  def update(hubspot_id, properties)
@@ -38,7 +38,7 @@ module HubspotClient
38
38
 
39
39
  return response if response.code == 200
40
40
 
41
- raise CompanyNotUpdated, 'Hubspot could not update'
41
+ raise CompanyNotUpdated, response
42
42
  end
43
43
 
44
44
  private
@@ -2,10 +2,10 @@
2
2
 
3
3
  module HubspotClient
4
4
  module Client
5
- class ContactNotFound < StandardError; end
6
- class ContactNotCreated < StandardError; end
7
- class ContactNotUpdated < StandardError; end
8
- class AssociationError < StandardError; end
5
+ class ContactNotFound < ClientBaseError; end
6
+ class ContactNotCreated < ClientBaseError; end
7
+ class ContactNotUpdated < ClientBaseError; end
8
+ class AssociationError < ClientBaseError; end
9
9
 
10
10
  class Contact
11
11
  include HTTParty
@@ -32,7 +32,7 @@ module HubspotClient
32
32
 
33
33
  return response if response.code == 201
34
34
 
35
- raise ContactNotCreated, 'Hubspot Contact Not created'
35
+ raise ContactNotCreated, response
36
36
  end
37
37
 
38
38
  def update(hubspot_id, properties)
@@ -42,7 +42,7 @@ module HubspotClient
42
42
 
43
43
  return response if response.code == 200
44
44
 
45
- raise ContactNotUpdated, 'Hubspot could not update'
45
+ raise ContactNotUpdated, response
46
46
  end
47
47
 
48
48
  def associate_with(hubspot_id, to_object_type, to_object_type_id, association_type = '1')
@@ -60,7 +60,7 @@ module HubspotClient
60
60
  response = self.class.get(path, headers: headers)
61
61
  return response if response.code == 200
62
62
 
63
- raise ContactNotFound, 'Hubspot Contact Not Found'
63
+ raise ContactNotFound, response
64
64
  end
65
65
 
66
66
  def find_query_params(query_params = {})
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ClientBaseError < StandardError
4
+ def initialize(response)
5
+ error_message = { status: response.code, body: JSON.parse(response.body) }
6
+ super(error_message)
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HubspotClient
4
+ module Model
5
+ class CommunicationPreference
6
+ def self.definitions
7
+ Client::CommunicationPreference.new.definitions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -3,8 +3,6 @@
3
3
  module HubspotClient
4
4
  module Model
5
5
  class Company < OpenStruct
6
- UPDATABLE_PROPERTIES = %i[name phone address city zip].freeze
7
-
8
6
  def self.find(hubspot_id: nil)
9
7
  response = Client::Company.new.find_by_id(hubspot_id)
10
8
 
@@ -14,16 +12,14 @@ module HubspotClient
14
12
  end
15
13
 
16
14
  def self.create(properties)
17
- sliced_properties = properties.slice(*UPDATABLE_PROPERTIES)
18
- response = Client::Company.new.create(sliced_properties)
15
+ response = Client::Company.new.create(properties)
19
16
 
20
17
  new(response['properties'])
21
18
  end
22
19
 
23
20
  def update(new_properties = {})
24
21
  assign_attributes(new_properties)
25
- properties = to_h.slice(*UPDATABLE_PROPERTIES)
26
- response = Client::Company.new.update(hs_object_id, properties)
22
+ response = Client::Company.new.update(hs_object_id, to_h)
27
23
 
28
24
  return true if response.code == 200
29
25
 
@@ -5,8 +5,6 @@ module HubspotClient
5
5
  class MissingParameter < StandardError; end
6
6
 
7
7
  class Contact < OpenStruct
8
- UPDATABLE_PROPERTIES = %i[firstname lastname email phone lifecyclestage].freeze
9
-
10
8
  def self.find(hubspot_id: nil, email: nil)
11
9
  response = if hubspot_id
12
10
  Client::Contact.new.find_by_id(hubspot_id)
@@ -20,16 +18,14 @@ module HubspotClient
20
18
  end
21
19
 
22
20
  def self.create(properties)
23
- sliced_properties = properties.slice(*UPDATABLE_PROPERTIES)
24
- response = Client::Contact.new.create(sliced_properties)
21
+ response = Client::Contact.new.create(properties)
25
22
 
26
23
  new(response['properties'])
27
24
  end
28
25
 
29
26
  def update(new_properties = {})
30
27
  assign_attributes(new_properties)
31
- properties = to_h.slice(*UPDATABLE_PROPERTIES)
32
- response = Client::Contact.new.update(hs_object_id, properties)
28
+ response = Client::Contact.new.update(hs_object_id, to_h)
33
29
 
34
30
  return true if response.code == 200
35
31
 
@@ -45,6 +41,18 @@ module HubspotClient
45
41
  self
46
42
  end
47
43
 
44
+ def create_communication_subscription(subscription_id:, legal_basis: nil, legal_basis_explanation: nil)
45
+ properties = {
46
+ emailAddress: email,
47
+ subscriptionId: subscription_id
48
+ }
49
+
50
+ properties[:legalBasis] = legal_basis if legal_basis
51
+ properties[:legalBasisExplanation] = legal_basis_explanation if legal_basis_explanation
52
+
53
+ Client::CommunicationPreference.new.subscribe(properties)
54
+ end
55
+
48
56
  def primary_company
49
57
  @primary_company ||= Company.find(hubspot_id: associatedcompanyid)
50
58
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HubspotClient
4
- VERSION = '0.1.0.beta2'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,13 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'httparty'
4
- require 'hubspot_client/version'
5
- require 'hubspot_client/configuration'
6
- require 'hubspot_client/client/contact'
4
+ require 'hubspot_client/client_base_error'
5
+ require 'hubspot_client/client/communication_preference'
7
6
  require 'hubspot_client/client/company'
7
+ require 'hubspot_client/client/contact'
8
8
  require 'hubspot_client/client/properties'
9
- require 'hubspot_client/model/contact'
9
+ require 'hubspot_client/configuration'
10
+ require 'hubspot_client/model/communication_preference'
10
11
  require 'hubspot_client/model/company'
12
+ require 'hubspot_client/model/contact'
13
+ require 'hubspot_client/version'
11
14
 
12
15
  module HubspotClient
13
16
  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.beta2
4
+ version: 0.2.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-29 00:00:00.000000000 Z
12
+ date: 2022-12-02 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: []
@@ -159,10 +161,13 @@ files:
159
161
  - bin/console
160
162
  - hubspot_client.gemspec
161
163
  - lib/hubspot_client.rb
164
+ - lib/hubspot_client/client/communication_preference.rb
162
165
  - lib/hubspot_client/client/company.rb
163
166
  - lib/hubspot_client/client/contact.rb
164
167
  - lib/hubspot_client/client/properties.rb
168
+ - lib/hubspot_client/client_base_error.rb
165
169
  - lib/hubspot_client/configuration.rb
170
+ - lib/hubspot_client/model/communication_preference.rb
166
171
  - lib/hubspot_client/model/company.rb
167
172
  - lib/hubspot_client/model/contact.rb
168
173
  - lib/hubspot_client/version.rb
@@ -184,11 +189,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
189
  version: 3.0.0
185
190
  required_rubygems_version: !ruby/object:Gem::Requirement
186
191
  requirements:
187
- - - ">"
192
+ - - ">="
188
193
  - !ruby/object:Gem::Version
189
- version: 1.3.1
194
+ version: '0'
190
195
  requirements: []
191
- rubygems_version: 3.3.22
196
+ rubygems_version: 3.3.3
192
197
  signing_key:
193
198
  specification_version: 4
194
199
  summary: Hubspot client