Skip to content

Commit

Permalink
Add NCCO parameter support for PHP
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Apr 12, 2019
1 parent 29f6856 commit 08d01cd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Call/Call.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ public function setTimeout($type, $length)
$this->data[$type . '_timeout'] = $length;
}

public function setNcco($ncco) {
$this->data['ncco'] = $ncco;
return $this;
}

public function getStatus()
{
if($this->lazyLoad()){
Expand Down
59 changes: 59 additions & 0 deletions test/Call/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ public function testCreatePostCall($payload, $method)
$this->assertInstanceOf('Nexmo\Call\Call', $call);
$this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId());
}

/**
* @dataProvider postCallNcco
*/
public function testCreatePostCallNcco($payload)
{
$this->nexmoClient->send(Argument::that(function(RequestInterface $request) use ($payload){
$ncco = [['action' => 'talk', 'text' => 'Hello World']];

$this->assertRequestUrl('api.nexmo.com', '/v1/calls', 'POST', $request);
$this->assertRequestBodyIsJson(json_encode($payload), $request);
$this->assertRequestJsonBodyContains('ncco', $ncco, $request);
return true;
}))->willReturn($this->getResponse('created', '201'));

$call = $this->collection->post($payload);

$this->assertInstanceOf('Nexmo\Call\Call', $call);
$this->assertEquals('e46fd8bd-504d-4044-9600-26dd18b41111', $call->getId());
}

/**
* @dataProvider postCall
Expand Down Expand Up @@ -228,6 +248,45 @@ public function getCall()
];
}

/**
* Creating a call with an NCCO can take a Call object or a simple array.
* @return array
*/
public function postCallNcco()
{
$raw = [
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'ncco' => [
[
'action' => 'talk',
'text' => 'Hello World'
]
]
];


$call = new Call();
$call->setTo('14843331234')
->setFrom('14843335555')
->setNcco([
[
'action' => 'talk',
'text' => 'Hello World'
]
]);

return [
'object' => [clone $call],
'array' => [$raw]
];
}
/**
* Creating a call can take a Call object or a simple array.
* @return array
Expand Down

0 comments on commit 08d01cd

Please sign in to comment.