ruby_hubspot_api 0.2 → 0.2.1.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 67b58c873d1e9277df15b213a804afe47189c888aab565963950bf9992050e07
4
- data.tar.gz: 62028c4b6b0a2ac9a9a29e88cf4762cbbdb909942415d1bc2bf02e3838b405eb
2
+ SHA1:
3
+ metadata.gz: 2ca83fa3cba8c574d585b31a359da74678d405d2
4
+ data.tar.gz: 151f119e552b17faff4d921cda1ceec62a3fc045
5
5
  SHA512:
6
- metadata.gz: 98ec373c58ef3aa92eb963d2ab567bd41204bd1c80552e0abacf4cadc1a6860d5b227dde78f5fbfe8b6d3cdff65536390116f468492c6f639e87c1a83f4e60ff
7
- data.tar.gz: 5bea871875782b5fd35ff62de85c11da16f7e763a88972ac3d6cbca3e6b700eca589eed7933058434d9c6574079b71fd5e2d0aabc8fcc3be288dd27d5a9ae405
6
+ metadata.gz: e2e95c0a9ef1b69ff862c7843bbb100b23d57fe29cfea0d2042a7593dc3760307d48027fc0b54a6ae05bd39c4721db7603e04a7b16a5ec51b50a1becc436fdc1
7
+ data.tar.gz: 9dd953ca1946b3f9c3f1d0616f377a330f7e894f6a0f1a1aa6e98fde137015b6c39148dec58437c5cf027d89b9e096dbeb36b144a368ed8f1e61aa2a673305d7
@@ -0,0 +1,47 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "main" ]
13
+ pull_request:
14
+ branches: [ "main" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.5', '2.6', '2.7', '3.0']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+
30
+ - name: Set up Ruby
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby-version }}
34
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
35
+
36
+ - name: Run tests
37
+ run: HUBSPOT_LOG_LEVEL=FATAL bundle exec rspec
38
+
39
+ - name: Upload coverage to Codecov
40
+ run: bash <(curl -s https://codecov.io/bash)
41
+ env:
42
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
43
+
44
+ - name: Upload coverage to Codacy
45
+ run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
46
+ env:
47
+ CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  # rspec failure tracking
7
7
  .rspec_status
8
8
  .pry_history
9
+ .ruby-version
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_hubspot_api (0.1.2.1)
4
+ ruby_hubspot_api (0.2.1)
5
5
  httparty (>= 0.1, < 1.0)
6
6
 
7
7
  GEM
@@ -9,14 +9,16 @@ GEM
9
9
  specs:
10
10
  addressable (2.8.7)
11
11
  public_suffix (>= 2.0.2, < 7.0)
12
- bigdecimal (3.1.8)
12
+ bigdecimal (3.0.2)
13
13
  byebug (11.1.3)
14
+ codecov (0.6.0)
15
+ simplecov (>= 0.15, < 0.22)
14
16
  coderay (1.1.3)
15
17
  crack (1.0.0)
16
18
  bigdecimal
17
19
  rexml
18
20
  diff-lcs (1.5.1)
19
- docile (1.4.1)
21
+ docile (1.3.5)
20
22
  dotenv (2.8.1)
21
23
  hashdiff (1.1.1)
22
24
  httparty (0.21.0)
@@ -25,15 +27,15 @@ GEM
25
27
  method_source (1.1.0)
26
28
  mini_mime (1.1.2)
27
29
  multi_xml (0.6.0)
28
- pry (0.13.1)
30
+ pry (0.14.2)
29
31
  coderay (~> 1.1)
30
32
  method_source (~> 1.0)
31
- pry-byebug (3.9.0)
33
+ pry-byebug (3.8.0)
32
34
  byebug (~> 11.0)
33
- pry (~> 0.13.0)
35
+ pry (~> 0.10)
34
36
  public_suffix (4.0.7)
35
37
  rake (13.2.1)
36
- rexml (3.3.7)
38
+ rexml (3.2.5)
37
39
  rspec (3.13.0)
38
40
  rspec-core (~> 3.13.0)
39
41
  rspec-expectations (~> 3.13.0)
@@ -47,32 +49,35 @@ GEM
47
49
  diff-lcs (>= 1.2.0, < 2.0)
48
50
  rspec-support (~> 3.13.0)
49
51
  rspec-support (3.13.1)
50
- simplecov (0.22.0)
52
+ simplecov (0.18.5)
51
53
  docile (~> 1.1)
52
54
  simplecov-html (~> 0.11)
53
- simplecov_json_formatter (~> 0.1)
54
55
  simplecov-html (0.13.1)
55
- simplecov_json_formatter (0.1.4)
56
+ simplecov-lcov (0.8.0)
56
57
  vcr (6.0.0)
57
- webmock (3.23.1)
58
+ webmock (3.18.1)
58
59
  addressable (>= 2.8.0)
59
60
  crack (>= 0.3.2)
60
61
  hashdiff (>= 0.4.0, < 2.0.0)
61
62
 
62
63
  PLATFORMS
64
+ ruby
63
65
  x86_64-darwin-18
66
+ x86_64-linux
64
67
 
65
68
  DEPENDENCIES
66
- bundler (>= 2.0)
69
+ bundler (>= 2.0, < 2.4.0)
70
+ codecov
67
71
  dotenv (>= 2.0)
68
72
  pry (>= 0.1)
69
73
  pry-byebug (>= 3.0)
70
74
  rake (>= 11.0, < 14.0)
71
75
  rspec (>= 3.0)
72
76
  ruby_hubspot_api!
73
- simplecov (>= 0.22, < 1.0)
77
+ simplecov
78
+ simplecov-lcov
74
79
  vcr (>= 6.0)
75
80
  webmock (>= 3.0)
76
81
 
77
82
  BUNDLED WITH
78
- 2.3.26
83
+ 2.2.34
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Ruby HubSpot API Gem
2
2
 
3
+ [![codecov](https://codecov.io/gh/sensadrome/ruby_hubspot_api/branch/main/graph/badge.svg)](https://codecov.io/gh/sensadrome/ruby_hubspot_api) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/504ca01245ee4928b6ed0b13801259e7)](https://app.codacy.com/gh/sensadrome/ruby_hubspot_api/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
4
+
3
5
  This gem was largely inspired by [hubspot-api-ruby](https://github.com/captaincontrat/hubspot-api-ruby) which, in turn, was inspired by the [hubspot-ruby](https://github.com/HubspotCommunity/hubspot-ruby) community gem. I wanted to use version 3 of the api and simplify some parts of the interface
4
6
 
5
7
  The Ruby HubSpot API gem is a starting point for building an ORM-like interface to HubSpot's API.
@@ -30,19 +32,54 @@ To authenticate API requests, you need a HubSpot access token. First you will ne
30
32
 
31
33
  You can configure the gem by adding this code to your initializer (for Rails) or to your startup configuration (in any other environment):
32
34
 
35
+ ##### Minimum configuration
36
+
33
37
  ```ruby
34
38
  Hubspot.configure do |config|
35
39
  config.access_token = 'your_access_token'
36
40
  end
37
41
  ```
38
42
 
43
+ ##### Full possible configuration
44
+
45
+ ```ruby
46
+ Hubspot.configure do |config|
47
+ config.access_token = 'your_access_token'
48
+ config.portal_id = 'your_portal_id'
49
+ config.client_secret = 'your_client_secret'
50
+ config.logger = Rails.logger
51
+ config.log_level = 'info' # debug,info,warn,error,fatal
52
+ config.timeout = 10 # seconds to timeout all api requests
53
+ config.open_timeout = 5 # open_timeout seconds
54
+ config.read_timeout = 5 # read_timeout seconds
55
+ config.write_timeout = 5 # swrite_timeout econds (ruby >= 2.6)
56
+ end
57
+ ```
58
+
39
59
  This configuration ensures that your API requests are authenticated using your HubSpot access token.
40
60
 
41
- ## Working with Objects
61
+ ## Working with Resources
62
+
63
+ This gem allows you to interact with Hubspot resources such as contacts and companies. You can perform operations on individual resources (e.g., creating or updating records) as well as on collections (e.g., listing or searching).
64
+
65
+ __please note__
66
+
67
+ > In the Hubspot API contacts, companies etc are referred to as "Objects" (e.g. CRM > Objects > Contacts) so when we use the word "Object" (with a capital O) we will be referring to an object in Hubspot
42
68
 
43
- _(N.B when referring to the resources in the api we will refer to them as Objects as per the Hubspot nomenclature)_
69
+ > In this gem we use the term Resource so as not to accidentally overload Object! When we use the term "Resource" we should be referring to the ruby ORM base class and when we say "resource" we should be referring to an instance of this class (or a class that inherits it)
44
70
 
45
- This gem allows you to interact with HubSpot objects such as contacts and companies. You can perform operations on individual instances (e.g., creating or updating records) as well as on collections (e.g., listing or searching).
71
+ ### Hubspot::Resource class
72
+
73
+ This is the base ORM class for all Hubspot CRM objects. You should not operate on this class but with the following classes each of which inherits from Hubspot::Resource
74
+
75
+ ```ruby
76
+ Hubspot::Contact # crm > contacts
77
+ Hubspot::Company # crm > companies
78
+ Hubspot::User # hubspot users (also referred to as 'owners')
79
+ Hubspot::Owner # alias of Hubspot::User if you prefer to use it
80
+ ```
81
+
82
+ however you can [add custom objects of your own](#user-content-custom-resources) based on your own custom defined Objects in Hubspot
46
83
 
47
84
  ### Creating and Saving an Object
48
85
 
@@ -178,12 +215,12 @@ This will automatically set the limits and handle paging for the most efficient
178
215
 
179
216
  By default Hubspot will only send back the [default hubspot properties](https://knowledge.hubspot.com/properties/hubspots-default-contact-properties)
180
217
 
181
- You can pass an array of properties to be return as follows:
218
+ You can pass an array of properties to be returned as follows:
182
219
 
183
220
  Example:
184
221
 
185
222
  ```ruby
186
- # Search for contacts with email containing "hubspot.com" and only return specific properties
223
+ # Get the full list of contacts and only return specific properties
187
224
  contacts = Hubspot::Contact.list(
188
225
  properties: ['firstname', 'lastname', 'email', 'mobile', 'custom_property_1']
189
226
  )
@@ -327,7 +364,9 @@ batch.each_page do |contacts|
327
364
  end
328
365
  ```
329
366
 
330
- Finally there is another helper method on re
367
+ Finally there is another helper method `batch_read_all` on any Hubspot::Resource class (Hubspot::Contact, Hubspot::Company, Hubspot::User etc) which will read all of the resources and return a HubSpot::Batch (with all of the resources).
368
+
369
+ You can then update the resources and call `update` on the batch.... see below
331
370
 
332
371
  #### Batch Update
333
372
 
@@ -348,13 +387,12 @@ batch.update
348
387
 
349
388
  Example using a batch
350
389
  ```ruby
351
- contact_ids = my_contacts.collect(&:hubspot_id).compact
352
- batch = Hubspot::contacts.batch_read(contact_ids)
390
+ user_ids = my_selected_users.collect(&:hubspot_id).compact
391
+ batch = Hubspot::User.batch_read(user_ids)
353
392
 
354
- batch.resources.each do |hubspot_contact|
355
- my_contact = my_contacts.find { |c| c.hubspot_id == hubspot_contact.id }
356
- # some logic or method to set any new/changed properties on hubspot_contact
357
- update_hubspot_contact_from_local(hubspot_contact, my_contact)
393
+ batch.resources.each do |hubspot_user|
394
+ # some logic or method to set any new/changed properties on hubspot_user
395
+ hubspot_user.sales_total = fetch_sales_total(user.email)
358
396
  end
359
397
 
360
398
  # now we have a batch with changed resources we can update the batch
@@ -404,6 +442,31 @@ else
404
442
  end
405
443
  ```
406
444
 
445
+ ## Custom Resources
446
+
447
+ If you have defined custom objects you can easily add them by creating a class that inherits from `Hubspot::Resource`
448
+
449
+ ```ruby
450
+ # lib/hubspot/projects.rb
451
+
452
+ require 'ruby_hubspot_api' # if not required by bundler already...
453
+
454
+ module Hubspot
455
+ class Project < Resource
456
+
457
+ # resource_name (part of the url in the api) will default
458
+ # to a simple plural of the class name - in this case 'projects'
459
+ # if the url for your custom object is different you can override it
460
+
461
+ def resource_name
462
+ 'company_projects'
463
+ end
464
+ end
465
+ end
466
+
467
+ projects = Hubspot::Projects.search(query: { status_in: ['upcoming', 'active', 'overrun'] }).all
468
+
469
+ ```
407
470
 
408
471
  ## Contributing
409
472
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # HubSpot API Client
4
+ # Handles all HTTP interactions with the HubSpot API. It manages GET, POST, PATCH, and DELETE requests.
3
5
  module Hubspot
4
6
  # All interations with the Hubspot API happen here...
5
7
  class ApiClient
@@ -15,6 +15,11 @@ module Hubspot
15
15
  apply_log_level
16
16
  end
17
17
 
18
+ # Apply the log level to the logger
19
+ def apply_log_level
20
+ @logger.level = @log_level
21
+ end
22
+
18
23
  private
19
24
 
20
25
  # Initialize the default logger
@@ -43,11 +48,6 @@ module Hubspot
43
48
  end
44
49
  # rubocop:enable Metrics/MethodLength
45
50
 
46
- # Apply the log level to the logger
47
- def apply_log_level
48
- @logger.level = @log_level
49
- end
50
-
51
51
  # Set the default log level based on environment
52
52
  def default_log_level
53
53
  if defined?(Rails) && Rails.env.test?
@@ -11,5 +11,9 @@ module Hubspot
11
11
  "#<#{self.class} #{formatted_attrs}>"
12
12
  end
13
13
  # :nocov:
14
+
15
+ def read_only?
16
+ modificationMetadata['readOnlyValue'] == true
17
+ end
14
18
  end
15
19
  end
@@ -82,6 +82,14 @@ module Hubspot
82
82
  properties.reject { |property| property['hubspotDefined'] }
83
83
  end
84
84
 
85
+ def updatable_properties
86
+ properties.reject(&:read_only?)
87
+ end
88
+
89
+ def read_only_properties
90
+ properties.select(&:read_only?)
91
+ end
92
+
85
93
  def property(property_name)
86
94
  properties.detect { |prop| prop.name == property_name }
87
95
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hubspot
4
- VERSION = '0.2'
4
+ VERSION = '0.2.1-1'
5
5
  end
data/lib/hubspot.rb CHANGED
@@ -20,6 +20,7 @@ module Hubspot
20
20
  yield(config) if block_given?
21
21
  set_client_headers if config.access_token
22
22
  set_request_timeouts
23
+ config.apply_log_level
23
24
  end
24
25
 
25
26
  def configured?
@@ -9,3 +9,30 @@ class Object
9
9
  end
10
10
  end
11
11
  end
12
+
13
+ # At some point this will seem like a bad idea ;)
14
+
15
+ # :nocov:
16
+ if RUBY_VERSION < '2.5.0'
17
+ class Hash
18
+ # Non-mutating version (returns a new hash with transformed keys)
19
+ def transform_keys
20
+ return enum_for(:transform_keys) unless block_given?
21
+ result = {}
22
+ each_key do |key|
23
+ result[yield(key)] = self[key]
24
+ end
25
+ result
26
+ end
27
+
28
+ # Mutating version (modifies the hash in place)
29
+ def transform_keys!
30
+ return enum_for(:transform_keys!) unless block_given?
31
+ keys.each do |key|
32
+ self[yield(key)] = delete(key)
33
+ end
34
+ self
35
+ end
36
+ end
37
+ end
38
+ # :nocov:end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  spec.homepage = 'https://github.com/sensadrome/ruby_hubspot_api'
17
17
  spec.license = 'MIT'
18
18
 
19
- spec.required_ruby_version = '>= 2.5'
19
+ spec.required_ruby_version = '>= 2.4'
20
20
 
21
21
  # Prevent pushing this gem to RubyGems.org.
22
22
  # To allow pushes either set the 'allowed_push_host'
@@ -40,12 +40,14 @@ Gem::Specification.new do |spec|
40
40
  # Define development dependencies
41
41
  spec.add_development_dependency 'rake', '>= 11.0', '< 14.0'
42
42
 
43
- spec.add_development_dependency 'bundler', '>= 2.0'
43
+ spec.add_development_dependency 'bundler', '>= 2.0', '< 2.4.0'
44
+ spec.add_development_dependency 'codecov'
44
45
  spec.add_development_dependency 'dotenv', '>= 2.0'
45
46
  spec.add_development_dependency 'pry', '>= 0.1'
46
47
  spec.add_development_dependency 'pry-byebug', '>= 3.0'
47
48
  spec.add_development_dependency 'rspec', '>= 3.0'
48
- spec.add_development_dependency 'simplecov', '>= 0.22', '< 1.0'
49
+ spec.add_development_dependency 'simplecov'
50
+ spec.add_development_dependency 'simplecov-lcov'
49
51
  spec.add_development_dependency 'vcr', '>= 6.0'
50
52
  spec.add_development_dependency 'webmock', '>= 3.0'
51
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_hubspot_api
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: 0.2.1.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Brook
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-29 00:00:00.000000000 Z
11
+ date: 2024-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -37,6 +37,9 @@ dependencies:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
39
  version: '2.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 2.4.0
40
43
  type: :development
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,6 +47,23 @@ dependencies:
44
47
  - - ">="
45
48
  - !ruby/object:Gem::Version
46
49
  version: '2.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 2.4.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: codecov
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
47
67
  - !ruby/object:Gem::Dependency
48
68
  name: dotenv
49
69
  requirement: !ruby/object:Gem::Requirement
@@ -106,20 +126,28 @@ dependencies:
106
126
  requirements:
107
127
  - - ">="
108
128
  - !ruby/object:Gem::Version
109
- version: '0.22'
110
- - - "<"
111
- - !ruby/object:Gem::Version
112
- version: '1.0'
129
+ version: '0'
113
130
  type: :development
114
131
  prerelease: false
115
132
  version_requirements: !ruby/object:Gem::Requirement
116
133
  requirements:
117
134
  - - ">="
118
135
  - !ruby/object:Gem::Version
119
- version: '0.22'
120
- - - "<"
136
+ version: '0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: simplecov-lcov
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
121
142
  - !ruby/object:Gem::Version
122
- version: '1.0'
143
+ version: '0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
123
151
  - !ruby/object:Gem::Dependency
124
152
  name: vcr
125
153
  requirement: !ruby/object:Gem::Requirement
@@ -176,10 +204,10 @@ extensions: []
176
204
  extra_rdoc_files: []
177
205
  files:
178
206
  - ".env.sample"
207
+ - ".github/workflows/ruby.yml"
179
208
  - ".gitignore"
180
209
  - ".rspec"
181
210
  - ".rubocop.yml"
182
- - ".ruby-version"
183
211
  - CHANGELOG.md
184
212
  - Gemfile
185
213
  - Gemfile.lock
@@ -218,14 +246,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
246
  requirements:
219
247
  - - ">="
220
248
  - !ruby/object:Gem::Version
221
- version: '2.5'
249
+ version: '2.4'
222
250
  required_rubygems_version: !ruby/object:Gem::Requirement
223
251
  requirements:
224
- - - ">="
252
+ - - ">"
225
253
  - !ruby/object:Gem::Version
226
- version: '0'
254
+ version: 1.3.1
227
255
  requirements: []
228
- rubygems_version: 3.2.3
256
+ rubyforge_project:
257
+ rubygems_version: 2.6.14.4
229
258
  signing_key:
230
259
  specification_version: 4
231
260
  summary: ruby_hubspot_api is an ORM-like wrapper for the Hubspot API
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.5.3