Skip to content

Commit

Permalink
add new routes
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonalvesan committed Aug 12, 2020
1 parent b23dd22 commit 5dbd74e
Show file tree
Hide file tree
Showing 20 changed files with 860 additions and 68 deletions.
11 changes: 11 additions & 0 deletions src/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
106 changes: 38 additions & 68 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
* <code>
* $url_token = [
* 'url' => '',
* 'token' => ''
* ]
* $params = [
* 'text' => '',
* 'number' => '',
* 'serviceId' => '',
* ];
* </code>
*
* @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.
*
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/Objects/Department.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EdsonAlvesan\DigiSac\Objects;


class Department extends BaseObject
{
/**
* {@inheritdoc}
*/
public function relations()
{
return [];
}
}
15 changes: 15 additions & 0 deletions src/Objects/Group.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EdsonAlvesan\DigiSac\Objects;


class Group extends BaseObject
{
/**
* {@inheritdoc}
*/
public function relations()
{
return [];
}
}
15 changes: 15 additions & 0 deletions src/Objects/Organization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EdsonAlvesan\DigiSac\Objects;


class Organization extends BaseObject
{
/**
* {@inheritdoc}
*/
public function relations()
{
return [];
}
}
15 changes: 15 additions & 0 deletions src/Objects/Person.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EdsonAlvesan\DigiSac\Objects;


class Person extends BaseObject
{
/**
* {@inheritdoc}
*/
public function relations()
{
return [];
}
}
15 changes: 15 additions & 0 deletions src/Objects/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EdsonAlvesan\DigiSac\Objects;


class Tag extends BaseObject
{
/**
* {@inheritdoc}
*/
public function relations()
{
return [];
}
}
15 changes: 15 additions & 0 deletions src/Objects/TicketTopic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace EdsonAlvesan\DigiSac\Objects;


class TicketTopic extends BaseObject
{
/**
* {@inheritdoc}
*/
public function relations()
{
return [];
}
}
69 changes: 69 additions & 0 deletions src/Traits/ContactTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace EdsonAlvesan\DigiSac\Traits;

use EdsonAlvesan\DigiSac\Objects\Contact;

trait ContactTrait
{

/**
* @return Contact
*/

public function getContact(array $url_token, $id, array $params)
{
if (!empty($url_token)) {
$this->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());
}

}
Empty file added src/Traits/CrudTrait.php
Empty file.
54 changes: 54 additions & 0 deletions src/Traits/DepartmentTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace EdsonAlvesan\DigiSac\Traits;

use EdsonAlvesan\DigiSac\Objects\Department;

trait DepartmentTrait
{

public function getDepartment(array $url_token, $id, array $params)
{
if (!empty($url_token)) {
$this->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());
}

}
10 changes: 10 additions & 0 deletions src/Traits/FileTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace EdsonAlvesan\DigiSac\Traits;

use EdsonAlvesan\DigiSac\Objects\Contact;

trait FileTrait
{

}
Loading

0 comments on commit 5dbd74e

Please sign in to comment.