-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,088 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Viber\Api; | ||
|
||
/** | ||
* Api entity interface | ||
* | ||
* @author Novikov Bogdan <[email protected]> | ||
*/ | ||
class Entity | ||
{ | ||
/** | ||
* Map api-response keys to class setters | ||
* | ||
* @var array | ||
*/ | ||
protected $propertiesMap = []; | ||
|
||
/** | ||
* Make new instance from api response array | ||
* | ||
* @param mixed $properties list of properties | ||
*/ | ||
public function __construct($properties = null) | ||
{ | ||
if (is_null($properties)) { | ||
return; | ||
} | ||
if (!is_array($properties) && !$properties instanceof ArrayAccess) { | ||
throw new ApiException('Properties must be an array or implement ArrayAccess'); | ||
} | ||
// call setters | ||
foreach ($properties as $apiProp => $apiValue) { | ||
if (isset($this->propertiesMap[$apiProp])) { | ||
$setterName = $this->propertiesMap[$apiProp]; | ||
$this->$setterName($apiValue); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Build array single-level array | ||
* | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* Build multi-level array for api call`s, filter or upgrade properties | ||
* | ||
* @return array | ||
*/ | ||
public function toApiArray() | ||
{ | ||
$entity = $this->toArray(); | ||
foreach ($entity as $name => &$value) { | ||
if (is_null($value)) { | ||
unset($entity[$name]); | ||
} else if ($value instanceof Entity) { | ||
$value = $value->toArray(); | ||
} | ||
} | ||
return $entity; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Viber\Api\Event; | ||
|
||
use Viber\Api\Exception\ApiException; | ||
|
||
/** | ||
* Event factory | ||
* | ||
* @author Novikov Bogdan <[email protected]> | ||
*/ | ||
class Factory | ||
{ | ||
/** | ||
* Make some event from api-request array | ||
* | ||
* @param array $data api request data | ||
* @return \Viber\Api\Event | ||
*/ | ||
public static function makeFromApi(array $data) | ||
{ | ||
if (isset($data['event'])) { | ||
switch ($data['event']) { | ||
case Type::MESSAGE: | ||
return new Message($data); | ||
case Type::SUBSCRIBED: | ||
return new Subscribed($data); | ||
case Type::CONVERSATION: | ||
return new Conversation($data); | ||
case Type::UNSUBSCRIBED: | ||
return new Unsubscribed($data); | ||
case Type::DELIVERED: | ||
return new Delivered($data); | ||
case Type::SEEN: | ||
return new Seen($data); | ||
case Type::FAILED: | ||
return new Failed($data); | ||
} | ||
} | ||
throw new ApiException('Unknow event data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,9 +44,4 @@ public function getMessage() | |
{ | ||
return $this->message; | ||
} | ||
|
||
public function getMessageText() | ||
{ | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Viber\Api\Event; | ||
|
||
/** | ||
* Available event types | ||
* | ||
* @author Novikov Bogdan <[email protected]> | ||
*/ | ||
interface Type | ||
{ | ||
const DELIVERED = 'delivered'; | ||
const SEEN = 'seen'; | ||
const FAILED = 'failed'; | ||
const SUBSCRIBED = 'subscribed'; | ||
const UNSUBSCRIBED = 'unsubscribed'; | ||
const CONVERSATION = 'conversation_started'; | ||
const MESSAGE = 'message'; | ||
} |
2 changes: 1 addition & 1 deletion
2
src/Api/Core/ApiException.php → src/Api/Exception/ApiException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace Viber\Api\Core; | ||
namespace Viber\Api\Exception; | ||
|
||
/** | ||
* Remote api error (api-level exception) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace Viber\Api; | ||
|
||
use Viber\Api\Core\Entity; | ||
use Viber\Api\Entity; | ||
|
||
/** | ||
* Message keyboard | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
namespace Viber\Api\Keyboard; | ||
|
||
use Viber\Api\Core\Entity; | ||
use Viber\Api\Entity; | ||
|
||
/** | ||
* Keyboard button | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,19 @@ | |
|
||
namespace Viber\Api; | ||
|
||
use Viber\Api\Core\Entity; | ||
use Viber\Api\Entity; | ||
|
||
/** | ||
* Viber general message object | ||
* General message object | ||
* | ||
* @author Novikov Bogdan <[email protected]> | ||
*/ | ||
class Message extends Entity | ||
{ | ||
/** | ||
* Viber user | ||
* Viber user id | ||
* | ||
* @var \Viber\Api\User | ||
* @var integer | ||
*/ | ||
protected $receiver; | ||
|
||
|
@@ -71,7 +71,7 @@ public function toArray() | |
/** | ||
* Get the value of Viber user | ||
* | ||
* @return \Viber\Api\User | ||
* @return string | ||
*/ | ||
public function getReceiver() | ||
{ | ||
|
@@ -81,11 +81,11 @@ public function getReceiver() | |
/** | ||
* Set the value of Viber user | ||
* | ||
* @param \Viber\Api\User receiver | ||
* @param string receiver | ||
* | ||
* @return self | ||
*/ | ||
public function setReceiver(\Viber\Api\User $receiver) | ||
public function setReceiver($receiver) | ||
{ | ||
$this->receiver = $receiver; | ||
|
||
|
@@ -102,20 +102,6 @@ public function getType() | |
return $this->type; | ||
} | ||
|
||
/** | ||
* Set the value of Message type | ||
* | ||
* @param string type | ||
* | ||
* @return self | ||
*/ | ||
public function setType($type) | ||
{ | ||
$this->type = $type; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the value of Sender information | ||
* | ||
|
Oops, something went wrong.