Fixes #3910 - Backport2Stable - Adjust placetel endpoints from EOL v1 to v2.

This commit is contained in:
Marcel Herrguth 2022-01-10 14:48:20 +01:00
parent e3afa31402
commit 3413a2909c
2 changed files with 10 additions and 13 deletions

View file

@ -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',
response = UserAgent.get(
'https://api.placetel.de/v2/sip_users',
{},
{
api_key: @config[:api_token],
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

View file

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