-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vonage API in PHP more simplified manner to use
- Loading branch information
1 parent
f2b6ba4
commit 8bada86
Showing
3 changed files
with
115 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,59 @@ | ||
<?php | ||
|
||
namespace Vonage; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Cookie\CookieJar; | ||
|
||
class Vonage | ||
{ | ||
protected $apiDomain = 'https://my.vonagebusiness.com'; | ||
private $cookie; | ||
private $client; | ||
|
||
public $data = array(); | ||
public $auth = array(); | ||
public $finalUrl; | ||
public $restBaseUrl; | ||
|
||
protected $vonageApiUrl = 'https://my.vonagebusiness.com'; | ||
|
||
/** | ||
* @param $username | ||
* @param $password | ||
* @param array $options | ||
*/ | ||
public function __construct($username, $password, $options = array()) | ||
{ | ||
$this->client = new Client(); | ||
$this->restBaseUrl = $this->apiDomain . '/presence/rest/'; | ||
$this->client = new Client(array('base_uri' => $this->restBaseUrl)); | ||
$this->cookie = new CookieJar(); | ||
$response = $this->client->get($this->apiDomain.'/appserver/rest/user/null', | ||
['cookies' => $this->cookie, 'query' => ['htmlLogin' => $username, 'htmlPassword' => $password]]); | ||
$body = $response->getBody()->getContents(); | ||
|
||
$response = $this->client->get($this->vonageApiUrl . '/appserver/rest/user/null', | ||
[ | ||
'cookies' => $this->cookie, | ||
'query' => ['htmlLogin' => $username, 'htmlPassword' => 'ltqpsmr7'] | ||
] | ||
); | ||
|
||
if (!empty($response->getBody()->getContents())) { | ||
$this->auth = json_decode($response->getBody()->getContents()); | ||
if (!empty($body)) { | ||
$this->auth = json_decode($body); | ||
} | ||
} | ||
|
||
/** | ||
* @param $number | ||
* @return bool|string | ||
* @param $url | ||
* @param array $params | ||
* @param array $options | ||
* @return array|string | ||
*/ | ||
public function makeCall($number) | ||
public function request($url, $params = array(), $options = array()) | ||
{ | ||
try { | ||
$response = $this->client->get($this->vonageApiUrl . '/presence/rest/clicktocall/' . $number, | ||
['cookies' => $this->cookie]); | ||
if(isset($params) && !empty($params) && is_array($params)){ | ||
$response = $this->client->get($url, ['cookies' => $this->cookie, 'query' => http_build_query($params)]); | ||
$this->finalUrl = urldecode($this->restBaseUrl . $url . '?' . http_build_query($params)); | ||
}else{ | ||
$response = $this->client->get($url, ['cookies' => $this->cookie]); | ||
$this->finalUrl = urldecode($this->restBaseUrl . $url); | ||
} | ||
|
||
return $response->getBody()->getContents(); | ||
} catch (\Exception $e) { | ||
return false; | ||
return array(); | ||
} | ||
|
||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters