hubspot_client 0.1.0 → 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: 64366ba11cb24670e4a304a5a16307402736fe0f941f725535f148a37329afdc
4
- data.tar.gz: d134c5b394c90e1b86d7cc716b20196289ba3c3c1b7768793d5d15fdca86ff0c
3
+ metadata.gz: 29ef10cf9b14d327f1d9990684aca8cfe7c7988cbf26cb4420c20bc14c18d237
4
+ data.tar.gz: fded388fb01ad2b338ba0ba32631553d24e72612fa0866644c9d95725b91542d
5
5
  SHA512:
6
- metadata.gz: 5be8964ed3c42cc2e01481da815de2d7f068ff1a4359f092ec1c89a864c761aa51c91cc6c79511004c685bcab19da1a8b7a81d0ec4cdf17b7ccc95de8fdb72b8
7
- data.tar.gz: b27567094d0c0cfe0166ee7ae13b0c99012b2f127cddb62d5f703916b17e32864257a39892109360625c528239ddbc0961fbc3df369be1c89c1ded0e0ab6e906
6
+ metadata.gz: e5b1458f89a50a95e1323b984329b10b47a992e05b8f1a662935ada633d019e111043de8e4ec31c453fb61f8421bca05be70c63d32629f556ac216b49e60d383
7
+ data.tar.gz: 512dfc4ba03b80366059709c74ea09559c5e925c339dbdc556b4a24efd0d81db9cedd99ff90c308890c5e1b7fce83c2aeb034ed1a1d69f9cf58e4565f8879774
data/.rubocop.yml CHANGED
@@ -8,4 +8,4 @@ Style/Documentation:
8
8
 
9
9
  Metrics/ModuleLength:
10
10
  Exclude:
11
- - 'spec/hubspot_client/model/contact_spec.rb'
11
+ # - 'spec/hubspot_client/model/contact_spec.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hubspot_client (0.1.0)
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
 
@@ -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
 
@@ -2,8 +2,8 @@
2
2
 
3
3
  module HubspotClient
4
4
  module Client
5
- class SubscriptionNotSuccessful < StandardError; end
6
- class FetchDefinitionsNotSuccessful < StandardError; end
5
+ class SubscriptionNotSuccessful < ClientBaseError; end
6
+ class FetchDefinitionsNotSuccessful < ClientBaseError; end
7
7
 
8
8
  class CommunicationPreference
9
9
  include HTTParty
@@ -17,7 +17,7 @@ module HubspotClient
17
17
 
18
18
  return response if response.code == 200
19
19
 
20
- raise FetchDefinitionsNotSuccessful
20
+ raise FetchDefinitionsNotSuccessful, response
21
21
  end
22
22
 
23
23
  def subscribe(properties)
@@ -27,7 +27,7 @@ module HubspotClient
27
27
 
28
28
  return response if response.code == 200
29
29
 
30
- raise SubscriptionNotSuccessful
30
+ raise SubscriptionNotSuccessful, response
31
31
  end
32
32
 
33
33
  def headers
@@ -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
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HubspotClient
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'httparty'
4
+ require 'hubspot_client/client_base_error'
4
5
  require 'hubspot_client/client/communication_preference'
5
6
  require 'hubspot_client/client/company'
6
7
  require 'hubspot_client/client/contact'
metadata CHANGED
@@ -1,7 +1,7 @@
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garllon
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-11-30 00:00:00.000000000 Z
12
+ date: 2022-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -165,6 +165,7 @@ files:
165
165
  - lib/hubspot_client/client/company.rb
166
166
  - lib/hubspot_client/client/contact.rb
167
167
  - lib/hubspot_client/client/properties.rb
168
+ - lib/hubspot_client/client_base_error.rb
168
169
  - lib/hubspot_client/configuration.rb
169
170
  - lib/hubspot_client/model/communication_preference.rb
170
171
  - lib/hubspot_client/model/company.rb
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubygems_version: 3.3.22
196
+ rubygems_version: 3.3.3
196
197
  signing_key:
197
198
  specification_version: 4
198
199
  summary: Hubspot client