From 5c93f4baa6f9a2e6155a8c0949423c5e277a9a05 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Fri, 30 Aug 2024 14:21:31 -0400 Subject: [PATCH 1/9] Adding access_token overrride to methods --- lib/easy_hubspot/base.rb | 4 +- lib/easy_hubspot/client.rb | 1 + lib/easy_hubspot/contact.rb | 28 +++--- lib/easy_hubspot/deal.rb | 20 ++-- lib/easy_hubspot/line_item.rb | 20 ++-- lib/easy_hubspot/product.rb | 20 ++-- spec/easy_hubspot/base_spec.rb | 36 +++++++ spec/easy_hubspot/contact_spec.rb | 161 +++++++++++++++++++++++++++--- 8 files changed, 231 insertions(+), 59 deletions(-) create mode 100644 spec/easy_hubspot/base_spec.rb diff --git a/lib/easy_hubspot/base.rb b/lib/easy_hubspot/base.rb index 5ab0039..3a642d3 100644 --- a/lib/easy_hubspot/base.rb +++ b/lib/easy_hubspot/base.rb @@ -4,9 +4,9 @@ module EasyHubspot # class EasyHubspot::Base class Base class << self - def headers + def headers(access_token = nil) { "Content-Type" => 'application/json', - "Authorization" => "Bearer #{EasyHubspot.configuration.access_token}" } + "Authorization" => "Bearer #{access_token || EasyHubspot.configuration.access_token}" } end def email?(string) diff --git a/lib/easy_hubspot/client.rb b/lib/easy_hubspot/client.rb index 6905260..e4f1304 100644 --- a/lib/easy_hubspot/client.rb +++ b/lib/easy_hubspot/client.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +require 'pry' module EasyHubspot # EasyHubspot::Client diff --git a/lib/easy_hubspot/contact.rb b/lib/easy_hubspot/contact.rb index 6b96e67..4483275 100644 --- a/lib/easy_hubspot/contact.rb +++ b/lib/easy_hubspot/contact.rb @@ -6,32 +6,32 @@ class Contact < EasyHubspot::Base class << self CONTACT_ENDPOINT = 'crm/v3/objects/contacts' - def get_contact(contact_id) - Client.do_get(determine_endpoint(contact_id), headers) + def get_contact(contact_id, access_token = nil) + Client.do_get(determine_endpoint(contact_id), headers(access_token)) end - def get_contacts - Client.do_get(CONTACT_ENDPOINT, headers) + def get_contacts(access_token = nil) + Client.do_get(CONTACT_ENDPOINT, headers(access_token)) end - def create_contact(body) - Client.do_post(CONTACT_ENDPOINT, body, headers) + def create_contact(body, access_token = nil) + Client.do_post(CONTACT_ENDPOINT, body, headers(access_token)) end - def update_contact(contact_id, body) - Client.do_patch(determine_endpoint(contact_id), body, headers) + def update_contact(contact_id, body, access_token = nil) + Client.do_patch(determine_endpoint(contact_id), body, headers(access_token)) end - def delete_contact(contact_id) - Client.do_delete(determine_endpoint(contact_id), headers) + def delete_contact(contact_id, access_token = nil) + Client.do_delete(determine_endpoint(contact_id), headers(access_token)) end - def update_or_create_contact(email, body) - res = get_contact(email) + def update_or_create_contact(email, body, access_token = nil) + res = get_contact(email, access_token) if res && res[:id] - update_contact(email, body) + update_contact(email, body, access_token) else - create_contact(body) + create_contact(body, access_token) end end diff --git a/lib/easy_hubspot/deal.rb b/lib/easy_hubspot/deal.rb index 9f02263..b221967 100644 --- a/lib/easy_hubspot/deal.rb +++ b/lib/easy_hubspot/deal.rb @@ -6,24 +6,24 @@ class Deal < EasyHubspot::Base class << self DEAL_ENDPOINT = 'crm/v3/objects/deals' - def get_deal(deal_id) - Client.do_get(deal_id_endpoint(deal_id), headers) + def get_deal(deal_id, access_token = nil) + Client.do_get(deal_id_endpoint(deal_id), headers(access_token)) end - def get_deals - Client.do_get(DEAL_ENDPOINT, headers) + def get_deals(access_token = nil) + Client.do_get(DEAL_ENDPOINT, headers(access_token)) end - def create_deal(body) - Client.do_post(DEAL_ENDPOINT, body, headers) + def create_deal(body, access_token = nil) + Client.do_post(DEAL_ENDPOINT, body, headers(access_token)) end - def update_deal(deal_id, body) - Client.do_patch(deal_id_endpoint(deal_id), body, headers) + def update_deal(deal_id, body, access_token = nil) + Client.do_patch(deal_id_endpoint(deal_id), body, headers(access_token)) end - def delete_deal(deal_id) - Client.do_delete(deal_id_endpoint(deal_id), headers) + def delete_deal(deal_id, access_token = nil) + Client.do_delete(deal_id_endpoint(deal_id), headers(access_token)) end private diff --git a/lib/easy_hubspot/line_item.rb b/lib/easy_hubspot/line_item.rb index 78eb161..9ffe7d9 100644 --- a/lib/easy_hubspot/line_item.rb +++ b/lib/easy_hubspot/line_item.rb @@ -6,24 +6,24 @@ class LineItem < EasyHubspot::Base class << self LINE_ITEM_ENDPOINT = 'crm/v3/objects/line_items' - def get_line_item(line_item_id) - Client.do_get(line_item_id_endpoint(line_item_id), headers) + def get_line_item(line_item_id, access_token = nil) + Client.do_get(line_item_id_endpoint(line_item_id), headers(access_token)) end - def get_line_items - Client.do_get(LINE_ITEM_ENDPOINT, headers) + def get_line_items(access_token = nil) + Client.do_get(LINE_ITEM_ENDPOINT, headers(access_token)) end - def create_line_item(body) - Client.do_post(LINE_ITEM_ENDPOINT, body, headers) + def create_line_item(body, access_token = nil) + Client.do_post(LINE_ITEM_ENDPOINT, body, headers(access_token)) end - def update_line_item(line_item_id, body) - Client.do_patch(line_item_id_endpoint(line_item_id), body, headers) + def update_line_item(line_item_id, body, access_token = nil) + Client.do_patch(line_item_id_endpoint(line_item_id), body, headers(access_token)) end - def delete_line_item(line_item_id) - Client.do_delete(line_item_id_endpoint(line_item_id), headers) + def delete_line_item(line_item_id, access_token = nil) + Client.do_delete(line_item_id_endpoint(line_item_id), headers(access_token)) end private diff --git a/lib/easy_hubspot/product.rb b/lib/easy_hubspot/product.rb index f2f4ba3..06aaa2d 100644 --- a/lib/easy_hubspot/product.rb +++ b/lib/easy_hubspot/product.rb @@ -6,24 +6,24 @@ class Product < EasyHubspot::Base class << self PRODUCT_ENDPOINT = 'crm/v3/objects/products' - def get_product(product_id) - Client.do_get(product_id_endpoint(product_id), headers) + def get_product(product_id, access_token = nil) + Client.do_get(product_id_endpoint(product_id), headers(access_token)) end - def get_products - Client.do_get(PRODUCT_ENDPOINT, headers) + def get_products(access_token = nil) + Client.do_get(PRODUCT_ENDPOINT, headers(access_token)) end - def create_product(body) - Client.do_post(PRODUCT_ENDPOINT, body, headers) + def create_product(body, access_token = nil) + Client.do_post(PRODUCT_ENDPOINT, body, headers(access_token)) end - def update_product(product_id, body) - Client.do_patch(product_id_endpoint(product_id), body, headers) + def update_product(product_id, body, access_token = nil) + Client.do_patch(product_id_endpoint(product_id), body, headers(access_token)) end - def delete_product(product_id) - Client.do_delete(product_id_endpoint(product_id), headers) + def delete_product(product_id, access_token = nil) + Client.do_delete(product_id_endpoint(product_id), headers(access_token)) end private diff --git a/spec/easy_hubspot/base_spec.rb b/spec/easy_hubspot/base_spec.rb new file mode 100644 index 0000000..fad2ec8 --- /dev/null +++ b/spec/easy_hubspot/base_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe EasyHubspot::Base do + global_access_token = 'YOUR-GLOBAL-ACCESS-TOKEN' + + before :all do + EasyHubspot.config do |config| + config.access_token = global_access_token + end + end + + describe '#headers' do + context 'when using the global access_token' do + let(:expected_headers) { + { "Content-Type" => 'application/json', "Authorization" => "Bearer #{global_access_token}" } + } + + it 'returns the expected Authorization Header' do + expect(described_class.headers).to eq(expected_headers) + end + end + + context 'when overriding the global access_token' do + let(:custom_access_token) { 'CUSTOM-PER-CALL-ACCESS-TOKEN' } + let(:expected_headers) { + { "Content-Type" => 'application/json', "Authorization" => "Bearer #{custom_access_token}" } + } + + it 'returns the expected Authorization Header' do + expect(described_class.headers(custom_access_token)).to eq(expected_headers) + end + end + end +end diff --git a/spec/easy_hubspot/contact_spec.rb b/spec/easy_hubspot/contact_spec.rb index 3c859ae..42650b8 100644 --- a/spec/easy_hubspot/contact_spec.rb +++ b/spec/easy_hubspot/contact_spec.rb @@ -9,6 +9,22 @@ end end + let(:base_url) { 'https://api.hubapi.com' } + let(:overwrite_access_token) { 'OVERWRITING-TOKEN' } + let(:expected_overwritten_headers_method_output) do + { + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer #{overwrite_access_token}" + } + end + let(:expected_overwritten_request_headers) do + { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'User-Agent' => 'Ruby' + }.merge(expected_overwritten_headers_method_output) + end + describe 'get_contact' do context 'when contact is found using contact_id' do before do @@ -48,19 +64,43 @@ .to_return(status: 200, body: load_contact_json('contact'), headers: {}) end - let(:response) { described_class.get_contact('amber_becker@quigley.io') } - it 'returns a contact' do + response = described_class.get_contact('amber_becker@quigley.io') + expect(response[:id]).to eq '701' + expect(response[:properties][:email]).to eq 'amber_becker@quigley.io' + end + end + + context 'when contact is found using email and overwriting the default access token' do + before do + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/contacts/amber_becker@quigley.io?idProperty=email') + .with(headers: expected_overwritten_request_headers) + .to_return(status: 200, body: load_contact_json('contact'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_get).and_call_original + end + + it 'returns the contact' do + response = described_class.get_contact('amber_becker@quigley.io', overwrite_access_token) expect(response[:id]).to eq '701' expect(response[:properties][:email]).to eq 'amber_becker@quigley.io' end + + it 'uses the correct access token' do + described_class.get_contact('amber_becker@quigley.io', overwrite_access_token) + expect(EasyHubspot::Client).to( + have_received(:do_get) + .with('crm/v3/objects/contacts/amber_becker@quigley.io?idProperty=email', expected_overwritten_headers_method_output) + ) + end end end describe 'get_contacts' do + let(:request_endpoint) { 'crm/v3/objects/contacts' } + context 'when contacts are found' do before do - stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/contacts') + stub_request(:get, "#{base_url}/#{request_endpoint}") .with( headers: { 'Accept' => '*/*', @@ -69,16 +109,35 @@ 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby' } - ) - .to_return(status: 200, body: load_contact_json('contacts'), headers: {}) + ).to_return(status: 200, body: load_contact_json('contacts'), headers: {}) end - let(:response) { described_class.get_contacts } - it 'returns a list of contacts' do + response = described_class.get_contacts + results = response[:results] + expect(results.count).to eq 10 + end + end + + context 'when overwriting the default access token' do + before do + stub_request(:get, "#{base_url}/#{request_endpoint}") + .with(headers: expected_overwritten_request_headers) + .to_return(status: 200, body: load_contact_json('contacts'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_get).and_call_original + end + + it 'returns the contact' do + response = described_class.get_contacts(overwrite_access_token) results = response[:results] expect(results.count).to eq 10 end + + it 'uses the correct access token' do + described_class.get_contacts(overwrite_access_token) + expect(EasyHubspot::Client).to have_received(:do_get) + .with(request_endpoint, expected_overwritten_headers_method_output) + end end end @@ -101,14 +160,38 @@ let(:body) do { properties: { email: 'example@gmail.com', firstname: 'John', lastname: 'Smith' } } end - let(:response) { described_class.create_contact(body) } it 'returns a contact' do + response = described_class.create_contact(body) expect(response[:id]).to eq '851' expect(response[:properties][:email]).to eq 'example@gmail.com' expect(response[:properties][:firstname]).to eq 'John' expect(response[:properties][:lastname]).to eq 'Smith' end + + context 'when overwriting the default access token' do + before do + stub_request(:post, 'https://api.hubapi.com/crm/v3/objects/contacts') + .with(headers: expected_overwritten_request_headers) + .to_return(status: 201, body: load_contact_json('create_contact'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_post).and_call_original + end + + it 'returns the contact' do + response = described_class.create_contact(body, overwrite_access_token) + expect(response[:id]).to eq '851' + expect(response[:properties][:email]).to eq 'example@gmail.com' + expect(response[:properties][:firstname]).to eq 'John' + expect(response[:properties][:lastname]).to eq 'Smith' + end + + it 'uses the correct access token' do + described_class.create_contact(body, overwrite_access_token) + expect(EasyHubspot::Client).to( + have_received(:do_post) + .with('crm/v3/objects/contacts', body, expected_overwritten_headers_method_output)) + end + end end describe 'update_contact' do @@ -131,9 +214,9 @@ let(:body) do { properties: { email: 'example@gmail.com', firstname: 'John', lastname: 'Smith' } } end - let(:response) { described_class.update_contact('851', body) } it 'returns a contact' do + response = described_class.update_contact('851', body) expect(response[:id]).to eq '851' expect(response[:properties][:email]).to eq 'example@gmail.com' expect(response[:properties][:firstname]).to eq 'Carl' @@ -160,15 +243,47 @@ let(:body) do { properties: { email: 'example@gmail.com', firstname: 'John', lastname: 'Smith' } } end - let(:response) { described_class.update_contact('example@gmail.com', body) } it 'returns a contact' do + response = described_class.update_contact('example@gmail.com', body) expect(response[:id]).to eq '851' expect(response[:properties][:email]).to eq 'example@gmail.com' expect(response[:properties][:firstname]).to eq 'Carl' expect(response[:properties][:lastname]).to eq 'Smith' end end + + context 'when contact is found using email while overriding the token' do + before do + stub_request(:patch, 'https://api.hubapi.com/crm/v3/objects/contacts/example@gmail.com?idProperty=email') + .with( + body: 'properties%5Bemail%5D=example%40gmail.com&properties%5Bfirstname%5D=John&properties%5Blastname%5D=Smith', + headers: expected_overwritten_request_headers + ) + .to_return(status: 200, body: load_contact_json('update_contact'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_patch).and_call_original + end + + let(:body) do + { properties: { email: 'example@gmail.com', firstname: 'John', lastname: 'Smith' } } + end + + it 'returns a contact' do + response = described_class.update_contact('example@gmail.com', body, overwrite_access_token) + expect(response[:id]).to eq '851' + expect(response[:properties][:email]).to eq 'example@gmail.com' + expect(response[:properties][:firstname]).to eq 'Carl' + expect(response[:properties][:lastname]).to eq 'Smith' + end + + it 'uses the correct access token' do + described_class.update_contact('example@gmail.com', body, overwrite_access_token) + expect(EasyHubspot::Client).to( + have_received(:do_patch) + .with('crm/v3/objects/contacts/example@gmail.com?idProperty=email', body, expected_overwritten_headers_method_output) + ) + end + end end describe 'delete_contact' do @@ -189,9 +304,8 @@ .to_return(status: 204, body: '', headers: {}) end - let(:response) { described_class.delete_contact('851') } - it 'returns no content' do + response = described_class.delete_contact('851') expect(response).to eq success end end @@ -211,11 +325,32 @@ .to_return(status: 204, body: '', headers: {}) end - let(:response) { described_class.delete_contact('example@gmail.com') } + it 'returns no content' do + response = described_class.delete_contact('example@gmail.com') + expect(response).to eq success + end + end + + context 'when contact is found using email and the access token is being overwritten' do + before do + stub_request(:delete, 'https://api.hubapi.com/crm/v3/objects/contacts/example@gmail.com?idProperty=email') + .with( + headers: expected_overwritten_request_headers + ).to_return(status: 204, body: '', headers: {}) + allow(EasyHubspot::Client).to receive(:do_delete).and_call_original + end it 'returns no content' do + response = described_class.delete_contact('example@gmail.com', overwrite_access_token) expect(response).to eq success end + + it 'uses the correct access token' do + described_class.delete_contact('example@gmail.com', overwrite_access_token) + expect(EasyHubspot::Client).to( + have_received(:do_delete) + .with('crm/v3/objects/contacts/example@gmail.com?idProperty=email', expected_overwritten_headers_method_output)) + end end end From 6b63ec29e990e2dd39dd0f26bd346031317feec4 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 15:55:40 -0400 Subject: [PATCH 2/9] Adding missing specs --- spec/easy_hubspot/deal_spec.rb | 110 +++++++++++++++++++++++-- spec/easy_hubspot/line_item_spec.rb | 123 +++++++++++++++++++++++++++- spec/easy_hubspot/product_spec.rb | 91 ++++++++++++++++++++ 3 files changed, 317 insertions(+), 7 deletions(-) diff --git a/spec/easy_hubspot/deal_spec.rb b/spec/easy_hubspot/deal_spec.rb index cca5870..7df2405 100644 --- a/spec/easy_hubspot/deal_spec.rb +++ b/spec/easy_hubspot/deal_spec.rb @@ -31,23 +31,61 @@ expect(response[:id]).to eq '11733930097' expect(response[:properties][:amount]).to eq '145.23' end + end - end - describe 'get_deals' do - context 'when deals are found' do + context 'when deal is found using deal_id and a different access token' do before do - stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/deals') + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/deals/11733930097') .with( headers: { 'Accept' => '*/*', 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - 'Authorization' => 'Bearer YOUR-PRIVATE-ACCESS-TOKEN', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', 'Content-Type' => 'application/json', 'User-Agent' => 'Ruby' } ) + .to_return(status: 200, body: load_deal_json('get_deal'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_get).and_call_original + end + + it 'returns a deal' do + response = described_class.get_deal('11733930097', 'ANOTHER-ACCESS-TOKEN') + expect(response[:id]).to eq '11733930097' + expect(response[:properties][:amount]).to eq '145.23' + end + + it 'called headers with the right arguments' do + described_class.get_deal('11733930097', 'ANOTHER-ACCESS-TOKEN') + + expect(EasyHubspot::Client).to(have_received(:do_get).with('crm/v3/objects/deals/11733930097', + { 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json' })) + end + + end + end + + describe 'get_deals' do + context 'when deals are found' do + before do + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/deals') + .with(headers: { 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer YOUR-PRIVATE-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' }) + .to_return(status: 200, body: load_deal_json('get_deals'), headers: {}) + + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/deals') + .with(headers: { 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' }) .to_return(status: 200, body: load_deal_json('get_deals'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:response) { described_class.get_deals } @@ -56,6 +94,11 @@ results = response[:results] expect(results.count).to eq 2 end + + it 'calls for headers with the right access token' do + described_class.get_deals('ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to(have_received(:headers).with('ANOTHER-ACCESS-TOKEN')) + end end end @@ -73,6 +116,21 @@ } ) .to_return(status: 200, body: load_deal_json('create_deal'), headers: {}) + + stub_request(:post, 'https://api.hubapi.com/crm/v3/objects/deals') + .with( + body: 'properties%5Bamount%5D=1500.00&properties%5Bclosedate%5D=2023-12-07T16%3A50%3A06.678Z&properties%5Bdealname%5D=New%20Big%20Deal&properties%5Bpipeline%5D=default', + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_deal_json('create_deal'), headers: {}) + + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:body) do @@ -86,6 +144,11 @@ expect(response[:properties][:closedate]).to eq '2023-12-07T16:50:06.678Z' expect(response[:properties][:dealname]).to eq 'New Big Deal' end + + it 'calls for headers with the right access token' do + described_class.create_deal(body, 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to(have_received(:headers).with('ANOTHER-ACCESS-TOKEN')) + end end describe 'update_deal' do @@ -103,6 +166,20 @@ } ) .to_return(status: 200, body: load_deal_json('update_deal'), headers: {}) + + stub_request(:patch, 'https://api.hubapi.com/crm/v3/objects/deals/12259629202') + .with( + body: 'properties%5Bamount%5D=1600.00&properties%5Bclosedate%5D=2023-11-07T16%3A50%3A06.678Z&properties%5Bdealname%5D=New%20Big%20Deal%20UPDATE&properties%5Bpipeline%5D=default', + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_deal_json('update_deal'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:body) do @@ -116,6 +193,11 @@ expect(response[:properties][:closedate]).to eq '2023-11-07T16:50:06.678Z' expect(response[:properties][:dealname]).to eq 'New Big Deal UPDATE' end + + it 'calls for headers with the right arguments' do + described_class.update_deal(12_259_629_202, body, 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to(have_received(:headers).with('ANOTHER-ACCESS-TOKEN')) + end end end @@ -135,6 +217,19 @@ } ) .to_return(status: 204, body: '', headers: {}) + + stub_request(:delete, 'https://api.hubapi.com/crm/v3/objects/deals/12259629202') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 204, body: '', headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:response) { described_class.delete_deal('12259629202') } @@ -142,6 +237,11 @@ it 'returns no content' do expect(response).to eq success end + + it 'headers to be fetched with the right access token' do + described_class.delete_deal('12259629202', 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to(have_received(:headers).with('ANOTHER-ACCESS-TOKEN')) + end end end diff --git a/spec/easy_hubspot/line_item_spec.rb b/spec/easy_hubspot/line_item_spec.rb index 2c6f5c1..114281f 100644 --- a/spec/easy_hubspot/line_item_spec.rb +++ b/spec/easy_hubspot/line_item_spec.rb @@ -27,13 +27,45 @@ let(:response) { described_class.get_line_item('4118976207') } - it 'returns a line item - ' do + it 'returns a line item' do + expect(response[:id]).to eq '4118976207' + expect(response[:properties][:amount]).to eq '215.460' + expect(response[:properties][:quantity]).to eq '3' + expect(response[:properties][:hs_product_id]).to eq '1175864298' + end + end + + context 'when line_item is found using line_item_id while overwriting the access_token' do + before do + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/line_items/4118976207') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer SOME-OTHER-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_line_item_json('get_line_item'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_get).and_call_original + end + + let(:response) { described_class.get_line_item('4118976207', 'SOME-OTHER-TOKEN') } + + it 'returns a line item' do expect(response[:id]).to eq '4118976207' expect(response[:properties][:amount]).to eq '215.460' expect(response[:properties][:quantity]).to eq '3' expect(response[:properties][:hs_product_id]).to eq '1175864298' end + + it 'called the client method with the right token' do + described_class.get_line_item('4118976207', 'SOME-OTHER-TOKEN') + expect(EasyHubspot::Client).to have_received(:do_get).with('crm/v3/objects/line_items/4118976207', + { 'Content-Type' => 'application/json', + 'Authorization' => 'Bearer SOME-OTHER-TOKEN' }) + end end end @@ -60,6 +92,39 @@ expect(results.count).to eq 2 end end + + context 'when line_item is found while overwriting the access_token' do + before do + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/line_items') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer SOME-OTHER-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_line_item_json('get_line_item'), headers: {}) + allow(EasyHubspot::Client).to receive(:do_get).and_call_original + end + + let(:response) { described_class.get_line_items('SOME-OTHER-TOKEN') } + + it 'returns a line item' do + expect(response[:id]).to eq '4118976207' + expect(response[:properties][:amount]).to eq '215.460' + expect(response[:properties][:quantity]).to eq '3' + expect(response[:properties][:hs_product_id]).to eq '1175864298' + end + + it 'called the client method with the right token' do + described_class.get_line_items('SOME-OTHER-TOKEN') + expect(EasyHubspot::Client).to have_received(:do_get).with('crm/v3/objects/line_items', + { 'Content-Type' => 'application/json', + 'Authorization' => 'Bearer SOME-OTHER-TOKEN' }) + end + end end describe 'create_line_item' do @@ -75,6 +140,18 @@ 'User-Agent' => 'Ruby' } ).to_return(status: 200, body: load_line_item_json('create_line_item'), headers: {}) + stub_request(:post, 'https://api.hubapi.com/crm/v3/objects/line_items') + .with( + body: 'properties%5Bname%5D=Blue%20Jeans&properties%5Bhs_product_id%5D=1175864298&properties%5Bprice%5D=71.82&properties%5Bquantity%5D=3', + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ).to_return(status: 200, body: load_line_item_json('create_line_item'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:body) do @@ -90,6 +167,11 @@ expect(response[:properties][:amount]).to eq '215.460' expect(response[:properties][:name]).to eq 'Blue Jeans' end + + it 'calls uses the correct access_token when overwritten' do + described_class.create_line_item(body, 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end describe 'update_line_item' do @@ -107,6 +189,20 @@ } ) .to_return(status: 200, body: load_line_item_json('update_line_item'), headers: {}) + + stub_request(:patch, 'https://api.hubapi.com/crm/v3/objects/line_items/4120050126') + .with( + body: 'properties%5Bquantity%5D=2', + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_line_item_json('update_line_item'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:body) do @@ -121,6 +217,11 @@ expect(response[:properties][:price]).to eq '71.82' expect(response[:properties][:amount]).to eq '143.640' end + + it 'calls headers with the right arguments' do + described_class.update_line_item(4_120_050_126, body, 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end end @@ -140,6 +241,19 @@ } ) .to_return(status: 204, body: '', headers: {}) + + stub_request(:delete, 'https://api.hubapi.com/crm/v3/objects/line_items/4120050126') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 204, body: '', headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:response) { described_class.delete_line_item('4120050126') } @@ -147,6 +261,11 @@ it 'returns no content' do expect(response).to eq success end + + it 'calls headers with the right arguments' do + described_class.delete_line_item('4120050126', 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end end diff --git a/spec/easy_hubspot/product_spec.rb b/spec/easy_hubspot/product_spec.rb index 9596950..1c849f1 100644 --- a/spec/easy_hubspot/product_spec.rb +++ b/spec/easy_hubspot/product_spec.rb @@ -23,6 +23,19 @@ } ) .to_return(status: 200, body: load_product_json('get_product'), headers: {}) + + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/products/1172707032') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_product_json('get_product'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:response) { described_class.get_product('1172707032') } @@ -31,6 +44,11 @@ expect(response[:id]).to eq '1172707032' expect(response[:properties][:price]).to eq '25' end + + it 'calls for headers with the right token' do + described_class.get_product('1172707032', 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end end @@ -48,6 +66,19 @@ } ) .to_return(status: 200, body: load_product_json('get_products'), headers: {}) + + stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/products') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_product_json('get_products'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:response) { described_class.get_products } @@ -56,6 +87,11 @@ results = response[:results] expect(results.count).to eq 2 end + + it 'calls for headers with the right access token' do + described_class.get_products('ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end end @@ -73,6 +109,20 @@ } ) .to_return(status: 200, body: load_product_json('create_product'), headers: {}) + + stub_request(:post, 'https://api.hubapi.com/crm/v3/objects/products') + .with( + body: 'properties%5Bprice%5D=75.00&properties%5Bname%5D=Blue%20Jeans&properties%5Bdescription%5D=Worn', + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_product_json('create_product'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:body) do @@ -86,6 +136,11 @@ expect(response[:properties][:name]).to eq 'Blue Jeans' expect(response[:properties][:description]).to eq 'Worn' end + + it 'called for headers with the right access code' do + described_class.create_product(body, 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end describe 'update_product' do @@ -103,6 +158,19 @@ } ) .to_return(status: 200, body: load_product_json('update_product'), headers: {}) + stub_request(:patch, 'https://api.hubapi.com/crm/v3/objects/products/1174789087') + .with( + body: 'properties%5Bprice%5D=100.00&properties%5Bname%5D=New', + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 200, body: load_product_json('update_product'), headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:body) do @@ -115,6 +183,11 @@ expect(response[:properties][:price]).to eq '100.00' expect(response[:properties][:description]).to eq 'New' end + + it 'calls for headers with the right access token' do + described_class.update_product(1_174_789_087, body, 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end end @@ -134,6 +207,19 @@ } ) .to_return(status: 204, body: '', headers: {}) + + stub_request(:delete, 'https://api.hubapi.com/crm/v3/objects/products/1174789087') + .with( + headers: { + 'Accept' => '*/*', + 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', + 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Ruby' + } + ) + .to_return(status: 204, body: '', headers: {}) + allow(EasyHubspot::Base).to receive(:headers).and_call_original end let(:response) { described_class.delete_product('1174789087') } @@ -141,6 +227,11 @@ it 'returns no content' do expect(response).to eq success end + + it 'calls for headers with the right access token' do + described_class.delete_product('1174789087', 'ANOTHER-ACCESS-TOKEN') + expect(EasyHubspot::Base).to have_received(:headers).with('ANOTHER-ACCESS-TOKEN') + end end end From 057d9de746d0b02af2b67c456a579b9cb614557c Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:25:30 -0400 Subject: [PATCH 3/9] Adding version info --- .github/workflows/build.yml | 4 ++-- CHANGELOG.md | 2 ++ lib/easy_hubspot/version.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ea6f4d..4382770 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,6 @@ name: RSpec with SimpleCov on: - pull_request: + pull_request: _target push: branches: - main @@ -29,4 +29,4 @@ jobs: - name: Publish code coverage run: | export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}" - ./cc-test-reporter after-build -r ${{secrets.CC_TEST_REPORTER_ID}} \ No newline at end of file + ./cc-test-reporter after-build -r ${{secrets.CC_TEST_REPORTER_ID}} diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a331d6..06dd450 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,6 @@ ## [Official Release] +- [1.0.2] - 2024-09-05 https://github.com/oroth8/easy_hubspot/pull/19 + - Adding `access_token` to class methods to allow for overriding the initializer - [1.0.0] - 2023-02-22 https://github.com/oroth8/easy_hubspot/pull/10 ## [Unreleased] diff --git a/lib/easy_hubspot/version.rb b/lib/easy_hubspot/version.rb index 570f3fd..839601e 100644 --- a/lib/easy_hubspot/version.rb +++ b/lib/easy_hubspot/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module EasyHubspot - VERSION = '1.0.1' + VERSION = '1.0.2' end From da0c7c43674c9bbe80a8d3adbc58b358f1ffd4c9 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:28:27 -0400 Subject: [PATCH 4/9] Fixing autocorrectable rubocop offenses --- lib/easy_hubspot/client.rb | 1 + spec/easy_hubspot/base_spec.rb | 12 ++++++------ spec/easy_hubspot/contact_spec.rb | 8 +++++--- spec/easy_hubspot/deal_spec.rb | 2 -- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/easy_hubspot/client.rb b/lib/easy_hubspot/client.rb index e4f1304..4313832 100644 --- a/lib/easy_hubspot/client.rb +++ b/lib/easy_hubspot/client.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require 'pry' module EasyHubspot diff --git a/spec/easy_hubspot/base_spec.rb b/spec/easy_hubspot/base_spec.rb index fad2ec8..8d1019b 100644 --- a/spec/easy_hubspot/base_spec.rb +++ b/spec/easy_hubspot/base_spec.rb @@ -13,9 +13,9 @@ describe '#headers' do context 'when using the global access_token' do - let(:expected_headers) { - { "Content-Type" => 'application/json', "Authorization" => "Bearer #{global_access_token}" } - } + let(:expected_headers) do + { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{global_access_token}" } + end it 'returns the expected Authorization Header' do expect(described_class.headers).to eq(expected_headers) @@ -24,9 +24,9 @@ context 'when overriding the global access_token' do let(:custom_access_token) { 'CUSTOM-PER-CALL-ACCESS-TOKEN' } - let(:expected_headers) { - { "Content-Type" => 'application/json', "Authorization" => "Bearer #{custom_access_token}" } - } + let(:expected_headers) do + { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{custom_access_token}" } + end it 'returns the expected Authorization Header' do expect(described_class.headers(custom_access_token)).to eq(expected_headers) diff --git a/spec/easy_hubspot/contact_spec.rb b/spec/easy_hubspot/contact_spec.rb index 42650b8..0c84853 100644 --- a/spec/easy_hubspot/contact_spec.rb +++ b/spec/easy_hubspot/contact_spec.rb @@ -136,7 +136,7 @@ it 'uses the correct access token' do described_class.get_contacts(overwrite_access_token) expect(EasyHubspot::Client).to have_received(:do_get) - .with(request_endpoint, expected_overwritten_headers_method_output) + .with(request_endpoint, expected_overwritten_headers_method_output) end end end @@ -189,7 +189,8 @@ described_class.create_contact(body, overwrite_access_token) expect(EasyHubspot::Client).to( have_received(:do_post) - .with('crm/v3/objects/contacts', body, expected_overwritten_headers_method_output)) + .with('crm/v3/objects/contacts', body, expected_overwritten_headers_method_output) + ) end end end @@ -349,7 +350,8 @@ described_class.delete_contact('example@gmail.com', overwrite_access_token) expect(EasyHubspot::Client).to( have_received(:do_delete) - .with('crm/v3/objects/contacts/example@gmail.com?idProperty=email', expected_overwritten_headers_method_output)) + .with('crm/v3/objects/contacts/example@gmail.com?idProperty=email', expected_overwritten_headers_method_output) + ) end end end diff --git a/spec/easy_hubspot/deal_spec.rb b/spec/easy_hubspot/deal_spec.rb index 7df2405..24c65b6 100644 --- a/spec/easy_hubspot/deal_spec.rb +++ b/spec/easy_hubspot/deal_spec.rb @@ -31,7 +31,6 @@ expect(response[:id]).to eq '11733930097' expect(response[:properties][:amount]).to eq '145.23' end - end context 'when deal is found using deal_id and a different access token' do @@ -63,7 +62,6 @@ { 'Authorization' => 'Bearer ANOTHER-ACCESS-TOKEN', 'Content-Type' => 'application/json' })) end - end end From e6c145efaafc308fba70f6308e95d782d32ab017 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:30:34 -0400 Subject: [PATCH 5/9] Updating build settings --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4382770..f101398 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,8 @@ name: RSpec with SimpleCov on: - pull_request: _target + pull_request_target: + types: + - opened push: branches: - main From 58a7d58be544b6fec5de1254860422f646044abf Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:33:48 -0400 Subject: [PATCH 6/9] Adding edited to list of coverage triggers --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f101398..3c3d460 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ on: pull_request_target: types: - opened + - edited push: branches: - main From 01943f57b8314b56f1eb1927aab5e3eb119eb966 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:37:03 -0400 Subject: [PATCH 7/9] Fixing rubocop offenses --- spec/easy_hubspot/contact_spec.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spec/easy_hubspot/contact_spec.rb b/spec/easy_hubspot/contact_spec.rb index 0c84853..bcafef9 100644 --- a/spec/easy_hubspot/contact_spec.rb +++ b/spec/easy_hubspot/contact_spec.rb @@ -136,7 +136,7 @@ it 'uses the correct access token' do described_class.get_contacts(overwrite_access_token) expect(EasyHubspot::Client).to have_received(:do_get) - .with(request_endpoint, expected_overwritten_headers_method_output) + .with(request_endpoint, expected_overwritten_headers_method_output) end end end @@ -436,10 +436,8 @@ describe 'update_or_create_contact' do context 'when contact is found using contact_id' do - let!(:email) { 'amber_becker@quigley.io' } - let(:response) { described_class.update_or_create_contact(email, body) } let!(:body) do - { properties: { email: email, firstname: 'Amber', lastname: 'Quigley', hs_content_membership_status: 'inactive' } } + { properties: { email: 'amber_becker@quigley.io', firstname: 'Amber', lastname: 'Quigley', hs_content_membership_status: 'inactive' } } end before do @@ -469,16 +467,15 @@ end it 'updates the contact' do + response = described_class.update_or_create_contact('amber_becker@quigley.io', body) expect(response).to eq JSON.parse load_contact_json('update_or_create_contact'), symbolize_names: true end end context "when contact isn't found" do - let!(:email) { 'not_found@gmail.com' } let!(:body) do - { properties: { email: email, firstname: 'Not', lastname: 'Found', hs_content_membership_status: 'active' } } + { properties: { email: 'not_found@gmail.com', firstname: 'Not', lastname: 'Found', hs_content_membership_status: 'active' } } end - let(:response) { described_class.update_or_create_contact(email, body) } before do stub_request(:get, 'https://api.hubapi.com/crm/v3/objects/contacts/not_found@gmail.com?idProperty=email') @@ -507,6 +504,7 @@ end it 'creates the contact' do + response = described_class.update_or_create_contact('not_found@gmail.com', body) expect(response).to eq JSON.parse load_contact_json('update_or_create_post'), symbolize_names: true end end From 5e29991c420ad9ae0a1835c561b0d55d91dd4d3a Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:41:14 -0400 Subject: [PATCH 8/9] Fixing missed rubocop auto-correctable offense --- spec/easy_hubspot/contact_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/easy_hubspot/contact_spec.rb b/spec/easy_hubspot/contact_spec.rb index bcafef9..5c614bc 100644 --- a/spec/easy_hubspot/contact_spec.rb +++ b/spec/easy_hubspot/contact_spec.rb @@ -136,7 +136,7 @@ it 'uses the correct access token' do described_class.get_contacts(overwrite_access_token) expect(EasyHubspot::Client).to have_received(:do_get) - .with(request_endpoint, expected_overwritten_headers_method_output) + .with(request_endpoint, expected_overwritten_headers_method_output) end end end From 6783efaadcb380e162fa12462f828790c959d256 Mon Sep 17 00:00:00 2001 From: Jose Blanco Date: Thu, 5 Sep 2024 16:48:20 -0400 Subject: [PATCH 9/9] Adding info to readme entry --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index fd8cd76..204bbe5 100644 --- a/README.md +++ b/README.md @@ -203,18 +203,14 @@ Please refrence the [hubspot docs](https://developers.hubspot.com/docs/api/crm/l EasyHubspot::LineItem.delete_line_item(123) ``` -## Error Handling +## Multiple Access Tokens + +If you need to choose your access token at call time, you can pass the access token as an argument to class methods as +follows: ```ruby -def call - begin - EasyHubspot::Contact.create_contact(body) - rescue EasyHubspot::HubspotApiError => e - # handle error code - # e.message = 'Contact already exists. Existing ID: 801' - Rails.logger.info(e.message) - end -end +# Finds the contact using the access token provided at call time instead of the one set during initialization +EasyHubspot::Contact.get_contact(123, different_access_token) ``` ## Development