From 820b9ac6a8924a294790e7760cb56d7f41c0ff99 Mon Sep 17 00:00:00 2001 From: Trosss <155624690+Trosss@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:46:43 +0100 Subject: [PATCH] Feature: Add default properties for tickets (#25) * add default properties for ticket * linting + update history.md --- History.md | 4 +++ hubspot-api-ruby.gemspec | 2 +- lib/hubspot/task.rb | 3 +- lib/hubspot/ticket.rb | 6 ++-- spec/fixtures/vcr_cassettes/ticket_find.yml | 36 ++++++++++----------- spec/lib/hubspot/ticket_spec.rb | 1 + 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/History.md b/History.md index d94c267c..2014dde6 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,7 @@ +## 0.17.1 + +* Add default properties for Ticket#find + ## 0.17.0 * Add various Ticket endpoints (#create!, #update!, #find) diff --git a/hubspot-api-ruby.gemspec b/hubspot-api-ruby.gemspec index 32f4db91..a6cc8b6f 100644 --- a/hubspot-api-ruby.gemspec +++ b/hubspot-api-ruby.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = "hubspot-api-ruby" - s.version = "0.17.0" + s.version = "0.17.1" s.require_paths = ["lib"] s.authors = ["Jonathan"] s.email = ["jonathan@hoggo.com"] diff --git a/lib/hubspot/task.rb b/lib/hubspot/task.rb index fe596776..d1dc5558 100644 --- a/lib/hubspot/task.rb +++ b/lib/hubspot/task.rb @@ -37,8 +37,7 @@ def create!(params = {}, ticket_id: nil) end def find(task_id, properties = DEFAULT_TASK_FIELDS) - response = Hubspot::Connection.get_json(TASK_PATH, { task_id: task_id, - properties: properties }) + response = Hubspot::Connection.get_json(TASK_PATH, task_id: task_id, properties:) new(response) end end diff --git a/lib/hubspot/ticket.rb b/lib/hubspot/ticket.rb index 2cb0d732..b7b27f25 100644 --- a/lib/hubspot/ticket.rb +++ b/lib/hubspot/ticket.rb @@ -9,6 +9,8 @@ module Hubspot class Ticket TICKETS_PATH = '/crm/v3/objects/tickets' TICKET_PATH = '/crm/v3/objects/tickets/:ticket_id' + DEFAULT_TICKET_FIELDS='content,createdate,hs_lastmodifieddate,hs_object_id,hs_pipeline,hs_pipeline_stage,'\ + 'hs_ticket_category,hs_ticket_priority,hubspot_owner_id,subject' attr_reader :properties, :id @@ -53,8 +55,8 @@ def update!(id, properties = {}) new(response) end - def find(ticket_id) - response = Hubspot::Connection.get_json(TICKET_PATH, { ticket_id: ticket_id }) + def find(ticket_id, properties = DEFAULT_TICKET_FIELDS) + response = Hubspot::Connection.get_json(TICKET_PATH, ticket_id: ticket_id, properties:) new(response) end end diff --git a/spec/fixtures/vcr_cassettes/ticket_find.yml b/spec/fixtures/vcr_cassettes/ticket_find.yml index dc0a054d..f3a8ea13 100644 --- a/spec/fixtures/vcr_cassettes/ticket_find.yml +++ b/spec/fixtures/vcr_cassettes/ticket_find.yml @@ -2,7 +2,7 @@ http_interactions: - request: method: get - uri: https://api.hubapi.com/crm/v3/objects/tickets/16174569112 + uri: https://api.hubapi.com/crm/v3/objects/tickets/16174569112?properties=content,createdate,hs_lastmodifieddate,hs_object_id,hs_pipeline,hs_pipeline_stage,hs_ticket_category,hs_ticket_priority,hubspot_owner_id,subject body: encoding: US-ASCII string: '' @@ -21,15 +21,15 @@ http_interactions: message: OK headers: Date: - - Thu, 07 Nov 2024 10:13:53 GMT + - Tue, 12 Nov 2024 16:01:03 GMT Content-Type: - application/json;charset=utf-8 Content-Length: - - '385' + - '407' Connection: - keep-alive Cf-Ray: - - 8dec8da119892a4f-CDG + - 8e17bd0bbc5602a6-CDG Cf-Cache-Status: - DYNAMIC Strict-Transport-Security: @@ -41,11 +41,11 @@ http_interactions: X-Content-Type-Options: - nosniff X-Hubspot-Correlation-Id: - - 31508645-2648-4e6e-97c3-7142b9b96adf + - 131904ae-ae8a-4380-8f31-482eccc6c0cf X-Hubspot-Ratelimit-Daily: - '1000000' X-Hubspot-Ratelimit-Daily-Remaining: - - '999898' + - '999738' X-Hubspot-Ratelimit-Interval-Milliseconds: - '10000' X-Hubspot-Ratelimit-Max: @@ -57,19 +57,19 @@ http_interactions: X-Hubspot-Ratelimit-Secondly-Remaining: - '18' Report-To: - - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=SNRbl9GPqZ2HWCZB2lAEretT1%2Fqgt3p65%2FUAWuVPf6v9n%2Bz7nE31KefUEsQK1ZjS7InIo6kTNg8QhSkkrKpl6ySWW5QNhQenoEAhjeqAfXFSTJL%2Bn%2BxBjXrkSAydGd4mf2SmXe%2BhHeiU8p34"}],"group":"cf-nel","max_age":604800}' + - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=ofSklgAg6IowcP5bF6O4PKRMABd%2BImOrrW4ONCNomomt66upt7NW%2BJn5HH5mX1lgZoUUqdA2OgTrO7JTrKREqI29b62nTV1u9o8VsHcK5xq7Tn1m3BVsOnl%2FfIYItieBwxKkwlGQdhi79Z3%2F"}],"group":"cf-nel","max_age":604800}' Nel: - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}' Server: - cloudflare body: encoding: ASCII-8BIT - string: '{"id":"16174569112","properties":{"content":null,"createdate":"2024-11-07T10:07:53.620Z","hs_lastmodifieddate":"2024-11-07T10:07:58.585Z","hs_object_id":"16174569112","hs_pipeline":"0","hs_pipeline_stage":"1","hs_ticket_category":null,"hs_ticket_priority":"MEDIUM","subject":"test - ticket"},"createdAt":"2024-11-07T10:07:53.620Z","updatedAt":"2024-11-07T10:07:58.585Z","archived":false}' - recorded_at: Thu, 07 Nov 2024 10:13:54 GMT + string: '{"id":"16174569112","properties":{"content":null,"createdate":"2024-11-07T10:07:53.620Z","hs_lastmodifieddate":"2024-11-12T15:59:09.800Z","hs_object_id":"16174569112","hs_pipeline":"0","hs_pipeline_stage":"1","hs_ticket_category":null,"hs_ticket_priority":"HIGH","hubspot_owner_id":null,"subject":"test + ticket"},"createdAt":"2024-11-07T10:07:53.620Z","updatedAt":"2024-11-12T15:59:09.800Z","archived":false}' + recorded_at: Tue, 12 Nov 2024 16:01:03 GMT - request: method: get - uri: https://api.hubapi.com/crm/v3/objects/tickets/996174569112 + uri: https://api.hubapi.com/crm/v3/objects/tickets/996174569112?properties=content,createdate,hs_lastmodifieddate,hs_object_id,hs_pipeline,hs_pipeline_stage,hs_ticket_category,hs_ticket_priority,hubspot_owner_id,subject body: encoding: US-ASCII string: '' @@ -88,7 +88,7 @@ http_interactions: message: Not Found headers: Date: - - Thu, 07 Nov 2024 10:14:12 GMT + - Tue, 12 Nov 2024 16:01:04 GMT Content-Type: - text/html;charset=iso-8859-1 Transfer-Encoding: @@ -96,7 +96,7 @@ http_interactions: Connection: - keep-alive Cf-Ray: - - 8dec8e157f2a6fb4-CDG + - 8e17bd0f3d1a7006-CDG Cf-Cache-Status: - DYNAMIC Cache-Control: @@ -110,25 +110,25 @@ http_interactions: X-Content-Type-Options: - nosniff X-Hubspot-Correlation-Id: - - 573a8517-3029-4383-a702-e522d8d7224a + - 994c9c16-0609-4254-8bbe-895de7606a94 X-Hubspot-Notfound: - 'true' X-Hubspot-Ratelimit-Daily: - '1000000' X-Hubspot-Ratelimit-Daily-Remaining: - - '999897' + - '999737' X-Hubspot-Ratelimit-Interval-Milliseconds: - '10000' X-Hubspot-Ratelimit-Max: - '190' X-Hubspot-Ratelimit-Remaining: - - '189' + - '188' X-Hubspot-Ratelimit-Secondly: - '19' X-Hubspot-Ratelimit-Secondly-Remaining: - '18' Report-To: - - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=4hxmisUUPmjx1eS%2Fq9QVapUy8Uu9YNkPQl31J7BY9s6i6L%2F2KeFbQNu53QFgIwsRip1QVM0tcjOhjofbw7bkpbKhQVeF5UA3LEb97HF23O37h0mWDBSCsjFyq%2FHh1mpkRlvfrqmI2avLSILz"}],"group":"cf-nel","max_age":604800}' + - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=CPAGnbE0ObqZ90RfiCW29MWRCIqbPsrDtKDY3G9Ghkmq70o2yB4O9%2F%2FD%2BGZOMt41Hyzvlz1fz6KKrpdVk%2B9uJZboJkgSizihrf%2F1eSWPafM59OU4E04VG4e%2BQ0vDIW1IQim0vMUMgEKx0khs"}],"group":"cf-nel","max_age":604800}' Nel: - '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}' Server: @@ -145,5 +145,5 @@ http_interactions:

Resource not found

- recorded_at: Thu, 07 Nov 2024 10:14:12 GMT + recorded_at: Tue, 12 Nov 2024 16:01:04 GMT recorded_with: VCR 6.3.1 diff --git a/spec/lib/hubspot/ticket_spec.rb b/spec/lib/hubspot/ticket_spec.rb index 8a39ffa5..56c1f0a3 100644 --- a/spec/lib/hubspot/ticket_spec.rb +++ b/spec/lib/hubspot/ticket_spec.rb @@ -14,6 +14,7 @@ VCR.use_cassette 'ticket' do expect(new_ticket.id).not_to be_nil expect(new_ticket.properties[:subject]).to eq('test ticket') + expect(new_ticket.properties[:hubspot_owner_id]).to be_nil end end end