From 920d0344123a37523a6a3b9652ef10b44dd85e35 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Fri, 7 Jan 2022 12:11:12 +0100 Subject: [PATCH] Fixes #3910 - Adjust placetel endpoints from EOL v1 to v2. --- app/models/cti/driver/placetel.rb | 19 ++++++++----------- spec/requests/integration/placetel_spec.rb | 4 ++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/models/cti/driver/placetel.rb b/app/models/cti/driver/placetel.rb index bdc91d045..634538bfc 100644 --- a/app/models/cti/driver/placetel.rb +++ b/app/models/cti/driver/placetel.rb @@ -88,12 +88,13 @@ class Cti::Driver::Placetel < Cti::Driver::Base list = Cache.read('placetelGetVoipUsers') return list if list - response = UserAgent.post( - 'https://api.placetel.de/api/getVoIPUsers.json', - { - api_key: @config[:api_token], - }, + response = UserAgent.get( + 'https://api.placetel.de/v2/sip_users', + {}, { + headers: { + Authorization: "Bearer #{@config[:api_token]}", + }, log: { facility: 'placetel', }, @@ -130,13 +131,9 @@ class Cti::Driver::Placetel < Cti::Driver::Base list = {} result.each do |entry| next if entry['name'].blank? + next if entry['sipuid'].blank? - if entry['uid'].present? - list[entry['uid']] = entry['name'] - end - next if entry['uid2'].blank? - - list[entry['uid2']] = entry['name'] + list[entry['sipuid']] = entry['name'] end Cache.write('placetelGetVoipUsers', list, { expires_in: 24.hours }) list diff --git a/spec/requests/integration/placetel_spec.rb b/spec/requests/integration/placetel_spec.rb index 693b9cd14..aed52aa06 100644 --- a/spec/requests/integration/placetel_spec.rb +++ b/spec/requests/integration/placetel_spec.rb @@ -569,8 +569,8 @@ RSpec.describe 'Integration Placetel', type: :request do config[:outbound][:default_caller_id] = '' Setting.set('placetel_config', config) - stub_request(:post, 'https://api.placetel.de/api/getVoIPUsers.json') - .to_return(status: 200, body: [{ 'callerid' => '03055571600', 'did' => 10, 'name' => 'Bob Smith', 'stype' => 3, 'uid' => '777008478072@example.com', 'uid2' => nil }, { 'callerid' => '03055571600', 'did' => 12, 'name' => 'Josef Müller', 'stype' => 3, 'uid' => '777042617425@example.com', 'uid2' => nil }].to_json) + stub_request(:get, 'https://api.placetel.de/v2/sip_users') + .to_return(status: 200, body: [{ 'callerid' => '03055571600', 'did' => 10, 'name' => 'Bob Smith', 'type' => 'standard', 'sipuid' => '777008478072@example.com' }, { 'callerid' => '03055571600', 'did' => 12, 'name' => 'Josef Müller', 'type' => 'standard', 'sipuid' => '777042617425@example.com' }].to_json) params = 'event=OutgoingCall&direction=out&to=099999222222&call_id=1234567890-2&from=777008478072@example.com' post "/api/v1/placetel/#{token}", params: params