Skip to content

Commit

Permalink
Vonage API in PHP more simplified manner to use
Browse files Browse the repository at this point in the history
  • Loading branch information
shahariaazam committed Aug 8, 2015
1 parent f2b6ba4 commit 8bada86
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 85 deletions.
50 changes: 30 additions & 20 deletions Vonage/Vonage.php
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();
}

}
}
143 changes: 80 additions & 63 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
require "vendor/autoload.php";
require "config.php";

$vonage = new \Vonage\Vonage(VONAGE_USERNAME, VONAGE_PASSWORD);
var_dump($vonage->makeCall('NumberToCall')); die();
$vonage = new \Vonage\Vonage('vonageUsername', 'VonagePassword');
$params = array(
'start' => date('Y-m-d\TH:i:sP')
);
var_dump($vonage->request('callhistory/{VonageExtensionNumber}', $params)); die();

0 comments on commit 8bada86

Please sign in to comment.