Skip to content

Commit 372efcb

Browse files
committed
Application Support
- Moving towards collection based naming: `$client->applications()` - New REST based APIs and configruation resources (applications / numbers) show: - Entities should not use requests / responses as data sources. - Exceptions should also be given the request / response directly. - Missing some test coverage of: - Fluent interface - Route based Auth selection - Need to better segment tests: - Of trait related code (test in simple container, use trait to test common entity features) - Of configuration objects (VoiceConfig, etc).
1 parent 15132e4 commit 372efcb

26 files changed

+1393
-166
lines changed

src/Account/Application/Application.php

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/Application/Application.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Nexmo Client Library for PHP
4+
*
5+
* @copyright Copyright (c) 2016 Nexmo, Inc. (http://nexmo.com)
6+
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
7+
*/
8+
9+
namespace Nexmo\Application;
10+
11+
12+
use Nexmo\Entity\JsonUnserializableInterface;
13+
use Nexmo\Entity\EntityInterface;
14+
use Nexmo\Entity\JsonResponseTrait;
15+
use Nexmo\Entity\JsonSerializableTrait;
16+
use Nexmo\Entity\Psr7Trait;
17+
18+
class Application implements EntityInterface, \JsonSerializable, JsonUnserializableInterface
19+
{
20+
use JsonSerializableTrait;
21+
use Psr7Trait;
22+
use JsonResponseTrait;
23+
24+
protected $voiceConfig;
25+
26+
protected $name;
27+
28+
protected $keys = [];
29+
30+
protected $id;
31+
32+
public function __construct($id = null)
33+
{
34+
$this->id = $id;
35+
}
36+
37+
public function getId()
38+
{
39+
return $this->id;
40+
}
41+
42+
public function setVoiceConfig(VoiceConfig $config)
43+
{
44+
$this->voiceConfig = $config;
45+
return $this;
46+
}
47+
48+
/**
49+
* @return VoiceConfig
50+
*/
51+
public function getVoiceConfig()
52+
{
53+
if(!isset($this->voiceConfig)){
54+
$this->setVoiceConfig(new VoiceConfig());
55+
$data = $this->getResponseData();
56+
if(isset($data['voice']) AND isset($data['voice']['webhooks'])){
57+
foreach($data['voice']['webhooks'] as $webhook){
58+
$this->voiceConfig->setWebhook($webhook['endpoint_type'], $webhook['endpoint'], $webhook['http_method']);
59+
}
60+
}
61+
}
62+
63+
return $this->voiceConfig;
64+
}
65+
66+
public function getPublicKey()
67+
{
68+
if(isset($this->keys['public_key'])){
69+
return $this->keys['public_key'];
70+
}
71+
}
72+
73+
public function getPrivateKey()
74+
{
75+
if(isset($this->keys['private_key'])){
76+
return $this->keys['private_key'];
77+
}
78+
}
79+
80+
public function setName($name)
81+
{
82+
$this->name = $name;
83+
return $this;
84+
}
85+
86+
public function getName()
87+
{
88+
return $this->name;
89+
}
90+
91+
public function jsonUnserialize(array $json)
92+
{
93+
$this->name = $json['name'];
94+
$this->id = $json['id'];
95+
$this->keys = $json['keys'];
96+
97+
//todo: make voice hydrate-able
98+
$this->voiceConfig = new VoiceConfig();
99+
if(isset($json['voice']) AND isset($json['voice']['webhooks'])){
100+
foreach($json['voice']['webhooks'] as $webhook){
101+
$this->voiceConfig->setWebhook($webhook['endpoint_type'], new Webhook($webhook['endpoint'], $webhook['http_method']));
102+
}
103+
}
104+
}
105+
106+
public function jsonSerialize()
107+
{
108+
return [
109+
'name' => $this->getName(),
110+
//currently, the request data does not match the response data
111+
'event_url' => (string) $this->getVoiceConfig()->getWebhook(VoiceConfig::EVENT),
112+
'answer_url' => (string) $this->getVoiceConfig()->getWebhook(VoiceConfig::ANSWER),
113+
'type' => 'voice' //currently the only type
114+
];
115+
}
116+
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
* @license https://github.com/Nexmo/nexmo-php/blob/master/LICENSE.txt MIT License
77
*/
88

9-
namespace Nexmo\Account\Application;
9+
namespace Nexmo\Application;
1010

11+
use Nexmo\Entity\EntityInterface;
1112

12-
use Nexmo\Client\ClientAwareInterface;
13-
use Nexmo\Client\ClientAwareTrait;
14-
15-
class Client implements ClientAwareInterface
13+
interface ApplicationInterface extends EntityInterface
1614
{
17-
use ClientAwareTrait;
15+
public function getId();
1816
}

0 commit comments

Comments
 (0)