hubspot-api-ruby 0.17.1 → 0.19.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: 45060ea19bf32fc857cbeb5d0a043b5c2c9668197ac25a518da74ecee2522e05
4
+ data.tar.gz: 68dfbf022d1580f26f51a7688151e8fc21c590e812e18b5b21475de9def30930
5
5
  SHA512:
6
- metadata.gz: c99b28adb56c9b75b842166278ff6094c7d1c562ad3579c26a78854728b02a527dafd44fe82d08360637438f64ba29914a5b8b3351f825908c503bd722744e50
7
- data.tar.gz: c9aa6f2112b7a3d9fc8b863c648971e54c4557659aa7c7ca509f5c2581f0bd038691a6254564bf9d06dc6199abc4d318960ffa7d0d3ff477b2d7ec080c900a26
6
+ metadata.gz: 413df289081df3767598dc9c5c542dfa4c5e729adf55d79631d101ff905440590cdcc8c532531e62d728940d624941a41031b584eb642e245b4990e7fdd1b268
7
+ data.tar.gz: 66f6e52964908bd067b9c43fc3a0f82b75328d4fb3588acf5c84f5ebe50660228ad3736a4ebb0f94dc4444619e011eaebd3d3e93afc3a63dc1ad072d4a762a7b
@@ -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.19.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
@@ -8,9 +8,10 @@ module Hubspot
8
8
  #
9
9
  class Task
10
10
  TASKS_PATH = '/crm/v3/objects/tasks'
11
- TASK_PATH = '/crm/v3/objects/tasks/:task_id'
12
- DEFAULT_TASK_FIELDS = 'hs_timestamp,hs_task_body,hubspot_owner_id,hs_task_subject,hs_task_status,hs_task_priority,'\
13
- 'hs_task_type,hs_task_reminders'
11
+ SEARCH_PATH = '/crm/v3/objects/tasks/search'
12
+ TASK_PATH = '/crm/v3/objects/tasks/:task_id'
13
+ DEFAULT_TASK_FIELDS = %w[hs_timestamp hs_task_body hubspot_owner_id hs_task_subject hs_task_status hs_task_priority
14
+ hs_task_type hs_task_reminders].freeze
14
15
 
15
16
  attr_reader :properties, :id
16
17
 
@@ -20,17 +21,10 @@ module Hubspot
20
21
  end
21
22
 
22
23
  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
24
+ def create!(params = {}, associations: [])
25
+ associations_hash = { associations: }
32
26
  properties = { hs_task_status: 'NOT_STARTED', hs_task_type: 'TODO' }.merge(params)
33
- post_data = associations_hash.merge({ properties: properties })
27
+ post_data = associations_hash.merge(properties:)
34
28
 
35
29
  response = Hubspot::Connection.post_json(TASKS_PATH, params: {}, body: post_data)
36
30
  new(response)
@@ -40,6 +34,15 @@ module Hubspot
40
34
  response = Hubspot::Connection.get_json(TASK_PATH, task_id: task_id, properties:)
41
35
  new(response)
42
36
  end
37
+
38
+ def search(properties = DEFAULT_TASK_FIELDS, body: {})
39
+ Hubspot::Connection.post_json(SEARCH_PATH, params: {}, body: { properties: }.merge(body))
40
+ end
41
+
42
+ def update!(task_id, properties = {})
43
+ response = Hubspot::Connection.patch_json(TASK_PATH, params: { task_id: }, body: { properties: })
44
+ new(response)
45
+ end
43
46
  end
44
47
  end
45
48
  end
@@ -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
@@ -41,4 +47,35 @@ RSpec.describe Hubspot::Task do
41
47
  end
42
48
  end
43
49
  end
50
+
51
+ describe 'search' do
52
+ subject(:search) do
53
+ body = { filterGroups: [
54
+ { filters: [{ propertyName: 'associations.ticket', operator: 'EQ',
55
+ value: '16676542642' }] }
56
+ ] }
57
+ described_class.search(%w[hs_task_subject hs_task_status], body:)
58
+ end
59
+
60
+ it 'returns list of tasks matching search body' do
61
+ VCR.use_cassette 'task_search' do
62
+ expect(search['total']).to eq(2)
63
+ expect(search['results'].map { |r| r['id'] }).to contain_exactly('65090432307', '65476695429')
64
+ end
65
+ end
66
+ end
67
+
68
+ describe 'update!' do
69
+ let(:task_id) { 64_483_143_324 }
70
+ let(:properties) { { hs_task_status: 'COMPLETED' } }
71
+
72
+ subject(:update_task) { described_class.update!(task_id, properties) }
73
+
74
+ it 'updates existing task, returns the updated entity' do
75
+ VCR.use_cassette 'task_update' do
76
+ task = update_task
77
+ expect(task.properties[:hs_task_status]).to eq('COMPLETED')
78
+ end
79
+ end
80
+ end
44
81
  end
@@ -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.19.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-12-11 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.16
355
+ rubygems_version: 3.5.22
356
356
  signing_key:
357
357
  specification_version: 4
358
358
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API