hubspot-api-ruby 0.17.1 → 0.18.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 +4 -4
- data/hubspot-api-ruby.gemspec +1 -1
- data/lib/hubspot/association.rb +9 -0
- data/lib/hubspot/task.rb +3 -10
- data/lib/hubspot/ticket.rb +2 -24
- data/spec/lib/hubspot/association_spec.rb +13 -0
- data/spec/lib/hubspot/task_spec.rb +7 -1
- data/spec/lib/hubspot/ticket_spec.rb +6 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84790661e8f1582c8b58fc95c7979549d703b6852ee340b80f11f22ec72f5703
|
4
|
+
data.tar.gz: 02ae5c6663904594004f87f922130643cc962fdf2a6d4dbc16d9d860a6c168c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e5fa62a26ffe1c2508ef02e805886abfc81295511f9745fd08c52555723f3dd7c0cbe38beb0a535884b856b821c7e09475b2209c01419471f79ab1ec288f943
|
7
|
+
data.tar.gz: bc94ed7bf54229971748b30c00ad3e31626469b70fdfb5c9a9e16b59b38bc6ceb1b2eb299ea8ae9798079ef546a164da5a6c864712d63671d35491c015b5afd8
|
data/hubspot-api-ruby.gemspec
CHANGED
data/lib/hubspot/association.rb
CHANGED
@@ -75,6 +75,15 @@ class Hubspot::Association
|
|
75
75
|
response['results'].map { |result| klass.find(result["toObjectId"]) }
|
76
76
|
end
|
77
77
|
|
78
|
+
# Utility function to build the association list required by some API endpoints
|
79
|
+
def build_association_param(origin, associated, associated_id)
|
80
|
+
{
|
81
|
+
to: { id: associated_id },
|
82
|
+
types: [{ associationCategory: 'HUBSPOT_DEFINED',
|
83
|
+
associationTypeId: Hubspot::Association::ASSOCIATION_DEFINITIONS[origin][associated] }]
|
84
|
+
}
|
85
|
+
end
|
86
|
+
|
78
87
|
private
|
79
88
|
|
80
89
|
def build_create_association_body(association, definition_id)
|
data/lib/hubspot/task.rb
CHANGED
@@ -20,17 +20,10 @@ module Hubspot
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class << self
|
23
|
-
def create!(params = {},
|
24
|
-
associations_hash = {
|
25
|
-
if ticket_id.present?
|
26
|
-
associations_hash['associations'] << {
|
27
|
-
"to": { "id": ticket_id },
|
28
|
-
"types": [{ "associationCategory": 'HUBSPOT_DEFINED',
|
29
|
-
"associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Task']['Ticket'] }]
|
30
|
-
}
|
31
|
-
end
|
23
|
+
def create!(params = {}, associations: [])
|
24
|
+
associations_hash = { associations: }
|
32
25
|
properties = { hs_task_status: 'NOT_STARTED', hs_task_type: 'TODO' }.merge(params)
|
33
|
-
post_data = associations_hash.merge(
|
26
|
+
post_data = associations_hash.merge(properties:)
|
34
27
|
|
35
28
|
response = Hubspot::Connection.post_json(TASKS_PATH, params: {}, body: post_data)
|
36
29
|
new(response)
|
data/lib/hubspot/ticket.rb
CHANGED
@@ -20,31 +20,9 @@ module Hubspot
|
|
20
20
|
end
|
21
21
|
|
22
22
|
class << self
|
23
|
-
def create!(params = {},
|
24
|
-
associations_hash = {
|
25
|
-
if contact_id.present?
|
26
|
-
associations_hash['associations'] << {
|
27
|
-
"to": { "id": contact_id },
|
28
|
-
"types": [{ "associationCategory": 'HUBSPOT_DEFINED',
|
29
|
-
"associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Contact'] }]
|
30
|
-
}
|
31
|
-
end
|
32
|
-
if company_id.present?
|
33
|
-
associations_hash['associations'] << {
|
34
|
-
"to": { "id": company_id },
|
35
|
-
"types": [{ "associationCategory": 'HUBSPOT_DEFINED',
|
36
|
-
"associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Company'] }]
|
37
|
-
}
|
38
|
-
end
|
39
|
-
if deal_id.present?
|
40
|
-
associations_hash['associations'] << {
|
41
|
-
"to": { "id": deal_id },
|
42
|
-
"types": [{ "associationCategory": 'HUBSPOT_DEFINED',
|
43
|
-
"associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Deal'] }]
|
44
|
-
}
|
45
|
-
end
|
23
|
+
def create!(params = {}, associations: [])
|
24
|
+
associations_hash = { associations: }
|
46
25
|
post_data = associations_hash.merge({ properties: params })
|
47
|
-
|
48
26
|
response = Hubspot::Connection.post_json(TICKETS_PATH, params: {}, body: post_data)
|
49
27
|
new(response)
|
50
28
|
end
|
@@ -162,4 +162,17 @@ RSpec.describe Hubspot::Association do
|
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
165
|
+
|
166
|
+
describe '.build_association_param' do
|
167
|
+
it 'returns proper association hash' do
|
168
|
+
result = described_class.build_association_param('Ticket', 'Company', 1337)
|
169
|
+
expect(result).to eq(
|
170
|
+
{
|
171
|
+
"to": { "id": 1337 },
|
172
|
+
"types": [{ "associationCategory": 'HUBSPOT_DEFINED',
|
173
|
+
"associationTypeId": 339 }]
|
174
|
+
}
|
175
|
+
)
|
176
|
+
end
|
177
|
+
end
|
165
178
|
end
|
@@ -6,7 +6,13 @@ RSpec.describe Hubspot::Task do
|
|
6
6
|
hs_task_subject: 'title of task',
|
7
7
|
hs_timestamp: DateTime.now.strftime('%Q')
|
8
8
|
}
|
9
|
-
|
9
|
+
associations = [
|
10
|
+
Hubspot::Association.build_association_param('Task', 'Ticket', 16_174_569_112),
|
11
|
+
Hubspot::Association.build_association_param('Task', 'Contact', 75_761_595_194),
|
12
|
+
Hubspot::Association.build_association_param('Task', 'Company', 25_571_271_600),
|
13
|
+
Hubspot::Association.build_association_param('Task', 'Deal', 28_806_796_888),
|
14
|
+
]
|
15
|
+
described_class.create!(params, associations:)
|
10
16
|
end
|
11
17
|
|
12
18
|
it 'creates a new task with valid properties' do
|
@@ -7,7 +7,12 @@ RSpec.describe Hubspot::Ticket do
|
|
7
7
|
hs_ticket_priority: 'MEDIUM',
|
8
8
|
subject: 'test ticket'
|
9
9
|
}
|
10
|
-
|
10
|
+
associations = [
|
11
|
+
Hubspot::Association.build_association_param('Ticket', 'Contact', 75_761_595_194),
|
12
|
+
Hubspot::Association.build_association_param('Ticket', 'Company', 25_571_271_600),
|
13
|
+
Hubspot::Association.build_association_param('Ticket', 'Deal', 28_806_796_888),
|
14
|
+
]
|
15
|
+
described_class.create!(params, associations:)
|
11
16
|
end
|
12
17
|
|
13
18
|
it 'creates a new ticket with valid properties' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hubspot-api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|