Update adapter to not use phone number anymore

This commit is contained in:
osaajani 2020-03-31 01:28:32 +02:00
parent d5be760843
commit 78abbef26e
5 changed files with 15 additions and 26 deletions

View File

@ -23,10 +23,9 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $number, string $datas);
public function __construct(string $datas);
/**
* Classname of the adapter.

View File

@ -33,12 +33,10 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $number, string $datas)
{
$this->number = $number;
$this->datas = json_decode($datas, true);
}
@ -178,7 +176,7 @@ namespace adapters;
}
/**
* Method called to read SMSs of the number.
* Method called to read SMSs of the phone
*
* @return array : Array of the sms reads
*/
@ -213,7 +211,6 @@ namespace adapters;
'at' => $decode['at'],
'text' => $decode['text'],
'origin' => $decode['number'],
'destination' => $this->number,
];
}

View File

@ -22,11 +22,6 @@ namespace adapters;
*/
class OvhSmsAdapter implements AdapterInterface
{
/**
* Phone number using the adapter.
*/
private $number;
/**
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
*/
@ -48,10 +43,8 @@ namespace adapters;
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $number, string $datas)
public function __construct(string $datas)
{
$this->number = $number;
$this->formatted_number = str_replace('+', '00', $number);
$this->datas = json_decode($datas, true);
$this->api = new Api(
@ -60,6 +53,9 @@ namespace adapters;
'ovh-eu',
$this->datas['consumer_key']
);
$this->number = $this->datas['number'];
$this->formatted_number = str_replace('+', '00', $this->number);
}
/**
@ -110,6 +106,12 @@ namespace adapters;
'description' => 'Service Name de votre service SMS chez OVH. Il s\'agit du nom associé à votre service SMS dans la console OVH, probablement quelque chose comme "sms-xxxxx-1" ou "xxxx" est votre identifiant client OVH.',
'required' => true,
],
[
'name' => 'number',
'title' => 'Numéro',
'description' => 'Numéro virtuel du téléphone chez OVH.',
'required' => true,
],
[
'name' => 'app_key',
'title' => 'Application Key',
@ -220,7 +222,6 @@ namespace adapters;
'at' => (new \DateTime($sms_details['creationDatetime']))->format('Y-m-d H:i:s'),
'text' => $sms_details['message'],
'origin' => $sms_details['sender'],
'destination' => $this->number,
];
//Remove the sms to prevent double reading as ovh do not offer a filter for unread messages only

View File

@ -20,11 +20,6 @@ namespace adapters;
*/
class TestAdapter implements AdapterInterface
{
/**
* Phone number using the adapter.
*/
private $number;
/**
* Datas used to configure interaction with the implemented service. (e.g : Api credentials, ports numbers, etc.).
*/
@ -43,12 +38,10 @@ namespace adapters;
/**
* Adapter constructor, called when instanciated by RaspiSMS.
*
* @param string $number : Phone number the adapter is used for
* @param json string $datas : JSON string of the datas to configure interaction with the implemented service
*/
public function __construct(string $number, string $datas)
public function __construct(string $datas)
{
$this->number = $number;
$this->datas = $datas;
}
@ -167,7 +160,6 @@ namespace adapters;
/**
* Method called on reception of a status update notification for a SMS.
*
* @return mixed : False on error, else array ['uid' => uid of the sms, 'status' => New status of the sms ('unknown', 'delivered', 'failed')]
*/
public static function status_change_callback()
{

View File

@ -82,7 +82,7 @@ class Phone extends AbstractDaemon
//Instanciate adapter
$adapter_class = $this->phone['adapter'];
$this->adapter = new $adapter_class($this->phone['number'], $this->phone['adapter_datas']);
$this->adapter = new $adapter_class($this->phone['adapter_datas']);
$this->logger->info('Starting Phone daemon with pid ' . getmypid());
}
@ -196,7 +196,7 @@ class Phone extends AbstractDaemon
$this->process_for_transfer($sms, $user_settings);
$internal_received->create($this->phone['id_user'], $sms['at'], $sms['text'], $sms['origin'], $sms['destination'], 'unread', $is_command);
$internal_received->create($this->phone['id_user'], $this->phone['id'], $sms['at'], $sms['text'], $sms['origin'], 'unread', $is_command);
}
}