ruby_hubspot_api 0.3.0 → 0.3.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
2
  SHA1:
3
- metadata.gz: 6052dfd71294e988924beeab1b89662673ceaf93
4
- data.tar.gz: 4b2e295931295d639e473a9b139df03ec7df1554
3
+ metadata.gz: 62b690c7e426369cd5979c4f6b5b0cec8b5a7620
4
+ data.tar.gz: 26047bb4aa34d3a91bf6c1aff80b6e3775220f4f
5
5
  SHA512:
6
- metadata.gz: caee0d8350205b6bcf45bb4ed4b5421f3fdaacaff87acfcb52c4845858bbafb664f70acbca1a564a34a99a166fd1072a838702d4bf4044b076cfd0b77e87f6a7
7
- data.tar.gz: 28cbb5b1ea5ebc076d7177e8f4ee35f450bbe7fbb33224a31c55f0801fc566b705cf9b65faf95453b91154675139fb33cfce557ea74e06afd001a09f710190bf
6
+ metadata.gz: a6512174b13fa2ef07740690864c79a6c3593c908c1fed37170ef35bf08ca7ae5ceb9a3e53fe12d53079eb4e4bb47a58801430103b96c9a7b78dfd67eaaabaa5
7
+ data.tar.gz: 6ea719cb62b217fdbbdb2009d64215369608ba8d3423b59245472fb64fcd957174c5cc28a0cbcbd1f5eaf904260d19e1989da528df913292c139b5f4d893110e
data/CHANGELOG.md CHANGED
@@ -1,139 +1,139 @@
1
1
 
2
2
  ## v0.3.0
3
3
 
4
- - Clarify usage
5
- - More usage clarification
6
- - Create ruby.yml
7
- - fix the github workflow
8
- - fix the github workflow properly
9
- - add plaatforms to Gemfile.lock
10
- - add ruby 2.5 and reduce log output
11
- - try calling rspec directly
12
- - Use ERB in VCR tests so as to be independent of the env vars
13
- - ignore ruby version file
14
- - test on ruby 3.0 too
15
- - determine if a Hubspot property is read_only (or by negation updatable)
16
- - adding codecov
17
- - Using earlier bundler
18
- - Adding lcov format
19
- - Add read-only properties to resource class
20
- - Add property check to the contact spec
21
- - Only apply lcov formatter if running on github
22
- - try to upload the coverage results to codacy too
23
- - Adding Codacy badge
24
- - Ensure we always apply the right log_level
25
- - Tidy up documentation of resource
26
- - Yep. Back ported to 2.4
27
- - adjust some rubocop settings
28
- - Tidy up somer doc comments
29
- - Add some handling of required properties
30
- - Update user model to force specific properties to be retrieved
31
- - Improve logic of resource matching
32
- - Adds :sparkle: attributes method to a resource
33
- - Tidy comments
34
- - Update the hierarchy to allow more flexibility
35
- - Fix find resources
36
- - Clear up processing results
37
- - Update batch spec
38
- - Bump the version
39
- - Adds validation for resource matcher
40
- - Dynamically add a method to batch to allow "resources" to be referred to as the resource_name
41
- - Ignore gem files
42
- - Drop cadacy for now
43
- - Update batch spec to check resource_matcher works
44
- - Ensure properties are passed as named argument
45
- - No cov for inspect
46
- - Allow ERB in json fixtures
47
- - Contact find_by_token spec
48
- - find_by_token method - uses v1 API
49
- - Tests the method missing setter for resource
50
- - Sanitize web mock output
51
- - Finish specs
52
- - check the env vars before sanitising
53
- - make erb explicitly determined by the file exension (.json.erb)
54
- - use safe navigation for extracting id
55
- - bump version
56
4
  - update gem version in lock file
