I am just wrapping up a package to submit to laravel to add ClickSend as an additional sms option for notifications... clicksend-notification-channel
I tried to mimic the conventions in the vonage package, all but this one file. I've never submitted or written a package for that matter. For a quick peer check, Is this okay?
Here is my logic for credentials...
/**
* Create a new ClickSend Client.
*
* @return \ClickSend\Api\SMSApi
*
* @throws \RuntimeException
*/
public function client() : Client
{
[$username, $password] = $this->firstComboOrFail([
'accountCredentials' => [
$this->config['account_username'], $this->config['account_password']
],
'apiCredentials' => [
$this->config['api_username'], $this->config['api_key']
]
]);
$credentials = Configuration::getDefaultConfiguration()
->setUsername($username)
->setPassword($password);
return new Client($this->client, $credentials);
}
private function firstComboOrFail(array $combos)
{
$credentials = collect($combos)
->first( fn($pair) => ! in_array(null, $pair, true));
if(! $credentials) {
throw new RuntimeException('Please provide your ClickSend API credentials.
Possible combinations: api_username + api_key OR account_username + account_password.');
}
return $credentials;
}
For comparison here is the vonage file (note: Vonage offers more possible credential combos).
I think mine is more readable. But I could be missing some convention or standard?