Skip to content

Commit

Permalink
Merge branch 'release/2.0.0-rc1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-konshin committed Jul 27, 2016
2 parents 69ba771 + cec80d1 commit ac9984a
Show file tree
Hide file tree
Showing 24 changed files with 242 additions and 186 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php
php:
- 5.3.29
- 5.4
- 5.5
- 5.6
- hhvm
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ all:

.PHONY: install
install:
composer install --prefer-source --no-interaction
composer install --prefer-dist --no-interaction

.PHONY: coveralls
coveralls:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# Requirements

- PHP 5.3.29+
- PHP 5.5+
- CURL extension
- MCrypt extension

Expand Down Expand Up @@ -205,7 +205,7 @@ $response = $platform->sendRequest($request);
# How to demo?
Clone the repo and create a file `demo/_credentials.php`:
Clone the repo and create a file `demo/_credentials.php` copy the contents from the file 'demo/_credentialsSample.php' as shown below:
```php
return array(
Expand All @@ -217,6 +217,8 @@ return array(
'server' => 'https://platform.devtest.ringcentral.com', // for production - https://platform.ringcentral.com
'smsNumber' => '18882223344', // any of SMS-enabled numbers on your RingCentral account
'mobileNumber' => '16501112233', // your own mobile number to which script will send sms
'dateFrom' => 'yyyy-mm-dd',
'dateTo' => 'yyyy-mm-dd'
);
```
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
],
"require": {
"ext-curl": "*",
"php": ">=5.3.29",
"ringcentral/psr7": "^1.2.0",
"pubnub/pubnub": "~3.7",
"symfony/event-dispatcher": "^2.7"
"php": ">=5.5.0",
"guzzlehttp/psr7": "^1.2.3",
"pubnub/pubnub": "^3.8.1",
"symfony/event-dispatcher": "^3.0.4",
"guzzlehttp/guzzle": "^6.2"
},
"require-dev": {
"phpunit/phpunit": "*",
Expand Down
14 changes: 9 additions & 5 deletions demo/_credentialsSample.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

return array(
'username' => '18881112233', // your RingCentral account phone number
'extension' => null, // or number
'username' => '18881112233', // your RingCentral account phone number
'extension' => null, // or number
'password' => 'yourPassword',
'appKey' => 'yourAppKey',
'appSecret' => 'yourAppSecret',
'server' => 'https: //platform.devtest.ringcentral.com', // for production - https://platform.ringcentral.com
'smsNumber' => '18882223344', // any of SMS-enabled numbers on your RingCentral account
'mobileNumber' => '16501112233', // your own mobile number to which script will send sms
'server' => 'https://platform.devtest.ringcentral.com', // for production - https://platform.ringcentral.com
'smsNumber' => '18882223344', // any of SMS-enabled numbers on your RingCentral account
'mobileNumber' => '16501112233', // your own mobile number to which script will send sms
'dateFrom' => 'yyyy-mm-dd', // dateFrom
'dateTo' => 'yyyy-mm-dd' // dateTo
);
1 change: 0 additions & 1 deletion demo/authData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use RingCentral\SDK\SDK;


// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
Expand Down
28 changes: 9 additions & 19 deletions demo/callRecording.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use RingCentral\SDK\SDK;



// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');


$rcsdk = new SDK($credentials['appKey'], $credentials['appSecret'], $credentials['server'], 'Demo', '1.0.0');

$platform = $rcsdk->platform();
Expand All @@ -31,41 +33,34 @@
$status = "Success";
$dir = $credentials['dateFrom'];
$fname = "recordings_${dir}.csv";
$fdir = "/DownloadRecordings/Recordings/${dir}";

// check if the directory exists
// mkdir('/AllianceRecordings/Recordings/${dir}', 0700);
$fdir = "/Recordings/${dir}";

if (is_dir($fdir) === false)
{
mkdir($fdir, 0777, true);
// mkdir("/AllianceRecordings/JSON/${dir}", 0755, true);
}

$file = fopen($fname,'w');

$fileHeaders = array("RecordingID","ContentURI","Filename","DownloadStatus");

fputcsv($file, $fileHeaders);
$fileContents = array();

$fileContents = array();



$timePerRecording = 6;

foreach ($callLogRecords as $i => $callLogRecord) {

$id = $callLogRecord->recording->id;

print "Downloading Call Log Record ${id}" . PHP_EOL;

$uri = $callLogRecord->recording->contentUri;

print "The contentURI is : ${uri}";
$uri = $callLogRecord->recording->contentUri;

print "Retrieving ${uri}" . PHP_EOL;

$apiResponse = $platform->get($callLogRecord->recording->contentUri);

$ext = ($apiResponse->response()->getHeader('Content-Type')[0] == 'audio/mpeg')
? 'mp3' : 'wav';

Expand All @@ -79,12 +74,8 @@
$status = "failure";
}

print "Wrote Recording for Call Log Record ${id}" . PHP_EOL;

file_put_contents("${fdir}/recording_${id}.json", json_encode($callLogRecord));

print "Wrote Metadata for Call Log Record ${id}" . PHP_EOL;

$end=microtime(true);

// Check if the recording completed wihtin 6 seconds.
Expand All @@ -93,7 +84,6 @@
sleep($timePerRecording-$time);
}