5
+ - bump version
6
+ - use safe navigation for extracting id
7
+ - make erb explicitly determined by the file exension (.json.erb)
8
+ - check the env vars before sanitising
9
+ - Finish specs
10
+ - Sanitize web mock output
11
+ - Tests the method missing setter for resource
12
+ - find_by_token method - uses v1 API
13
+ - Contact find_by_token spec
14
+ - Allow ERB in json fixtures
15
+ - No cov for inspect
16
+ - Ensure properties are passed as named argument
17
+ - Update batch spec to check resource_matcher works
18
+ - Drop cadacy for now
19
+ - Ignore gem files
20
+ - Dynamically add a method to batch to allow "resources" to be referred to as the resource_name
21
+ - Adds validation for resource matcher
22
+ - Bump the version
23
+ - Update batch spec
24
+ - Clear up processing results
25
+ - Fix find resources
26
+ - Update the hierarchy to allow more flexibility
27
+ - Tidy comments
28
+ - Adds :sparkle: attributes method to a resource
29
+ - Improve logic of resource matching
30
+ - Update user model to force specific properties to be retrieved
31
+ - Add some handling of required properties
32
+ - Tidy up somer doc comments
33
+ - adjust some rubocop settings
34
+ - Yep. Back ported to 2.4
35
+ - Tidy up documentation of resource
36
+ - Ensure we always apply the right log_level
37
+ - Adding Codacy badge
38
+ - try to upload the coverage results to codacy too
39
+ - Only apply lcov formatter if running on github
40
+ - Add property check to the contact spec
41
+ - Add read-only properties to resource class
42
+ - Adding lcov format
43
+ - Using earlier bundler
44
+ - adding codecov
45
+ - determine if a Hubspot property is read_only (or by negation updatable)
46
+ - test on ruby 3.0 too
47
+ - ignore ruby version file
48
+ - Use ERB in VCR tests so as to be independent of the env vars
49
+ - try calling rspec directly
50
+ - add ruby 2.5 and reduce log output
51
+ - add plaatforms to Gemfile.lock
52
+ - fix the github workflow properly
53
+ - fix the github workflow
54
+ - Create ruby.yml
55
+ - More usage clarification
56
+ - Clarify usage
57
57
 
58
58
  ## v0.2.0
59
59
 
60
- - Get the development dependencies right!
61
- - Bump the version again
62
- - describe find_by method
63
- - update lock
64
- - batch :sparkle: upsert spec
65
- - Borrowing Object#blank? method cos it actually really helps...
66
- - batch implemntation
67
- - logger.debug the post body and response body
68
- - Adds a changes? Method on resource
69
- - Adds instance method resource_name on resource
70
- - Ensure keys are stringified
71
- - Add all end points to the batch spec
72
- - Adds create and archive methods to batches
73
- - Tidy up resource code
74
- - Cover the previously nocov'd code
75
- - Add api client logging spec
76
- - add configurable timeouts to requests
77
- - Move rate limit handling to the client
78
- - Simplify mocked responses in batch spec
79
- - Adds PagedBatch as pager for batch/read request
80
- - Update the Readme to add Batch operations
81
60
  - bump version
61
+ - Update the Readme to add Batch operations
62
+ - Adds PagedBatch as pager for batch/read request
63
+ - Simplify mocked responses in batch spec
64
+ - Move rate limit handling to the client
65
+ - add configurable timeouts to requests
66
+ - Add api client logging spec
67
+ - Cover the previously nocov'd code
68
+ - Tidy up resource code
69
+ - Adds create and archive methods to batches
70
+ - Add all end points to the batch spec
71
+ - Ensure keys are stringified
72
+ - Adds instance method resource_name on resource
73
+ - Adds a changes? Method on resource
74
+ - logger.debug the post body and response body
75
+ - batch implemntation
76
+ - Borrowing Object#blank? method cos it actually really helps...
77
+ - batch :sparkle: upsert spec
78
+ - update lock
79
+ - describe find_by method
80
+ - Bump the version again
81
+ - Get the development dependencies right!
82
82
 
83
83
  ## v0.1.2
84
84
 
85
- - Fix the Readme
86
- - Sure the search param is values where passing an array
87
- - update changelog and Gemfile.lock
88
85
  - bump version
86
+ - update changelog and Gemfile.lock
87
+ - Sure the search param is values where passing an array
88
+ - Fix the Readme
89
89
 
90
90
  ## v0.1.1
91
91
 
92
- - adds the version numbers to the gemspec
93
- - Fix dependencies
94
92
  - bump version
93
+ - Fix dependencies
94
+ - adds the version numbers to the gemspec
95
95
 
96
96
  ## v0.1.0
97
97
 
