diff --git a/Gemfile.lock b/Gemfile.lock index b13d32f..d791e9e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - lago-ruby-client (0.51.0.pre.beta) + lago-ruby-client (0.52.2.pre.beta) jwt openssl diff --git a/lib/lago/api/connection.rb b/lib/lago/api/connection.rb index 48dc8ee..22535ed 100644 --- a/lib/lago/api/connection.rb +++ b/lib/lago/api/connection.rb @@ -34,7 +34,7 @@ def put(path = uri.path, identifier:, body:) end def get(path = uri.path, identifier:) - uri_path = identifier.nil? ? path : "#{path}/#{identifier}" + uri_path = identifier.nil? ? path : "#{path}/#{URI.encode_www_form_component(identifier)}" response = http_client.send_request( 'GET', uri_path, diff --git a/spec/lago/api/connection_spec.rb b/spec/lago/api/connection_spec.rb index 52d40ac..394fe84 100644 --- a/spec/lago/api/connection_spec.rb +++ b/spec/lago/api/connection_spec.rb @@ -6,10 +6,12 @@ subject(:connection) do described_class.new( 'fake-api-key', - URI('https://testapi.example.org/') + uri ) end + let(:uri) { URI('https://testapi.example.org') } + context 'when an unsuccessful request is made' do before do stub_request(:post, 'https://testapi.example.org/NOTFOUND') @@ -23,4 +25,23 @@ } end end + + describe '#get' do + let(:identifier) { 'gid://app/Customer/1234' } + let(:http_client) { connection.send(:http_client) } + + before do + stub_request(:get, 'https://testapi.example.org:443/gid:%2F%2Fapp%2FCustomer%2F1234') + + allow(URI).to receive(:encode_www_form_component) + .with(identifier) + .and_return('gid:%2F%2Fapp%2FCustomer%2F1234') + + connection.get(identifier:) + end + + it 'encodes the identifier' do + expect(URI).to have_received(:encode_www_form_component).with(identifier) + end + end end