-
Notifications
You must be signed in to change notification settings - Fork 121
PHP Version #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
PHP Version #51
Conversation
SamuelMwangiW
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary for a library
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use phpunit.xml.dist instead. This allows maintainers to override phpunit.xml locally during development. This is especially important as I intend to push a PR that adds tests and the test credentials are expected to be in phpunit.xml.
This is also why phpunit.xml is now added to .gitignore
| } | ||
|
|
||
| $this->baseUrl = 'https://api.' . $this->baseDomain . '/version1/'; | ||
| $this->voiceUrl = 'https://voice.africastalking.com/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Voice is disabled on sandbox.
| $sms = new SMS($this->client, $this->username, $this->apiKey, $content); | ||
| return $sms; | ||
| } | ||
|
|
||
| public function content() | ||
| { | ||
| $content = new Content($this->contentClient, $this->username, $this->apiKey); | ||
| return $content; | ||
| } | ||
|
|
||
| public function airtime() | ||
| { | ||
| $airtime = new Airtime($this->client, $this->username, $this->apiKey); | ||
| return $airtime; | ||
| } | ||
|
|
||
| public function voice() | ||
| { | ||
| $voice = new Voice($this->voiceClient, $this->username, $this->apiKey); | ||
| return $voice; | ||
| } | ||
|
|
||
| public function application() | ||
| { | ||
| $application = new Application($this->client, $this->username, $this->apiKey); | ||
| return $application; | ||
| } | ||
|
|
||
| public function mobileData() | ||
| { | ||
| $mobileData = new MobileData($this->mobileDataClient, $this->username, $this->apiKey); | ||
| return $mobileData; | ||
| } | ||
|
|
||
| public function token() | ||
| { | ||
| $token = new Token($this->tokenClient, $this->username, $this->apiKey); | ||
| return $token; | ||
| } | ||
| public const BASE_DOMAIN = 'africastalking.com'; | ||
|
|
||
| public const BASE_SANDBOX_DOMAIN = 'sandbox.' . self::BASE_DOMAIN; | ||
|
|
||
| protected string $username; | ||
|
|
||
| protected string $apiKey; | ||
|
|
||
| protected Client $client; | ||
|
|
||
| protected Client $contentClient; | ||
|
|
||
| protected Client $voiceClient; | ||
|
|
||
| protected Client $tokenClient; | ||
|
|
||
| protected Client $mobileDataClient; | ||
|
|
||
| protected string $baseDomain; | ||
|
|
||
| public string $baseUrl; | ||
|
|
||
| protected string $voiceUrl; | ||
|
|
||
| protected string $checkoutTokenUrl; | ||
|
|
||
| protected string $contentUrl; | ||
|
|
||
| protected string $mobileDataUrl; | ||
|
|
||
| public function __construct(string $username, string $apiKey) | ||
| { | ||
| if ($username === 'sandbox') { | ||
| $this->baseDomain = self::BASE_SANDBOX_DOMAIN; | ||
| } else { | ||
| $this->baseDomain = self::BASE_DOMAIN; | ||
| } | ||
|
|
||
| $this->baseUrl = 'https://api.' . $this->baseDomain . '/version1/'; | ||
| $this->voiceUrl = 'https://voice.africastalking.com/'; | ||
| $this->mobileDataUrl = 'https://bundles.' . $this->baseDomain . '/'; | ||
| $this->contentUrl = ($username === 'sandbox') ? ($this->baseUrl) : ('https://content.' . $this->baseDomain . '/version1/'); | ||
| $this->checkoutTokenUrl = 'https://api.' . $this->baseDomain . '/'; | ||
|
|
||
| if ($username === 'sandbox') { | ||
| $this->contentUrl = $this->baseUrl; | ||
| } | ||
|
|
||
| $this->username = $username; | ||
| $this->apiKey = $apiKey; | ||
|
|
||
| $this->client = new Client([ | ||
| 'base_uri' => $this->baseUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/x-www-form-urlencoded', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->contentClient = new Client([ | ||
| 'base_uri' => $this->contentUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/x-www-form-urlencoded', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->voiceClient = new Client([ | ||
| 'base_uri' => $this->voiceUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/x-www-form-urlencoded', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->mobileDataClient = new Client([ | ||
| 'base_uri' => $this->mobileDataUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/json', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->tokenClient = new Client([ | ||
| 'base_uri' => $this->checkoutTokenUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/json', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public function sms(): SMS | ||
| { | ||
| $content = new Content($this->contentClient, $this->username, $this->apiKey); | ||
|
|
||
| return new SMS($this->client, $this->username, $this->apiKey, $content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable is unnecessary here
| $content = new Content($this->contentClient, $this->username, $this->apiKey); | ||
| return $content; | ||
| } | ||
|
|
||
| public function airtime() | ||
| { | ||
| $airtime = new Airtime($this->client, $this->username, $this->apiKey); | ||
| return $airtime; | ||
| } | ||
|
|
||
| public function voice() | ||
| { | ||
| $voice = new Voice($this->voiceClient, $this->username, $this->apiKey); | ||
| return $voice; | ||
| } | ||
|
|
||
| public function application() | ||
| { | ||
| $application = new Application($this->client, $this->username, $this->apiKey); | ||
| return $application; | ||
| } | ||
|
|
||
| public function mobileData() | ||
| { | ||
| $mobileData = new MobileData($this->mobileDataClient, $this->username, $this->apiKey); | ||
| return $mobileData; | ||
| } | ||
|
|
||
| public function token() | ||
| { | ||
| $token = new Token($this->tokenClient, $this->username, $this->apiKey); | ||
| return $token; | ||
| } | ||
| public const BASE_DOMAIN = 'africastalking.com'; | ||
|
|
||
| public const BASE_SANDBOX_DOMAIN = 'sandbox.' . self::BASE_DOMAIN; | ||
|
|
||
| protected string $username; | ||
|
|
||
| protected string $apiKey; | ||
|
|
||
| protected Client $client; | ||
|
|
||
| protected Client $contentClient; | ||
|
|
||
| protected Client $voiceClient; | ||
|
|
||
| protected Client $tokenClient; | ||
|
|
||
| protected Client $mobileDataClient; | ||
|
|
||
| protected string $baseDomain; | ||
|
|
||
| public string $baseUrl; | ||
|
|
||
| protected string $voiceUrl; | ||
|
|
||
| protected string $checkoutTokenUrl; | ||
|
|
||
| protected string $contentUrl; | ||
|
|
||
| protected string $mobileDataUrl; | ||
|
|
||
| public function __construct(string $username, string $apiKey) | ||
| { | ||
| if ($username === 'sandbox') { | ||
| $this->baseDomain = self::BASE_SANDBOX_DOMAIN; | ||
| } else { | ||
| $this->baseDomain = self::BASE_DOMAIN; | ||
| } | ||
|
|
||
| $this->baseUrl = 'https://api.' . $this->baseDomain . '/version1/'; | ||
| $this->voiceUrl = 'https://voice.africastalking.com/'; | ||
| $this->mobileDataUrl = 'https://bundles.' . $this->baseDomain . '/'; | ||
| $this->contentUrl = ($username === 'sandbox') ? ($this->baseUrl) : ('https://content.' . $this->baseDomain . '/version1/'); | ||
| $this->checkoutTokenUrl = 'https://api.' . $this->baseDomain . '/'; | ||
|
|
||
| if ($username === 'sandbox') { | ||
| $this->contentUrl = $this->baseUrl; | ||
| } | ||
|
|
||
| $this->username = $username; | ||
| $this->apiKey = $apiKey; | ||
|
|
||
| $this->client = new Client([ | ||
| 'base_uri' => $this->baseUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/x-www-form-urlencoded', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->contentClient = new Client([ | ||
| 'base_uri' => $this->contentUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/x-www-form-urlencoded', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->voiceClient = new Client([ | ||
| 'base_uri' => $this->voiceUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/x-www-form-urlencoded', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->mobileDataClient = new Client([ | ||
| 'base_uri' => $this->mobileDataUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/json', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
|
|
||
| $this->tokenClient = new Client([ | ||
| 'base_uri' => $this->checkoutTokenUrl, | ||
| 'headers' => [ | ||
| 'apikey' => $this->apiKey, | ||
| 'Content-Type' => 'application/json', | ||
| 'Accept' => 'application/json', | ||
| ], | ||
| ]); | ||
| } | ||
|
|
||
| public function sms(): SMS | ||
| { | ||
| $content = new Content($this->contentClient, $this->username, $this->apiKey); | ||
|
|
||
| return new SMS($this->client, $this->username, $this->apiKey, $content); | ||
| } | ||
|
|
||
| public function content(): Content | ||
| { | ||
| return new Content($this->contentClient, $this->username, $this->apiKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable is unnecessary here
| } | ||
|
|
||
| protected function buildSay($options) | ||
| protected function buildSay(string|array $options): array|string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests were failing that $options received is an array or string.
| // change trimSilence to true or false string | ||
| $trimSilence ? $trimSilence = "true" : $trimSilence ="false"; | ||
| $trimSilence ? $trimSilence = 'true' : $trimSilence = 'false'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look right but can't update without tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes to tests besides formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes to tests besides formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes to tests.
|
Please squash commits while merging |
The SDK is overdue for a major review.
This is a first of (hopefully multiple) PRs aimed at bringing the SDK to the AI age.
This PR is restricted to the following:
composer.lockfile - This being a library, the lock file is only required for local development and ignored in user-space