Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search and update tasks #27

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.19.0

* Add Task#search endpoint
* Add Task#update! endpoint

## 0.18.0

* BREAKING CHANGE : Ticket#create! and Task#create now takes association param (array), build it using Association.build_association_param
Expand Down
2 changes: 1 addition & 1 deletion hubspot-api-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "hubspot-api-ruby"
s.version = "0.18.0"
s.version = "0.19.0"
s.require_paths = ["lib"]
s.authors = ["Jonathan"]
s.email = ["jonathan@hoggo.com"]
Expand Down
16 changes: 13 additions & 3 deletions lib/hubspot/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ module Hubspot
#
class Task
TASKS_PATH = '/crm/v3/objects/tasks'
TASK_PATH = '/crm/v3/objects/tasks/:task_id'
DEFAULT_TASK_FIELDS = 'hs_timestamp,hs_task_body,hubspot_owner_id,hs_task_subject,hs_task_status,hs_task_priority,'\
'hs_task_type,hs_task_reminders'
SEARCH_PATH = '/crm/v3/objects/tasks/search'
TASK_PATH = '/crm/v3/objects/tasks/:task_id'
DEFAULT_TASK_FIELDS = %w[hs_timestamp hs_task_body hubspot_owner_id hs_task_subject hs_task_status hs_task_priority
hs_task_type hs_task_reminders].freeze

attr_reader :properties, :id

Expand All @@ -33,6 +34,15 @@ def find(task_id, properties = DEFAULT_TASK_FIELDS)
response = Hubspot::Connection.get_json(TASK_PATH, task_id: task_id, properties:)
new(response)
end

def search(properties = DEFAULT_TASK_FIELDS, body: {})
Hubspot::Connection.post_json(SEARCH_PATH, params: {}, body: { properties: }.merge(body))
end

def update!(task_id, properties = {})
response = Hubspot::Connection.patch_json(TASK_PATH, params: { task_id: }, body: { properties: })
new(response)
end
end
end
end
63 changes: 63 additions & 0 deletions spec/fixtures/vcr_cassettes/task_search.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions spec/fixtures/vcr_cassettes/task_update.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 32 additions & 1 deletion spec/lib/hubspot/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Hubspot::Association.build_association_param('Task', 'Ticket', 16_174_569_112),
Hubspot::Association.build_association_param('Task', 'Contact', 75_761_595_194),
Hubspot::Association.build_association_param('Task', 'Company', 25_571_271_600),
Hubspot::Association.build_association_param('Task', 'Deal', 28_806_796_888),
Hubspot::Association.build_association_param('Task', 'Deal', 28_806_796_888)
]
described_class.create!(params, associations:)
end
Expand Down Expand Up @@ -47,4 +47,35 @@
end
end
end

describe 'search' do
subject(:search) do
body = { filterGroups: [
{ filters: [{ propertyName: 'associations.ticket', operator: 'EQ',
value: '16676542642' }] }
] }
described_class.search(%w[hs_task_subject hs_task_status], body:)
end

it 'returns list of tasks matching search body' do
VCR.use_cassette 'task_search' do
expect(search['total']).to eq(2)
expect(search['results'].map { |r| r['id'] }).to contain_exactly('65090432307', '65476695429')
end
end
end

describe 'update!' do
let(:task_id) { 64_483_143_324 }
let(:properties) { { hs_task_status: 'COMPLETED' } }

subject(:update_task) { described_class.update!(task_id, properties) }

it 'updates existing task, returns the updated entity' do
VCR.use_cassette 'task_update' do
task = update_task
expect(task.properties[:hs_task_status]).to eq('COMPLETED')
end
end
end
end
Loading