diff --git a/lib/hubspot/connection.rb b/lib/hubspot/connection.rb index 19306a73..81f8e08c 100644 --- a/lib/hubspot/connection.rb +++ b/lib/hubspot/connection.rb @@ -59,7 +59,7 @@ def patch_json(path, options) format: :json, read_timeout: read_timeout(options), open_timeout: open_timeout(options), - ) + ) log_request_and_response(url, response, options[:body]) handle_response(response).yield_self do |r| diff --git a/lib/hubspot/task.rb b/lib/hubspot/task.rb index a3d5acde..74cd5613 100644 --- a/lib/hubspot/task.rb +++ b/lib/hubspot/task.rb @@ -10,28 +10,27 @@ class Task TASKS_PATH = '/crm/v3/objects/tasks' TASK_PATH = '/crm/v3/objects/tasks/:task_id' - attr_reader :properties - attr_reader :id + attr_reader :properties, :id def initialize(response_hash) - @id = response_hash["id"] + @id = response_hash['id'] @properties = response_hash['properties'].deep_symbolize_keys end - class << self - def create!(params={}, ticket_id: nil) - associations_hash = {"associations" => []} + class << self + def create!(params = {}, ticket_id: nil) + associations_hash = { 'associations' => [] } if ticket_id.present? - associations_hash["associations"] << { + associations_hash['associations'] << { "to": { "id": ticket_id }, - "types": [ { "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Task']['Ticket'] } ] + "types": [{ "associationCategory": 'HUBSPOT_DEFINED', + "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Task']['Ticket'] }] } end properties = { hs_task_status: 'NOT_STARTED', hs_task_type: 'TODO' }.merge(params) post_data = associations_hash.merge({ properties: properties }) - response = Hubspot::Connection.post_json(TASKS_PATH, params: {}, body: post_data ) + response = Hubspot::Connection.post_json(TASKS_PATH, params: {}, body: post_data) new(response) end diff --git a/lib/hubspot/ticket.rb b/lib/hubspot/ticket.rb index b4e5eb1b..49b5c112 100644 --- a/lib/hubspot/ticket.rb +++ b/lib/hubspot/ticket.rb @@ -10,40 +10,39 @@ class Ticket TICKETS_PATH = '/crm/v3/objects/tickets' TICKET_PATH = '/crm/v3/objects/tickets/:ticket_id' - attr_reader :properties - attr_reader :id + attr_reader :properties, :id def initialize(response_hash) - @id = response_hash["id"] + @id = response_hash['id'] @properties = response_hash['properties'].deep_symbolize_keys end class << self - def create!(params={}, contact_id: nil, company_id: nil, deal_id: nil ) - associations_hash = {"associations" => []} + def create!(params = {}, contact_id: nil, company_id: nil, deal_id: nil) + associations_hash = { 'associations' => [] } if contact_id.present? - associations_hash["associations"] << { + associations_hash['associations'] << { "to": { "id": contact_id }, - "types": [ { "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Contact'] } ] + "types": [{ "associationCategory": 'HUBSPOT_DEFINED', + "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Contact'] }] } end if company_id.present? - associations_hash["associations"] << { + associations_hash['associations'] << { "to": { "id": company_id }, - "types": [ { "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Company'] } ] + "types": [{ "associationCategory": 'HUBSPOT_DEFINED', + "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Company'] }] } end if deal_id.present? - associations_hash["associations"] << { + associations_hash['associations'] << { "to": { "id": deal_id }, - "types": [ { "associationCategory": "HUBSPOT_DEFINED", - "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Deal'] } ] + "types": [{ "associationCategory": 'HUBSPOT_DEFINED', + "associationTypeId": Hubspot::Association::ASSOCIATION_DEFINITIONS['Ticket']['Deal'] }] } end post_data = associations_hash.merge({ properties: params }) - response = Hubspot::Connection.post_json(TICKETS_PATH, params: {}, body: post_data ) + response = Hubspot::Connection.post_json(TICKETS_PATH, params: {}, body: post_data) new(response) end diff --git a/lib/hubspot/ticket_properties.rb b/lib/hubspot/ticket_properties.rb index d8d1ec23..a65f7941 100644 --- a/lib/hubspot/ticket_properties.rb +++ b/lib/hubspot/ticket_properties.rb @@ -2,7 +2,7 @@ module Hubspot class TicketProperties < Properties CREATE_PROPERTY_PATH = '/crm/v3/properties/ticket' class << self - def create!(params={}) + def create!(params = {}) superclass.create!(CREATE_PROPERTY_PATH, params) end end diff --git a/spec/lib/hubspot/task_spec.rb b/spec/lib/hubspot/task_spec.rb index 01987f63..8ca29f46 100644 --- a/spec/lib/hubspot/task_spec.rb +++ b/spec/lib/hubspot/task_spec.rb @@ -6,7 +6,7 @@ hs_task_subject: 'title of task', hs_timestamp: DateTime.now.strftime('%Q') } - described_class.create!(params, ticket_id: 16174569112) + described_class.create!(params, ticket_id: 16_174_569_112) end it 'creates a new task with valid properties' do @@ -18,9 +18,9 @@ end end end - + describe 'find' do - let(:task_id) { 64075014222 } + let(:task_id) { 64_075_014_222 } subject(:existing_task) { described_class.find(task_id, 'hs_task_subject,hs_task_status') } @@ -32,7 +32,7 @@ end context 'when task does not exist' do - let(:task_id) { 996174569112 } + let(:task_id) { 996_174_569_112 } it 'returns nil' do VCR.use_cassette 'task_find' do diff --git a/spec/lib/hubspot/ticket_properties_spec.rb b/spec/lib/hubspot/ticket_properties_spec.rb index 756b1510..e309881e 100644 --- a/spec/lib/hubspot/ticket_properties_spec.rb +++ b/spec/lib/hubspot/ticket_properties_spec.rb @@ -33,7 +33,7 @@ it 'should return the valid parameters' do VCR.use_cassette 'ticket_create_property' do response = Hubspot::TicketProperties.create!(params) - expect(Hubspot::TicketProperties.same?(params, response.compact.except("options"))).to be true + expect(Hubspot::TicketProperties.same?(params, response.compact.except('options'))).to be true end end end diff --git a/spec/lib/hubspot/ticket_spec.rb b/spec/lib/hubspot/ticket_spec.rb index b4d37abe..6022ef93 100644 --- a/spec/lib/hubspot/ticket_spec.rb +++ b/spec/lib/hubspot/ticket_spec.rb @@ -4,10 +4,10 @@ params = { hs_pipeline: '0', hs_pipeline_stage: '1', - hs_ticket_priority: "MEDIUM", + hs_ticket_priority: 'MEDIUM', subject: 'test ticket' } - described_class.create!(params, contact_id: 75761595194, company_id: 25571271600, deal_id: 28806796888) + described_class.create!(params, contact_id: 75_761_595_194, company_id: 25_571_271_600, deal_id: 28_806_796_888) end it 'creates a new ticket with valid properties' do @@ -19,7 +19,7 @@ end describe 'find' do - let(:ticket_id) { 16174569112 } + let(:ticket_id) { 16_174_569_112 } subject(:existing_ticket) { described_class.find(ticket_id) } @@ -31,7 +31,7 @@ end context 'when ticket does not exist' do - let(:ticket_id) { 996174569112 } + let(:ticket_id) { 996_174_569_112 } it 'returns nil' do VCR.use_cassette 'ticket_find' do @@ -42,11 +42,11 @@ end describe 'update!' do - let(:ticket_id) { 16174569112 } + let(:ticket_id) { 16_174_569_112 } let(:properties) do { - hs_ticket_priority: "HIGH", - subject: "New name" + hs_ticket_priority: 'HIGH', + subject: 'New name' } end @@ -55,8 +55,8 @@ it 'updates existing ticket, returns the updated entity' do VCR.use_cassette 'ticket_update' do ticket = update_ticket - ticket.properties[:subject] = "Updated name" - ticket.properties[:subject] = "HIGH" + ticket.properties[:subject] = 'Updated name' + ticket.properties[:subject] = 'HIGH' end end end