hubspot_v3 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d55ee9f31364c57b484162bf1e574a5412e9f207072480c51025f4b624e1bc66
4
+ data.tar.gz: 6ca13e0d86d8229f188d27b655453271f93e99938d78c36d14231def5bc207b5
5
+ SHA512:
6
+ metadata.gz: 48b74f1e180b916db063dc5c3f1669d4d4bc3f1c38f64969d6bc3b73035337ea3d1e3b66ba4ab44add9b2e71cd72637645d77b5f22d86e51d195240e42521af0
7
+ data.tar.gz: cb09957b5b996fb56de04cce204d12dda956524c0dc4df73b5a3569c795a193648f7c9968594508d9d55dfcf9e09def66691ca4f76b2d36903045295861b773f
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in hubspot_v3.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hubspot_v3 (0.1.0)
5
+ httparty (~> 0.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.4.4)
11
+ httparty (0.20.0)
12
+ mime-types (~> 3.0)
13
+ multi_xml (>= 0.5.2)
14
+ mime-types (3.3.1)
15
+ mime-types-data (~> 3.2015)
16
+ mime-types-data (3.2021.0901)
17
+ multi_xml (0.6.0)
18
+ rake (13.0.6)
19
+ rspec (3.10.0)
20
+ rspec-core (~> 3.10.0)
21
+ rspec-expectations (~> 3.10.0)
22
+ rspec-mocks (~> 3.10.0)
23
+ rspec-core (3.10.1)
24
+ rspec-support (~> 3.10.0)
25
+ rspec-expectations (3.10.1)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.10.0)
28
+ rspec-mocks (3.10.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-support (3.10.2)
32
+
33
+ PLATFORMS
34
+ x86_64-linux
35
+
36
+ DEPENDENCIES
37
+ hubspot_v3!
38
+ rake (~> 13.0)
39
+ rspec (~> 3.0)
40
+
41
+ BUNDLED WITH
42
+ 2.2.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tomas Valent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,236 @@
1
+ # HubspotV3
2
+
3
+ Ruby gem wrapper around Hubspot API V3
4
+
5
+ Currently this gem focuses on **Batch** update/create/search of Contacts. More info in [source code](https://github.com/Pobble/hubspot_v3/blob/master/lib/hubspot_v3.rb)
6
+
7
+
8
+ Reason why Batch (or Bulk) operations are preferred by this gem is that Hubspot has a strict [limits on number of requests](https://developers.hubspot.com/apisbytier)
9
+ (around 100 requests per 10seconds, up to 200 requests per 10 seconds).
10
+ When dealing with large number of Contacts single request operations are
11
+ killing those limits quite quickly.
12
+
13
+
14
+ ## Other solutions out there
15
+
16
+ Gem currently covers only features that are needed for our use cases, however this repo/gem is open for any Pull Requests with additional features.
17
+
18
+ If you need other features and wish not to contribute to this gem there are 2 existing Hubspot gems out there:
19
+
20
+ * [Official gem](https://github.com/HubSpot/hubspot-api-ruby) based on V3 API but is just generated Ruby code
21
+ * [Community gem](https://github.com/HubspotCommunity/hubspot-ruby) which is better code quality but based on V1 API
22
+
23
+ It's possible to use our gem along with any of these two gems.
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem 'hubspot_v3', github: 'Pobble/hubspot_v3'
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle install
36
+
37
+ ## Usage
38
+
39
+ ### set API key
40
+
41
+ ```
42
+ HubspotV3.config.apikey = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
43
+ ```
44
+
45
+ ### Contacts - Search
46
+
47
+ ```
48
+
49
+ bodyhash = {
50
+ "filterGroups":[
51
+ {
52
+ "filters": [
53
+ {
54
+ "propertyName": "email",
55
+ "operator": "EQ",
56
+ "value": email
57
+ }
58
+ ]
59
+ }
60
+ ]
61
+ }
62
+ HubspotV3.contacts_search(bodyhash)
63
+ ```
64
+
65
+ * Full list of search filters and operators can be found in [official hubspot docs](https://developers.hubspot.com/docs/api/crm/contacts)
66
+ * More examples how to use `HubspotV3.contacts_search` can be found in [Search examples](https://github.com/Pobble/hubspot_v3/blob/master/README_SEARCH_EXAMPLES.md)
67
+
68
+
69
+ ### Contacts - find by email
70
+
71
+ ```
72
+ HubspotV3.contacts_search_by_emails(["hello@pobble.com", "info@pobble.com"])
73
+ [
74
+ {"id"=>"901",
75
+ "properties"=>
76
+ {"createdate"=>"2020-09-10T10:29:54.714Z",
77
+ "email"=>"hello@pobble.com",
78
+ "firstname"=>nil,
79
+ "hs_object_id"=>"901",
80
+ "lastmodifieddate"=>"2021-10-13T10:16:19.015Z",
81
+ "lastname"=>"test"},
82
+ "createdAt"=>"2020-09-10T10:29:54.714Z",
83
+ "updatedAt"=>"2021-10-13T10:16:19.015Z",
84
+ "archived"=>false},
85
+ {"id"=>"3401",
86
+ "properties"=>
87
+ {"createdate"=>"2021-10-13T13:31:04.599Z",
88
+ "email"=>"info@pobble.com",
89
+ "firstname"=>"Bryan",
90
+ "hs_object_id"=>"3401",
91
+ "lastmodifieddate"=>"2021-10-13T13:31:07.126Z",
92
+ "lastname"=>"Cooper"},
93
+ "createdAt"=>"2021-10-13T13:31:04.599Z",
94
+ "updatedAt"=>"2021-10-13T13:31:07.126Z",
95
+ "archived"=>false}
96
+ ]
97
+ ```
98
+
99
+ > Note: will search only primary email of a Contact
100
+
101
+ ### Contacts - find by email & results mapped by email
102
+
103
+ ```
104
+ HubspotV3.contacts_search_by_emails(["hello@pobble.com", "info@pobble.com"])
105
+
106
+ {
107
+ "anas+10093@pobble.com" => {
108
+ "id" => "901",
109
+ "properties" => {
110
+ "createdate" => "2020-09-10T10:29:54.714Z",
111
+ "email" => "hello@pobble.com",
112
+ "firstname" => nil,
113
+ "hs_object_id" => "901",
114
+ "lastmodifieddate" => "2021-10-13T10:16:19.015Z",
115
+ "lastname" => "test"
116
+ },
117
+ "createdAt" => "2020-09-10T10:29:54.714Z",
118
+ "updatedAt" => "2021-10-13T10:16:19.015Z",
119
+ "archived" => false
120
+ },
121
+ "bcooper@biglytics.net" => {
122
+ "id" => "3401",
123
+ "properties" => {
124
+ "createdate" => "2021-10-13T13:31:04.599Z",
125
+ "email" => "info@pobble.com",
126
+ "firstname" => "Bryan",
127
+ "hs_object_id" => "3401",
128
+ "lastmodifieddate" => "2021-10-13T13:31:07.126Z",
129
+ "lastname" => "Cooper"
130
+ },
131
+ "createdAt" => "2021-10-13T13:31:04.599Z",
132
+ "updatedAt" => "2021-10-13T13:31:07.126Z",
133
+ "archived" => false
134
+ }
135
+ }
136
+ ```
137
+
138
+ > Note: will search only primary email of a Contact
139
+
140
+ ### Contacts - Batch Create
141
+
142
+ ```
143
+ bodyhash = {
144
+ "inputs": [
145
+ {
146
+ "properties": {
147
+ "email": "equivalent@eq8.eu",
148
+ "firstname": "Tomas",
149
+ "lastname": "Talent",
150
+ }
151
+ }
152
+ ]
153
+ }
154
+
155
+ begin
156
+ HubspotV3.contacts_create(bodyhash)
157
+ rescue HubspotV3::RequestFailedError => e
158
+ puts e.message
159
+ # => 409 - Contact already exists. Existing ID: 3401
160
+
161
+ httparty_response_object = e.httparty_response
162
+ # => #<HTTParty::Response:0x1d920 parsed_response={"status"=>"error"...
163
+ end
164
+ ```
165
+
166
+ ### Contacts - Batch Update
167
+
168
+ ```
169
+ bodyhash = {
170
+ "inputs": [
171
+ {
172
+ "id": "1",
173
+ "properties": {
174
+ "company": "Biglytics",
175
+ "email": "bcooper@biglytics.net",
176
+ "firstname": "Bryan",
177
+ "lastname": "Cooper",
178
+ "phone": "(877) 929-0687",
179
+ "website": "biglytics.net"
180
+ }
181
+ }
182
+ ]
183
+ }
184
+ HubspotV3.contacts_update(bodyhash)
185
+ ```
186
+
187
+ ## Test your app
188
+
189
+ You can use http interceptor like [webmock](https://github.com/bblimke/webmock), [vcr](https://github.com/vcr/vcr).
190
+
191
+ Or you can use explicit contracts provided in this gem.
192
+
193
+ ```
194
+ require 'hubspot_v3'
195
+ require 'hubspot_v3/mock_contract'
196
+
197
+ HubspotV3::MockContract.contacts_search_by_emails(["hello@pobble.com", "notfound@pobble.com", "info@pobble.com"])
198
+ # [
199
+ # {
200
+ # "id" => 1589, "properties" => {
201
+ # "email"=>"hello@pobble.com",
202
+ # ...
203
+ # }
204
+ # },
205
+ {
206
+ # "id" => 1485, "properties" => {
207
+ # "email"=>"info@pobble.com",
208
+ # ...
209
+ # }
210
+ # }
211
+ # ]
212
+
213
+ HubspotV3::MockContract.contacts_search_by_emails_mapped(["hello@pobble.com", "notfound@pobble.com", "info@pobble.com"]).keys
214
+ # => ["hello@pobble.com", "info@pobble.com"]
215
+ ```
216
+
217
+ `id` field of test Contact contracts is calculated as `'info@pobble.com'.bytes.sum == 1485`, create contacts will be `'info@pobble.com'.bytes.sum + 1_000_000 == 1001485`
218
+
219
+ > More info on how to use [Contract tests](https://blog.eq8.eu/article/explicit-contracts-for-rails-http-api-usecase.html)
220
+
221
+
222
+
223
+ ## Development
224
+
225
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
226
+
227
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
228
+
229
+
230
+ ## Contributing
231
+
232
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Pobble/hubspot_v3.
233
+
234
+ ## License
235
+
236
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,72 @@
1
+
2
+
3
+
4
+ ### Find by primary email
5
+
6
+ ```
7
+ bodyhash = {
8
+ "filterGroups":[
9
+ {
10
+ "filters": [
11
+ {
12
+ "propertyName": "email",
13
+ "operator": "EQ",
14
+ "value": "equivalent@eq8.eu"
15
+ }
16
+ ]
17
+ }
18
+ ]
19
+ }
20
+ HubspotV3.contacts_search(bodyhash)
21
+ ```
22
+
23
+
24
+
25
+ ### Find contacts that have multiple emails
26
+
27
+ Let say you want a list of all Hubspot Contacts that have secondary
28
+ email.
29
+
30
+ ```
31
+ bodyhash = {
32
+ "filterGroups":[
33
+ {
34
+ "filters": [
35
+ {
36
+ "propertyName": "hs_additional_emails",
37
+ "operator": "HAS_PROPERTY"
38
+ }
39
+ ]
40
+ }
41
+ ],
42
+ "properties": [
43
+ "hs_additional_emails",
44
+ "email"
45
+ ],
46
+ "limit": 99,
47
+ "after": 0
48
+ }
49
+
50
+ a= HubspotV3.contacts_search(bodyhash)
51
+ ```
52
+
53
+ Now you can map these to a CSV:
54
+
55
+
56
+ ```
57
+ # vid,primary_email,secondary_emails
58
+ a.map do |res|
59
+ [res.fetch('id'), res.fetch('properties').fetch('email'), res.fetch('properties').fetch('hs_additional_emails')]
60
+ end
61
+ ```
62
+
63
+
64
+
65
+ ## More info
66
+
67
+
68
+ Full list of search filters and operators can be found in [official hubspot docs](https://developers.hubspot.com/docs/api/crm/contacts)
69
+
70
+ ![Screenshot from 2021-11-25 12-04-08](https://user-images.githubusercontent.com/721990/143430312-4d94aa49-5d8e-4910-8076-628b62a7a954.png)
71
+
72
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "hubspot_v3"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hubspot_v3/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hubspot_v3"
7
+ spec.version = HubspotV3::VERSION
8
+ spec.authors = ["Tomas Valent"]
9
+ spec.email = ["equivalent@eq8.eu"]
10
+
11
+ spec.summary = "Hubspot API v3 Ruby gem"
12
+ spec.description = "Ruby wrapper around Hubspot API v3 with simple implementation and batch endpoints support"
13
+ spec.homepage = "https://github.com/Pobble/hubspot_v3"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/Pobble/hubspot_v3"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ # Uncomment to register a new dependency of your gem
30
+ # spec.add_dependency "example-gem", "~> 1.0"
31
+ spec.add_dependency "httparty", "~> 0.2"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
@@ -0,0 +1,13 @@
1
+ module HubspotV3
2
+ class Config
3
+ attr_writer :apikey, :contract
4
+
5
+ def apikey
6
+ @apikey || raise('Hubspot API key is not set. Set it with HubspotV3.config.apikey="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"')
7
+ end
8
+ end
9
+
10
+ def self.config
11
+ @config ||= Config.new
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module HubspotV3
2
+ module Helpers
3
+ extend self
4
+
5
+ def map_search_by_email(results_ary)
6
+ results_ary.inject({}) do |hash, result|
7
+ hash[result.fetch('properties').fetch('email')] = result
8
+ hash
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,107 @@
1
+ module HubspotV3
2
+ module MockContract
3
+ extend self
4
+
5
+ def contacts_update(bodyhash)
6
+ inputs = _fetch_inputs(bodyhash)
7
+
8
+ inputs.map do |input|
9
+ id = _fetch_input_id(input)
10
+ properties = _fetch_input_properties(input)
11
+
12
+ {
13
+ "id"=>id,
14
+ "properties"=>properties,
15
+ "createdAt"=>"2021-10-18T15:12:14.245Z",
16
+ "updatedAt"=>"2021-10-18T15:12:16.539Z",
17
+ "archived"=>false
18
+ }
19
+ end
20
+ end
21
+
22
+ def contacts_create(bodyhash)
23
+ inputs = _fetch_inputs(bodyhash)
24
+
25
+ inputs.map do |input|
26
+ properties = _fetch_input_properties(input)
27
+
28
+ email = properties.fetch('email') { raise KeyError.new("Item in Inputs hash must contain key 'properties.email' - hash['inputs'][0]['properties']['email']") }
29
+ id = _calculate_id(email) + 1_000_000
30
+
31
+ sanitized_email = _sanitize_email_as_hubspot_would(email) # sanitize after id was generated
32
+
33
+ default_properties = {
34
+ "createdate"=>"2021-10-18T15:12:14.245Z",
35
+ "email"=>sanitized_email,
36
+ "hs_all_contact_vids"=>"3451",
37
+ "hs_email_domain"=>sanitized_email.split('@').last,
38
+ "hs_is_unworked"=>"true",
39
+ "hs_object_id"=>id,
40
+ "hs_pipeline"=>"contacts-lifecycle-pipeline",
41
+ "lastmodifieddate"=>"2021-10-18T15:12:14.245Z",
42
+ }
43
+
44
+ properties = default_properties.merge(properties)
45
+
46
+ {
47
+ "id"=>id,
48
+ "properties"=> properties,
49
+ "createdAt"=>"2021-10-18T15:12:14.245Z",
50
+ "updatedAt"=>"2021-10-18T15:12:14.245Z",
51
+ "archived"=>false
52
+ }
53
+ end
54
+ end
55
+
56
+ def contacts_search_by_emails(emails)
57
+ emails = emails.reject { |e| e.match?(/notfound/)}
58
+
59
+ emails.map do |email|
60
+ id = _calculate_id(email)
61
+ first_name = email.split('@').first
62
+ last_name = email.split('@').last
63
+ sanitized_email = _sanitize_email_as_hubspot_would(email) # sanitize after id was generated
64
+
65
+ {
66
+ "id"=>id,
67
+ "createdAt"=>"2020-09-10T10:29:54.714Z",
68
+ "updatedAt"=>"2021-10-13T10:16:19.015Z",
69
+ "archived"=>false,
70
+ "properties"=> {
71
+ "createdate"=>"2020-09-10T10:29:54.714Z",
72
+ "email"=>sanitized_email,
73
+ "firstname"=>first_name,
74
+ "hs_object_id"=>id,
75
+ "lastmodifieddate"=>"2021-10-13T10:16:19.015Z",
76
+ "lastname"=>last_name
77
+ }
78
+ }
79
+ end
80
+ end
81
+
82
+ def contacts_search_by_emails_mapped(emails_ary)
83
+ HubspotV3::Helpers.map_search_by_email(contacts_search_by_emails(emails_ary))
84
+ end
85
+
86
+ def _calculate_id(email)
87
+ email.bytes.sum # sum of asci values of the email string
88
+ end
89
+
90
+ def _sanitize_email_as_hubspot_would(email)
91
+ # Hubspot downcase all emails e.g. tomas@Pobble.com would be tomas@pobble.com
92
+ email.downcase.strip
93
+ end
94
+
95
+ def _fetch_inputs(bodyhash)
96
+ bodyhash.fetch('inputs') { raise KeyError.new("Inputs hash must contain key 'inputs' - hash['inputs']") }
97
+ end
98
+
99
+ def _fetch_input_properties(input)
100
+ input.fetch('properties') { raise KeyError.new("Item in Inputs hash must contain key 'properties' - hash['inputs'][0]['properties']") }
101
+ end
102
+
103
+ def _fetch_input_id(input)
104
+ input.fetch('id') { raise KeyError.new("Item in Inputs hash must contain key 'id' - hash['inputs'][0]['id']") }
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HubspotV3
4
+ VERSION = "0.1.0"
5
+ end
data/lib/hubspot_v3.rb ADDED
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'json'
5
+ require_relative "hubspot_v3/version"
6
+ require_relative "hubspot_v3/config"
7
+ require_relative "hubspot_v3/helpers"
8
+
9
+ module HubspotV3
10
+ class RequestFailedError < StandardError
11
+ attr_reader :httparty_response
12
+ def initialize(message, httparty_response = nil)
13
+ super(message)
14
+ @httparty_response = httparty_response
15
+ end
16
+ end
17
+
18
+ API_URL='https://api.hubapi.com'
19
+ CONTACTS_SEARCH='/crm/v3/objects/contacts/search'
20
+ CONTACTS_CREATE='/crm/v3/objects/contacts/batch/create'
21
+ CONTACTS_UPDATE='/crm/v3/objects/contacts/batch/update'
22
+
23
+ def self.contacts_create(bodyhash)
24
+ post(CONTACTS_CREATE, bodyhash)
25
+ end
26
+
27
+ def self.contacts_update(bodyhash)
28
+ post(CONTACTS_UPDATE, bodyhash)
29
+ end
30
+
31
+ def self.contacts_search(bodyhash)
32
+ post(CONTACTS_SEARCH, bodyhash)
33
+ end
34
+
35
+ def self.contacts_search_by_emails(emails_ary)
36
+ filters_group_ary = emails_ary.map do |e|
37
+ {
38
+ "filters": [
39
+ {
40
+ "propertyName": "email",
41
+ "operator": "EQ",
42
+ "value": e
43
+ }
44
+ ]
45
+ }
46
+ end
47
+
48
+ bodyhash = { "filterGroups": filters_group_ary }
49
+ contacts_search(bodyhash)
50
+ end
51
+
52
+ def self.contacts_search_by_emails_mapped(emails_ary)
53
+ HubspotV3::Helpers.map_search_by_email(contacts_search_by_emails(emails_ary))
54
+ end
55
+
56
+ def self.url(path)
57
+ "#{API_URL}#{path}?hapikey=#{config.apikey}"
58
+ end
59
+
60
+ def self.post(path, bodyhash)
61
+ res = HTTParty.post(url(path), {
62
+ body: bodyhash.to_json,
63
+ headers: {'Content-Type' => 'application/json'}
64
+ })
65
+ case res.code
66
+ when 200, 201
67
+ res.parsed_response['results']
68
+ else
69
+ raise HubspotV3::RequestFailedError.new("#{res.code} - #{res.parsed_response['message']}", res)
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hubspot_v3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Valent
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description: Ruby wrapper around Hubspot API v3 with simple implementation and batch
28
+ endpoints support
29
+ email:
30
+ - equivalent@eq8.eu
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE.txt
40
+ - README.md
41
+ - README_SEARCH_EXAMPLES.md
42
+ - Rakefile
43
+ - bin/console
44
+ - bin/setup
45
+ - hubspot_v3.gemspec
46
+ - lib/hubspot_v3.rb
47
+ - lib/hubspot_v3/config.rb
48
+ - lib/hubspot_v3/helpers.rb
49
+ - lib/hubspot_v3/mock_contract.rb
50
+ - lib/hubspot_v3/version.rb
51
+ homepage: https://github.com/Pobble/hubspot_v3
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/Pobble/hubspot_v3
56
+ source_code_uri: https://github.com/Pobble/hubspot_v3
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 2.3.0
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.3.7
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Hubspot API v3 Ruby gem
76
+ test_files: []