hubspot-api-ruby 0.18.0 → 0.20.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: 84790661e8f1582c8b58fc95c7979549d703b6852ee340b80f11f22ec72f5703
4
- data.tar.gz: 02ae5c6663904594004f87f922130643cc962fdf2a6d4dbc16d9d860a6c168c8
3
+ metadata.gz: 98ed008fd84b2f589251de5d0419a1e22823df7767b59d1e19df1a8f30ac11c3
4
+ data.tar.gz: 5586bece57acb191f44e73eed781b6e122c3e072b84d6eadee6ee5cb0d4c8344
5
5
  SHA512:
6
- metadata.gz: 7e5fa62a26ffe1c2508ef02e805886abfc81295511f9745fd08c52555723f3dd7c0cbe38beb0a535884b856b821c7e09475b2209c01419471f79ab1ec288f943
7
- data.tar.gz: bc94ed7bf54229971748b30c00ad3e31626469b70fdfb5c9a9e16b59b38bc6ceb1b2eb299ea8ae9798079ef546a164da5a6c864712d63671d35491c015b5afd8
6
+ metadata.gz: cff09103b5a37c8a50a10ec24e1feba246af33b4d8f39512817ad6f1e505c1a37a5ca3b40fe5db7ca9d9da02f1ca6fd17ba1359d095a5952794e313b2398a5fa
7
+ data.tar.gz: dda419b3e0d59f80d1126b8bcb4e5d057c3e8ea869c0595be1ea8a21c6702d418630ec18431204817cf58943d25fecfaccc23727e99008f790e1c083f3fd105b
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hubspot-api-ruby"
3
- s.version = "0.18.0"
3
+ s.version = "0.20.0"
4
4
  s.require_paths = ["lib"]
5
5
  s.authors = ["Jonathan"]
6
6
  s.email = ["jonathan@hoggo.com"]
data/lib/hubspot/owner.rb CHANGED
@@ -2,24 +2,21 @@ module Hubspot
2
2
  #
3
3
  # HubSpot Owners API
4
4
  #
5
- # {http://developers.hubspot.com/docs/methods/owners/get_owners}
5
+ # {https://developers.hubspot.com/docs/reference/api/crm/owners/v3}
6
+ #
6
7
  #
7
- # TODO: Create an Owner
8
- # TODO: Update an Owner
9
- # TODO: Delete an Owner
10
8
  class Owner
11
- GET_OWNER_PATH = '/owners/v2/owners/:owner_id' # GET
12
- GET_OWNERS_PATH = '/owners/v2/owners' # GET
13
- CREATE_OWNER_PATH = '/owners/v2/owners' # POST
14
- UPDATE_OWNER_PATH = '/owners/v2/owners/:owner_id' # PUT
15
- DELETE_OWNER_PATH = '/owners/v2/owners/:owner_id' # DELETE
16
-
9
+ GET_OWNER_PATH = '/crm/v3/owners/:owner_id' # GET
10
+ GET_OWNERS_PATH = '/crm/v3/owners' # GET
11
+ CREATE_OWNER_PATH = "/crm/v3/owners" # POST
12
+ UPDATE_OWNER_PATH = '/crm/v3/owners/:owner_id' # PUT
13
+ DELETE_OWNER_PATH = '/crm/v3/owners/:owner_id' # DELETE
17
14
 
18
15
  attr_reader :properties, :owner_id, :email
19
16
 
20
17
  def initialize(property_hash)
21
18
  @properties = property_hash
22
- @owner_id = @properties['ownerId']
19
+ @owner_id = @properties['id']
23
20
  @email = @properties['email']
24
21
  end
25
22
 
@@ -28,29 +25,46 @@ module Hubspot
28
25
  end
29
26
 
30
27
  class << self
31
- def all(include_inactive=false)
32
- path = GET_OWNERS_PATH
33
- params = { includeInactive: include_inactive }
28
+ def all(include_archived: false, limit: 100, after: nil)
29
+ path = GET_OWNERS_PATH
30
+ params = {
31
+ archived: include_archived,
32
+ limit: limit,
33
+ after: after
34
+ }.compact
35
+
34
36
  response = Hubspot::Connection.get_json(path, params)
35
- response.map { |r| new(r) }
37
+ {
38
+ results: response['results'].map { |r| new(r) },
39
+ pagination: {
40
+ next: response['paging']&.dig('next', 'after'),
41
+ total: response['total']
42
+ }
43
+ }
36
44
  end
