Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add filter for compagnies and contacts, create filter trait #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Resources/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Freshdesk\Resources\Traits\AllTrait;
use Freshdesk\Resources\Traits\CreateTrait;
use Freshdesk\Resources\Traits\DeleteTrait;
use Freshdesk\Resources\Traits\FilterTrait;
use Freshdesk\Resources\Traits\UpdateTrait;
use Freshdesk\Resources\Traits\ViewTrait;

Expand All @@ -24,7 +25,7 @@
class Company extends AbstractResource
{

use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait;
use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait, FilterTrait;

/**
* The resource endpoint
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Freshdesk\Resources\Traits\AllTrait;
use Freshdesk\Resources\Traits\CreateTrait;
use Freshdesk\Resources\Traits\DeleteTrait;
use Freshdesk\Resources\Traits\FilterTrait;
use Freshdesk\Resources\Traits\UpdateTrait;
use Freshdesk\Resources\Traits\ViewTrait;

Expand All @@ -24,7 +25,7 @@
*/
class Contact extends AbstractResource
{
use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait;
use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait, FilterTrait;

/**
* The resource endpoint
Expand Down
33 changes: 3 additions & 30 deletions src/Resources/Ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Freshdesk\Resources\Traits\AllTrait;
use Freshdesk\Resources\Traits\CreateTrait;
use Freshdesk\Resources\Traits\DeleteTrait;
use Freshdesk\Resources\Traits\FilterTrait;
use Freshdesk\Resources\Traits\UpdateTrait;
use Freshdesk\Resources\Traits\ViewTrait;

Expand All @@ -24,7 +25,7 @@
class Ticket extends AbstractResource
{

use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait;
use AllTrait, CreateTrait, ViewTrait, UpdateTrait, DeleteTrait, FilterTrait;

/**
* The resource endpoint
Expand All @@ -35,7 +36,7 @@ class Ticket extends AbstractResource

/**
* Restore a ticket
*
*
* Restores a previously deleted ticket
*
* @api
Expand Down Expand Up @@ -130,32 +131,4 @@ public function timeEntries($id, array $query = null)

return $this->api()->request('GET', $this->endpoint($end), null, $query);
}

/**
* Filters by ticket fields
*
* Make sure to pass a valid $filtersQuery string example: "type:question"
*
* @api
* @param string $filtersQuery
* @return array|null
* @throws \Freshdesk\Exceptions\AccessDeniedException
* @throws \Freshdesk\Exceptions\ApiException
* @throws \Freshdesk\Exceptions\AuthenticationException
* @throws \Freshdesk\Exceptions\ConflictingStateException
* @throws \Freshdesk\Exceptions\NotFoundException
* @throws \Freshdesk\Exceptions\RateLimitExceededException
* @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
* @throws \Freshdesk\Exceptions\MethodNotAllowedException
* @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
* @throws \Freshdesk\Exceptions\ValidationException
*/
public function search(string $filtersQuery)
{
$end = '/search'.$this->endpoint();
$query = [
'query' => '"'.$filtersQuery.'"',
];
return $this->api()->request('GET', $end, null, $query);
}
}
2 changes: 1 addition & 1 deletion src/Resources/Traits/AllTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract protected function endpoint($end = null);
abstract protected function api();

/**
* Get a list of all agents.
* Get a list of all items of a resource.
*
* Use filters ($query) to view only specific resources (those which match the criteria that you choose).
*
Expand Down
54 changes: 54 additions & 0 deletions src/Resources/Traits/FilterTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Freshdesk\Resources\Traits;

/**
* Create Trait
*
* @package Freshdesk\Resources\Traits
*/
trait FilterTrait
{

/**
* @param null $end string
* @return string
* @internal
*/
abstract protected function endpoint($end = null);

/**
* @return \Freshdesk\Api
* @internal
*/
abstract protected function api();

/**
* Filter a resource
*
* Filter a resource by $query
* Make sure to pass a valid $query string
*
* @api
* @param string $query
* @return array|null
* @throws \Freshdesk\Exceptions\AccessDeniedException
* @throws \Freshdesk\Exceptions\ApiException
* @throws \Freshdesk\Exceptions\AuthenticationException
* @throws \Freshdesk\Exceptions\ConflictingStateException
* @throws \Freshdesk\Exceptions\NotFoundException
* @throws \Freshdesk\Exceptions\RateLimitExceededException
* @throws \Freshdesk\Exceptions\UnsupportedContentTypeException
* @throws \Freshdesk\Exceptions\MethodNotAllowedException
* @throws \Freshdesk\Exceptions\UnsupportedAcceptHeaderException
* @throws \Freshdesk\Exceptions\ValidationException
*/
public function filter(string $query)
{
$end = '/search'.$this->endpoint();
$query = [
'query' => '"'.$query.'"',
];
return $this->api()->request('GET', $end, null, $query);
}
}
3 changes: 2 additions & 1 deletion tests/Resources/CompanyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setUp()
parent::setUp();

$this->class = Company::class;
}
}

public function methodsThatShouldExist()
{
Expand All @@ -27,6 +27,7 @@ public function methodsThatShouldExist()
['view'],
['update'],
['delete'],
['filter'],
['fields'],
];
}
Expand Down
1 change: 1 addition & 0 deletions tests/Resources/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function methodsThatShouldExist()
['view'],
['update'],
['delete'],
['filter'],
['fields'],
['makeAgent'],
];
Expand Down
4 changes: 2 additions & 2 deletions tests/Resources/TicketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function methodsThatShouldExist()
['view'],
['update'],
['delete'],
['filter'],
['fields'],
['restore'],
['fields'],
['conversations'],
['timeEntries'],
['search']
['timeEntries']
];
}

Expand Down