This repository has been archived by the owner on Aug 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
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
1 parent
123cdad
commit 4ecbdec
Showing
1 changed file
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Laravel Zendesk | ||
|
||
This package provides a ```Zendesk``` facade that acts as a wrapper to the [zendesk/zendesk_api_client_php](https://github.com/zendesk/zendesk_api_client_php) package. | ||
|
||
**NB:** Currently only supports token-based authentication. | ||
|
||
## Installation | ||
|
||
Install via composer by adding the following to your composer.json: | ||
|
||
``` | ||
... | ||
"require": { | ||
"huddledigital/zendesk-laravel": "~1.0" | ||
} | ||
... | ||
``` | ||
|
||
Add service provider to ```config/app.php```: | ||
|
||
``` | ||
... | ||
'Huddle\Zendesk\Providers\ZendeskServiceProvider', | ||
... | ||
``` | ||
|
||
Add alias to ```config/app.php```: | ||
|
||
``` | ||
... | ||
'Zendesk' => 'Huddle\Zendesk\Facades\Zendesk', | ||
... | ||
``` | ||
|
||
## Configuration | ||
|
||
Set your configuration using **environment variables**, either in your ```.env``` file or on your server's control panel: | ||
|
||
- ```ZENDESK_SUBDOMAIN``` - the subdomain for your Zendesk organisation. | ||
- ```ZENDESK_USERNAME``` - the username for the authenticating account. | ||
- ```ZENDESK_TOKEN``` - the access token. To generate an access token within Zendesk, click on Settings, API, enable Token Access and click 'add new token'. | ||
|
||
## Usage | ||
|
||
### Facade | ||
|
||
The ```Zendesk``` facade acts as a wrapper for an instance of the ```Zendesk\API\Client``` class. Any methods available on this class ([documentation here](https://github.com/zendesk/zendesk_api_client_php#usage)) are available through the facade. for example: | ||
|
||
``` | ||
// Get all tickets | ||
Zendesk::tickets()->findAll(); | ||
// Create a new ticket | ||
Zendesk::tickets()->create([ | ||
'subject' => 'Subject', | ||
'comment' => [ | ||
'body' => 'Ticket content.' | ||
], | ||
'priority' => 'normal' | ||
]); | ||
// Update multiple tickets | ||
Zendesk::ticket([123, 456])->update([ | ||
'status' => 'urgent' | ||
]); | ||
// Delete a ticket | ||
Zendesk::ticket(123)->delete(); | ||
``` | ||
|
||
### Dependency injection | ||
|
||
If you'd prefer not to use the facade, you can skip adding the alias to ```config/app.php``` and instead inject ```Huddle\Zendesk\Services\ZendeskService``` into your class. You can then use all of the same methods on this object as you would on the facade. | ||
|
||
``` | ||
<?php | ||
use Huddle\Zendesk\Services\ZendeskService; | ||
class MyClass { | ||
public function __construct(ZendeskService $zendesk_service) { | ||
$this->zendesk_service = $zendesk_service; | ||
} | ||
public function addTicket() { | ||
$this->zendesk_service->tickets()->create([ | ||
'subject' => 'Subject', | ||
'comment' => [ | ||
'body' => 'Ticket content.' | ||
], | ||
'priority' => 'normal' | ||
]); | ||
} | ||
} | ||
``` | ||