Skip to content

Commit

Permalink
rubocop -A
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Yves committed Nov 7, 2024
1 parent 920e343 commit 36e624c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/hubspot/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
19 changes: 9 additions & 10 deletions lib/hubspot/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 14 additions & 15 deletions lib/hubspot/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/hubspot/ticket_properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/hubspot/task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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') }

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/hubspot/ticket_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions spec/lib/hubspot/ticket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 36e624c

Please sign in to comment.