From 5dbd74e4454d2351027d3df0e379a5caf0166019 Mon Sep 17 00:00:00 2001 From: Edson Alves Date: Wed, 12 Aug 2020 09:50:03 -0300 Subject: [PATCH] add new routes --- src/Actions.php | 11 +++ src/Api.php | 106 ++++++++++----------------- src/Objects/Department.php | 15 ++++ src/Objects/Group.php | 15 ++++ src/Objects/Organization.php | 15 ++++ src/Objects/Person.php | 15 ++++ src/Objects/Tag.php | 15 ++++ src/Objects/TicketTopic.php | 15 ++++ src/Traits/ContactTrait.php | 69 +++++++++++++++++ src/Traits/CrudTrait.php | 0 src/Traits/DepartmentTrait.php | 54 ++++++++++++++ src/Traits/FileTrait.php | 10 +++ src/Traits/GroupTrait.php | 87 ++++++++++++++++++++++ src/Traits/MessageTrait.php | 96 ++++++++++++++++++++++++ src/Traits/OrganizationTrait.php | 54 ++++++++++++++ src/Traits/PersonTrait.php | 54 ++++++++++++++ src/Traits/ServiceTrait.php | 122 +++++++++++++++++++++++++++++++ src/Traits/TagTrait.php | 54 ++++++++++++++ src/Traits/TicketTopicTrait.php | 54 ++++++++++++++ src/Traits/UserTrait.php | 67 +++++++++++++++++ 20 files changed, 860 insertions(+), 68 deletions(-) create mode 100644 src/Objects/Department.php create mode 100644 src/Objects/Group.php create mode 100644 src/Objects/Organization.php create mode 100644 src/Objects/Person.php create mode 100644 src/Objects/Tag.php create mode 100644 src/Objects/TicketTopic.php create mode 100644 src/Traits/ContactTrait.php create mode 100644 src/Traits/CrudTrait.php create mode 100644 src/Traits/DepartmentTrait.php create mode 100644 src/Traits/FileTrait.php create mode 100644 src/Traits/GroupTrait.php create mode 100644 src/Traits/MessageTrait.php create mode 100644 src/Traits/OrganizationTrait.php create mode 100644 src/Traits/PersonTrait.php create mode 100644 src/Traits/ServiceTrait.php create mode 100644 src/Traits/TagTrait.php create mode 100644 src/Traits/TicketTopicTrait.php create mode 100644 src/Traits/UserTrait.php diff --git a/src/Actions.php b/src/Actions.php index 049641d..e4d6452 100644 --- a/src/Actions.php +++ b/src/Actions.php @@ -52,4 +52,15 @@ class Actions * @var string */ const RECORD_VIDEO = 'record_video'; + + /** + * Sets Methods HTTP. + * + * @var string + */ + + const GET = 'GET'; + const POST = 'POST'; + const PUT = 'PUT'; + const DELETE = 'DELETE'; } diff --git a/src/Api.php b/src/Api.php index e27b87d..ac90053 100644 --- a/src/Api.php +++ b/src/Api.php @@ -10,17 +10,27 @@ use EdsonAlvesan\DigiSac\Objects\Message; use EdsonAlvesan\DigiSac\Objects\User; use EdsonAlvesan\DigiSac\Objects\Service; +use EdsonAlvesan\DigiSac\Objects\Contact; use Illuminate\Support\Str; +use EdsonAlvesan\DigiSac\Actions; +use EdsonAlvesan\DigiSac\Traits\ContactTrait; +use EdsonAlvesan\DigiSac\Traits\FileTrait; +use EdsonAlvesan\DigiSac\Traits\MessageTrait; +use EdsonAlvesan\DigiSac\Traits\ServiceTrait; +use EdsonAlvesan\DigiSac\Traits\UserTrait; /** * Class Api. */ class Api { + + use ContactTrait, FileTrait, MessageTrait, ServiceTrait, UserTrait; + /** * @var string Version number of the DigiSac Bot PHP SDK. */ - const VERSION = '1.0.0'; + const VERSION = '1.0.1'; /** * @var string The name of the environment variable that contains the DigiSac API Access Token. @@ -224,73 +234,7 @@ public function isAsyncRequest() { return $this->isAsyncRequest; } - - - /** - * A simple method for testing your bot's auth token. - * Returns basic information about the bot in form of a User object. - * - * @return User - */ - public function getMe() - { - $response = $this->post('getMe'); - - return new User($response->getDecodedBody()); - } - - /** - * A simple method for testing service. - * Returns basic information Service object. - * $ id = '' // Rest - * $params = [ - * - * ]; - * - * @return Service - */ - public function getService(array $url_token, $id, array $params) - { - if (!empty($url_token)) { - $this->url_token = $url_token; - } - - $response = $this->get('services', $id, $params); - - return new Service($response->getDecodedBody()); - } - - /** - * Send text messages. - * - * - * $url_token = [ - * 'url' => '', - * 'token' => '' - * ] - * $params = [ - * 'text' => '', - * 'number' => '', - * 'serviceId' => '', - * ]; - * - * - * @return Message - */ - public function sendMessage(array $url_token, array $params) - { - if (!empty($url_token)) { - $this->url_token = $url_token; - } - - $response = $this->post('messages', $params); - - - return new Message($response->getDecodedBody()); - } - - - + /** * Sends a GET request to DigiSac API and returns the result. * @@ -337,6 +281,32 @@ protected function post($endpoint, array $params = [], $fileUpload = false) ); } + /** + * Sends a PUT request to DigiSac API and returns the result. + * + * @param string $endpoint + * @param array $params + * @param bool $fileUpload Set true if a file is being uploaded. + * + * @return DigiSacResponse + */ + protected function put($endpoint, array $params = [], $fileUpload = false) + { + if ($fileUpload) { + $params = ['multipart' => $params]; + } else { + $params = ['form_params' => $params]; + } + + + return $this->sendRequest( + 'PUT', + $endpoint, + null, + $params + ); + } + /** * Sends a multipart/form-data request to DigiSac API and returns the result. * Used primarily for file uploads. diff --git a/src/Objects/Department.php b/src/Objects/Department.php new file mode 100644 index 0000000..5367a42 --- /dev/null +++ b/src/Objects/Department.php @@ -0,0 +1,15 @@ +url_token = $url_token; + } + + $response = $this->get('contacts', $id, $params); + + return new Contact($response->getDecodedBody()); + } + + public function addContact(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('contacts', $params); + + return new Contact($response->getDecodedBody()); + } + + public function updateContact(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('contacts', $params); + + return new Contact($response->getDecodedBody()); + } + + public function deleteContact(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('contacts', $id); + + return new Contact($response->getDecodedBody()); + } + + public function contactExists(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('contacts', $params); + + return new Contact($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/CrudTrait.php b/src/Traits/CrudTrait.php new file mode 100644 index 0000000..e69de29 diff --git a/src/Traits/DepartmentTrait.php b/src/Traits/DepartmentTrait.php new file mode 100644 index 0000000..542b1a8 --- /dev/null +++ b/src/Traits/DepartmentTrait.php @@ -0,0 +1,54 @@ +url_token = $url_token; + } + + $response = $this->get('departments', $id, $params); + + return new Department($response->getDecodedBody()); + } + + public function addDepartment(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('departments', $params); + + return new Department($response->getDecodedBody()); + } + + public function updateDepartment(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('departments', $params); + + return new Department($response->getDecodedBody()); + } + + public function deleteDepartment(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('departments', $id); + + return new Department($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/FileTrait.php b/src/Traits/FileTrait.php new file mode 100644 index 0000000..3fd89ed --- /dev/null +++ b/src/Traits/FileTrait.php @@ -0,0 +1,10 @@ +url_token = $url_token; + } + + $response = $this->get('users', $id, $params); + + return new Group($response->getDecodedBody()); + } + + public function createGroup(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('users', $params); + + return new Group($response->getDecodedBody()); + } + + public function getGroupParticipants(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->get('users', $id, $params); + + return new Group($response->getDecodedBody()); + } + + public function addGroupParticipant(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('users', $params); + + return new Group($response->getDecodedBody()); + } + + public function removeGroupParticipant(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('users', $id); + + return new Group($response->getDecodedBody()); + } + + public function makeGroupAdmin(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('users', $id); + + return new Group($response->getDecodedBody()); + } + + public function removeGroupAdmin(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('users', $id); + + return new Group($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/MessageTrait.php b/src/Traits/MessageTrait.php new file mode 100644 index 0000000..bf18da2 --- /dev/null +++ b/src/Traits/MessageTrait.php @@ -0,0 +1,96 @@ +url_token = $url_token; + } + + $response = $this->get('messages', $id, $params); + + return new Message($response->getDecodedBody()); + } + + + /** + * Send text messages. + * + * + * $url_token = [ + * 'url' => '', + * 'token' => '' + * ] + * $params = [ + * 'text' => '', + * 'number' => '', + * 'serviceId' => '', + * ]; + * + * + * @return Message + */ + public function sendMessage(array $url_token, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('messages', $params); + + + return new Message($response->getDecodedBody()); + } + + public function revokeMessage(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('messages/'.$id.'/revoke'); + + return new Message($response->getDecodedBody()); + } + + public function syncFileMessage(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('messages/'.$id.'/sync-file'); + + return new Message($response->getDecodedBody()); + } + + public function forwardMessage(array $url_token, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('messages/forward'); + + return new Message($response->getDecodedBody()); + } + + public function deleteManyMessage(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('messages/many'); + + return new Message($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/OrganizationTrait.php b/src/Traits/OrganizationTrait.php new file mode 100644 index 0000000..e647663 --- /dev/null +++ b/src/Traits/OrganizationTrait.php @@ -0,0 +1,54 @@ +url_token = $url_token; + } + + $response = $this->get('organizations', $id, $params); + + return new Organization($response->getDecodedBody()); + } + + public function addOrganization(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('organizations', $params); + + return new Organization($response->getDecodedBody()); + } + + public function updateOrganization(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('organizations', $params); + + return new Organization($response->getDecodedBody()); + } + + public function deleteOrganization(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('organizations', $id); + + return new Organization($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/PersonTrait.php b/src/Traits/PersonTrait.php new file mode 100644 index 0000000..38d4e32 --- /dev/null +++ b/src/Traits/PersonTrait.php @@ -0,0 +1,54 @@ +url_token = $url_token; + } + + $response = $this->get('people', $id, $params); + + return new Person($response->getDecodedBody()); + } + + public function addPerson(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('people', $params); + + return new Person($response->getDecodedBody()); + } + + public function updatePerson(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('people', $params); + + return new Person($response->getDecodedBody()); + } + + public function deletePerson(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('people', $id); + + return new Person($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/ServiceTrait.php b/src/Traits/ServiceTrait.php new file mode 100644 index 0000000..67b3562 --- /dev/null +++ b/src/Traits/ServiceTrait.php @@ -0,0 +1,122 @@ +url_token = $url_token; + } + + $response = $this->get('services', $id, $params); + + return new Service($response->getDecodedBody()); + } + + public function addService(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('services', $params); + + return new Service($response->getDecodedBody()); + } + + public function updateService(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('services', $params); + + return new Service($response->getDecodedBody()); + } + + public function deleteService(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('services', $id); + + return new Service($response->getDecodedBody()); + } + + public function screenshotService(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->get('services/'.$id.'/screenshot', $id, $params); + + return new Service($response->getDecodedBody()); + } + + public function takeoverService(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('services/'.$id.'/takeover'); + + return new Service($response->getDecodedBody()); + } + + public function shutdownService(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('services/'.$id.'/shutdown'); + + return new Service($response->getDecodedBody()); + } + + public function restartService(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('services/'.$id.'/restart'); + + return new Service($response->getDecodedBody()); + } + + public function logoutService(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('services/'.$id.'/logout'); + + return new Service($response->getDecodedBody()); + } + + + + +} \ No newline at end of file diff --git a/src/Traits/TagTrait.php b/src/Traits/TagTrait.php new file mode 100644 index 0000000..3959408 --- /dev/null +++ b/src/Traits/TagTrait.php @@ -0,0 +1,54 @@ +url_token = $url_token; + } + + $response = $this->get('tags', $id, $params); + + return new Tag($response->getDecodedBody()); + } + + public function addTag(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('tags', $params); + + return new Tag($response->getDecodedBody()); + } + + public function updateTag(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('tags', $params); + + return new Tag($response->getDecodedBody()); + } + + public function deleteTag(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('tags', $id); + + return new Tag($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/TicketTopicTrait.php b/src/Traits/TicketTopicTrait.php new file mode 100644 index 0000000..e93c9f5 --- /dev/null +++ b/src/Traits/TicketTopicTrait.php @@ -0,0 +1,54 @@ +url_token = $url_token; + } + + $response = $this->get('ticket-topics', $id, $params); + + return new TicketTopic($response->getDecodedBody()); + } + + public function addTicketTopic(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('ticket-topics', $params); + + return new TicketTopic($response->getDecodedBody()); + } + + public function updateTicketTopic(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('ticket-topics', $params); + + return new TicketTopic($response->getDecodedBody()); + } + + public function deleteTicketTopic(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('ticket-topics', $id); + + return new TicketTopic($response->getDecodedBody()); + } + +} \ No newline at end of file diff --git a/src/Traits/UserTrait.php b/src/Traits/UserTrait.php new file mode 100644 index 0000000..71623ae --- /dev/null +++ b/src/Traits/UserTrait.php @@ -0,0 +1,67 @@ +post('getMe'); + + return new User($response->getDecodedBody()); + } + + public function getUser(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->get('users', $id, $params); + + return new User($response->getDecodedBody()); + } + + public function addUser(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->post('users', $params); + + return new User($response->getDecodedBody()); + } + + public function updateUser(array $url_token, $id, array $params) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->put('users', $params); + + return new User($response->getDecodedBody()); + } + + public function deleteUser(array $url_token, $id) + { + if (!empty($url_token)) { + $this->url_token = $url_token; + } + + $response = $this->delete('users', $id); + + return new User($response->getDecodedBody()); + } + +} \ No newline at end of file