$fileContents = array($id, $uri, $filename, $status);
fputcsv($file, $fileContents);

Expand Down
1 change: 0 additions & 1 deletion demo/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use RingCentral\SDK\SDK;


// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
Expand Down
1 change: 0 additions & 1 deletion demo/fax.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use RingCentral\SDK\SDK;


// Create SDK instance

$credentials = require(__DIR__ . '/_credentials.php');
Expand Down
21 changes: 14 additions & 7 deletions demo/subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use RingCentral\SDK\SDK;
use RingCentral\SDK\Subscription\Events\NotificationEvent;
use RingCentral\SDK\Subscription\Events\SuccessEvent;
use RingCentral\SDK\Subscription\Subscription;


// Create SDK instance
$credentials = require('_credentials.php');


$credentials = require(__DIR__ . '/_credentials.php');

Expand All @@ -24,8 +26,9 @@
$subscription = $rcsdk->createSubscription();

$subscription->addEvents(array(
'/account/~/extension/~/message-store',
'/account/~/extension/~/presence'));
'/account/~/extension/~/message-store',
'/account/~/extension/~/presence'
));

$subscription->setKeepPolling(true);

Expand All @@ -35,10 +38,14 @@

print 'Subscribing' . PHP_EOL;

$subscription->addListener(Subscription::EVENT_TIMEOUT, function () {
print 'Timeout' . PHP_EOL;
});

$subscription->addListener(Subscription::EVENT_RENEW_SUCCESS, function (SuccessEvent $e) {
print 'Renewed' . PHP_EOL;
});

$subscription->register();

print 'End' . PHP_EOL;

while (1>0) {
sleep(1);
}
4 changes: 4 additions & 0 deletions src/Core/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ static function json_parse($json = '', $assoc = false, $depth = 512)

$parsed = \json_decode($json, $assoc, $depth);

//if (JSON_ERROR_NONE !== json_last_error()) {
// throw new \RuntimeException('JSON Error: Unable to parse into JSON: ' . json_last_error());
//}

$error = json_last_error();

switch ($error) {
Expand Down
40 changes: 22 additions & 18 deletions src/Http/ApiResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,16 @@ class ApiResponse
/** @var RequestInterface */
protected $_request;

protected $_raw;

/**
* TODO Support strams
* @param RequestInterface $request Reqeuest used to get the response
* @param mixed $body Stream body
* @param int $status Status code for the response, if any
* @param RequestInterface $request Reqeuest used to get the response
* @param ResponseInterface $response Response
*/
public function __construct(RequestInterface $request = null, $body = null, $status = 200)
public function __construct(RequestInterface $request = null, ResponseInterface $response = null)
{

$this->_request = $request;
$this->_raw = $body;

$body = (string)$body;

// Make the HTTP message complete
if (substr($body, 0, 5) !== 'HTTP/') {
$body = "HTTP/1.1 " . $status . " OK\r\n" . $body;
}

$this->_response = \RingCentral\Psr7\parse_response($body);
$this->_response = $response;

}

Expand Down Expand Up @@ -168,7 +156,9 @@ public function multipart()
// Step 3. Create status info object

$statusInfoPart = array_shift($parts);
$statusInfoObj = new self(null, trim($statusInfoPart), $this->response()->getStatusCode());
$statusInfoObj = new self(null,
self::createResponse(trim($statusInfoPart), $this->response()->getStatusCode())
);
$statusInfo = $statusInfoObj->json()->response;

// Step 4. Parse all parts into Response objects
Expand All @@ -177,7 +167,7 @@ public function multipart()

$partInfo = $statusInfo[$i];

$this->_multiparts[] = new self(null, trim($part), $partInfo->status);
$this->_multiparts[] = new self(null, self::createResponse(trim($part), $partInfo->status));

}

