Skip to content

Commit 0bad3e8

Browse files
authored
Merge pull request #2 from CoreProc/develop
Access token is now optional and added ability to include custom parameters
2 parents 8b00a71 + c7d0c30 commit 0bad3e8

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

src/GlobeLabsSmsChannel.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public function send($notifiable, Notification $notification)
3535

3636
$contactInfo = $notifiable->routeNotificationFor('globeLabsSms');
3737

38-
// The contact info should include an access_token and a address
39-
if (empty($contactInfo['access_token']) || empty($contactInfo['address'])) {
40-
throw new CouldNotSendNotification('Missing variables from your routeNotificationForGlobeLabs().');
38+
// The contact info should include an address (mobile number). We are making access_token optional. The API
39+
// response will catch that anyway.
40+
if (empty($contactInfo['address'])) {
41+
throw new CouldNotSendNotification('Missing address variable from your routeNotificationForGlobeLabs().');
4142
}
4243

4344
$message = $notification->toGlobeLabsSms($notifiable);

src/GlobeLabsSmsMessage.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class GlobeLabsSmsMessage
1616

1717
protected $address;
1818

19-
protected $globeLabsSmsApiSendUrl = 'https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/{senderAddress}/requests?access_token={accessToken}';
19+
protected $globeLabsSmsApiSendUrl = 'https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/{senderAddress}/requests';
20+
21+
protected $requestParams;
2022

2123
public static function create($notifiable)
2224
{
@@ -37,7 +39,20 @@ public function getApiSendUrl()
3739
$url = config('broadcasting.connections.globe_labs_sms.api_send_url', $this->globeLabsSmsApiSendUrl);
3840

3941
$url = str_replace('{senderAddress}', $this->getSenderAddress(), $url);
40-
$url = str_replace('{accessToken}', $this->getAccessToken(), $url);
42+
43+
$urlParams = [];
44+
45+
if (! empty($this->getAccessToken())) {
46+
$urlParams['access_token'] = $this->getAccessToken();
47+
}
48+
49+
$httpQuery = http_build_query($urlParams);
50+
51+
if (! empty($httpQuery)) {
52+
$httpQuery = '?'.$httpQuery;
53+
}
54+
55+
$url = $url.$httpQuery;
4156

4257
return $url;
4358
}
@@ -101,6 +116,24 @@ public function setMessage($message)
101116
return $this;
102117
}
103118

119+
/**
120+
* An additional method to accommodate any additional parameters needed by the API.
121+
*
122+
* @param $requestParams
123+
* @return GlobeLabsSmsMessage
124+
*/
125+
public function setRequestParams($requestParams)
126+
{
127+
$this->requestParams = $requestParams;
128+
129+
return $this;
130+
}
131+
132+
public function getRequestParams()
133+
{
134+
return $this->requestParams;
135+
}
136+
104137
public function toJson()
105138
{
106139
$request['outboundSMSMessageRequest']['address'] = $this->getAddress();
@@ -112,6 +145,10 @@ public function toJson()
112145

113146
$request['outboundSMSMessageRequest']['outboundSMSTextMessage']['message'] = $this->getMessage();
114147

148+
if (! empty($this->getRequestParams())) {
149+
$request = array_merge($request, $this->getRequestParams());
150+
}
151+
115152
return json_encode($request);
116153
}
117154
}

0 commit comments

Comments
 (0)