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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b564d62844c37b49655f638b63d9f42d26b802df97c24c3b6655df9769101ae
4
- data.tar.gz: 9b11ad78ab56c1fa39f52493804efae39d918ee605ef069228722e26ede03d25
3
+ metadata.gz: 84790661e8f1582c8b58fc95c7979549d703b6852ee340b80f11f22ec72f5703
4
+ data.tar.gz: 02ae5c6663904594004f87f922130643cc962fdf2a6d4dbc16d9d860a6c168c8
5
5
  SHA512:
6
- metadata.gz: c99b28adb56c9b75b842166278ff6094c7d1c562ad3579c26a78854728b02a527dafd44fe82d08360637438f64ba29914a5b8b3351f825908c503bd722744e50
7
- data.tar.gz: c9aa6f2112b7a3d9fc8b863c648971e54c4557659aa7c7ca509f5c2581f0bd038691a6254564bf9d06dc6199abc4d318960ffa7d0d3ff477b2d7ec080c900a26
6
+ metadata.gz: 7e5fa62a26ffe1c2508ef02e805886abfc81295511f9745fd08c52555723f3dd7c0cbe38beb0a535884b856b821c7e09475b2209c01419471f79ab1ec288f943
7
+ data.tar.gz: bc94ed7bf54229971748b30c00ad3e31626469b70fdfb5c9a9e16b59b38bc6ceb1b2eb299ea8ae9798079ef546a164da5a6c864712d63671d35491c015b5afd8
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hubspot-api-ruby"
3
- s.version = "0.17.1"
3
+ s.version = "0.18.0"
4
4
  s.require_paths = ["lib"]
5
5
  s.authors = ["Jonathan"]
6
6
  s.email = ["jonathan@hoggo.com"]
@@ -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 = {}, ticket_id: nil)
24
- associations_hash = { 'associations' => [] }
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({ properties: properties })
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)
@@ -20,31 +20,9 @@ module Hubspot
20
20
  end
21
21
 
22
22
  class << self
23
- def create!(params = {}, contact_id: nil, company_id: nil, deal_id: nil)
24
- associations_hash = { 'associations' => [] }
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
- described_class.create!(params, ticket_id: 16_174_569_112)
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
- described_class.create!(params, contact_id: 75_761_595_194, company_id: 25_571_271_600, deal_id: 28_806_796_888)
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.17.1
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-13 00:00:00.000000000 Z
11
+ date: 2024-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport