From 074940a216fd01a1f18231e5a337d0fc2f125ea8 Mon Sep 17 00:00:00 2001 From: rh-taro Date: Fri, 23 Jun 2023 23:58:47 +0900 Subject: [PATCH] Make base_uri changeable with environment variables --- lib/pardot/client.rb | 2 +- spec/pardot/client_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/pardot/client.rb b/lib/pardot/client.rb index 79a3d01..0463fbd 100644 --- a/lib/pardot/client.rb +++ b/lib/pardot/client.rb @@ -1,7 +1,7 @@ module Pardot class Client include HTTParty - base_uri 'https://pi.pardot.com' + base_uri ENV.fetch('PARDOT_URL', 'https://pi.pardot.com') format :xml include Authentication diff --git a/spec/pardot/client_spec.rb b/spec/pardot/client_spec.rb index 9e98da0..b000cc8 100644 --- a/spec/pardot/client_spec.rb +++ b/spec/pardot/client_spec.rb @@ -7,6 +7,28 @@ def create_client @client = Pardot::Client.new 'user@test.com', 'foo', 'bar' end + describe '#base_uri' do + context 'without PARDOT_URL' do + before do + ENV.delete('PARDOT_URL') + end + + it 'return default value' do + expect(Pardot::Client.base_uri).to eq('https://pi.pardot.com') + end + end + + context 'with PARDOT_URL' do + before do + ENV['PARDOT_URL'] = 'https://pi.demo.pardot.com' + end + + it 'return ENV value' do + expect(Pardot::Client.base_uri).to eq('https://pi.pardot.com') + end + end + end + describe 'client with Salesforce access_token' do it 'should set properties' do @client = Pardot::Client.new nil, nil, nil, 3, 'access_token_value', '0Uv000000000001CAA'