98
- - Setup the configuration block
99
- - Adds spec for config
100
- - Set the auth headers when access_token configured
101
- - Version spec
102
- - don't test for client id
103
- - Load api client and add exception handler
104
- - Initial bases class Resource for api crud
105
- - Contact class with spec
106
- - Cassettes for contact spec
107
- - company model and spec with cassettes
108
- - Adds PagedCollection for paged results (list / search)
109
- - Adds Hubspot configuration to tests
110
- - Update required files
111
- - Adds list method to return PagedCollection
112
- - Add interface for search
113
- - VCR configuration
114
- - Contact/search cassette
115
- - Sample ENV file for developers
116
- - console with configuration if env vars set
117
- - Readme file
118
- - MIT license
119
- - allow connections if vcr_record_mode is on
120
- - Fix rubocop config
121
- - Update Readme
122
- - Log api requests and add interface to set logging
123
- - Update exception handing logic and add more exception classes
124
- - Test all parts of the config code
125
- - Adds user model (aliased to Owner) and specs
126
- - Add a configured? method to Hubspot module
127
- - Adds a dummy Hubspot::Property class
128
- - Update Paged request handling based on method
129
- - Adds a find_by mechanism for resources
130
- - Use the Hubspot::Property class to return properties for a given resource object
131
- - Update the specs for 100% coverage
132
- - Update the sample .env file
133
- - Reorder and clarify Readme
134
- - When we use limit(1) we should only return the object not an array
135
- - Test that we only get the properties we ask for or the defaults
136
- - Flatten the properties array into a comma separated list
137
- - Improve the intialiser
138
98
  - Update the changeling and link in gem spec