37
45
 
38
- def find(id, include_inactive=false)
39
- path = GET_OWNER_PATH
40
- response = Hubspot::Connection.get_json(path, owner_id: id,
41
- include_inactive: include_inactive)
46
+ def find(id, id_property: nil)
47
+ path = GET_OWNER_PATH
48
+ params = { owner_id: id }
49
+ params[:idProperty] = id_property if id_property
50
+ response = Hubspot::Connection.get_json(path, params)
42
51
  new(response)
43
52
  end
44
53
 
45
- def find_by_email(email, include_inactive=false)
46
- path = GET_OWNERS_PATH
47
- params = { email: email, includeInactive: include_inactive }
54
+ def find_by_email(email, include_archived: false, limit: 100, after: nil)
55
+ path = GET_OWNERS_PATH
56
+ params = {
57
+ email: email,
58
+ archived: include_archived,
59
+ limit: limit,
60
+ after: after
61
+ }.compact
48
62
  response = Hubspot::Connection.get_json(path, params)
49
- response.blank? ? nil : new(response.first)
63
+ response['results'].blank? ? nil : new(response['results'].first)
50
64
  end
51
65
 
52
- def find_by_emails(emails, include_inactive=false)
53
- emails.map { |email| find_by_email(email, include_inactive) }.reject(&:blank?)
66
+ def find_by_emails(emails = [], include_archived: false)
67
+ emails.map { |email| find_by_email(email, include_archived: include_archived) }.reject(&:nil?)
54
68
  end
55
69
  end
56
70
  end
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
 
@@ -33,6 +34,15 @@ module Hubspot
33
34
  response = Hubspot::Connection.get_json(TASK_PATH, task_id: task_id, properties:)
34
35
  new(response)
35
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
36
46
  end
37
47
  end
38
48
  end
@@ -2,7 +2,7 @@ describe Hubspot::Owner do
2
2
  let(:example_owners) do
3
3
  VCR.use_cassette('owner_example') do
4
4
  headers = { Authorization: "Bearer #{ENV.fetch('HUBSPOT_ACCESS_TOKEN')}" }
5
- HTTParty.get('https://api.hubapi.com/owners/v2/owners', headers: headers).parsed_response
5
+ HTTParty.get('https://api.hubapi.com/crm/v3/owners', headers: headers).parsed_response['results']
6
6
  end
7
7
  end
8
8
 
@@ -13,7 +13,22 @@ describe Hubspot::Owner do
13
13
  owners = Hubspot::Owner.all
14
14
 
15
15
  expect(owners.blank?).to be false
16
- compare_owners(owners, example_owners)
16
+ expect(owners[:results].blank?).to be false
17
+ compare_owners(owners[:results], example_owners)
18
+ end
19
+ end
20
+
21
+ describe '.find' do
22
+ cassette 'owner_find_by_id'
23
+
24
+ let(:sample) { example_owners.first }
25
+ let(:id) { sample['id'] }
26
+
27
+ it 'should find a user via their id' do
28
+ owner = Hubspot::Owner.find(id)
29
+ sample.map do |key, val|
30
+ expect(owner[key]).to eq(val)
31
+ end
17
32
  end
18
33
  end
19
34
 
@@ -10,7 +10,7 @@ RSpec.describe Hubspot::Task do
10
10
  Hubspot::Association.build_association_param('Task', 'Ticket', 16_174_569_112),
11
11
  Hubspot::Association.build_association_param('Task', 'Contact', 75_761_595_194),
12
12
  Hubspot::Association.build_association_param('Task', 'Company', 25_571_271_600),
13
- Hubspot::Association.build_association_param('Task', 'Deal', 28_806_796_888),
13
+ Hubspot::Association.build_association_param('Task', 'Deal', 28_806_796_888)
14
14
  ]
15
15
  described_class.create!(params, associations:)
16
16
  end
@@ -47,4 +47,35 @@ RSpec.describe Hubspot::Task do
47
47
  end
48
48
  end
49
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
50
81
  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.18.0
4
+ version: 0.20.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-21 00:00:00.000000000 Z
11
+ date: 2025-03-07 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.3
356
356
  signing_key:
357
357
  specification_version: 4
358
358
  summary: hubspot-api-ruby is a wrapper for the HubSpot REST API