From af88e523c67d39931572010d9f1d1e7da3cf2c85 Mon Sep 17 00:00:00 2001 From: pengxli Date: Wed, 24 Jan 2018 11:07:19 +0800 Subject: [PATCH] bug TROPO-12574 name shouldn't be a necessary parameter in WebAPI SDK --- tests/CallTest.php | 36 ++--- tests/ConferenceTest.php | 25 ++- tests/MessageTest.php | 25 ++- tests/RecordTest.php | 33 ++-- tests/RedirectTest.php | 7 +- tests/SayTest.php | 84 ++-------- tests/TransferTest.php | 55 +++---- tropo.class.php | 326 ++++++++++++--------------------------- 8 files changed, 185 insertions(+), 406 deletions(-) diff --git a/tests/CallTest.php b/tests/CallTest.php index 38ef5c6..5ded659 100644 --- a/tests/CallTest.php +++ b/tests/CallTest.php @@ -7,21 +7,15 @@ class CallTest extends PHPUnit_Framework_TestCase public function testCallWithMinOptions() { $tropo = new Tropo(); - $params = array( - 'name' => 'foo' - ); - $tropo->call("sip:pengxli@192.168.26.1:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:pengxli@192.168.26.1:5678","name":"foo"}}]}'); + $tropo->call("sip:pengxli@192.168.26.1:5678"); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:pengxli@192.168.26.1:5678"}}]}'); } public function testCallWithExtraToOptiions() { $tropo = new Tropo(); $call = array('sip:pengxli@192.168.26.1:5678', 'sip:pengxli@192.168.26.206:5678'); - $params = array( - 'name' => 'foo' - ); - $tropo->call($call, $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@192.168.26.206:5678"],"name":"foo"}}]}'); + $tropo->call($call); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@192.168.26.206:5678"]}}]}'); } public function testCallWithAllOptions() { @@ -36,7 +30,6 @@ public function testCallWithAllOptions() { 'from' => '3055551000', 'headers' => $headers, 'machineDetection' => false, - 'name' => 'foo', 'network' => Network::$sip, 'required' => true, 'timeout' => 30.0, @@ -46,7 +39,7 @@ public function testCallWithAllOptions() { 'label' => 'callLabel' ); $tropo->call($call, $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@192.168.26.206:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@192.168.26.206:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); } public function testCallWithAllOptions1() { @@ -61,7 +54,6 @@ public function testCallWithAllOptions1() { 'from' => '3055551000', 'headers' => $headers, 'machineDetection' => 'For the most accurate results, the "introduction" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.', - 'name' => 'foo', 'network' => Network::$sip, 'required' => true, 'timeout' => 30.0, @@ -71,22 +63,22 @@ public function testCallWithAllOptions1() { 'label' => 'callLabel' ); $tropo->call($call, $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@192.168.26.206:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@192.168.26.206:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); } public function testCreateMinObject() { $tropo = new Tropo(); - $call = new Call("sip:pengxli@192.168.26.1:5678", null, null, null, null, null, null, null, null, null, null, "foo"); + $call = new Call("sip:pengxli@192.168.26.1:5678"); $tropo->call($call); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:pengxli@192.168.26.1:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":"sip:pengxli@192.168.26.1:5678"}}]}'); } public function testCreateObject1() { $tropo = new Tropo(); $to = array("sip:pengxli@192.168.26.1:5678", "sip:pengxli@172.16.72.131:5678"); - $call = new Call($to, null, null, null, null, null, null, null, null, null, null, "foo"); + $call = new Call($to); $tropo->call($call); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"]}}]}'); } public function testCreateObject2() { @@ -94,9 +86,9 @@ public function testCreateObject2() { $to = array("sip:pengxli@192.168.26.1:5678", "sip:pengxli@172.16.72.131:5678"); $allowSignals = array('exit', 'quit'); $headers = array('foo' => 'bar', 'bling' => 'baz'); - $call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, false, Voice::$US_English_female_allison, "foo", true, "http://192.168.26.203/result.php", "suppress", "callLabel"); + $call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, false, Voice::$US_English_female_allison, null, true, "http://192.168.26.203/result.php", "suppress", "callLabel"); $tropo->call($call); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":false,"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); } public function testCreateObject3() { @@ -105,9 +97,9 @@ public function testCreateObject3() { $allowSignals = array('exit', 'quit'); $headers = array('foo' => 'bar', 'bling' => 'baz'); $machineDetection = 'For the most accurate results, the "introduction" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.'; - $call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, $machineDetection, Voice::$US_English_female_allison, "foo", true, "http://192.168.26.203/result.php", "suppress", "callLabel"); + $call = new Call($to, "3055551000", Network::$sip, Channel::$voice, false, 30.0, $headers, null, $allowSignals, $machineDetection, Voice::$US_English_female_allison, null, true, "http://192.168.26.203/result.php", "suppress", "callLabel"); $tropo->call($call); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","name":"foo","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"call":{"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"from":"3055551000","network":"SIP","channel":"VOICE","timeout":30,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"allowSignals":["exit","quit"],"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","required":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"callLabel"}}]}'); } } ?> \ No newline at end of file diff --git a/tests/ConferenceTest.php b/tests/ConferenceTest.php index fa055b9..0ed5cf5 100644 --- a/tests/ConferenceTest.php +++ b/tests/ConferenceTest.php @@ -7,11 +7,8 @@ class ConferenceTest extends PHPUnit_Framework_TestCase public function testConferenceWithMinOptions() { $tropo = new Tropo(); - $params = array( - 'name' => 'foo' - ); - $tropo->conference("1234", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234"}}]}'); + $tropo->conference("1234"); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234"}}]}'); } public function testConferenceWithAllOptions() { @@ -23,14 +20,13 @@ public function testConferenceWithAllOptions() { 'joinPrompt' => true, 'leavePrompt' => true, 'mute' => false, - 'name' => 'foo', 'playTones' => true, 'required' => true, 'terminator' => '*', 'promptLogSecurity' => 'suppress', ); $tropo->conference("1234", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}'); } public function testConferenceWithAllOptions1() { @@ -50,29 +46,28 @@ public function testConferenceWithAllOptions1() { 'joinPrompt' => $joinPrompt, 'leavePrompt' => $leavePrompt, 'mute' => false, - 'name' => 'foo', 'playTones' => true, 'required' => true, 'terminator' => '*', 'promptLogSecurity' => 'suppress', ); $tropo->conference("1234", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":{"value":"I am coming.","voice":"allison"},"leavePrompt":{"value":"I am leaving.","voice":"allison"}}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":{"value":"I am coming.","voice":"allison"},"leavePrompt":{"value":"I am leaving.","voice":"allison"}}}]}'); } public function testCreateMinObject() { $tropo = new Tropo(); - $conference = new Conference("foo", "1234"); + $conference = new Conference(null, "1234"); $tropo->conference($conference); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234"}}]}'); } public function testCreateObject1() { $tropo = new Tropo(); $allowSignals = array('exit', 'quit'); - $conference = new Conference("foo", "1234", false, null, true, true, "*", $allowSignals, 5.0, true, true, null, "suppress"); + $conference = new Conference(null, "1234", false, null, true, true, "*", $allowSignals, 5.0, true, true, null, "suppress"); $tropo->conference($conference); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":true,"leavePrompt":true}}]}'); } public function testCreateObject2() { @@ -86,9 +81,9 @@ public function testCreateObject2() { 'value' => 'I am leaving.', 'voice' => Voice::$US_English_female_allison ); - $conference = new Conference("foo", "1234", false, null, true, true, "*", $allowSignals, 5.0, $joinPrompt, $leavePrompt, null, "suppress"); + $conference = new Conference(null, "1234", false, null, true, true, "*", $allowSignals, 5.0, $joinPrompt, $leavePrompt, null, "suppress"); $tropo->conference($conference); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"name":"foo","id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":{"value":"I am coming.","voice":"allison"},"leavePrompt":{"value":"I am leaving.","voice":"allison"}}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"conference":{"id":"1234","mute":false,"playTones":true,"required":true,"terminator":"*","allowSignals":["exit","quit"],"interdigitTimeout":5,"promptLogSecurity":"suppress","joinPrompt":{"value":"I am coming.","voice":"allison"},"leavePrompt":{"value":"I am leaving.","voice":"allison"}}}]}'); } } ?> \ No newline at end of file diff --git a/tests/MessageTest.php b/tests/MessageTest.php index 58b1218..7912160 100644 --- a/tests/MessageTest.php +++ b/tests/MessageTest.php @@ -8,11 +8,10 @@ class MessageTest extends PHPUnit_Framework_TestCase public function testMessageWithMinOptions() { $tropo = new Tropo(); $params = array( - 'to' => 'sip:pengxli@192.168.26.1:5678', - 'name' => 'foo' + 'to' => 'sip:pengxli@192.168.26.1:5678' ); $tropo->message("This is an announcement.", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is an announcement."},"to":"sip:pengxli@192.168.26.1:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is an announcement."},"to":"sip:pengxli@192.168.26.1:5678"}}]}'); } public function testMessageWithExtraSayOptiions() { @@ -20,11 +19,10 @@ public function testMessageWithExtraSayOptiions() { $say = "Remember, you have a meeting at 2 PM."; $params = array( 'say' => $say, - 'to' => 'sip:pengxli@192.168.26.1:5678', - 'name' => 'foo' + 'to' => 'sip:pengxli@192.168.26.1:5678' ); $tropo->message("This is an announcement.", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."}],"to":"sip:pengxli@192.168.26.1:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."}],"to":"sip:pengxli@192.168.26.1:5678"}}]}'); } public function testMessageWithAllOptions() { @@ -35,7 +33,6 @@ public function testMessageWithAllOptions() { $params = array( 'say' => $say, 'to' => $to, - 'name' => 'foo', 'answerOnMedia' => false, 'channel' => Channel::$voice, 'from' => '3055551000', @@ -47,14 +44,14 @@ public function testMessageWithAllOptions() { 'headers' => $headers ); $tropo->message("This is an announcement.", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."},{"value":"This is tropo.com."}],"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"name":"foo","channel":"VOICE","network":"SIP","from":"3055551000","voice":"allison","timeout":60,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"required":true,"promptLogSecurity":"suppress"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."},{"value":"This is tropo.com."}],"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"channel":"VOICE","network":"SIP","from":"3055551000","voice":"allison","timeout":60,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"required":true,"promptLogSecurity":"suppress"}}]}'); } public function testCreateMinObject() { $tropo = new Tropo(); - $message = new Message(new Say("This is an announcement."), "sip:pengxli@192.168.26.1:5678", null, null, null, null, null, null, null, "foo"); + $message = new Message(new Say("This is an announcement."), "sip:pengxli@192.168.26.1:5678"); $tropo->message($message); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is an announcement."},"to":"sip:pengxli@192.168.26.1:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":{"value":"This is an announcement."},"to":"sip:pengxli@192.168.26.1:5678"}}]}'); } public function testCreateObject1() { @@ -63,9 +60,9 @@ public function testCreateObject1() { new Say("This is an announcement."), new Say("Remember, you have a meeting at 2 PM.") ); - $message = new Message($say, "sip:pengxli@192.168.26.1:5678", null, null, null, null, null, null, null, "foo"); + $message = new Message($say, "sip:pengxli@192.168.26.1:5678"); $tropo->message($message); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."}],"to":"sip:pengxli@192.168.26.1:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."}],"to":"sip:pengxli@192.168.26.1:5678"}}]}'); } public function testCreateObject2() { @@ -80,9 +77,9 @@ public function testCreateObject2() { 'sip:pengxli@172.16.72.131:5678' ); $headers = array('foo' => 'bar', 'bling' => 'baz'); - $message = new Message($say, $to, Channel::$voice, Network::$sip, "3055551000", Voice::$US_English_female_allison, 60, false, $headers, "foo", true, "suppress"); + $message = new Message($say, $to, Channel::$voice, Network::$sip, "3055551000", Voice::$US_English_female_allison, 60, false, $headers, null, true, "suppress"); $tropo->message($message); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."},{"value":"This is tropo.com."}],"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"name":"foo","channel":"VOICE","network":"SIP","from":"3055551000","voice":"allison","timeout":60,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"required":true,"promptLogSecurity":"suppress"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"message":{"say":[{"value":"This is an announcement."},{"value":"Remember, you have a meeting at 2 PM."},{"value":"This is tropo.com."}],"to":["sip:pengxli@192.168.26.1:5678","sip:pengxli@172.16.72.131:5678"],"channel":"VOICE","network":"SIP","from":"3055551000","voice":"allison","timeout":60,"answerOnMedia":false,"headers":{"foo":"bar","bling":"baz"},"required":true,"promptLogSecurity":"suppress"}}]}'); } } ?> \ No newline at end of file diff --git a/tests/RecordTest.php b/tests/RecordTest.php index bc041ea..56505cc 100644 --- a/tests/RecordTest.php +++ b/tests/RecordTest.php @@ -8,22 +8,20 @@ class RecordTest extends PHPUnit_Framework_TestCase public function testRecordWithMinOptions() { $tropo = new Tropo(); $record = array( - 'url' => 'http://192.168.26.203/tropo-webapi-php/upload_file.php', - 'name' => 'foo' + 'url' => 'http://192.168.26.203/tropo-webapi-php/upload_file.php' ); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}}}]}'); } public function testRecordWithMinOptions1() { $tropo = new Tropo(); $url = new Url('http://192.168.26.203/tropo-webapi-php/upload_file.php', 'root', '111111', 'POST'); $record = array( - 'url' => $url, - 'name' => 'foo' + 'url' => $url ); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"}}}]}'); } public function testRecordWithMinOptions2() { @@ -33,11 +31,10 @@ public function testRecordWithMinOptions2() { new Url('http://192.168.26.204/tropo-webapi-php/upload_file.php') ); $record = array( - 'url' => $url, - 'name' => 'foo' + 'url' => $url ); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"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"}],"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"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"}]}}]}'); } public function testRecordWithAllOptions() { @@ -65,7 +62,6 @@ public function testRecordWithAllOptions() { 'maxSilence' => 5.0, 'maxTime' => 30.0, 'method' => 'POST', - 'name' => 'foo', 'required' => true, 'transcription' => $transcription, 'url' => 'http://192.168.26.203/tropo-webapi-php/upload_file.php', @@ -77,15 +73,15 @@ public function testRecordWithAllOptions() { 'promptLogSecurity' => 'suppress' ); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit","language":"en-uk"},"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"voice":"allison","interdigitTimeout":5,"asyncUpload":false,"name":"foo","promptLogSecurity":"suppress"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit","language":"en-uk"},"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"voice":"allison","interdigitTimeout":5,"asyncUpload":false,"promptLogSecurity":"suppress"}}]}'); } public function testCreateMinObject() { $tropo = new Tropo(); - $record = new Record(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "http://192.168.26.203/tropo-webapi-php/upload_file.php", null, null, null, null, "foo", null); + $record = new Record(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "http://192.168.26.203/tropo-webapi-php/upload_file.php"); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"}}}]}'); } public function testCreateObject() { @@ -97,27 +93,26 @@ public function testCreateObject() { new Say("Sorry, I did not hear anything. Please call back.", null , "timeout") ); $transcription = new Transcription("mailto:you@yourmail.com", "1234", "omit", "en-uk"); - $record = new Record(2, $allowSignals, true, true, $choices, AudioFormat::$mp3, 5.0, 30.0, "POST", "111111", true, $say, 30.0, $transcription, "root", "http://192.168.26.203/tropo-webapi-php/upload_file.php", Voice::$US_English_female_allison, null, 5.0, false, "foo", "suppress"); + $record = new Record(2, $allowSignals, true, true, $choices, AudioFormat::$mp3, 5.0, 30.0, "POST", "111111", true, $say, 30.0, $transcription, "root", "http://192.168.26.203/tropo-webapi-php/upload_file.php", Voice::$US_English_female_allison, null, 5.0, false, null, "suppress"); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit","language":"en-uk"},"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"voice":"allison","interdigitTimeout":5,"asyncUpload":false,"name":"foo","promptLogSecurity":"suppress"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"attempts":2,"allowSignals":["exit","quit"],"bargein":true,"beep":true,"choices":{"terminator":"*"},"format":"audio/mp3","maxSilence":5,"maxTime":30,"required":true,"say":[{"value":"Please leave a message."},{"event":"timeout","value":"Sorry, I did not hear anything. Please call back."}],"timeout":30,"transcription":{"id":"1234","url":"mailto:you@yourmail.com","emailFormat":"omit","language":"en-uk"},"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php","username":"root","password":"111111","method":"POST"},"voice":"allison","interdigitTimeout":5,"asyncUpload":false,"promptLogSecurity":"suppress"}}]}'); } public function testRecordWithSensitivity() { $tropo = new Tropo(); $record = array( 'url' => 'http://192.168.26.203/tropo-webapi-php/upload_file.php', - 'name' => 'foo', 'sensitivity' => 0.5 ); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"},"name":"foo","sensitivity":0.5}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"},"sensitivity":0.5}}]}'); } public function testCreateObjectWithSensitivity() { $tropo = new Tropo(); - $record = new Record(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "http://192.168.26.203/tropo-webapi-php/upload_file.php", null, null, null, null, "foo", null, 0.5); + $record = new Record(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "http://192.168.26.203/tropo-webapi-php/upload_file.php", null, null, null, null, null, null, 0.5); $tropo->record($record); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"},"name":"foo","sensitivity":0.5}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"record":{"url":{"url":"http://192.168.26.203/tropo-webapi-php/upload_file.php"},"sensitivity":0.5}}]}'); } } diff --git a/tests/RedirectTest.php b/tests/RedirectTest.php index 3de9b9e..2f1355d 100644 --- a/tests/RedirectTest.php +++ b/tests/RedirectTest.php @@ -8,20 +8,19 @@ public function testRedirect() { $tropo = new Tropo(); $params = array( - 'name' => 'foo', 'required' => true ); $tropo->redirect("sip:pengxli@192.168.26.1:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"redirect":{"to":"sip:pengxli@192.168.26.1:5678","name":"foo","required":true}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"redirect":{"to":"sip:pengxli@192.168.26.1:5678","required":true}}]}'); } public function testRedirect1() { $tropo = new Tropo(); - $redirect = new Redirect("sip:pengxli@192.168.26.1:5678", null, "foo", true); + $redirect = new Redirect("sip:pengxli@192.168.26.1:5678", null, null, true); $tropo->redirect($redirect); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"redirect":{"to":"sip:pengxli@192.168.26.1:5678","name":"foo","required":true}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"redirect":{"to":"sip:pengxli@192.168.26.1:5678","required":true}}]}'); } } diff --git a/tests/SayTest.php b/tests/SayTest.php index 76b3174..7b8bc83 100644 --- a/tests/SayTest.php +++ b/tests/SayTest.php @@ -4,13 +4,25 @@ class SayTest extends TestCase { + public function testSayWithMinOptions() { + $tropo = new Tropo(); + $tropo->say("Please enter your account number..."); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number..."}]}]}'); + } + + public function testSayWithOptions() { + $tropo = new Tropo(); + $tropo->say("Please enter your account number...",array('name' => 'say')); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","name":"say"}]}]}'); + } + public function testCreateSayObject() { $tropo = new Tropo(); $allowSignals = array('exit','quit'); - $say = new Say("Please enter your account number...", SayAs::$date, null, Voice::$US_English_female_allison, $allowSignals, "say", true, "suppress"); + $say = new Say("Please enter your account number...", SayAs::$date, null, Voice::$US_English_female_allison, $allowSignals, null, true, "suppress"); $tropo->say($say); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"name":"say","required":true,"promptLogSecurity":"suppress"}]}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress"}]}]}'); } public function testCreateSayObject1() @@ -18,7 +30,6 @@ public function testCreateSayObject1() $tropo = new Tropo(); $allowSignals = array('exit','quit'); $params = array( - "name"=>"say", "as"=>SayAs::$date, "event"=>"event", "voice"=>Voice::$US_English_female_allison, @@ -26,7 +37,7 @@ public function testCreateSayObject1() "promptLogSecurity"=>"suppress", "required"=>true); $tropo->say("Please enter your account number...",$params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"name":"say","required":true,"promptLogSecurity":"suppress"}]}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"say":[{"value":"Please enter your account number...","as":"DATE","voice":"allison","allowSignals":["exit","quit"],"required":true,"promptLogSecurity":"suppress"}]}]}'); } public function testFailsSayWithNoValueParameter1() @@ -47,39 +58,6 @@ public function testFailsSayWithNoValueParameter2() } } - public function testFailsSayWithNoNameParameter() - { - $tropo = new Tropo(); - try{ - $say = new Say("Please enter your account number..."); - $tropo->say($say); - } catch (Exception $e) { - $this->assertEquals($e->getMessage(), "Missing required property: 'name'"); - } - } - - public function testFailsSayWithNoNameParameter1() - { - $tropo = new Tropo(); - try{ - $say = new Say("Please enter your account number...", null, null, null, null, null, null, null); - $tropo->say($say); - } catch (Exception $e) { - $this->assertEquals($e->getMessage(), "Missing required property: 'name'"); - } - } - - public function testFailsSayWithNoNameParameter2() - { - $tropo = new Tropo(); - try{ - $say = new Say("Please enter your account number...", null, null, null, null, "", null, null); - $tropo->say($say); - } catch (Exception $e) { - $this->assertEquals($e->getMessage(), "Missing required property: 'name'"); - } - } - public function testFailsSayWithNoValueParameter4() { $tropo = new Tropo(); @@ -99,37 +77,5 @@ public function testFailsSayWithNoValueParameter5() $this->assertEquals($e->getMessage(), "Argument 1 passed to Tropo::say() must be a string or an instance of Say."); } } - - public function testFailsSayWithNoNameParameter3() - { - $tropo = new Tropo(); - try{ - $tropo->say("Please enter your account number..."); - } catch (Exception $e) { - $this->assertEquals($e->getMessage(), "When Argument 1 passed to Tropo::say() is a string, argument 2 passed to Tropo::say() must be of the type array."); - } - } - - public function testFailsSayWithNoNameParameter4() - { - $tropo = new Tropo(); - $params = array("name"=>null); - try{ - $tropo->say("Please enter your account number...",$params); - } catch (Exception $e) { - $this->assertEquals($e->getMessage(), "Required property: 'name' must be a string."); - } - } - - public function testFailsSayWithNoNameParameter5() - { - $tropo = new Tropo(); - $params = array("name"=>""); - try{ - $tropo->say("Please enter your account number...",$params); - } catch (Exception $e) { - $this->assertEquals($e->getMessage(), "Required property: 'name' must be a string."); - } - } } ?> \ No newline at end of file diff --git a/tests/TransferTest.php b/tests/TransferTest.php index 9040982..199b881 100644 --- a/tests/TransferTest.php +++ b/tests/TransferTest.php @@ -7,76 +7,65 @@ class TransferTest extends PHPUnit_Framework_TestCase public function testTransferWithMinOptions() { $tropo = new Tropo(); - $params = array( - 'name' => 'foo' - ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678"}}]}'); } public function testTransferWithMinOptions1() { $tropo = new Tropo(); - $params = array( - 'name' => 'foo' - ); $tropo->transfer(array("sip:pengxli@172.16.72.131:5678", "sip:pengxli@192.168.26.1:5678"), $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":["sip:pengxli@172.16.72.131:5678","sip:pengxli@192.168.26.1:5678"],"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":["sip:pengxli@172.16.72.131:5678","sip:pengxli@192.168.26.1:5678"]}}]}'); } public function testTransferWithChoicesOptions() { $tropo = new Tropo(); $choices = new Choices(null, null, "#"); $params = array( - 'name' => 'foo', 'choices' => $choices, ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"#"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"#"}}}]}'); } public function testTransferWithChoicesOptions1() { $tropo = new Tropo(); $params = array( - 'name' => 'foo', 'choices' => '#', ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"#"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"#"}}}]}'); } public function testTransferWithChoicesAndTerminatorOptions() { $tropo = new Tropo(); $choices = new Choices(null, null, "#"); $params = array( - 'name' => 'foo', 'choices' => $choices, 'terminator' => '*', ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"*"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"*"}}}]}'); } public function testTransferWithChoicesAndTerminatorOptions1() { $tropo = new Tropo(); $params = array( - 'name' => 'foo', 'choices' => '#', 'terminator' => '*', ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"*"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","choices":{"terminator":"*"}}}]}'); } public function testTransferWithOnOptions() { $tropo = new Tropo(); $on = new On("ring", null, new Say("http://www.phono.com/audio/holdmusic.mp3")); $params = array( - 'name' => 'foo', 'ringRepeat' => 2, 'on' => $on, ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","ringRepeat":2,"on":{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","ringRepeat":2,"on":{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}}}}]}'); } public function testTransferWithAllOptions() { @@ -96,7 +85,6 @@ public function testTransferWithAllOptions() { 'from' => '14155551212', 'timeout' => 30.0, 'answerOnMedia' => false, - 'name' => 'foo', 'required' => true, 'allowSignals' => $allowSignals, 'machineDetection' => false, @@ -112,7 +100,7 @@ public function testTransferWithAllOptions() { 'label' => 'transferLabel' ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":false,"voice":"allison","name":"foo","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":false,"voice":"allison","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); } public function testTransferWithAllOptions1() { @@ -132,7 +120,6 @@ public function testTransferWithAllOptions1() { 'from' => '14155551212', 'timeout' => 30.0, 'answerOnMedia' => false, - 'name' => 'foo', 'required' => true, 'allowSignals' => $allowSignals, 'machineDetection' => 'For the most accurate results, the "introduction" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.', @@ -148,38 +135,38 @@ public function testTransferWithAllOptions1() { 'label' => 'transferLabel' ); $tropo->transfer("sip:pengxli@172.16.72.131:5678", $params); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","name":"foo","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); } public function testCreateMinObject() { $tropo = new Tropo(); - $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", null, null, null, null, null, null, null, null, null, null, "foo"); + $transfer = new Transfer("sip:pengxli@172.16.72.131:5678"); $tropo->transfer($transfer); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678"}}]}'); } public function testCreateObject() { $tropo = new Tropo(); - $transfer = new Transfer(array("sip:pengxli@172.16.72.131:5678", "sip:pengxli@192.168.26.1:5678"), null, null, null, null, null, null, null, null, null, null, "foo"); + $transfer = new Transfer(array("sip:pengxli@172.16.72.131:5678", "sip:pengxli@192.168.26.1:5678")); $tropo->transfer($transfer); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":["sip:pengxli@172.16.72.131:5678","sip:pengxli@192.168.26.1:5678"],"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":["sip:pengxli@172.16.72.131:5678","sip:pengxli@192.168.26.1:5678"]}}]}'); } public function testCreateObject1() { $tropo = new Tropo(); $choices = new Choices(null, null, "#"); - $transfer = new Transfer(array("sip:pengxli@172.16.72.131:5678", "sip:pengxli@192.168.26.1:5678"), null, $choices, null, null, null, null, null, null, null, null, "foo"); + $transfer = new Transfer(array("sip:pengxli@172.16.72.131:5678", "sip:pengxli@192.168.26.1:5678"), null, $choices); $tropo->transfer($transfer); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":["sip:pengxli@172.16.72.131:5678","sip:pengxli@192.168.26.1:5678"],"choices":{"terminator":"#"},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":["sip:pengxli@172.16.72.131:5678","sip:pengxli@192.168.26.1:5678"],"choices":{"terminator":"#"}}}]}'); } public function testCreateObject2() { $tropo = new Tropo(); $on = new On("ring", null, new Say("http://www.phono.com/audio/holdmusic.mp3")); - $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", null, null, null, 2, null, $on, null, null, null, null, "foo"); + $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", null, null, null, 2, null, $on); $tropo->transfer($transfer); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","ringRepeat":2,"on":{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},"name":"foo"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","ringRepeat":2,"on":{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}}}}]}'); } public function testCreateObject3() { @@ -196,9 +183,9 @@ public function testCreateObject3() { $ask = new Ask(3, true, new Choices("[5 DIGITS]", "dtmf", null), null, "ask", true, $say); $onConnect = new On("connect", null, null, null, $ask); $on = array($onRing, $onConnect); - $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", false, $choices, "14155551212", 2, 30.0, $on, $allowSignals, $headers, false, Voice::$US_English_female_allison, "foo", true, 5.0, true, "http://192.168.26.203/result.php", "suppress", "transferLabel"); + $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", false, $choices, "14155551212", 2, 30.0, $on, $allowSignals, $headers, false, Voice::$US_English_female_allison, null, true, 5.0, true, "http://192.168.26.203/result.php", "suppress", "transferLabel"); $tropo->transfer($transfer); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":false,"voice":"allison","name":"foo","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":false,"voice":"allison","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); } public function testCreateObject4() { @@ -216,9 +203,9 @@ public function testCreateObject4() { $ask = new Ask(3, true, new Choices("[5 DIGITS]", "dtmf", null), null, "ask", true, $say); $onConnect = new On("connect", null, null, null, $ask); $on = array($onRing, $onConnect); - $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", false, $choices, "14155551212", 2, 30.0, $on, $allowSignals, $headers, $machineDetection, Voice::$US_English_female_allison, "foo", true, 5.0, true, "http://192.168.26.203/result.php", "suppress", "transferLabel"); + $transfer = new Transfer("sip:pengxli@172.16.72.131:5678", false, $choices, "14155551212", 2, 30.0, $on, $allowSignals, $headers, $machineDetection, Voice::$US_English_female_allison, null, true, 5.0, true, "http://192.168.26.203/result.php", "suppress", "transferLabel"); $tropo->transfer($transfer); - $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","name":"foo","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); + $this->assertEquals(sprintf($tropo), '{"tropo":[{"transfer":{"to":"sip:pengxli@172.16.72.131:5678","answerOnMedia":false,"choices":{"terminator":"#"},"from":"14155551212","ringRepeat":2,"timeout":30,"on":[{"event":"ring","say":{"value":"http://www.phono.com/audio/holdmusic.mp3"}},{"event":"connect","ask":{"attempts":3,"bargein":true,"choices":{"value":"[5 DIGITS]","mode":"dtmf"},"name":"ask","required":true,"say":[{"event":"nomatch","value":"Sorry. Please enter you 5 digit account number again."},{"event":"timeout","value":"Sorry, I did not hear anything."},{"value":"Please enter 5 digit account number."}]}}],"allowSignals":["exit","quit"],"headers":{"foo":"bar","bling":"baz"},"machineDetection":{"introduction":"For the most accurate results, the \"introduction\" should be long enough to give Tropo time to detect a human or machine. The longer the introduction, the more time we have to determine how the call was answered.","voice":"allison"},"voice":"allison","required":true,"interdigitTimeout":5,"playTones":true,"callbackUrl":"http://192.168.26.203/result.php","promptLogSecurity":"suppress","label":"transferLabel"}}]}'); } } diff --git a/tropo.class.php b/tropo.class.php index f85bd30..95329ce 100644 --- a/tropo.class.php +++ b/tropo.class.php @@ -172,9 +172,6 @@ public function call($call, Array $params=NULL) { if(null === $call->getTo()) { throw new Exception("Missing required property: 'to'"); } - if(null === $call->getName()) { - throw new Exception("Missing required property: 'name'"); - } if (is_string($call->getTo()) && ($call->getTo() != '')) { } elseif (is_array($call->getTo())) { foreach ($call->getTo() as $value) { @@ -185,9 +182,6 @@ public function call($call, Array $params=NULL) { } else { throw new Exception("Required property: 'to' must be a string or a string of array."); } - if (!(is_string($call->getName()) && ($call->getName() != ''))) { - throw new Exception("Required property: 'to' must be a string."); - } } elseif (is_array($call) || (is_string($call) && ($call !== ''))) { @@ -207,31 +201,22 @@ public function call($call, Array $params=NULL) { $to = $call; } - if (isset($params) && is_array($params)) { + if (isset($params)) { - if (array_key_exists('name', $params)) { - if (is_string($params["name"]) && ($params["name"] !=='')) { - $name = $params["name"]; - } else { - throw new Exception("'name' must be is a string."); + if (is_array($params)) { + $p = array('from', 'network', 'channel', 'answerOnMedia', 'timeout', 'headers', 'allowSignals', 'machineDetection', 'voice', 'name', 'required', 'callbackUrl', 'promptLogSecurity', 'label'); + foreach ($p as $option) { + $$option = null; + if (array_key_exists($option, $params)) { + $$option = $params[$option]; + } } + $call = new Call($to, $from, $network, $channel, $answerOnMedia, $timeout, $headers, null, $allowSignals, $machineDetection, $voice, $name, $required, $callbackUrl, $promptLogSecurity, $label); } else { - throw new Exception("Missing required property: 'name'"); + throw new Exception("When Argument 1 passed to Tropo::call() is a string, argument 2 passed to Tropo::call() must be of the type array."); } - - $p = array('from', 'network', 'channel', 'answerOnMedia', 'timeout', 'headers', 'allowSignals', 'machineDetection', 'voice', 'required', 'callbackUrl', 'promptLogSecurity', 'label'); - foreach ($p as $option) { - $$option = null; - if (array_key_exists($option, $params)) { - $$option = $params[$option]; - } - } - $call = new Call($to, $from, $network, $channel, $answerOnMedia, $timeout, $headers, null, $allowSignals, $machineDetection, $voice, $name, $required, $callbackUrl, $promptLogSecurity, $label); - } else { - - throw new Exception("When Argument 1 passed to Tropo::call() is a string, argument 2 passed to Tropo::call() must be of the type array."); - + $call = new Call($to); } } else { @@ -255,42 +240,30 @@ public function conference($conference, Array $params=NULL) { if(null === $conference->getId()) { throw new Exception("Missing required property: 'id'"); } - if(null === $conference->getName()) { - throw new Exception("Missing required property: 'name'"); - } - if (!(is_string($conference->getName()) && ($conference->getName() != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } if (!(is_string($conference->getId()) && ($conference->getId() != ''))) { throw new Exception("Required property: 'id' must be a string."); } } elseif (is_string($conference) && ($conference !== '')) { - if (isset($params) && is_array($params)) { + $id = $conference; + if (isset($params)) { - if (array_key_exists('name', $params)) { - if (is_string($params["name"]) && ($params["name"] !=='')) { - $name = $params["name"]; - } else { - throw new Exception("'name' must be is a string."); + if (is_array($params)) { + $p = array('name', 'mute', 'on', 'playTones', 'required', 'terminator', 'allowSignals', 'interdigitTimeout', 'joinPrompt', 'leavePrompt', 'voice', 'promptLogSecurity'); + foreach ($p as $option) { + $$option = null; + if (array_key_exists($option, $params)) { + $$option = $params[$option]; + } } + $conference = new Conference($name, $id, $mute, $on, $playTones, $required, $terminator, $allowSignals, $interdigitTimeout, $joinPrompt, $leavePrompt, $voice, $promptLogSecurity); } else { - throw new Exception("Missing required property: 'name'"); + throw new Exception("When Argument 1 passed to Tropo::conference() is a string, argument 2 passed to Tropo::conference() must be of the type array."); } - - $p = array('name', 'mute', 'on', 'playTones', 'required', 'terminator', 'allowSignals', 'interdigitTimeout', 'joinPrompt', 'leavePrompt', 'voice', 'promptLogSecurity'); - foreach ($p as $option) { - $$option = null; - if (array_key_exists($option, $params)) { - $$option = $params[$option]; - } - } - $id = $conference; - $conference = new Conference($name, $id, $mute, $on, $playTones, $required, $terminator, $allowSignals, $interdigitTimeout, $joinPrompt, $leavePrompt, $voice, $promptLogSecurity); } else { - throw new Exception("When Argument 1 passed to Tropo::conference() is a string, argument 2 passed to Tropo::conference() must be of the type array."); + $conference = new Conference(null, $id); } } else { @@ -326,9 +299,6 @@ public function message($message, Array $params=null) { if(null === $message->getTo()) { throw new Exception("Missing required property: 'to'"); } - if(null === $message->getName()) { - throw new Exception("Missing required property: 'name'"); - } if (is_string($message->getTo()) && ($message->getTo() != '')) { } elseif (is_array($message->getTo())) { foreach ($message->getTo() as $value) { @@ -339,9 +309,6 @@ public function message($message, Array $params=null) { } else { throw new Exception("Required property: 'to' must be a string or a string of array."); } - if(!(is_string($message->getName()) && ($message->getName() != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } } elseif (is_string($message) && ($message!=='')) { if (isset($params) && is_array($params)) { @@ -363,16 +330,6 @@ public function message($message, Array $params=null) { throw new Exception("Missing required property: 'to'"); } - if (array_key_exists('name', $params)) { - if (is_string($params["name"]) && ($params["name"] !=='')) { - $name = $params["name"]; - } else { - throw new Exception("'name' must be is a string."); - } - } else { - throw new Exception("Missing required property: 'name'"); - } - if (array_key_exists('say', $params)) { if (is_array($params["say"])) { $say[] = new Say($message); @@ -391,7 +348,7 @@ public function message($message, Array $params=null) { $say = new Say($message); } - $p = array('channel', 'network', 'from', 'voice', 'timeout', 'answerOnMedia','headers','required','promptLogSecurity'); + $p = array('channel', 'network', 'from', 'voice', 'timeout', 'answerOnMedia','headers','name','required','promptLogSecurity'); foreach ($p as $option) { $$option = null; if (is_array($params) && array_key_exists($option, $params)) { @@ -513,15 +470,9 @@ public function record($record) { if(null === $record->getUrl()) { throw new Exception("Missing required property: 'url'"); } - if(null === $record->getName()) { - throw new Exception("Missing required property: 'name'"); - } // if (!(is_string($record->getUrl()) && ($record->getUrl() != ''))) { // throw new Exception("Required property: 'url' must be a string."); // } - if (!(is_string($record->getName()) && ($record->getName() != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } } elseif (is_array($record)) { @@ -529,15 +480,9 @@ public function record($record) { if (!array_key_exists('url', $params)) { throw new Exception("Missing required property: 'url'"); } - if (!array_key_exists('name', $params)) { - throw new Exception("Missing required property: 'name'"); - } // if (!(is_string($params['url']) && ($params['url'] != ''))) { // throw new Exception("Required property: 'url' must be a string."); // } - if (!(is_string($params['name']) && ($params['name'] != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } $p = array('voice', 'emailFormat', 'transcription', 'terminator'); foreach ($p as $option) { $params[$option] = array_key_exists($option, $params) ? $params[$option] : null; @@ -613,40 +558,31 @@ public function redirect($redirect, Array $params=NULL) { if(null === $redirect->getTo()) { throw new Exception("Missing required property: 'to'"); } - if(null === $redirect->getName()) { - throw new Exception("Missing required property: 'name'"); - } if (!(is_string($redirect->getTo()) && ($redirect->getTo() != ''))) { throw new Exception("Required property: 'to' must be a string."); } - if (!(is_string($redirect->getName()) && ($redirect->getName() != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } } elseif (is_string($redirect) && ($redirect !== '')) { - if (isset($params) && is_array($params)) { + if (isset($params)) { - if (array_key_exists('name', $params)) { - if (is_string($params["name"]) && ($params["name"] !=='')) { + if (is_array($params)) { + $required = null; + if (array_key_exists('required', $params)) { + $required = $params["required"]; + } + $name = null; + if (array_key_exists('name', $params)) { $name = $params["name"]; - } else { - throw new Exception("'name' must be is a string."); } - } else { - throw new Exception("Missing required property: 'name'"); - } - $required = null; - if (array_key_exists('required', $params)) { - $required = $params["required"]; + $redirect = new Redirect($redirect, null, $name, $required); + } else { + throw new Exception("When Argument 1 passed to Tropo::redirect() is a string, argument 2 passed to Tropo::redirect() must be of the type array."); } - - $redirect = new Redirect($redirect, null, $name, $required); - } else { - throw new Exception("When Argument 1 passed to Tropo::redirect() is a string, argument 2 passed to Tropo::redirect() must be of the type array."); + $redirect = new Redirect($redirect); } @@ -685,33 +621,18 @@ public function say($say, Array $params=NULL) { throw new Exception("Missing required property: 'value'"); - } - if(!(is_string($say->getName()) && ($say->getName() != ''))) { - - throw new Exception("Missing required property: 'name'"); - } $say->setEvent(null); } elseif (is_string($say) && ($say != '')) { - if (isset($params) && is_array($params)) { - - if (array_key_exists('name', $params)) { + $value = $say; - if (is_string($params['name']) && ($params['name'] != '')) { + if (isset($params)) { - $name = $params['name']; - - } else { - - throw new Exception("Required property: 'name' must be a string."); - - } - - $p = array('as', 'event','voice', 'allowSignals', 'required', 'promptLogSecurity'); - $value = $say; + if (is_array($params)) { + $p = array('as', 'event','voice', 'allowSignals', 'name', 'required', 'promptLogSecurity'); foreach ($p as $option) { $$option = null; if (array_key_exists($option, $params)) { @@ -721,16 +642,12 @@ public function say($say, Array $params=NULL) { $voice = isset($voice) ? $voice : $this->_voice; $event = null; $say = new Say($value, $as, $event, $voice, $allowSignals, $name, $required, $promptLogSecurity); - } else { - - throw new Exception("Missing required property: 'name'"); - + throw new Exception("When Argument 1 passed to Tropo::say() is a string, argument 2 passed to Tropo::say() must be of the type array."); } - } else { - throw new Exception("When Argument 1 passed to Tropo::say() is a string, argument 2 passed to Tropo::say() must be of the type array."); + $say = new Say($value); } } else { @@ -809,9 +726,6 @@ public function transfer($transfer, Array $params=NULL) { if(null === $transfer->getTo()) { throw new Exception("Missing required property: 'to'"); } - if(null === $transfer->getName()) { - throw new Exception("Missing required property: 'name'"); - } if (is_string($transfer->getTo()) && ($transfer->getTo() != '')) { } elseif (is_array($transfer->getTo())) { foreach ($transfer->getTo() as $value) { @@ -822,9 +736,6 @@ public function transfer($transfer, Array $params=NULL) { } else { throw new Exception("Required property: 'to' must be a string or a string of array."); } - if (!(is_string($transfer->getName()) && ($transfer->getName() != ''))) { - throw new Exception("Required property: 'to' must be a string."); - } } elseif (is_array($transfer) || (is_string($transfer) && ($transfer !== ''))) {//$transfer is a non-empty string or a non-empty string of array @@ -844,67 +755,61 @@ public function transfer($transfer, Array $params=NULL) { $to = $transfer; } - if (isset($params) && is_array($params)) { + if (isset($params)) { - if (array_key_exists('name', $params)) { - if (is_string($params["name"]) && ($params["name"] !=='')) { - $name = $params["name"]; - } else { - throw new Exception("'name' must be is a string."); - } - } else { - throw new Exception("Missing required property: 'name'"); - } - - $choices = null; - if (array_key_exists('choices', $params)) { + if (is_array($params)) { + $choices = null; + if (array_key_exists('choices', $params)) { - if ($params["choices"] instanceof Choices) { - $choices = $params["choices"]; - } elseif (is_string($params["choices"]) && ($params["choices"] !== '')) { - $choices = new Choices(null, null, $params["choices"]); - } else { - $choices = null; + if ($params["choices"] instanceof Choices) { + $choices = $params["choices"]; + } elseif (is_string($params["choices"]) && ($params["choices"] !== '')) { + $choices = new Choices(null, null, $params["choices"]); + } else { + $choices = null; + } } - } - if (array_key_exists('terminator', $params)) { - if (is_string($params["terminator"]) && ($params["terminator"] !== '')) { - $choices = new Choices(null, null, $params["terminator"]); - } - } - - $p = array('answerOnMedia', 'ringRepeat', 'timeout', 'from', 'allowSignals', 'headers', 'machineDetection', 'voice', 'required', 'interdigitTimeout', 'playTones', 'callbackUrl', 'promptLogSecurity', 'label'); - foreach ($p as $option) { - $$option = null; - if (array_key_exists($option, $params)) { - $$option = $params[$option]; + if (array_key_exists('terminator', $params)) { + if (is_string($params["terminator"]) && ($params["terminator"] !== '')) { + $choices = new Choices(null, null, $params["terminator"]); + } } - } - $on = null; - if (array_key_exists('on', $params)) { - if ($params['on'] instanceof On) { - if (is_string($params['on']->getEvent()) && ((strtolower($params['on']->getEvent()) == 'ring') || (strtolower($params['on']->getEvent()) == 'connect'))) { - $on = $params['on']; - } else { - throw new TropoException("The only event allowed on transfer is 'ring' or 'connect'"); + + $p = array('answerOnMedia', 'ringRepeat', 'timeout', 'from', 'allowSignals', 'headers', 'machineDetection', 'voice', 'name', 'required', 'interdigitTimeout', 'playTones', 'callbackUrl', 'promptLogSecurity', 'label'); + foreach ($p as $option) { + $$option = null; + if (array_key_exists($option, $params)) { + $$option = $params[$option]; } - } elseif (is_array($params['on'])) { - foreach ($params['on'] as $value) { - if ($value instanceof On) { - if (is_string($value->getEvent()) && ((strtolower($value->getEvent()) == 'ring') || (strtolower($value->getEvent()) == 'connect'))) { - $on[] = $value; - } else { - throw new TropoException("The only event allowed on transfer is 'ring' or 'connect'"); + } + $on = null; + if (array_key_exists('on', $params)) { + if ($params['on'] instanceof On) { + if (is_string($params['on']->getEvent()) && ((strtolower($params['on']->getEvent()) == 'ring') || (strtolower($params['on']->getEvent()) == 'connect'))) { + $on = $params['on']; + } else { + throw new TropoException("The only event allowed on transfer is 'ring' or 'connect'"); + } + } elseif (is_array($params['on'])) { + foreach ($params['on'] as $value) { + if ($value instanceof On) { + if (is_string($value->getEvent()) && ((strtolower($value->getEvent()) == 'ring') || (strtolower($value->getEvent()) == 'connect'))) { + $on[] = $value; + } else { + throw new TropoException("The only event allowed on transfer is 'ring' or 'connect'"); + } } } } } + $transfer = new Transfer($to, $answerOnMedia, $choices, $from, $ringRepeat, $timeout, $on, $allowSignals, $headers, $machineDetection, $voice, $name, $required, $interdigitTimeout, $playTones, $callbackUrl, $promptLogSecurity, $label); + } else { + throw new Exception("When Argument 1 passed to Tropo::transfer() is a string or a string of array, argument 2 passed to Tropo::transfer() must be of the type array."); } - $transfer = new Transfer($to, $answerOnMedia, $choices, $from, $ringRepeat, $timeout, $on, $allowSignals, $headers, $machineDetection, $voice, $name, $required, $interdigitTimeout, $playTones, $callbackUrl, $promptLogSecurity, $label); } else { - throw new Exception("When Argument 1 passed to Tropo::transfer() is a string or a string of array, argument 2 passed to Tropo::transfer() must be of the type array."); + $transfer = new Transfer($to); } @@ -1455,13 +1360,10 @@ public function getName() { * @param StartRecording $recording * @param string|array $allowSignals */ - public function __construct($to, $from=NULL, $network=NULL, $channel=NULL, $answerOnMedia=NULL, $timeout=NULL, Array $headers=NULL, StartRecording $recording=NULL, $allowSignals=NULL, $machineDetection=NULL, $voice=NULL, $name, $required=NULL, $callbackUrl=NULL, $promptLogSecurity=NULL, $label=NULL) { + public function __construct($to, $from=NULL, $network=NULL, $channel=NULL, $answerOnMedia=NULL, $timeout=NULL, Array $headers=NULL, StartRecording $recording=NULL, $allowSignals=NULL, $machineDetection=NULL, $voice=NULL, $name=NULL, $required=NULL, $callbackUrl=NULL, $promptLogSecurity=NULL, $label=NULL) { if(!isset($to)) { throw new Exception("Missing required property: 'to'"); } - if(!isset($name)) { - throw new Exception("Missing required property: 'name'"); - } if (is_string($to) && ($to != '')) { } elseif (is_array($to)) { foreach ($to as $value) { @@ -1472,9 +1374,6 @@ public function __construct($to, $from=NULL, $network=NULL, $channel=NULL, $answ } else { throw new Exception("Required property: 'to' must be a string or a string of array."); } - if (!(is_string($name) && ($name != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } $this->_to = $to; $this->_from = $from; $this->_network = $network; @@ -1516,7 +1415,7 @@ public function __toString() { } } if(isset($this->_voice)) { $this->voice = $this->_voice; } - $this->name = $this->_name; + if(isset($this->_name)) { $this->name = $this->_name; } if(isset($this->_required)) { $this->required = $this->_required; } if(isset($this->_callbackUrl)) { $this->callbackUrl = $this->_callbackUrl; } if(isset($this->_promptLogSecurity)) { $this->promptLogSecurity = $this->_promptLogSecurity; } @@ -1616,16 +1515,10 @@ public function getId() { * @param string|array $allowSignals * @param int $interdigitTimeout */ - public function __construct($name, $id, $mute=NULL, On $on=NULL, $playTones=NULL, $required=NULL, $terminator=NULL, $allowSignals=NULL, $interdigitTimeout=NULL, $joinPrompt=NULL, $leavePrompt=NULL, $voice=NULL, $promptLogSecurity=NULL) { - if(!isset($name)) { - throw new Exception("Missing required property: 'name'"); - } + public function __construct($name=NULL, $id, $mute=NULL, On $on=NULL, $playTones=NULL, $required=NULL, $terminator=NULL, $allowSignals=NULL, $interdigitTimeout=NULL, $joinPrompt=NULL, $leavePrompt=NULL, $voice=NULL, $promptLogSecurity=NULL) { if(!isset($id)) { throw new Exception("Missing required property: 'id'"); } - if (!(is_string($name) && ($name != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } if (!(is_string($id) && ($id != ''))) { throw new Exception("Required property: 'id' must be a string."); } @@ -1647,7 +1540,7 @@ public function __construct($name, $id, $mute=NULL, On $on=NULL, $playTones=NULL * */ public function __toString() { - $this->name = $this->_name; + if(isset($this->_name)) { $this->name = $this->_name; } $this->id = $this->_id; if(isset($this->_mute)) { $this->mute = $this->_mute; } if(isset($this->_playTones)) { $this->playTones = $this->_playTones; } @@ -1733,16 +1626,13 @@ public function getName() { * @param array $headers */ // Say $say, $to, $channel=null, $network=null, $from=null, $voice=null, $timeout=null, $answerOnMedia=null, Array $headers=null - public function __construct($say, $to, $channel=null, $network=null, $from=null, $voice=null, $timeout=null, $answerOnMedia=null, Array $headers=null, $name, $required=null, $promptLogSecurity=null) { + public function __construct($say, $to, $channel=null, $network=null, $from=null, $voice=null, $timeout=null, $answerOnMedia=null, Array $headers=null, $name=null, $required=null, $promptLogSecurity=null) { if(!isset($say)) { throw new Exception("Missing required property: 'say'"); } if(!isset($to)) { throw new Exception("Missing required property: 'to'"); } - if(!isset($name)) { - throw new Exception("Missing required property: 'name'"); - } if ($say instanceof Say) { $this->_say = sprintf('%s', $say); } elseif (is_array($say)) { @@ -1771,11 +1661,7 @@ public function __construct($say, $to, $channel=null, $network=null, $from=null, } else { throw new Exception("Required property: 'to' must be a string or a string of array."); } - if (is_string($name) && ($name != '')) { - $this->_name = $name; - } else { - throw new Exception("Required property: 'name' must be a string."); - } + $this->_name = $name; $this->_channel = $channel; $this->_network = $network; $this->_from = $from; @@ -1794,7 +1680,7 @@ public function __construct($say, $to, $channel=null, $network=null, $from=null, public function __toString() { if(isset($this->_say)) { $this->say = json_decode($this->_say); } $this->to = $this->_to; - $this->name = $this->_name; + if(isset($this->_name)) { $this->name = $this->_name; } if(isset($this->_channel)) { $this->channel = $this->_channel; } if(isset($this->_network)) { $this->network = $this->_network; } if(isset($this->_from)) { $this->from = $this->_from; } @@ -1941,13 +1827,10 @@ public function getName() { * @param int $minConfidence * @param int $interdigitTimeout */ - public function __construct($attempts=NULL, $allowSignals=NULL, $bargein=NULL, $beep=NULL, Choices $choices=NULL, $format=NULL, $maxSilence=NULL, $maxTime=NULL, $method=NULL, $password=NULL, $required=NULL, $say=NULL, $timeout=NULL, Transcription $transcription=NULL, $username=NULL, $url, $voice=NULL, $minConfidence=NULL, $interdigitTimeout=NULL, $asyncUpload=NULL, $name, $promptLogSecurity=NULL, $sensitivity=NULL) { + public function __construct($attempts=NULL, $allowSignals=NULL, $bargein=NULL, $beep=NULL, Choices $choices=NULL, $format=NULL, $maxSilence=NULL, $maxTime=NULL, $method=NULL, $password=NULL, $required=NULL, $say=NULL, $timeout=NULL, Transcription $transcription=NULL, $username=NULL, $url, $voice=NULL, $minConfidence=NULL, $interdigitTimeout=NULL, $asyncUpload=NULL, $name=NULL, $promptLogSecurity=NULL, $sensitivity=NULL) { if(!isset($url)) { throw new Exception("Missing required property: 'url'"); } - if(!isset($name)) { - throw new Exception("Missing required property: 'name'"); - } if (is_string($url) && ($url != '')) { $this->_url = sprintf('%s', new Url($url, $username, $password, $method)); } else if ($url instanceof Url) { @@ -1966,9 +1849,6 @@ public function __construct($attempts=NULL, $allowSignals=NULL, $bargein=NULL, $ } else { throw new Exception("Property: 'url' must be a valid string, an instance of Url or an array of Urls."); } - if (!(is_string($name) && ($name != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } $this->_attempts = $attempts; $this->_allowSignals = $allowSignals; $this->_bargein = $bargein; @@ -2066,21 +1946,15 @@ public function getName() { * @param Endpoint $to * @param Endpoint $from */ - public function __construct($to, $from=NULL, $name, $required) { + public function __construct($to, $from=NULL, $name=NULL, $required) { if(!isset($to)) { throw new Exception("Missing required property: 'to'"); } - if(!isset($name)) { - throw new Exception("Missing required property: 'name'"); - } if (!(is_string($to) && ($to != ''))) { throw new Exception("Required property: 'to' must be a string."); } - if (!(is_string($name) && ($name != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } $this->_to = sprintf('%s', $to); - $this->_name = sprintf('%s', $name); + $this->_name = $name; $this->_required = $required; } @@ -2090,7 +1964,7 @@ public function __construct($to, $from=NULL, $name, $required) { */ public function __toString() { $this->to = $this->_to; - $this->name = $this->_name; + if(isset($this->_name)) { $this->name = $this->_name; } if(isset($this->_required)) { $this->required = $this->_required; } return json_encode($this); } @@ -2767,13 +2641,10 @@ public function getName() { * @param string|array $allowSignals * @param array $headers */ - public function __construct($to, $answerOnMedia=NULL, Choices $choices=NULL, $from=NULL, $ringRepeat=NULL, $timeout=NULL, $on=NULL, $allowSignals=NULL, Array $headers=NULL, $machineDetection=NULL, $voice=NULL, $name, $required=NULL, $interdigitTimeout=NULL, $playTones=NULL, $callbackUrl=NULL, $promptLogSecurity=NULL, $label=NULL) { + public function __construct($to, $answerOnMedia=NULL, Choices $choices=NULL, $from=NULL, $ringRepeat=NULL, $timeout=NULL, $on=NULL, $allowSignals=NULL, Array $headers=NULL, $machineDetection=NULL, $voice=NULL, $name=NULL, $required=NULL, $interdigitTimeout=NULL, $playTones=NULL, $callbackUrl=NULL, $promptLogSecurity=NULL, $label=NULL) { if(!isset($to)) { throw new Exception("Missing required property: 'to'"); } - if(!isset($name)) { - throw new Exception("Missing required property: 'name'"); - } if (is_string($to) && ($to != '')) { } elseif (is_array($to)) { foreach ($to as $value) { @@ -2784,9 +2655,6 @@ public function __construct($to, $answerOnMedia=NULL, Choices $choices=NULL, $fr } else { throw new Exception("Required property: 'to' must be a string or a string of array."); } - if (!(is_string($name) && ($name != ''))) { - throw new Exception("Required property: 'name' must be a string."); - } $this->_to = $to; $this->_answerOnMedia = $answerOnMedia; $this->_choices = isset($choices) ? sprintf('%s', $choices) : null; @@ -2850,7 +2718,7 @@ public function __toString() { } } if(isset($this->_voice)) { $this->voice = $this->_voice; } - $this->name = $this->_name; + if(isset($this->_name)) { $this->name = $this->_name; } if(isset($this->_required)) { $this->required = $this->_required; } if(isset($this->_interdigitTimeout)) { $this->interdigitTimeout = $this->_interdigitTimeout; } if(isset($this->_playTones)) { $this->playTones = $this->_playTones; }