99
+ - Improve the intialiser
100
+ - Flatten the properties array into a comma separated list
101
+ - Test that we only get the properties we ask for or the defaults
102
+ - When we use limit(1) we should only return the object not an array
103
+ - Reorder and clarify Readme
104
+ - Update the sample .env file
105
+ - Update the specs for 100% coverage
106
+ - Use the Hubspot::Property class to return properties for a given resource object
107
+ - Adds a find_by mechanism for resources
108
+ - Update Paged request handling based on method
109
+ - Adds a dummy Hubspot::Property class
110
+ - Add a configured? method to Hubspot module
111
+ - Adds user model (aliased to Owner) and specs
112
+ - Test all parts of the config code
113
+ - Update exception handing logic and add more exception classes
114
+ - Log api requests and add interface to set logging
115
+ - Update Readme
116
+ - Fix rubocop config
117
+ - allow connections if vcr_record_mode is on
118
+ - MIT license
119
+ - Readme file
120
+ - console with configuration if env vars set
121
+ - Sample ENV file for developers
122
+ - Contact/search cassette
123
+ - VCR configuration
124
+ - Add interface for search
125
+ - Adds list method to return PagedCollection
126
+ - Update required files
127
+ - Adds Hubspot configuration to tests
128
+ - Adds PagedCollection for paged results (list / search)
129
+ - company model and spec with cassettes
130
+ - Cassettes for contact spec
131
+ - Contact class with spec
132
+ - Initial bases class Resource for api crud
133
+ - Load api client and add exception handler
134
+ - don't test for client id
135
+ - Version spec
136
+ - Set the auth headers when access_token configured
137
+ - Adds spec for config
138
+ - Setup the configuration block
139
139
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_hubspot_api (0.3.0)
4
+ ruby_hubspot_api (0.3.1)
5
5
  httparty (>= 0.1, < 1.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -120,7 +120,7 @@ puts "Contact: #{contact.firstname} #{contact.lastname}"
120
120
 
121
121
  ### Updating an Existing Object
122
122
 
123
- To update an existing object, you can either modify the object and call `save`, or use the `update` method specifying the properties you want to update. You can test whether or not the object will need to upload changes to the api by using the changes? method
123
+ To update an existing object, you can either modify the object and call `save`, or use the `update` method specifying the properties you want to update. You can test whether or not the object will need to upload changes to the api by using the changes? method. If you don't want to check for changes? you can use the method `save!` on the resource which will raise a Hubspot::NothingToDoError if there are no changes.
124
124
 
125
125
  Example using `save`:
126
126
 
@@ -136,6 +136,22 @@ contact.save # true
136
136
  contact.changes? # false
137
137
  ```
138
138
 
139
+ Example using `save!`:
140
+
141
+ ```ruby
142
+ contact = Hubspot::Contact.find(1)
143
+
144
+ MyDecorator.new(contact).apply_changes!
145
+
146
+ begin
147
+ contact.save!
148
+ rescue Hubspot::NothingToDoError = _
149
+ puts "Nothing changed, cancelled api call"
150
+ rescue Hubspot::RequestError => e
151
+ puts "API Error: #{e.message}"
152
+ end
153
+ ```
154
+
139
155
  Example using `update`:
140
156
 
141
157
  ```ruby
@@ -274,6 +290,26 @@ end
274
290
  - **lte**: Less than or equal to.
275
291
  - **IN**: Matches any of the values in an array.
276
292
 
293
+ #### Searching for empty values (NOT_HAS_PROPERTY)
294
+
295
+ Any empty value in your search will be matched using the correect filter in Hubspot
296
+
297
+ ```ruby
298
+ # Search for companies with no value for a given field
299
+ companies = Hubspot::Company.search(query: { client_category: nil }, properties: %w[name number_of_employees])
300
+ # Request body: {"filterGroups":[{"filters":[{"propertyName":"client_category","operator":"NOT_HAS_PROPERTY"}]}]
301
+
302
+ puts "Searching for uncategorised customers"
303
+ puts ""
304
+
305
+ companies.each do |company|
306
+ category = company_category_by_size(company.number_of_employees)
307
+ company.update(client_category: category)
308
+
309
+ puts " Found: #{company.name} (size #{company.number_of_employees}) - filed under #{category}"
310
+ end
311
+ ```
312
+
277
313
  #### Specifying Properties in Search
278
314
 
279
315
  When performing a search, you can also specify which properties to return.
@@ -19,6 +19,7 @@ module Hubspot
19
19
  class RateLimitExceededError < RequestError; end
20
20
  class NotConfiguredError < StandardError; end
21
21
  class ArgumentError < StandardError; end
22
+ class NothingToDoError < StandardError; end
22
23
 
23
24
  class << self
24
25
  def error_from_response(response)
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
3
4
  require_relative './api_client'
4
5
  require_relative './exceptions'
5
6
 
@@ -263,6 +263,8 @@ module Hubspot
263
263
  #
264
264
  # If no suffix is provided, the default comparison is equality (`EQ`).
265
265
  #
266
+ # If no value is provided, or is empty the NOT_HAS_PROPERTY operator will be used
267
+ #
266
268
  # query - [String, Hash] The query for searching. This can be either:
267
269
  # - A String: for full-text search.
268
270
  # - A Hash: where each key represents a property and may have suffixes for the comparison
@@ -356,9 +358,9 @@ module Hubspot
356
358
  filter_groups = [{ filters: [] }]
357
359
 
358
360
  filters.each do |key, value|
359
- filter = extract_property_and_operator(key)
361
+ filter = extract_property_and_operator(key, value)
360
362
  value_key = value.is_a?(Array) ? :values : :value
361
- filter[value_key] = value
363
+ filter[value_key] = value unless value.blank?
362
364
  filter_groups.first[:filters] << filter
363
365
  end
364
366
 
@@ -366,7 +368,9 @@ module Hubspot
366
368
  end
367
369
 
368
370
  # Extract property name and operator from the key
369
- def extract_property_and_operator(key)
371
+ def extract_property_and_operator(key, value)
372
+ return { propertyName: key.to_s, operator: 'NOT_HAS_PROPERTY' } if value.blank?
373
+
370
374
  OPERATOR_MAP.each do |suffix, hubspot_operator|
371
375
  if key.to_s.end_with?(suffix)
372
376
  return {
@@ -454,6 +458,12 @@ module Hubspot
454
458
  end
455
459
  end
456
460
 
461
+ def save!
462
+ raise NothingToDoError, 'Nothing to save' unless changes?
463
+
464
+ save
465
+ end
466
+
457
467
  # If the resource exists in Hubspot
458
468
  #
459
469
  # Returns Boolean
@@ -622,6 +632,8 @@ module Hubspot
622
632
  def create_new
623
633
  created_resource = self.class.create(@changes)
624
634
  @id = created_resource.id
635
+ @properties.merge!(@changes)
636
+ @changes = {}
625
637
  @id ? true : false
626
638
  end
627
639
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hubspot
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
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.3.0
4
+ version: 0.3.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-10-15 00:00:00.000000000 Z
11
+ date: 2024-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake