Skip to content

Commit

Permalink
bug TROPO-12571 tropo-webapi-php startRecording url
Browse files Browse the repository at this point in the history
  • Loading branch information
pengxli committed Dec 22, 2017
1 parent 58453e9 commit 63d3725
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 17 deletions.
37 changes: 33 additions & 4 deletions tests/StartRecordingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,36 @@ public function testStartRecordingWithMinOptions() {
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

public function testStartRecordingWithMinOptions1() {
$tropo = new Tropo();
$url = new Url('http://192.168.26.203/tropo-webapi-php/upload_file.php');
$startRecording = array(
'url' => $url
);
$tropo->startRecording($startRecording);
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

public function testStartRecordingWithMinOptions2() {
$tropo = new Tropo();
$url = array(
new Url('http://192.168.26.203/tropo-webapi-php/upload_file.php', 'root', '111111', 'POST'),
new Url('http://192.168.26.204/tropo-webapi-php/upload_file.php')
);
$startRecording = array(
'url' => $url
);
$tropo->startRecording($startRecording);
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"url":[{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},{"url":"http://192.168.26.204/tropo-webapi-php/upload_file.php"}]}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

public function testRecordWithAllOptions() {
Expand All @@ -34,7 +63,7 @@ public function testRecordWithAllOptions() {
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/au","method":"POST","password":"111111","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:[email protected]","transcriptionLanguage":"pt-br","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/au","url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:[email protected]","transcriptionLanguage":"pt-br","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

public function testCreateMinObject() {
Expand All @@ -44,7 +73,7 @@ public function testCreateMinObject() {
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

public function testCreateObject() {
Expand All @@ -54,7 +83,7 @@ public function testCreateObject() {
$say = new Say("I am now recording!", null, null, null, null, "say");
$tropo->say($say);
$tropo->stopRecording();
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/mp3","method":"POST","password":"111111","url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:[email protected]","transcriptionLanguage":"pt-br","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
$this->assertEquals(sprintf($tropo), '{"tropo":[{"startRecording":{"format":"audio/mp3","url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"transcriptionID":"1234","transcriptionEmailFormat":"plain","transcriptionOutURI":"mailto:[email protected]","transcriptionLanguage":"pt-br","asyncUpload":false}},{"say":[{"value":"I am now recording!","name":"say"}]},{"stopRecording":"null"}]}');
}

}
Expand Down
41 changes: 28 additions & 13 deletions tropo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -754,18 +754,18 @@ public function startRecording($startRecording) {
if(null === $startRecording->getUrl()) {
throw new Exception("Missing required property: 'url'");
}
if (!(is_string($startRecording->getUrl()) && ($startRecording->getUrl() != ''))) {
throw new Exception("Required property: 'url' must be a string.");
}
// if (!(is_string($startRecording->getUrl()) && ($startRecording->getUrl() != ''))) {
// throw new Exception("Required property: 'url' must be a string.");
// }

} elseif (is_array($startRecording)) {

if (!array_key_exists('url', $startRecording)) {
throw new Exception("Missing required property: 'url'");
}
if (!(is_string($startRecording['url']) && ($startRecording['url'] != ''))) {
throw new Exception("Required property: 'url' must be a string.");
}
// if (!(is_string($startRecording['url']) && ($startRecording['url'] != ''))) {
// throw new Exception("Required property: 'url' must be a string.");
// }

$params = $startRecording;
$p = array('format', 'method', 'password', 'url', 'username', 'transcriptionID', 'transcriptionEmailFormat', 'transcriptionOutURI', 'asyncUpload', 'transcriptionLanguage');
Expand Down Expand Up @@ -2625,14 +2625,29 @@ public function __construct($format=NULL, $method=NULL, $password=NULL, $url, $u
if(!isset($url)) {
throw new Exception("Missing required property: 'url'");
}
if (!(is_string($url) && ($url != ''))) {
throw new Exception("Required property: 'url' must be a string.");
if (is_string($url) && ($url != '')) {
$this->_url = sprintf('%s', new Url($url, $username, $password, $method));
} else if ($url instanceof Url) {
$this->_url = sprintf('%s', $url);
} else if (is_array($url) && count($url) > 0) {
foreach ($url as $key => $value) {
if (!($value instanceof Url)) {
throw new Exception("Property: 'url' must be a valid string, an instance of Url or an array of Urls.");
}
$this->_url[$key] = sprintf('%s', $value);
}
foreach ($this->_url as $key => $value) {
$this->_url[$key] = json_decode($value);
}
$this->_url = json_encode($this->_url);
} else {
throw new Exception("Property: 'url' must be a valid string, an instance of Url or an array of Urls.");
}
$this->_format = $format;
$this->_method = $method;
$this->_password = $password;
$this->_url = $url;
$this->_username = $username;
//$this->_method = $method;
//$this->_password = $password;
//$this->_url = $url;
//$this->_username = $username;
$this->_transcriptionID = $transcriptionID;
$this->_transcriptionEmailFormat = $transcriptionEmailFormat;
$this->_transcriptionOutURI = $transcriptionOutURI;
Expand All @@ -2648,7 +2663,7 @@ public function __toString() {
if(isset($this->_format)) { $this->format = $this->_format; }
if(isset($this->_method)) { $this->method = $this->_method; }
if(isset($this->_password)) { $this->password = $this->_password; }
if(isset($this->_url)) { $this->url = $this->_url; }
if(isset($this->_url)) { $this->url = json_decode($this->_url); }
if(isset($this->_username)) { $this->username = $this->_username; }
if(isset($this->_transcriptionID)) { $this->transcriptionID = $this->_transcriptionID; }
if(isset($this->_transcriptionEmailFormat)) { $this->transcriptionEmailFormat = $this->_transcriptionEmailFormat; }
Expand Down

0 comments on commit 63d3725

Please sign in to comment.