hubspot-api-ruby 0.17.0 → 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: 1c10bc271fecc20b749272010f29ca4d5e667872c39ed5ecd68a2cfd564b8311
4
- data.tar.gz: c4b4459027deb4700a09876fd9d4e46a450753f26c83e982383f15121379571f
3
+ metadata.gz: 84790661e8f1582c8b58fc95c7979549d703b6852ee340b80f11f22ec72f5703
4
+ data.tar.gz: 02ae5c6663904594004f87f922130643cc962fdf2a6d4dbc16d9d860a6c168c8
5
5
  SHA512:
6
- metadata.gz: a7d72b4aef781a7ba1857859d1572e7df94ba10635ebd13687012e9b2895bc1d0b7e16e19b6ce48cbc5fd736137eab144d7bed289a5c70607a576421404a779e
7
- data.tar.gz: 160173f51c195de7214027940d471ee999fdf7df351a05f36654ba669aa50091c1e3d16cd7e0da1d6fe355398bedeec60777a92615cbd9bd63ce84b07924172f
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.0"
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,25 +20,17 @@ 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)
37
30
  end
38
31
 
39
32
  def find(task_id, properties = DEFAULT_TASK_FIELDS)
40
- response = Hubspot::Connection.get_json(TASK_PATH, { task_id: task_id,
41
- properties: properties })
33
+ response = Hubspot::Connection.get_json(TASK_PATH, task_id: task_id, properties:)
42
34
  new(response)
43
35
  end
44
36
  end
@@ -9,6 +9,8 @@ module Hubspot
9
9
  class Ticket
10
10
  TICKETS_PATH = '/crm/v3/objects/tickets'
11
11
  TICKET_PATH = '/crm/v3/objects/tickets/:ticket_id'
12
+ DEFAULT_TICKET_FIELDS='content,createdate,hs_lastmodifieddate,hs_object_id,hs_pipeline,hs_pipeline_stage,'\
13
+ 'hs_ticket_category,hs_ticket_priority,hubspot_owner_id,subject'
12
14
 
13
15
  attr_reader :properties, :id
14
16
 
@@ -18,31 +20,9 @@ module Hubspot
18
20
  end
19
21
 
20
22
  class << self
21
- def create!(params = {}, contact_id: nil, company_id: nil, deal_id: nil)
22
- associations_hash = { 'associations' => [] }
23
- if contact_id.present?
24
- associations_hash['associations'] << {
25
- "to": { "id": contact_id },
26
- "types": [{ "associationCategory": 'HUBSPOT_DEFINED',
27
- "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Contact'] }]
28
- }
29
- end
30
- if company_id.present?
31
- associations_hash['associations'] << {
32
- "to": { "id": company_id },
33
- "types": [{ "associationCategory": 'HUBSPOT_DEFINED',
34
- "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Company'] }]
35
- }
36
- end
37
- if deal_id.present?
38
- associations_hash['associations'] << {
39
- "to": { "id": deal_id },
40
- "types": [{ "associationCategory": 'HUBSPOT_DEFINED',
41
- "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Deal'] }]
42
- }
43
- end
23
+ def create!(params = {}, associations: [])
24
+ associations_hash = { associations: }
44
25
  post_data = associations_hash.merge({ properties: params })
45
-
46
26
  response = Hubspot::Connection.post_json(TICKETS_PATH, params: {}, body: post_data)
47
27
  new(response)
48
28
  end
@@ -53,8 +33,8 @@ module Hubspot
53
33
  new(response)
54
34
  end
55
35
 
56
- def find(ticket_id)
57
- response = Hubspot::Connection.get_json(TICKET_PATH, { ticket_id: ticket_id })
36
+ def find(ticket_id, properties = DEFAULT_TICKET_FIELDS)
37
+ response = Hubspot::Connection.get_json(TICKET_PATH, ticket_id: ticket_id, properties:)
58
38
  new(response)
59
39
  end
60
40
  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,13 +7,19 @@ 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
14
19
  VCR.use_cassette 'ticket' do
15
20
  expect(new_ticket.id).not_to be_nil
16
21
  expect(new_ticket.properties[:subject]).to eq('test ticket')
22
+ expect(new_ticket.properties[:hubspot_owner_id]).to be_nil
17
23
  end
18
24
  end
19
25
  end
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.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-08 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
@@ -352,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
352
352
  - !ruby/object:Gem::Version
353
353
  version: '0'
354
354
  requirements: []
355
- rubygems_version: 3.5.3
355
+ rubygems_version: 3.5.16
356
356
  signing_key:
357
357
  specification_version: 4
358
358
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API