Expand Down Expand Up @@ -267,4 +257,18 @@ protected function getContentType()
return $this->response()->getHeaderLine('content-type');
}

static function createResponse($body = '', $status = 200)
{

// Make the HTTP message complete
if (substr($body, 0, 5) !== 'HTTP/') {
$body = "HTTP/1.1 " . $status . " Foo\r\n" . $body;
}

$response = \GuzzleHttp\Psr7\parse_response((string)$body);

return $response->withStatus($status);

}

}
18 changes: 9 additions & 9 deletions src/Http/ApiResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testMultipart()
"{\"baz\" : \"qux\"}\n" .
"--Boundary_1245_945802293_1394135045248--\n";

$r = new ApiResponse(null, $goodMultipartMixedResponse, 207);
$r = new ApiResponse(null, ApiResponse::createResponse($goodMultipartMixedResponse, 207));
$parts = $r->multipart();

$this->assertEquals(2, count($parts));
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testMultipartWithErrorPart()
"{\"message\" : \"object not found\"}\n" .
"--Boundary_1245_945802293_1394135045248--\n";

$r = new ApiResponse(null, $multipartMixedResponseWithErrorPart, 207);
$r = new ApiResponse(null, ApiResponse::createResponse($multipartMixedResponseWithErrorPart, 207));
$parts = $r->multipart();

$this->assertEquals(2, count($parts));
Expand Down Expand Up @@ -87,7 +87,7 @@ public function testMultipartCorruptedResponse()
"{\"foo\" : \"bar\"}\n" .
"--Boundary_1245_945802293_1394135045248--\n";

$r3 = new ApiResponse(null, $badMultipartMixedResponse, 207);
$r3 = new ApiResponse(null, ApiResponse::createResponse($badMultipartMixedResponse, 207));
$r3->multipart();

}
Expand All @@ -99,7 +99,7 @@ public function testMultipartCorruptedResponse()
public function testMultipartOnNotAMultipartResponse()
{

$r3 = new ApiResponse(null, "Content-Type: text/plain\n\nWhatever", 207);
$r3 = new ApiResponse(null, ApiResponse::createResponse("Content-Type: text/plain\n\nWhatever", 207));
$r3->multipart();

}
Expand All @@ -124,15 +124,15 @@ public function testMultipartWitoutBoundary()
"{\"foo\" : \"bar\"}\n" .
"--Boundary_1245_945802293_1394135045248--\n";

$r3 = new ApiResponse(null, $response, 207);
$r3 = new ApiResponse(null, ApiResponse::createResponse($response, 207));
$r3->multipart();

}

public function testGetJson()
{

$r = new ApiResponse(null, "content-type: application/json\n\n{\"foo\":\"bar\"}", 200);
$r = new ApiResponse(null, ApiResponse::createResponse("content-type: application/json\n\n{\"foo\":\"bar\"}", 200));

$this->assertEquals('{"foo":"bar"}', $r->text());
$this->assertEquals('bar', $r->json()->foo);
Expand All @@ -149,7 +149,7 @@ public function testGetJson()
public function testGetJsonWithNotJSON()
{

$r = new ApiResponse(null, "content-type: application/not-a-json\n\nfoo", 200);
$r = new ApiResponse(null, ApiResponse::createResponse("content-type: application/not-a-json\n\nfoo", 200));
$r->json();

}
Expand All @@ -161,7 +161,7 @@ public function testGetJsonWithNotJSON()
public function testGetJsonWithCorruptedJSON()
{

$r = new ApiResponse(null, "content-type: application/json\n\n{\"foo\";\"bar\"}", 200);
$r = new ApiResponse(null, ApiResponse::createResponse("content-type: application/json\n\n{\"foo\";\"bar\"}", 200));
$r->json();

}
Expand All @@ -173,7 +173,7 @@ public function testGetJsonWithCorruptedJSON()
public function testGetJsonWithEmptyJSON()
{

$r = new ApiResponse(null, "content-type: application/json\n\nnull", 200);
$r = new ApiResponse(null, ApiResponse::createResponse("content-type: application/json\n\nnull", 200));
$r->json();

}
Expand Down
Loading

0 comments on commit ac9984a

Please sign in to comment.