diff --git a/.travis.yml b/.travis.yml
index 13e01993..ddf0091a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,11 @@
language: php
php:
+ - 5.6
- 5.5
# - 5.4
# - hhvm
-before_script: composer self-update && composer install
-script: phpunit --testsuite "Zendesk API Unit Test Suites"
+install:
+ - travis_retry composer self-update && composer install
+script:
+ - vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites"
+ - vendor/bin/phpcs --extensions=php --standard=PSR2 --report=summary -np src/ tests/
diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 00000000..f2270537
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,30 @@
+Changed:
+
+* on tickets, can no longer do $client->tickets(["organization_id" -> 1231])->findAll(), etc. (also user_id)
+* separate findMany method
+* change interface of find to just take ID, then params
+* added updateMany method, support both ways of updating
+* change update so that it takes ID as first param
+* change delete so that it takes id
+* add deleteMany method to tickets
+* Add property chained properties to store all previous chained calls
+* Removed setting of last ID on instantiation of Resource
+* Allowed pattern `$client->ticket(id)->find()` for consistency with chaining pattern
+* Make $id in delete and update optional to allow passing of the id via chaining pattern
+
+Topics
+* removed Topics::create() - was implementing lastId
+* remove Topics::findAll() - can no longer do $client->users(123)->topics()->findAll()
+
+UserFields
+* remove CRUD methods
+
+Forums
+* remove CRUD methods - (most methods)
+* no unique case so test is empty
+
+Tickets
+* markAsSpam method now only accepts an int value for an ID or an array of ID's
+
+Users
+* Remove tickets, identities, and other relational methods
diff --git a/README.md b/README.md
index 5f2b0031..a6b57bd6 100755
--- a/README.md
+++ b/README.md
@@ -2,10 +2,17 @@
[![Build Status](https://travis-ci.org/zendesk/zendesk_api_client_php.svg?branch=master)](https://travis-ci.org/zendesk/zendesk_api_client_php)
+## API Client Version
+
+This is the second version of our PHP API client and it is **currently in BETA**. The previous version of the API client can be found on the [v1 branch](https://github.com/zendesk/zendesk_api_client_php/tree/v1).
+
## API version support
This client **only** supports Zendesk's API v2. Please see our [API documentation](http://developer.zendesk.com) for more information.
+## Requirements
+* PHP 5.5+
+
## Installation
The Zendesk PHP API client can be installed using [Composer](https://packagist.org/packages/zendesk/zendesk_api_client_php).
@@ -27,7 +34,7 @@ Inside of `composer.json` specify the following:
Configuration is done through an instance of `Zendesk\API\Client`.
The block is mandatory and if not passed, an error will be thrown.
-```php
+```
use Zendesk\API\Client as ZendeskAPI;
$subdomain = "subdomain";
@@ -43,25 +50,26 @@ $client->setAuth('token', $token); // set either token or password
### Basic Operations
-```php
+```
// Get all tickets
$tickets = $client->tickets()->findAll();
print_r($tickets);
// Create a new ticket
-$newTicket = $client->tickets()->create(array(
- 'subject' => 'The quick brown fox jumps over the lazy dog',
- 'comment' => array (
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
-));
+$newTicket = $client->tickets()->create([
+ 'subject' => 'The quick brown fox jumps over the lazy dog',
+ 'comment' => [
+ 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, '
+ . 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
+ ],
+ 'priority' => 'normal'
+]);
print_r($newTicket);
// Update multiple tickets
-$client->ticket(array (123, 456))->update(array (
- 'status' => 'urgent'
-));
+$client->ticket([123, 456])->update([
+ 'status' => 'urgent'
+]);
// Delete a ticket
$client->ticket(123)->delete();
@@ -69,28 +77,176 @@ $client->ticket(123)->delete();
### Attachments
-```php
-$attachment = $client->attachments()->upload(array(
+```
+$attachment = $client->attachments()->upload([
'file' => getcwd().'/tests/assets/UK.png',
'type' => 'image/png',
'name' => 'UK.png' // Optional parameter, will default to filename.ext
-));
+]);
```
### Test suite
The test suite is run via phpunit. Note that these are all live tests that must be run targeted at a real Zendesk instance. Credentials can be provided by setting the environment variables in phpunit.xml; a sample is provided at phpunit.xml.dist.
+To run the unit tests: `vendor/bin/phpunit --testsuite "Zendesk API Unit Test Suites"`
+
+To run the live tests: `vendor/bin/phpunit --testsuite "Zendesk API Live Test Suites"`
+
+
### Side-loading
+```
+$tickets = $this->client->tickets()->sideload(['users', 'groups'])->findAll();
+```
+
+
+
+## Coding Standard
+This project strictly follows the [PSR-2](http://www.php-fig.org/psr/psr-2/) coding standard.
+
+[PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer) is used to verify that the standard is being followed.
+
+In addition to the PSR2 standard which we try to follow the following rules as much as possible:
+
+### PHPDoc
+
+All Classes, Class Methods and Properties should have docblocs.
+
+#### Classes
+
+Class docblocks should contain:
+* A short description of the class
+* Any methods available that are called via magic method with what that method returns.
+
+A good example is
+```
+/**
+ * Client class, base level access
+ *
+ * @method Debug debug()
+ * @method Tickets ticket()
+ * @method Views views()
+ */
+```
+
+
+#### Methods
+
+Method docblocks should contain:
+* A short description of what the method does.
+* The parameters passed with what type to expect.
+* Description of the parameters passed with examples(optional).
+* The type of the return.
+* All the possible exceptions the method may throw.
+
+A good example of this is
+
+```
+/**
+ * Find a specific ticket by id or series of ids
+ *
+ * @param integer|null $id
+ * @param array $queryParams
+ *
+ * @return Array
+ *
+ * @throws MissingParametersException
+ * @throws \Exception
+ */
+```
+
+#### Properties
+
+Class properties docblocs should contain:
+* A short description of the property (optional)
+* The var type
+
+A good example of this
+
+```
+/**
+ * This contains the Auth object to be used for authenticating with the Client
+ *
+ * @var Zendesk\API\Utilities\Auth
+ */
+```
+
+### Arrays
+The short notations for declaring arrays (`[]`) is preferred over the longer `array()`.
+
+Align `=>`s following the longest key to make the arrays easier to read.
+
+```
+[
+ 'findAll' => "users/{userId}/{$this->resourceName}.json",
+ 'find' => "users/{userId}/{$this->resourceName}/{id}.json",
+ 'update' => "users/{userId}/{$this->resourceName}/{id}.json",
+ 'makePrimary' => "users/{userId}/{$this->resourceName}/{id}/make_primary.json",
+ 'verify' => "users/{userId}/{$this->resourceName}/{id}/verify.json",
+ 'requestVerification' => "users/{userId}/{$this->resourceName}/{id}/request_verification.json",
+ 'delete' => "users/{userId}/{$this->resourceName}/{id}.json",
+ 'create' => "users/{userId}/{$this->resourceName}.json",
+ 'createAsEndUser' => "end_users/{userId}/{$this->resourceName}.json",
+]
+```
+
+### Grouped assignment statements
+
+Align the `=` for grouped assignment statements.
+
+```
+$headers = 'sample';
+$lastRequestBody = 'example';
+$lastResponseCode = 'something';
+$lastResponseHeaders = 'test';
+$lastResponseError = 'test2';
+
+```
+
+
+### Traits
+
+#### Declaration
+
+* Traits are added after class constants and arranged alphabetically when declared.
+* Group traits accordingly by adding a new line after each group.
+* Groups are ordered as follows:
+1. Instantiator
+2. Single resource
+3. Bulk traits
+
+#### Resource Traits
+
+When adding a resource, use traits to define available API calls. Resource traits are namespaced under `Zendesk\API\Traits\Resource`.
+
+**Single Resource**
+* Create
+* Delete
+* Find
+* FindAll
+* Update
+* Defaults - this adds **Find**, **FindAll**, **Create**, **Update**, and **Delete**
+
+**Bulk traits**
+* CreateMany
+* DeleteMany
+* FindMany
+* UpdateMany
+
+#### Utility Traits
+
+Use `Zendesk\API\Traits\Utility\InstantiatorTrait` when you want a resource to be chainable to other resources. See `Zendesk/API/Resources/Tickets.php`.
+
```php
-$tickets = $this->client->tickets()->sideload(array('users', 'groups'))->findAll();
+$this->client->tickets()->comments()->findAll();
```
## Note on Patches/Pull Requests
1. Fork the project.
2. Make your feature addition or bug fix.
3. Add tests for it. This is important so that we don't break your improvement in a future version unintentionally.
+4. Please follow the [coding standard described above](#coding-standard).
4. Commit and do not mess with version or history. (If you want to have
your own version, that is fine but bump version in a commit by itself I can
ignore when we pull)
diff --git a/composer.json b/composer.json
index 935b94b4..1c4c0eef 100755
--- a/composer.json
+++ b/composer.json
@@ -1,20 +1,23 @@
{
- "name": "zendesk/zendesk_api_client_php",
- "description": "PHP Client for Zendesk REST API. See http://developer.zendesk.com/api-docs",
- "license": "Apache License Version 2.0",
- "homepage": "https://github.com/zendesk/zendesk_api_client_php",
- "require": {
- "php": ">=5.3.1"
- },
- "require-dev": {
- "phpunit/phpunit": "4.5.*",
- "squizlabs/php_codesniffer": "2.*",
- "phpmd/phpmd" : "@stable",
- "internations/http-mock": "dev-master"
- },
- "autoload": {
- "psr-0": {
- "Zendesk\\API\\": "src/"
- }
+ "name": "zendesk/zendesk_api_client_php",
+ "description": "PHP Client for Zendesk REST API. See http://developer.zendesk.com/api-docs",
+ "license": "Apache License Version 2.0",
+ "version": "2.0.0-beta",
+ "homepage": "https://github.com/zendesk/zendesk_api_client_php",
+ "require": {
+ "php": ">=5.3.1",
+ "guzzlehttp/guzzle": "~6.0",
+ "mmucklo/inflect": "0.3.*"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "4.5.*",
+ "squizlabs/php_codesniffer": "2.*",
+ "phpmd/phpmd": "@stable",
+ "fzaninotto/faker": ">=1.5.0"
+ },
+ "autoload": {
+ "psr-0": {
+ "Zendesk\\API\\": "src/"
}
+ }
}
diff --git a/composer.lock b/composer.lock
index b6df821e..69b1d2dd 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,42 +4,44 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "7bed5cf724443ea9677025e94ef12843",
- "packages": [],
- "packages-dev": [
+ "hash": "8a1558ef13839986e50fe26f17673542",
+ "packages": [
{
- "name": "doctrine/instantiator",
- "version": "1.0.4",
+ "name": "guzzlehttp/guzzle",
+ "version": "6.0.2",
"source": {
"type": "git",
- "url": "https://github.com/doctrine/instantiator.git",
- "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119"
+ "url": "https://github.com/guzzle/guzzle.git",
+ "reference": "a8dfeff00eb84616a17fea7a4d72af35e750410f"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119",
- "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119",
+ "url": "https://api.github.com/repos/guzzle/guzzle/zipball/a8dfeff00eb84616a17fea7a4d72af35e750410f",
+ "reference": "a8dfeff00eb84616a17fea7a4d72af35e750410f",
"shasum": ""
},
"require": {
- "php": ">=5.3,<8.0-DEV"
+ "guzzlehttp/promises": "~1.0",
+ "guzzlehttp/psr7": "~1.1",
+ "php": ">=5.5.0"
},
"require-dev": {
- "athletic/athletic": "~0.1.8",
- "ext-pdo": "*",
- "ext-phar": "*",
+ "ext-curl": "*",
"phpunit/phpunit": "~4.0",
- "squizlabs/php_codesniffer": "2.0.*@ALPHA"
+ "psr/log": "~1.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.0.x-dev"
+ "dev-master": "6.0-dev"
}
},
"autoload": {
- "psr-0": {
- "Doctrine\\Instantiator\\": "src"
+ "files": [
+ "src/functions_include.php"
+ ],
+ "psr-4": {
+ "GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -48,85 +50,57 @@
],
"authors": [
{
- "name": "Marco Pivetta",
- "email": "ocramius@gmail.com",
- "homepage": "http://ocramius.github.com/"
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
}
],
- "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
- "homepage": "https://github.com/doctrine/instantiator",
+ "description": "Guzzle is a PHP HTTP client library",
+ "homepage": "http://guzzlephp.org/",
"keywords": [
- "constructor",
- "instantiate"
+ "client",
+ "curl",
+ "framework",
+ "http",
+ "http client",
+ "rest",
+ "web service"
],
- "time": "2014-10-13 12:58:55"
+ "time": "2015-07-04 20:09:24"
},
{
- "name": "guzzle/guzzle",
- "version": "v3.9.3",
+ "name": "guzzlehttp/promises",
+ "version": "1.0.1",
"source": {
"type": "git",
- "url": "https://github.com/guzzle/guzzle3.git",
- "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9"
+ "url": "https://github.com/guzzle/promises.git",
+ "reference": "2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9",
- "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9",
+ "url": "https://api.github.com/repos/guzzle/promises/zipball/2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7",
+ "reference": "2ee5bc7f1a92efecc90da7f6711a53a7be26b5b7",
"shasum": ""
},
"require": {
- "ext-curl": "*",
- "php": ">=5.3.3",
- "symfony/event-dispatcher": "~2.1"
- },
- "replace": {
- "guzzle/batch": "self.version",
- "guzzle/cache": "self.version",
- "guzzle/common": "self.version",
- "guzzle/http": "self.version",
- "guzzle/inflection": "self.version",
- "guzzle/iterator": "self.version",
- "guzzle/log": "self.version",
- "guzzle/parser": "self.version",
- "guzzle/plugin": "self.version",
- "guzzle/plugin-async": "self.version",
- "guzzle/plugin-backoff": "self.version",
- "guzzle/plugin-cache": "self.version",
- "guzzle/plugin-cookie": "self.version",
- "guzzle/plugin-curlauth": "self.version",
- "guzzle/plugin-error-response": "self.version",
- "guzzle/plugin-history": "self.version",
- "guzzle/plugin-log": "self.version",
- "guzzle/plugin-md5": "self.version",
- "guzzle/plugin-mock": "self.version",
- "guzzle/plugin-oauth": "self.version",
- "guzzle/service": "self.version",
- "guzzle/stream": "self.version"
+ "php": ">=5.5.0"
},
"require-dev": {
- "doctrine/cache": "~1.3",
- "monolog/monolog": "~1.0",
- "phpunit/phpunit": "3.7.*",
- "psr/log": "~1.0",
- "symfony/class-loader": "~2.1",
- "zendframework/zend-cache": "2.*,<2.3",
- "zendframework/zend-log": "2.*,<2.3"
- },
- "suggest": {
- "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated."
+ "phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.9-dev"
+ "dev-master": "1.0-dev"
}
},
"autoload": {
- "psr-0": {
- "Guzzle": "src/",
- "Guzzle\\Tests": "tests/"
- }
+ "psr-4": {
+ "GuzzleHttp\\Promise\\": "src/"
+ },
+ "files": [
+ "src/functions.php"
+ ]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@@ -137,56 +111,96 @@
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
+ }
+ ],
+ "description": "Guzzle promises library",
+ "keywords": [
+ "promise"
+ ],
+ "time": "2015-06-24 16:16:25"
+ },
+ {
+ "name": "guzzlehttp/psr7",
+ "version": "1.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/guzzle/psr7.git",
+ "reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/guzzle/psr7/zipball/af0e1758de355eb113917ad79c3c0e3604bce4bd",
+ "reference": "af0e1758de355eb113917ad79c3c0e3604bce4bd",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.4.0",
+ "psr/http-message": "~1.0"
+ },
+ "provide": {
+ "psr/http-message-implementation": "1.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "GuzzleHttp\\Psr7\\": "src/"
},
+ "files": [
+ "src/functions.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
{
- "name": "Guzzle Community",
- "homepage": "https://github.com/guzzle/guzzle/contributors"
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
}
],
- "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle",
- "homepage": "http://guzzlephp.org/",
+ "description": "PSR-7 message implementation",
"keywords": [
- "client",
- "curl",
- "framework",
"http",
- "http client",
- "rest",
- "web service"
+ "message",
+ "stream",
+ "uri"
],
- "time": "2015-03-18 18:23:50"
+ "time": "2015-06-24 19:55:15"
},
{
- "name": "internations/http-mock",
- "version": "dev-master",
+ "name": "mmucklo/inflect",
+ "version": "v0.3.0",
"source": {
"type": "git",
- "url": "https://github.com/InterNations/http-mock.git",
- "reference": "907aa25cd4783d676b16a180f37be0b4ead311fd"
+ "url": "https://github.com/mmucklo/inflect.git",
+ "reference": "b665bcd3d4c23b6aa1990b6405ff96dd437689e9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/InterNations/http-mock/zipball/907aa25cd4783d676b16a180f37be0b4ead311fd",
- "reference": "907aa25cd4783d676b16a180f37be0b4ead311fd",
+ "url": "https://api.github.com/repos/mmucklo/inflect/zipball/b665bcd3d4c23b6aa1990b6405ff96dd437689e9",
+ "reference": "b665bcd3d4c23b6aa1990b6405ff96dd437689e9",
"shasum": ""
},
"require": {
- "guzzle/guzzle": "*",
- "jeremeamia/superclosure": "~2",
- "lstrojny/hmmmath": ">=0.5.0",
- "php": ">=5.4.0",
- "silex/silex": "~1",
- "symfony/process": "*"
+ "php": ">=5.3.17"
},
"require-dev": {
- "internations/kodierungsregelwerksammlung": "dev-master",
- "internations/testing-component": "dev-master",
- "phpunit/phpunit": "~4"
+ "phpunit/phpunit": "3.7.*"
},
"type": "library",
"autoload": {
"psr-0": {
- "InterNations\\Component\\HttpMock\\": "src/"
+ "Inflect": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -195,48 +209,50 @@
],
"authors": [
{
- "name": "Lars Strojny",
- "email": "lars.strojny@internations.org"
+ "name": "Sho Kuwamoto",
+ "email": "sho@kuwamoto.org"
},
{
- "name": "Max Beutel",
- "email": "max.beutel@internations.org"
+ "name": "Matthew J. Mucklo",
+ "email": "mmucklo@gmail.com"
}
],
- "description": "Mock HTTP requests on the server side in your PHP unit tests",
- "time": "2015-02-07 03:56:06"
+ "description": "inflect - a memoizing inflector for php",
+ "keywords": [
+ "inflect",
+ "inflector",
+ "pluralize",
+ "singularize",
+ "urlify"
+ ],
+ "time": "2015-05-16 04:16:08"
},
{
- "name": "jeremeamia/SuperClosure",
- "version": "2.1.0",
+ "name": "psr/http-message",
+ "version": "1.0",
"source": {
"type": "git",
- "url": "https://github.com/jeremeamia/super_closure.git",
- "reference": "b712f39c671e5ead60c7ebfe662545456aade833"
+ "url": "https://github.com/php-fig/http-message.git",
+ "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/jeremeamia/super_closure/zipball/b712f39c671e5ead60c7ebfe662545456aade833",
- "reference": "b712f39c671e5ead60c7ebfe662545456aade833",
+ "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
+ "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298",
"shasum": ""
},
"require": {
- "nikic/php-parser": "~1.0",
- "php": ">=5.4"
- },
- "require-dev": {
- "codeclimate/php-test-reporter": "~0.1.2",
- "phpunit/phpunit": "~4.0"
+ "php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "2.1-dev"
+ "dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
- "SuperClosure\\": "src/"
+ "Psr\\Http\\Message\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -245,48 +261,56 @@
],
"authors": [
{
- "name": "Jeremy Lindblom",
- "email": "jeremeamia@gmail.com",
- "homepage": "https://github.com/jeremeamia",
- "role": "Developer"
+ "name": "PHP-FIG",
+ "homepage": "http://www.php-fig.org/"
}
],
- "description": "Serialize Closure objects, including their context and binding",
- "homepage": "https://github.com/jeremeamia/super_closure",
+ "description": "Common interface for HTTP messages",
"keywords": [
- "closure",
- "function",
- "lambda",
- "parser",
- "serializable",
- "serialize",
- "tokenizer"
+ "http",
+ "http-message",
+ "psr",
+ "psr-7",
+ "request",
+ "response"
],
- "time": "2015-03-11 20:06:43"
- },
+ "time": "2015-05-04 20:22:00"
+ }
+ ],
+ "packages-dev": [
{
- "name": "lstrojny/hmmmath",
- "version": "0.5.0",
+ "name": "doctrine/instantiator",
+ "version": "1.0.5",
"source": {
"type": "git",
- "url": "https://github.com/lstrojny/hmmmath.git",
- "reference": "f39b9beaae1366e783aceefe0a77b2a9bf1e2f5c"
+ "url": "https://github.com/doctrine/instantiator.git",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/lstrojny/hmmmath/zipball/f39b9beaae1366e783aceefe0a77b2a9bf1e2f5c",
- "reference": "f39b9beaae1366e783aceefe0a77b2a9bf1e2f5c",
+ "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d",
+ "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
+ "require": {
+ "php": ">=5.3,<8.0-DEV"
+ },
"require-dev": {
- "internations/kodierungsregelwerksammlung": "dev-master",
- "internations/testing-component": "dev-master",
- "phpunit/phpunit": "~3"
+ "athletic/athletic": "~0.1.8",
+ "ext-pdo": "*",
+ "ext-phar": "*",
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "~2.0"
},
"type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.0.x-dev"
+ }
+ },
"autoload": {
- "psr-0": {
- "hmmmath\\": "src/"
+ "psr-4": {
+ "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/"
}
},
"notification-url": "https://packagist.org/downloads/",
@@ -295,57 +319,70 @@
],
"authors": [
{
- "name": "Lars Strojny",
- "email": "lars@strojny.net"
+ "name": "Marco Pivetta",
+ "email": "ocramius@gmail.com",
+ "homepage": "http://ocramius.github.com/"
}
],
- "description": "Collection of math related PHP functions",
- "time": "2014-03-25 20:15:27"
+ "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors",
+ "homepage": "https://github.com/doctrine/instantiator",
+ "keywords": [
+ "constructor",
+ "instantiate"
+ ],
+ "time": "2015-06-14 21:17:01"
},
{
- "name": "nikic/php-parser",
- "version": "v1.3.0",
+ "name": "fzaninotto/faker",
+ "version": "v1.5.0",
"source": {
"type": "git",
- "url": "https://github.com/nikic/PHP-Parser.git",
- "reference": "dff239267fd1befa1cd40430c9ed12591aa720ca"
+ "url": "https://github.com/fzaninotto/Faker.git",
+ "reference": "d0190b156bcca848d401fb80f31f504f37141c8d"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/dff239267fd1befa1cd40430c9ed12591aa720ca",
- "reference": "dff239267fd1befa1cd40430c9ed12591aa720ca",
+ "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/d0190b156bcca848d401fb80f31f504f37141c8d",
+ "reference": "d0190b156bcca848d401fb80f31f504f37141c8d",
"shasum": ""
},
"require": {
- "ext-tokenizer": "*",
- "php": ">=5.3"
+ "php": ">=5.3.3"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~4.0",
+ "squizlabs/php_codesniffer": "~1.5"
+ },
+ "suggest": {
+ "ext-intl": "*"
},
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.3-dev"
+ "dev-master": "1.5.x-dev"
}
},
"autoload": {
- "files": [
- "lib/bootstrap.php"
- ]
+ "psr-4": {
+ "Faker\\": "src/Faker/"
+ }
},
"notification-url": "https://packagist.org/downloads/",
"license": [
- "BSD-3-Clause"
+ "MIT"
],
"authors": [
{
- "name": "Nikita Popov"
+ "name": "François Zaninotto"
}
],
- "description": "A PHP parser written in PHP",
+ "description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
- "parser",
- "php"
+ "data",
+ "faker",
+ "fixtures"
],
- "time": "2015-05-02 15:40:40"
+ "time": "2015-05-29 06:29:14"
},
{
"name": "pdepend/pdepend",
@@ -559,16 +596,16 @@
},
{
"name": "phpunit/php-code-coverage",
- "version": "2.1.2",
+ "version": "2.1.9",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
- "reference": "6b7d2094ca2a685a2cad846cb7cd7a30e8b9470f"
+ "reference": "5bd48b86cd282da411bb80baac1398ce3fefac41"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6b7d2094ca2a685a2cad846cb7cd7a30e8b9470f",
- "reference": "6b7d2094ca2a685a2cad846cb7cd7a30e8b9470f",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5bd48b86cd282da411bb80baac1398ce3fefac41",
+ "reference": "5bd48b86cd282da411bb80baac1398ce3fefac41",
"shasum": ""
},
"require": {
@@ -617,7 +654,7 @@
"testing",
"xunit"
],
- "time": "2015-06-01 07:35:26"
+ "time": "2015-07-26 12:54:47"
},
{
"name": "phpunit/php-file-iterator",
@@ -666,16 +703,16 @@
},
{
"name": "phpunit/php-text-template",
- "version": "1.2.0",
+ "version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-text-template.git",
- "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a"
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
- "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
+ "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686",
"shasum": ""
},
"require": {
@@ -684,20 +721,17 @@
"type": "library",
"autoload": {
"classmap": [
- "Text/"
+ "src/"
]
},
"notification-url": "https://packagist.org/downloads/",
- "include-path": [
- ""
- ],
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Sebastian Bergmann",
- "email": "sb@sebastian-bergmann.de",
+ "email": "sebastian@phpunit.de",
"role": "lead"
}
],
@@ -706,20 +740,20 @@
"keywords": [
"template"
],
- "time": "2014-01-30 17:20:04"
+ "time": "2015-06-21 13:50:34"
},
{
"name": "phpunit/php-timer",
- "version": "1.0.5",
+ "version": "1.0.7",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-timer.git",
- "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c"
+ "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
- "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
+ "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b",
"shasum": ""
},
"require": {
@@ -728,13 +762,10 @@
"type": "library",
"autoload": {
"classmap": [
- "PHP/"
+ "src/"
]
},
"notification-url": "https://packagist.org/downloads/",
- "include-path": [
- ""
- ],
"license": [
"BSD-3-Clause"
],
@@ -750,20 +781,20 @@
"keywords": [
"timer"
],
- "time": "2013-08-02 07:42:54"
+ "time": "2015-06-21 08:01:12"
},
{
"name": "phpunit/php-token-stream",
- "version": "1.4.1",
+ "version": "1.4.3",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-token-stream.git",
- "reference": "eab81d02569310739373308137284e0158424330"
+ "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/eab81d02569310739373308137284e0158424330",
- "reference": "eab81d02569310739373308137284e0158424330",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/7a9b0969488c3c54fd62b4d504b3ec758fd005d9",
+ "reference": "7a9b0969488c3c54fd62b4d504b3ec758fd005d9",
"shasum": ""
},
"require": {
@@ -799,7 +830,7 @@
"keywords": [
"tokenizer"
],
- "time": "2015-04-08 04:46:07"
+ "time": "2015-06-19 03:43:16"
},
{
"name": "phpunit/phpunit",
@@ -875,22 +906,23 @@
},
{
"name": "phpunit/phpunit-mock-objects",
- "version": "2.3.3",
+ "version": "2.3.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git",
- "reference": "253c005852591fd547fc18cd5b7b43a1ec82d8f7"
+ "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/253c005852591fd547fc18cd5b7b43a1ec82d8f7",
- "reference": "253c005852591fd547fc18cd5b7b43a1ec82d8f7",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/18dfbcb81d05e2296c0bcddd4db96cade75e6f42",
+ "reference": "18dfbcb81d05e2296c0bcddd4db96cade75e6f42",
"shasum": ""
},
"require": {
"doctrine/instantiator": "~1.0,>=1.0.2",
"php": ">=5.3.3",
- "phpunit/php-text-template": "~1.2"
+ "phpunit/php-text-template": "~1.2",
+ "sebastian/exporter": "~1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.4"
@@ -926,104 +958,20 @@
"mock",
"xunit"
],
- "time": "2015-05-29 05:19:18"
- },
- {
- "name": "pimple/pimple",
- "version": "v1.1.1",
- "source": {
- "type": "git",
- "url": "https://github.com/silexphp/Pimple.git",
- "reference": "2019c145fe393923f3441b23f29bbdfaa5c58c4d"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/silexphp/Pimple/zipball/2019c145fe393923f3441b23f29bbdfaa5c58c4d",
- "reference": "2019c145fe393923f3441b23f29bbdfaa5c58c4d",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.0"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "1.1.x-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Pimple": "lib/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- }
- ],
- "description": "Pimple is a simple Dependency Injection Container for PHP 5.3",
- "homepage": "http://pimple.sensiolabs.org",
- "keywords": [
- "container",
- "dependency injection"
- ],
- "time": "2013-11-22 08:30:29"
- },
- {
- "name": "psr/log",
- "version": "1.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/php-fig/log.git",
- "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b",
- "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b",
- "shasum": ""
- },
- "type": "library",
- "autoload": {
- "psr-0": {
- "Psr\\Log\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "PHP-FIG",
- "homepage": "http://www.php-fig.org/"
- }
- ],
- "description": "Common interface for logging libraries",
- "keywords": [
- "log",
- "psr",
- "psr-3"
- ],
- "time": "2012-12-21 11:40:51"
+ "time": "2015-07-10 06:54:24"
},
{
"name": "sebastian/comparator",
- "version": "1.1.1",
+ "version": "1.2.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/comparator.git",
- "reference": "1dd8869519a225f7f2b9eb663e225298fade819e"
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/1dd8869519a225f7f2b9eb663e225298fade819e",
- "reference": "1dd8869519a225f7f2b9eb663e225298fade819e",
+ "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22",
+ "reference": "937efb279bd37a375bcadf584dec0726f84dbf22",
"shasum": ""
},
"require": {
@@ -1037,7 +985,7 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.1.x-dev"
+ "dev-master": "1.2.x-dev"
}
},
"autoload": {
@@ -1074,7 +1022,7 @@
"compare",
"equality"
],
- "time": "2015-01-29 16:28:08"
+ "time": "2015-07-26 15:48:44"
},
{
"name": "sebastian/diff",
@@ -1130,16 +1078,16 @@
},
{
"name": "sebastian/environment",
- "version": "1.2.2",
+ "version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/environment.git",
- "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e"
+ "reference": "4fe0a44cddd8cc19583a024bdc7374eb2fef0b87"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/5a8c7d31914337b69923db26c4221b81ff5a196e",
- "reference": "5a8c7d31914337b69923db26c4221b81ff5a196e",
+ "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4fe0a44cddd8cc19583a024bdc7374eb2fef0b87",
+ "reference": "4fe0a44cddd8cc19583a024bdc7374eb2fef0b87",
"shasum": ""
},
"require": {
@@ -1176,20 +1124,20 @@
"environment",
"hhvm"
],
- "time": "2015-01-01 10:01:08"
+ "time": "2015-07-26 06:42:57"
},
{
"name": "sebastian/exporter",
- "version": "1.2.0",
+ "version": "1.2.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/exporter.git",
- "reference": "84839970d05254c73cde183a721c7af13aede943"
+ "reference": "7ae5513327cb536431847bcc0c10edba2701064e"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943",
- "reference": "84839970d05254c73cde183a721c7af13aede943",
+ "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e",
+ "reference": "7ae5513327cb536431847bcc0c10edba2701064e",
"shasum": ""
},
"require": {
@@ -1242,7 +1190,7 @@
"export",
"exporter"
],
- "time": "2015-01-27 07:23:06"
+ "time": "2015-06-21 07:55:53"
},
{
"name": "sebastian/global-state",
@@ -1297,16 +1245,16 @@
},
{
"name": "sebastian/recursion-context",
- "version": "1.0.0",
+ "version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/recursion-context.git",
- "reference": "3989662bbb30a29d20d9faa04a846af79b276252"
+ "reference": "994d4a811bafe801fb06dccbee797863ba2792ba"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252",
- "reference": "3989662bbb30a29d20d9faa04a846af79b276252",
+ "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba",
+ "reference": "994d4a811bafe801fb06dccbee797863ba2792ba",
"shasum": ""
},
"require": {
@@ -1346,20 +1294,20 @@
],
"description": "Provides functionality to recursively process PHP variables",
"homepage": "http://www.github.com/sebastianbergmann/recursion-context",
- "time": "2015-01-24 09:48:32"
+ "time": "2015-06-21 08:04:50"
},
{
"name": "sebastian/version",
- "version": "1.0.5",
+ "version": "1.0.6",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/version.git",
- "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4"
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/ab931d46cd0d3204a91e1b9a40c4bc13032b58e4",
- "reference": "ab931d46cd0d3204a91e1b9a40c4bc13032b58e4",
+ "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
+ "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6",
"shasum": ""
},
"type": "library",
@@ -1381,117 +1329,35 @@
],
"description": "Library that helps with managing the version number of Git-hosted PHP projects",
"homepage": "https://github.com/sebastianbergmann/version",
- "time": "2015-02-24 06:35:25"
+ "time": "2015-06-21 13:59:46"
},
{
- "name": "silex/silex",
- "version": "v1.2.4",
+ "name": "squizlabs/php_codesniffer",
+ "version": "2.3.3",
"source": {
"type": "git",
- "url": "https://github.com/silexphp/Silex.git",
- "reference": "417deb440eecf776df868d8760d0b7d8e2c4e6d1"
+ "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
+ "reference": "c1a26c729508f73560c1a4f767f60b8ab6b4a666"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/silexphp/Silex/zipball/417deb440eecf776df868d8760d0b7d8e2c4e6d1",
- "reference": "417deb440eecf776df868d8760d0b7d8e2c4e6d1",
+ "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/c1a26c729508f73560c1a4f767f60b8ab6b4a666",
+ "reference": "c1a26c729508f73560c1a4f767f60b8ab6b4a666",
"shasum": ""
},
"require": {
- "php": ">=5.3.3",
- "pimple/pimple": "~1.0",
- "symfony/event-dispatcher": "~2.3,<2.7",
- "symfony/http-foundation": "~2.3,<2.7",
- "symfony/http-kernel": "~2.3,<2.7",
- "symfony/routing": "~2.3,<2.7"
- },
- "require-dev": {
- "doctrine/dbal": "~2.2",
- "monolog/monolog": "~1.4,>=1.4.1",
- "swiftmailer/swiftmailer": "5.*",
- "symfony/browser-kit": "~2.3,<2.7",
- "symfony/config": "~2.3,<2.7",
- "symfony/css-selector": "~2.3,<2.7",
- "symfony/debug": "~2.3,<2.7",
- "symfony/dom-crawler": "~2.3,<2.7",
- "symfony/finder": "~2.3,<2.7",
- "symfony/form": "~2.3,<2.7",
- "symfony/locale": "~2.3,<2.7",
- "symfony/monolog-bridge": "~2.3,<2.7",
- "symfony/options-resolver": "~2.3,<2.7",
- "symfony/process": "~2.3,<2.7",
- "symfony/security": "~2.3,<2.7",
- "symfony/serializer": "~2.3,<2.7",
- "symfony/translation": "~2.3,<2.7",
- "symfony/twig-bridge": "~2.3,<2.7",
- "symfony/validator": "~2.3,<2.7",
- "twig/twig": ">=1.8.0,<2.0-dev"
- },
- "suggest": {
- "symfony/browser-kit": "~2.3",
- "symfony/css-selector": "~2.3",
- "symfony/dom-crawler": "~2.3",
- "symfony/form": "~2.3"
+ "ext-tokenizer": "*",
+ "ext-xmlwriter": "*",
+ "php": ">=5.1.2"
},
+ "bin": [
+ "scripts/phpcs",
+ "scripts/phpcbf"
+ ],
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "1.2.x-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Silex": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Igor Wiedler",
- "email": "igor@wiedler.ch"
- }
- ],
- "description": "The PHP micro-framework based on the Symfony2 Components",
- "homepage": "http://silex.sensiolabs.org",
- "keywords": [
- "microframework"
- ],
- "time": "2015-04-11 12:43:27"
- },
- {
- "name": "squizlabs/php_codesniffer",
- "version": "2.3.2",
- "source": {
- "type": "git",
- "url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
- "reference": "e96d8579fbed0c95ecf2a0501ec4f307a4aa6404"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/e96d8579fbed0c95ecf2a0501ec4f307a4aa6404",
- "reference": "e96d8579fbed0c95ecf2a0501ec4f307a4aa6404",
- "shasum": ""
- },
- "require": {
- "ext-tokenizer": "*",
- "ext-xmlwriter": "*",
- "php": ">=5.1.2"
- },
- "bin": [
- "scripts/phpcs",
- "scripts/phpcbf"
- ],
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.0.x-dev"
+ "dev-master": "2.0.x-dev"
}
},
"autoload": {
@@ -1537,20 +1403,20 @@
"phpcs",
"standards"
],
- "time": "2015-04-28 23:28:20"
+ "time": "2015-06-24 03:16:23"
},
{
"name": "symfony/config",
- "version": "v2.7.0",
+ "version": "v2.7.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/Config.git",
- "reference": "537e9912063e66aa70cbcddd7d6e6e8db61d98e4"
+ "reference": "6c905bbed1e728226de656e4c07d620dfe9e80d9"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/Config/zipball/537e9912063e66aa70cbcddd7d6e6e8db61d98e4",
- "reference": "537e9912063e66aa70cbcddd7d6e6e8db61d98e4",
+ "url": "https://api.github.com/repos/symfony/Config/zipball/6c905bbed1e728226de656e4c07d620dfe9e80d9",
+ "reference": "6c905bbed1e728226de656e4c07d620dfe9e80d9",
"shasum": ""
},
"require": {
@@ -1587,80 +1453,20 @@
],
"description": "Symfony Config Component",
"homepage": "https://symfony.com",
- "time": "2015-05-15 13:33:16"
- },
- {
- "name": "symfony/debug",
- "version": "v2.7.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Debug.git",
- "reference": "1df2971b27a6ff73dae4ea622f42802000ec332d"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Debug/zipball/1df2971b27a6ff73dae4ea622f42802000ec332d",
- "reference": "1df2971b27a6ff73dae4ea622f42802000ec332d",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.9",
- "psr/log": "~1.0"
- },
- "conflict": {
- "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2"
- },
- "require-dev": {
- "symfony/class-loader": "~2.2",
- "symfony/http-foundation": "~2.1",
- "symfony/http-kernel": "~2.3.24|~2.5.9|~2.6,>=2.6.2",
- "symfony/phpunit-bridge": "~2.7"
- },
- "suggest": {
- "symfony/http-foundation": "",
- "symfony/http-kernel": ""
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.7-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Symfony\\Component\\Debug\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony Debug Component",
- "homepage": "https://symfony.com",
- "time": "2015-05-22 14:54:25"
+ "time": "2015-07-09 16:07:40"
},
{
"name": "symfony/dependency-injection",
- "version": "v2.7.0",
+ "version": "v2.7.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/DependencyInjection.git",
- "reference": "137bf489c5151c7eb1e4b7dd34a123f9a74b966d"
+ "reference": "d56b1b89a0c8b34a6eca6211ec76c43256ec4030"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/137bf489c5151c7eb1e4b7dd34a123f9a74b966d",
- "reference": "137bf489c5151c7eb1e4b7dd34a123f9a74b966d",
+ "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/d56b1b89a0c8b34a6eca6211ec76c43256ec4030",
+ "reference": "d56b1b89a0c8b34a6eca6211ec76c43256ec4030",
"shasum": ""
},
"require": {
@@ -1707,79 +1513,20 @@
],
"description": "Symfony DependencyInjection Component",
"homepage": "https://symfony.com",
- "time": "2015-05-29 14:44:44"
- },
- {
- "name": "symfony/event-dispatcher",
- "version": "v2.6.9",
- "target-dir": "Symfony/Component/EventDispatcher",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/EventDispatcher.git",
- "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/672593bc4b0043a0acf91903bb75a1c82d8f2e02",
- "reference": "672593bc4b0043a0acf91903bb75a1c82d8f2e02",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "psr/log": "~1.0",
- "symfony/config": "~2.0,>=2.0.5",
- "symfony/dependency-injection": "~2.6",
- "symfony/expression-language": "~2.6",
- "symfony/phpunit-bridge": "~2.7",
- "symfony/stopwatch": "~2.3"
- },
- "suggest": {
- "symfony/dependency-injection": "",
- "symfony/http-kernel": ""
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.6-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\EventDispatcher\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony EventDispatcher Component",
- "homepage": "https://symfony.com",
- "time": "2015-05-02 15:18:45"
+ "time": "2015-07-09 16:07:40"
},
{
"name": "symfony/filesystem",
- "version": "v2.7.0",
+ "version": "v2.7.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/Filesystem.git",
- "reference": "ae4551fd6d4d4f51f2e7390fbc902fbd67f3b7ba"
+ "reference": "2d7b2ddaf3f548f4292df49a99d19c853d43f0b8"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/Filesystem/zipball/ae4551fd6d4d4f51f2e7390fbc902fbd67f3b7ba",
- "reference": "ae4551fd6d4d4f51f2e7390fbc902fbd67f3b7ba",
+ "url": "https://api.github.com/repos/symfony/Filesystem/zipball/2d7b2ddaf3f548f4292df49a99d19c853d43f0b8",
+ "reference": "2d7b2ddaf3f548f4292df49a99d19c853d43f0b8",
"shasum": ""
},
"require": {
@@ -1815,270 +1562,20 @@
],
"description": "Symfony Filesystem Component",
"homepage": "https://symfony.com",
- "time": "2015-05-15 13:33:16"
- },
- {
- "name": "symfony/http-foundation",
- "version": "v2.6.9",
- "target-dir": "Symfony/Component/HttpFoundation",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/HttpFoundation.git",
- "reference": "f9b28dcc6d3e50f5568b42dda7292656a9fe8432"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/f9b28dcc6d3e50f5568b42dda7292656a9fe8432",
- "reference": "f9b28dcc6d3e50f5568b42dda7292656a9fe8432",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "symfony/expression-language": "~2.4",
- "symfony/phpunit-bridge": "~2.7"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.6-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\HttpFoundation\\": ""
- },
- "classmap": [
- "Symfony/Component/HttpFoundation/Resources/stubs"
- ]
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony HttpFoundation Component",
- "homepage": "https://symfony.com",
- "time": "2015-05-22 14:53:08"
- },
- {
- "name": "symfony/http-kernel",
- "version": "v2.6.9",
- "target-dir": "Symfony/Component/HttpKernel",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/HttpKernel.git",
- "reference": "7c883eb1a5d8b52b1fa6d4134b82304c6bb7007f"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/7c883eb1a5d8b52b1fa6d4134b82304c6bb7007f",
- "reference": "7c883eb1a5d8b52b1fa6d4134b82304c6bb7007f",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3",
- "psr/log": "~1.0",
- "symfony/debug": "~2.6,>=2.6.2",
- "symfony/event-dispatcher": "~2.5.9|~2.6,>=2.6.2",
- "symfony/http-foundation": "~2.5,>=2.5.4"
- },
- "require-dev": {
- "symfony/browser-kit": "~2.3",
- "symfony/class-loader": "~2.1",
- "symfony/config": "~2.0,>=2.0.5",
- "symfony/console": "~2.3",
- "symfony/css-selector": "~2.0,>=2.0.5",
- "symfony/dependency-injection": "~2.2",
- "symfony/dom-crawler": "~2.0,>=2.0.5",
- "symfony/expression-language": "~2.4",
- "symfony/finder": "~2.0,>=2.0.5",
- "symfony/phpunit-bridge": "~2.7",
- "symfony/process": "~2.0,>=2.0.5",
- "symfony/routing": "~2.2",
- "symfony/stopwatch": "~2.3",
- "symfony/templating": "~2.2",
- "symfony/translation": "~2.0,>=2.0.5",
- "symfony/var-dumper": "~2.6"
- },
- "suggest": {
- "symfony/browser-kit": "",
- "symfony/class-loader": "",
- "symfony/config": "",
- "symfony/console": "",
- "symfony/dependency-injection": "",
- "symfony/finder": "",
- "symfony/var-dumper": ""
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.6-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\HttpKernel\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony HttpKernel Component",
- "homepage": "https://symfony.com",
- "time": "2015-05-29 22:55:07"
- },
- {
- "name": "symfony/process",
- "version": "v2.7.0",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Process.git",
- "reference": "e0a82b58e36afc60f8e79b8bc85a22bb064077c1"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Process/zipball/e0a82b58e36afc60f8e79b8bc85a22bb064077c1",
- "reference": "e0a82b58e36afc60f8e79b8bc85a22bb064077c1",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.9"
- },
- "require-dev": {
- "symfony/phpunit-bridge": "~2.7"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.7-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Symfony\\Component\\Process\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony Process Component",
- "homepage": "https://symfony.com",
- "time": "2015-05-15 13:33:16"
- },
- {
- "name": "symfony/routing",
- "version": "v2.6.9",
- "target-dir": "Symfony/Component/Routing",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/Routing.git",
- "reference": "dc9df18a1cfe87de65e270e8f01407ca6d7c39cb"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/Routing/zipball/dc9df18a1cfe87de65e270e8f01407ca6d7c39cb",
- "reference": "dc9df18a1cfe87de65e270e8f01407ca6d7c39cb",
- "shasum": ""
- },
- "require": {
- "php": ">=5.3.3"
- },
- "require-dev": {
- "doctrine/annotations": "~1.0",
- "doctrine/common": "~2.2",
- "psr/log": "~1.0",
- "symfony/config": "~2.2",
- "symfony/expression-language": "~2.4",
- "symfony/http-foundation": "~2.3",
- "symfony/phpunit-bridge": "~2.7",
- "symfony/yaml": "~2.0,>=2.0.5"
- },
- "suggest": {
- "doctrine/annotations": "For using the annotation loader",
- "symfony/config": "For using the all-in-one router or any loader",
- "symfony/expression-language": "For using expression matching",
- "symfony/yaml": "For using the YAML loader"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "2.6-dev"
- }
- },
- "autoload": {
- "psr-0": {
- "Symfony\\Component\\Routing\\": ""
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
- "description": "Symfony Routing Component",
- "homepage": "https://symfony.com",
- "keywords": [
- "router",
- "routing",
- "uri",
- "url"
- ],
- "time": "2015-05-15 13:32:45"
+ "time": "2015-07-09 16:07:40"
},
{
"name": "symfony/yaml",
- "version": "v2.7.0",
+ "version": "v2.7.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
- "reference": "4a29a5248aed4fb45f626a7bbbd330291492f5c3"
+ "reference": "4bfbe0ed3909bfddd75b70c094391ec1f142f860"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/Yaml/zipball/4a29a5248aed4fb45f626a7bbbd330291492f5c3",
- "reference": "4a29a5248aed4fb45f626a7bbbd330291492f5c3",
+ "url": "https://api.github.com/repos/symfony/Yaml/zipball/4bfbe0ed3909bfddd75b70c094391ec1f142f860",
+ "reference": "4bfbe0ed3909bfddd75b70c094391ec1f142f860",
"shasum": ""
},
"require": {
@@ -2114,14 +1611,13 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
- "time": "2015-05-02 15:21:08"
+ "time": "2015-07-01 11:25:50"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
- "phpmd/phpmd": 0,
- "internations/http-mock": 20
+ "phpmd/phpmd": 0
},
"prefer-stable": false,
"prefer-lowest": false,
diff --git a/index.php b/index.php
index 7740ba24..9d093869 100755
--- a/index.php
+++ b/index.php
@@ -1,11 +1,11 @@
tickets()->create(array(
- 'subject' => 'The quick brown fox jumps over the lazy dog',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
+ 'subject' => 'The quick brown fox jumps over the lazy dog',
+ 'comment' => array(
+ 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
+ ),
+ 'priority' => 'normal'
));
print_r($newTicket);
// Update multiple tickets
$client->ticket(array(123, 456))->update(array(
- 'status' => 'urgent'
+ 'status' => 'urgent'
));
// Delete a ticket
diff --git a/oauth.php b/oauth.php
index 3cc90607..faefceef 100755
--- a/oauth.php
+++ b/oauth.php
@@ -1,26 +1,26 @@
getDebug()->lastResponseCode == 200) && ($response->access_token)) {
- echo "
Success!
";
- echo "Your OAuth token is: " . $response->access_token . "
";
- echo "Use this code before any other API call:
";
- echo "<?
\$client = new ZendeskAPI(\$subdomain, \$username);
\$client->setAuth('oauth_token', '" . $response->access_token . "');
?>
";
- } else {
- echo "Error!
";
- echo "We couldn't get an access token for you. Please check your credentials and try again.
";
- }
+ $response = Http::oauth($client, $_REQUEST['code'], $oAuthId, $oAuthSecret);
+ if (($client->getDebug()->lastResponseCode == 200) && ($response->access_token)) {
+ echo "Success!
";
+ echo "Your OAuth token is: " . $response->access_token . "
";
+ echo "Use this code before any other API call:
";
+ echo "<?
\$client = new ZendeskAPI(\$subdomain, \$username);
\$client->setAuth('oauth_token', '" . $response->access_token . "');
?>
";
+ } else {
+ echo "Error!
";
+ echo "We couldn't get an access token for you. Please check your credentials and try again.
";
+ }
} else {
- echo "Click to request an OAuth token";
+ echo "Click to request an OAuth token";
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 89d0b425..00aa23da 100755
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -8,18 +8,17 @@
convertWarningsToExceptions="true"
>
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Zendesk/API/ActivityStream.php b/src/Zendesk/API/ActivityStream.php
deleted file mode 100755
index 870cc035..00000000
--- a/src/Zendesk/API/ActivityStream.php
+++ /dev/null
@@ -1,67 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Find a specific activity
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('activities/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/AppInstallations.php b/src/Zendesk/API/AppInstallations.php
deleted file mode 100755
index b44f9bbf..00000000
--- a/src/Zendesk/API/AppInstallations.php
+++ /dev/null
@@ -1,99 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update an app installation
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('apps/installations/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, $params, 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete an app installation
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('apps/installations/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Apps.php b/src/Zendesk/API/Apps.php
deleted file mode 100755
index 3d7abe4e..00000000
--- a/src/Zendesk/API/Apps.php
+++ /dev/null
@@ -1,207 +0,0 @@
-installations = new AppInstallations($client);
- }
-
- /**
- * Uploads an app - see http://developer.zendesk.com/documentation/rest_api/apps.html for workflow
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function upload(array $params)
- {
- if (!$this->hasKeys($params, array('file'))) {
- throw new MissingParametersException(__METHOD__, array('file'));
- }
- $endPoint = Http::prepare('apps/uploads.json');
- $response = Http::send($this->client, $endPoint, array('uploaded_data' => $params['file']), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create an app
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('apps.json');
- $response = Http::send($this->client, $endPoint, $params, 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 202)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Get a job status
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function jobStatus(array $params)
- {
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('apps/job_statuses/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update an app
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('file', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('file', 'id'));
- }
- $endPoint = Http::prepare('apps/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, array('uploaded_data' => $params['file']), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete an app
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('apps/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Send an app notification
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function sendNotification(array $params)
- {
- $endPoint = Http::prepare('apps/notify.json');
- $response = Http::send($this->client, $endPoint, $params, 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param int|null $id
- *
- * @return AppInstallations
- */
- public function installations($id = null)
- {
- return ($id != null ? $this->installations->setLastId($id) : $this->installations);
- }
-
- /**
- * @param int $id
- *
- * @return AppInstallations
- */
- public function installation($id)
- {
- return $this->installations->setLastId($id);
- }
-
-}
diff --git a/src/Zendesk/API/Attachments.php b/src/Zendesk/API/Attachments.php
deleted file mode 100755
index 70575461..00000000
--- a/src/Zendesk/API/Attachments.php
+++ /dev/null
@@ -1,153 +0,0 @@
-hasKeys($params, array('file'))) {
- throw new MissingParametersException(__METHOD__, array('file'));
- }
- if (!file_exists($params['file'])) {
- throw new CustomException('File ' . $params['file'] . ' could not be found in ' . __METHOD__);
- }
- if (!$params['name'] && strrpos($params['file'], '/') > -1) {
- $path_array = explode('/', $params['file']);
- $file_index = count($path_array) - 1;
- $params['name'] = $path_array[$file_index];
- }
- if (!$params['name'] && strrpos($params['file'], '/') == false) {
- $params['name'] = $params['file'];
- }
-
- $endPoint = Http::prepare('uploads.json?filename=' . urlencode($params['name']) . (isset($params['optional_token']) ? '&token=' . $params['optional_token'] : ''));
- $response = Http::send($this->client, $endPoint, array('filename' => $params['file']), 'POST',
- (isset($params['type']) ? $params['type'] : 'application/binary'));
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Upload an attachment from a buffer in memory
- * $params must include:
- * 'body' - the raw file data to upload
- * 'name' - the filename
- * 'type' - the MIME type of the file
- * Optional:
- * 'optional_token' - an existing token
- *
- * @param array $params
- *
- * @throws CustomException
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function uploadWithBody(array $params)
- {
- if (!$this->hasKeys($params, array('body'))) {
- throw new MissingParametersException(__METHOD__, array('body'));
- }
- if (!$params['name']) {
- throw new MissingParametersException(__METHOD__, array('name'));
- }
- $endPoint = Http::prepare('uploads.json?filename=' . $params['name'] . (isset($params['optional_token']) ? '&token=' . $params['optional_token'] : ''));
- $response = Http::send($this->client, $endPoint, array('body' => $params['body']), 'POST',
- (isset($params['type']) ? $params['type'] : 'application/binary'));
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete one or more attachments by token or id
- * $params must include one of these:
- * 'token' - the token given to you after the original upload
- * 'id' - the id of the attachment
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params)
- {
- if (!$this->hasAnyKey($params, array('id', 'token'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'token'));
- }
- $endPoint = Http::prepare(($params['token'] ? 'uploads/' . $params['token'] : 'attachments/' . $params['id']) . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Get a list of uploaded attachments (by id)
- * $params must include:
- * 'id' - the id of the attachment
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params)
- {
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('attachments/' . $id . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/AuditLogs.php b/src/Zendesk/API/AuditLogs.php
deleted file mode 100755
index ef09b933..00000000
--- a/src/Zendesk/API/AuditLogs.php
+++ /dev/null
@@ -1,64 +0,0 @@
-client, $endPoint, $params, 'GET');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific audit log
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('audit_logs/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Autocomplete.php b/src/Zendesk/API/Autocomplete.php
deleted file mode 100755
index 8d6555b5..00000000
--- a/src/Zendesk/API/Autocomplete.php
+++ /dev/null
@@ -1,40 +0,0 @@
-hasKeys($params, array('name'))) {
- throw new MissingParametersException(__METHOD__, array('name'));
- }
- $endPoint = Http::prepare('autocomplete/tags.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params['name']), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Automations.php b/src/Zendesk/API/Automations.php
deleted file mode 100755
index 016580c8..00000000
--- a/src/Zendesk/API/Automations.php
+++ /dev/null
@@ -1,151 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific automation
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('automations/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create an automation
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('automations.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update an automation
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('automations/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete an automation
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('automations/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Categories.php b/src/Zendesk/API/Categories.php
deleted file mode 100755
index 61a35890..00000000
--- a/src/Zendesk/API/Categories.php
+++ /dev/null
@@ -1,151 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific category
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('categories/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new category
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('categories.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a category
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('categories/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a category
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('categories/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Client.php b/src/Zendesk/API/Client.php
deleted file mode 100755
index c7bce9d7..00000000
--- a/src/Zendesk/API/Client.php
+++ /dev/null
@@ -1,521 +0,0 @@
-subdomain = $subdomain;
- $this->username = $username;
- $this->hostname = $hostname;
- $this->scheme = $scheme;
- $this->port = $port;
-
- if (empty($subdomain)) {
- $this->apiUrl = "$scheme://$hostname:$port/api/{$this->apiVer}/";
- } else {
- $this->apiUrl = "$scheme://$subdomain.$hostname:$port/api/{$this->apiVer}/";
- }
-
- $this->debug = new Debug();
- $this->tickets = new Tickets($this);
- $this->ticketFields = new TicketFields($this);
- $this->ticketForms = new TicketForms($this);
- $this->twitter = new Twitter($this);
- $this->attachments = new Attachments($this);
- $this->requests = new Requests($this);
- $this->views = new Views($this);
- $this->users = new Users($this);
- $this->userFields = new UserFields($this);
- $this->groups = new Groups($this);
- $this->groupMemberships = new GroupMemberships($this);
- $this->customRoles = new CustomRoles($this);
- $this->forums = new Forums($this);
- $this->categories = new Categories($this);
- $this->topics = new Topics($this);
- $this->settings = new Settings($this);
- $this->activityStream = new ActivityStream($this);
- $this->auditLogs = new AuditLogs($this);
- $this->autocomplete = new Autocomplete($this);
- $this->automations = new Automations($this);
- $this->jobStatuses = new JobStatuses($this);
- $this->macros = new Macros($this);
- $this->dynamicContent = new DynamicContent($this);
- $this->oauthClients = new OAuthClients($this);
- $this->oauthTokens = new OAuthTokens($this);
- $this->organizationFields = new OrganizationFields($this);
- $this->organizations = new Organizations($this);
- $this->satisfactionRatings = new SatisfactionRatings($this);
- $this->search = new Search($this);
- $this->sharingAgreements = new SharingAgreements($this);
- $this->suspendedTickets = new SuspendedTickets($this);
- $this->tags = new Tags($this);
- $this->targets = new Targets($this);
- $this->triggers = new Triggers($this);
- $this->voice = new Voice($this);
- $this->locales = new Locales($this);
- $this->push_notification_devices = new PushNotificationDevices($this);
- }
-
- /**
- * Configure the authorization method
- *
- * @param string $method
- * @param string $value
- */
- public function setAuth($method, $value)
- {
- switch ($method) {
- case 'password':
- $this->password = $value;
- $this->token = '';
- $this->oAuthToken = '';
- break;
- case 'token':
- $this->password = '';
- $this->token = $value;
- $this->oAuthToken = '';
- break;
- case 'oauth_token':
- $this->password = '';
- $this->token = '';
- $this->oAuthToken = $value;
- break;
- }
- }
-
- /**
- * Returns the supplied subdomain
- *
- * @return string
- */
- public function getSubdomain()
- {
- return $this->subdomain;
- }
-
- /**
- * Returns the generated api URL
- *
- * @return string
- */
- public function getApiUrl()
- {
- return $this->apiUrl;
- }
-
- /**
- * Returns a text value indicating the type of authorization configured
- *
- * @return string
- */
- public function getAuthType()
- {
- return ($this->oAuthToken ? 'oauth_token' : ($this->token ? 'token' : 'password'));
- }
-
- /**
- * Compiles an auth string with either token, password or OAuth credentials
- *
- * @return string
- */
- public function getAuthText()
- {
- return ($this->oAuthToken ? $this->oAuthToken : $this->username . ($this->token ? '/token:' . $this->token : ':' . $this->password));
- }
-
- /**
- * Set debug information as an object
- *
- * @param mixed $lastRequestHeaders
- * @param mixed $lastResponseCode
- * @param string $lastResponseHeaders
- * @param mixed $lastResponseError
- */
- public function setDebug($lastRequestHeaders, $lastResponseCode, $lastResponseHeaders, $lastResponseError)
- {
- $this->debug->lastRequestHeaders = $lastRequestHeaders;
- $this->debug->lastResponseCode = $lastResponseCode;
- $this->debug->lastResponseHeaders = $lastResponseHeaders;
- $this->debug->lastResponseError = $lastResponseError;
- }
-
- /**
- * Returns debug information in an object
- *
- * @return Debug
- */
- public function getDebug()
- {
- return $this->debug;
- }
-
- /**
- * Sideload setter
- *
- * @param array|null $fields
- *
- * @return Client
- */
- public function setSideload(array $fields = null)
- {
- $this->sideload = $fields;
-
- return $this;
- }
-
- /**
- * Sideload getter
- *
- * @param array|null $params
- *
- * @return array|null
- */
- public function getSideload(array $params = null)
- {
- return ((isset($params['sideload'])) && (is_array($params['sideload'])) ? $params['sideload'] : $this->sideload);
- }
-
- /**
- * Generic method to object getter. Since all objects are protected, this method
- * exposes a getter function with the same name as the protected variable, for example
- * $client->tickets can be referenced by $client->tickets()
- *
- * @param $name
- * @param $arguments
- *
- * @throws CustomException
- */
- public function __call($name, $arguments)
- {
- if (isset($this->$name)) {
- return ((isset($arguments[0])) && ($arguments[0] != null) ? $this->$name->setLastId($arguments[0]) : $this->$name);
- }
- $namePlural = $name . 's'; // try pluralize
- if (isset($this->$namePlural)) {
- return $this->$namePlural->setLastId($arguments[0]);
- } else {
- throw new CustomException("No method called $name available in " . __CLASS__);
- }
- }
-
- /*
- * These ones don't follow the usual construct
- */
-
- /**
- * @param int $id
- *
- * @return $this
- */
- public function category($id)
- {
- return $this->categories->setLastId($id);
- }
-
- /**
- * @param int|null $id
- *
- * @return ActivityStream
- */
- public function activities($id = null)
- {
- return ($id != null ? $this->activityStream()->setLastId($id) : $this->activityStream());
- }
-
- /**
- * @param int $id
- *
- * @return ActivityStream
- */
- public function activity($id)
- {
- return $this->activityStream()->setLastId($id);
- }
-
- /**
- * @param int $id
- *
- * @return JobStatuses
- */
- public function jobStatus($id)
- {
- return $this->jobStatuses()->setLastId($id);
- }
-
- /**
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function search(array $params)
- {
- return $this->search->performSearch($params);
- }
-
- /**
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function anonymousSearch(array $params)
- {
- return $this->search->anonymousSearch($params);
- }
-
-}
diff --git a/src/Zendesk/API/ClientAbstract.php b/src/Zendesk/API/ClientAbstract.php
deleted file mode 100755
index cb9c40b3..00000000
--- a/src/Zendesk/API/ClientAbstract.php
+++ /dev/null
@@ -1,105 +0,0 @@
-client = $client;
- }
-
- /**
- * Saves an id for future methods in the chain
- *
- * @param int $id
- *
- * @return $this
- */
- public function setLastId($id)
- {
- $this->lastId = $id;
-
- return $this;
- }
-
- /**
- * Saves an id for future methods in the chain
- *
- * @return int
- */
- public function getLastId()
- {
- return $this->lastId;
- }
-
- /**
- * Check that all parameters have been supplied
- *
- * @param array $params
- * @param array $mandatory
- *
- * @return bool
- */
- public function hasKeys(array $params, array $mandatory)
- {
- for ($i = 0; $i < count($mandatory); $i++) {
- if (!array_key_exists($mandatory[$i], $params)) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Check that any parameter has been supplied
- *
- * @param array $params
- * @param array $mandatory
- *
- * @return bool
- */
- public function hasAnyKey(array $params, array $mandatory)
- {
- for ($i = 0; $i < count($mandatory); $i++) {
- if (array_key_exists($mandatory[$i], $params)) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Enable side-loading (beta) - flags until the next chain
- *
- * @param array $fields
- *
- * @return $this
- */
- public function sideload(array $fields = array())
- {
- $this->client->setSideload($fields);
-
- return $this;
- }
-
-}
diff --git a/src/Zendesk/API/ClientInterface.php b/src/Zendesk/API/ClientInterface.php
deleted file mode 100755
index 5b4a9003..00000000
--- a/src/Zendesk/API/ClientInterface.php
+++ /dev/null
@@ -1,12 +0,0 @@
-handle = curl_init($url);
- }
-
- public function close()
- {
- return curl_close($this->handle);
- }
-
- public function copy_handle()
- {
- return curl_copy_handle($this->handle);
- }
-
- public function errno()
- {
- return curl_errno($this->handle);
- }
-
- public function error()
- {
- return curl_error($this->handle);
- }
-
- public function escape($str)
- {
- return curl_escape($this->handle, $str);
- }
-
- public function exec()
- {
- return curl_exec($this->handle);
- }
-
- public function file_create($filename, $mimetype = null, $postname = null)
- {
- return curl_file_create($filename, $mimetype, $postname);
- }
-
- public function getinfo($opt = 0)
- {
- return curl_getinfo($this->handle, $opt);
- }
-
- public function pause($bitmask)
- {
- return curl_pause($this->handle, $bitmask);
- }
-
- public function reset()
- {
- return curl_reset($this->handle);
- }
-
- public function setopt_array($options)
- {
- return curl_setopt_array($this->handle, $options);
- }
-
- public function setopt($option, $value)
- {
- return curl_setopt($this->handle, $option, $value);
- }
-
- public function strerror($errornum)
- {
- return curl_strerror($errornum);
- }
-
- public function unescape($str)
- {
- return curl_unescape($this->handle, $str);
- }
-
- public function version($age = CURLVERSION_NOW)
- {
- return curl_version($age);
- }
-}
diff --git a/src/Zendesk/API/CustomRoles.php b/src/Zendesk/API/CustomRoles.php
deleted file mode 100755
index d44f5423..00000000
--- a/src/Zendesk/API/CustomRoles.php
+++ /dev/null
@@ -1,37 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Debug.php b/src/Zendesk/API/Debug.php
index e860ddcb..fb87c753 100755
--- a/src/Zendesk/API/Debug.php
+++ b/src/Zendesk/API/Debug.php
@@ -4,11 +4,13 @@
/**
* Debug helper class
- * @package Zendesk\API
*/
class Debug
{
-
+ /**
+ * @var mixed
+ */
+ public $lastRequestBody;
/**
* @var mixed
*/
@@ -32,13 +34,14 @@ class Debug
public function __toString()
{
$lastError = $this->lastResponseError;
- if (!is_string($lastError)) {
+ if (! is_string($lastError)) {
$lastError = json_encode($lastError);
}
$output = 'LastResponseCode: ' . $this->lastResponseCode
- . ', LastResponseError: ' . $lastError
- . ', LastResponseHeaders: ' . $this->lastResponseHeaders
- . ', LastRequestHeaders: ' . $this->lastRequestHeaders;
+ . ', LastResponseError: ' . $lastError
+ . ', LastResponseHeaders: ' . $this->lastResponseHeaders
+ . ', LastRequestHeaders: ' . $this->lastRequestHeaders
+ . ', LastRequestBody: ' . $this->lastRequestBody;
return $output;
}
diff --git a/src/Zendesk/API/DynamicContent.php b/src/Zendesk/API/DynamicContent.php
deleted file mode 100755
index 9529cbcf..00000000
--- a/src/Zendesk/API/DynamicContent.php
+++ /dev/null
@@ -1,90 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a dynamic content
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('dynamic_content/items.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a dynamic content
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('dynamic_content/items/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Exceptions/ApiResponseException.php b/src/Zendesk/API/Exceptions/ApiResponseException.php
new file mode 100644
index 00000000..c488e763
--- /dev/null
+++ b/src/Zendesk/API/Exceptions/ApiResponseException.php
@@ -0,0 +1,59 @@
+getResponse();
+ $message = $response->getReasonPhrase();
+
+ $level = floor($response->getStatusCode() / 100);
+ // Check if business-level error message
+ // https://developer.zendesk.com/rest_api/docs/core/introduction#requests
+ if ($response->getHeaderLine('Content-Type') == 'application/json; charset=UTF-8') {
+ $responseBody = json_decode($response->getBody()->getContents());
+
+ $this->errorDetails = $responseBody->details;
+ $message = $responseBody->description . "\n" . 'Errors: ' . print_r($this->errorDetails, true);
+ } elseif ($level == '5') {
+ $message = 'Zendesk may be experiencing internal issues or undergoing scheduled maintenance.';
+ }
+
+ parent::__construct($message, $response->getStatusCode());
+ }
+
+ /**
+ * Returns an array of error fields with descriptions.
+ *
+ * {
+ * "email": [{
+ * "description": "Email: roge@example.org is already being used by another user",
+ * "error": "DuplicateValue"
+ * }],
+ * "external_id":[{
+ * "description": "External has already been taken",
+ * "error": "DuplicateValue"
+ * }]
+ * }
+ *
+ * @return array
+ */
+ public function getErrorDetails()
+ {
+ return $this->errorDetails;
+ }
+}
diff --git a/src/Zendesk/API/Exceptions/AuthException.php b/src/Zendesk/API/Exceptions/AuthException.php
new file mode 100755
index 00000000..aa8da1c3
--- /dev/null
+++ b/src/Zendesk/API/Exceptions/AuthException.php
@@ -0,0 +1,11 @@
+getDebug() for details' . $detail,
- $code, $previous);
+ parent::__construct(
+ 'Response to ' . $method . ' is not valid. Call $client->getDebug() for details' . $detail,
+ $code,
+ $previous
+ );
}
-
}
diff --git a/src/Zendesk/API/Exceptions/RouteException.php b/src/Zendesk/API/Exceptions/RouteException.php
new file mode 100644
index 00000000..c78edab3
--- /dev/null
+++ b/src/Zendesk/API/Exceptions/RouteException.php
@@ -0,0 +1,7 @@
+client->forums()->getLastId() != null) {
- $params['forum_id'] = $this->client->forums()->getLastId();
- $this->client->forums()->setLastId(null);
- }
- $endPoint = Http::prepare((isset($params['forum_id']) ? 'forum/' . $params['forum_id'] . '/subscriptions.json' : 'forum_subscriptions.json'),
- null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific forum subscription
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('forum_subscriptions/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new forum subscription
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->client->forums()->getLastId() != null) {
- $params['forum_id'] = $this->client->forums()->getLastId();
- $this->client->forums()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('user_id', 'forum_id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'forum_id'));
- }
- $endPoint = Http::prepare('forum_subscriptions.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a forum subscription
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('forum_subscriptions/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Forums.php b/src/Zendesk/API/Forums.php
deleted file mode 100755
index 5624d0b2..00000000
--- a/src/Zendesk/API/Forums.php
+++ /dev/null
@@ -1,190 +0,0 @@
-subscriptions = new ForumSubscriptions($client);
- }
-
- /**
- * List all forums
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function findAll(array $params = array())
- {
- $endPoint = Http::prepare((isset($params['category_id']) ? 'categories/' . $params['category_id'] . '/forums.json' : 'forums.json'),
- null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific forum
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('forums/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new forum
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('forums.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a forum
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('forums/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a forum
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('forums/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param int|null $id
- *
- * @return ForumSubscriptions
- */
- public function subscriptions($id = null)
- {
- return ($id != null ? $this->subscriptions->setLastId($id) : $this->subscriptions);
- }
-
- /**
- * @param int $id
- *
- * @return ForumSubscriptions
- */
- public function subscription($id)
- {
- return $this->subscriptions->setLastId($id);
- }
-}
diff --git a/src/Zendesk/API/GroupMemberships.php b/src/Zendesk/API/GroupMemberships.php
deleted file mode 100755
index 6ef033d9..00000000
--- a/src/Zendesk/API/GroupMemberships.php
+++ /dev/null
@@ -1,208 +0,0 @@
-client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->client->groups()->getLastId() != null) {
- $params['group_id'] = $this->client->groups()->getLastId();
- $this->client->groups()->setLastId(null);
- }
- $endPoint = Http::prepare(
- (isset($params['assignable']) ? (isset($params['group_id']) ? 'groups/' . $params['group_id'] . '/memberships/assignable.json' : 'group_memberships/assignable.json') :
- (isset($params['user_id']) ? 'users/' . $params['user_id'] . '/group_memberships.json' :
- (isset($params['group_id']) ? 'groups/' . $params['group_id'] . '/memberships.json' : 'group_memberships.json'))),
- $this->client->getSideload($params), $params
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific group membership by id
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((isset($params['user_id']) ? 'users/' . $params['user_id'] . '/group_memberships/' . $params['id'] . '.json' : 'group_memberships/' . $params['id'] . '.json'),
- $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new group membership
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->client->groups()->getLastId() != null) {
- $params['group_id'] = $this->client->groups()->getLastId();
- $this->client->groups()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('user_id', 'group_id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'group_id'));
- }
- $endPoint = Http::prepare((isset($params['user_id']) ? 'users/' . $params['user_id'] . '/group_memberships.json' : 'group_memberships.json'));
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create multiple new group memberships
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function createMany(array $params) {
- $endPoint = Http::prepare('group_memberships/create_many.json');
- $response = Http::send($this->client, $endPoint, array (self::OBJ_NAME_PLURAL => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
- return $response;
- }
-
- /**
- * Delete a group membership
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((isset($params['user_id']) ? 'users/' . $params['user_id'] . '/group_memberships/' . $params['id'] . '.json' : 'group_memberships/' . $params['id'] . '.json'));
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Make this group membership the default
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function makeDefault(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('user_id', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'id'));
- }
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/group_memberships/' . $params['id'] . '/make_default.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Groups.php b/src/Zendesk/API/Groups.php
deleted file mode 100755
index 01a26ea2..00000000
--- a/src/Zendesk/API/Groups.php
+++ /dev/null
@@ -1,179 +0,0 @@
-client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- $endPoint = Http::prepare(
- (isset($params['user_id']) ? 'users/' . $params['user_id'] . '/groups.json' :
- (isset($params['assignable']) ? 'groups/assignable.json' : 'groups.json')),
- $this->client->getSideload($params), $params
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific group
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('groups/' . $params['id'] . '.json', $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new group
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('groups.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a group
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('groups/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a group
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('groups/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * @param int|null $id
- *
- * @return GroupMemberships
- */
- public function members($id = null)
- {
- return ($id != null ? $this->client->groupMemberships()->setLastId($id) : $this->client->groupMemberships());
- }
-
- /**
- * @param int $id
- *
- * @return GroupMemberships
- */
- public function member($id)
- {
- return $this->client->groupMemberships()->setLastId($id);
- }
-
-}
diff --git a/src/Zendesk/API/Http.php b/src/Zendesk/API/Http.php
old mode 100755
new mode 100644
index 55bea614..3c219075
--- a/src/Zendesk/API/Http.php
+++ b/src/Zendesk/API/Http.php
@@ -2,6 +2,12 @@
namespace Zendesk\API;
+use GuzzleHttp\Exception\RequestException;
+use GuzzleHttp\Psr7\LazyOpenStream;
+use GuzzleHttp\Psr7\Request;
+use Zendesk\API\Exceptions\ApiResponseException;
+use Zendesk\API\Exceptions\AuthException;
+
/**
* HTTP functions via curl
* @package Zendesk\API
@@ -13,179 +19,151 @@ class Http
/**
* Prepares an endpoint URL with optional side-loading
*
- * @param string $endPoint
* @param array $sideload
* @param array $iterators
*
* @return string
*/
- public static function prepare($endPoint, array $sideload = null, array $iterators = null)
+ public static function prepareQueryParams(array $sideload = null, array $iterators = null)
{
- $addParams = array();
+ $addParams = [];
// First look for side-loaded variables
if (is_array($sideload)) {
$addParams['include'] = implode(',', $sideload);
}
+
// Next look for special collection iterators
if (is_array($iterators)) {
foreach ($iterators as $k => $v) {
- if (in_array($k, array('per_page', 'page', 'sort_order', 'sort_by'))) {
+ if (in_array($k, ['per_page', 'page', 'sort_order', 'sort_by'])) {
$addParams[$k] = $v;
}
}
}
- // Send it back...
- if (count($addParams)) {
- return $endPoint . (strpos($endPoint, '?') === false ? '?' : '&') . http_build_query($addParams);
- } else {
- return $endPoint;
- }
+
+ return $addParams;
}
/**
* Use the send method to call every endpoint except for oauth/tokens
*
- * @param Client $client
- * @param string $endPoint
- * @param array $json
- * @param string $method
- * @param string $contentType
- *
- * @throws \Exception
+ * @param HttpClient $client
+ * @param string $endPoint E.g. "/tickets.json"
+ * @param array $options
+ * Available options are listed below:
+ * array $queryParams Array of unencoded key-value pairs, e.g. ["ids" => "1,2,3,4"]
+ * array $postFields Array of unencoded key-value pairs, e.g. ["filename" => "blah.png"]
+ * string $method "GET", "POST", etc. Default is GET.
+ * string $contentType Default is "application/json"
*
- * @return mixed
+ * @return array The response body, parsed from JSON into an associative array
+ * @throws ApiResponseException
+ * @throws AuthException
*/
public static function send(
- Client $client,
+ HttpClient $client,
$endPoint,
- $json = array(),
- $method = 'GET',
- $contentType = 'application/json'
+ $options = []
) {
- $url = $client->getApiUrl() . $endPoint;
- $method = strtoupper($method);
-
- $curl = (isset(self::$curl)) ? self::$curl : new CurlRequest;
- $curl->setopt(CURLOPT_URL, $url);
+ $options = array_merge(
+ [
+ 'method' => 'GET',
+ 'contentType' => 'application/json',
+ 'postFields' => null,
+ 'queryParams' => null
+ ],
+ $options
+ );
- if ($method === 'POST') {
- $curl->setopt(CURLOPT_POST, true);
+ $headers = [
+ 'Accept' => 'application/json',
+ 'Content-Type' => $options['contentType'],
+ 'User-Agent' => $client->getUserAgent()
+ ];
- } else {
- if ($method === 'PUT') {
- $curl->setopt(CURLOPT_CUSTOMREQUEST, 'PUT');
+ $request = new Request(
+ $options['method'],
+ $client->getApiUrl() . $endPoint,
+ $headers
+ );
- } else {
- $st = http_build_query((array)$json);
- $curl->setopt(CURLOPT_URL,
- $url . ($st !== array() ? (strpos($url, '?') === false ? '?' : '&') . $st : ''));
- $curl->setopt(CURLOPT_CUSTOMREQUEST, $method);
+ $requestOptions = [];
+
+ if (! empty($options['multipart'])) {
+ $request = $request->withoutHeader('Content-Type');
+ $requestOptions['multipart'] = $options['multipart'];
+ } elseif (! empty($options['postFields'])) {
+ $request = $request->withBody(\GuzzleHttp\Psr7\stream_for(json_encode($options['postFields'])));
+ } elseif (! empty($options['file'])) {
+ if (is_file($options['file'])) {
+ $fileStream = new LazyOpenStream($options['file'], 'r');
+ $request = $request->withBody($fileStream);
}
}
- $httpHeader = array('Accept: application/json');
- if ($client->getAuthType() == 'oauth_token') {
- $httpHeader[] = 'Authorization: Bearer ' . $client->getAuthText();
-
- } else {
- $curl->setopt(CURLOPT_USERPWD, $client->getAuthText());
- }
-
- /* DO NOT SET CONTENT TYPE IF UPLOADING */
- if (!isset($json['uploaded_data'])) {
- if (isset($json['filename'])) {
- $filename = $json['filename'];
- $file = fopen($filename, 'r');
- $size = filesize($filename);
- $fileData = fread($file, $size);
- $json = $fileData;
- $curl->setopt(CURLOPT_INFILE, $file);
- $curl->setopt(CURLOPT_INFILESIZE, $size);
- } else {
- if (isset($json['body'])) {
- $curl->setopt(CURLOPT_INFILESIZE, strlen($json['body']));
- $json = $json['body'];
- }
+ if (! empty($options['queryParams'])) {
+ foreach ($options['queryParams'] as $queryKey => $queryValue) {
+ $uri = $request->getUri();
+ $uri = $uri->withQueryValue($uri, $queryKey, $queryValue);
+ $request = $request->withUri($uri, true);
}
-
- $httpHeader[] = 'Content-Type: ' . $contentType;
- } else {
- $contentType = '';
}
- if ($contentType === 'application/json') {
- $json = json_encode($json);
+ try {
+ list ($request, $requestOptions) = $client->getAuth()->prepareRequest($request, $requestOptions);
+ $response = $client->guzzle->send($request, $requestOptions);
+ } catch (RequestException $e) {
+ throw new ApiResponseException($e);
+ } finally {
+ $client->setDebug(
+ $request->getHeaders(),
+ $request->getBody()->getContents(),
+ isset($response) ? $response->getStatusCode() : null,
+ isset($response) ? $response->getHeaders() : null,
+ isset($e) ? $e : null
+ );
+
+ $request->getBody()->rewind();
}
- $curl->setopt(CURLOPT_POSTFIELDS, $json);
- $curl->setopt(CURLOPT_HTTPHEADER, $httpHeader);
- $curl->setopt(CURLINFO_HEADER_OUT, true);
- $curl->setopt(CURLOPT_RETURNTRANSFER, true);
- $curl->setopt(CURLOPT_CONNECTTIMEOUT, 30);
- $curl->setopt(CURLOPT_TIMEOUT, 30);
- $curl->setopt(CURLOPT_SSL_VERIFYPEER, false);
- $curl->setopt(CURLOPT_HEADER, true);
- $curl->setopt(CURLOPT_VERBOSE, true);
- $curl->setopt(CURLOPT_FOLLOWLOCATION, true);
- $curl->setopt(CURLOPT_MAXREDIRS, 3);
-
- $response = $curl->exec();
- if ($response === false) {
- throw new \Exception(sprintf('Curl error message: "%s" in %s', $curl->error(), __METHOD__));
+ if (isset($file)) {
+ fclose($file);
}
- $headerSize = $curl->getinfo(CURLINFO_HEADER_SIZE);
- $responseBody = substr($response, $headerSize);
- $responseObject = json_decode($responseBody);
- $client->setDebug(
- $curl->getinfo(CURLINFO_HEADER_OUT),
- $curl->getinfo(CURLINFO_HTTP_CODE),
- substr($response, 0, $headerSize),
- (isset($responseObject->error) ? $responseObject : null)
- );
-
- $responseCode = $client->getDebug()->lastResponseCode;
-
- if ($responseCode >= 400) {
- print($client->getDebug());
- throw new ResponseException(__METHOD__);
- }
+ $client->setSideload(null);
- $curl->close();
- self::$curl = null;
-
- return $responseObject;
+ return json_decode($response->getBody()->getContents());
}
/**
* Specific case for OAuth. Run /oauth.php via your browser to get an access token
*
- * @param Client $client
- * @param string $code
- * @param string $oAuthId
- * @param string $oAuthSecret
+ * @param HttpClient $client
+ * @param string $code
+ * @param string $oAuthId
+ * @param string $oAuthSecret
*
* @throws \Exception
- *
* @return mixed
*/
- public static function oauth(Client $client, $code, $oAuthId, $oAuthSecret)
+ public static function oauth(HttpClient $client, $code, $oAuthId, $oAuthSecret)
{
$url = 'https://' . $client->getSubdomain() . '.zendesk.com/oauth/tokens';
- $method = 'POST';
+
+ $protocol = ($_SERVER['HTTPS']) ? 'https://' : 'http://';
$curl = (isset(self::$curl)) ? self::$curl : new CurlRequest;
$curl->setopt(CURLOPT_URL, $url);
$curl->setopt(CURLOPT_POST, true);
- $curl->setopt(CURLOPT_POSTFIELDS, json_encode(array(
- 'grant_type' => 'authorization_code',
- 'code' => $code,
- 'client_id' => $oAuthId,
+ $curl->setopt(CURLOPT_POSTFIELDS, json_encode([
+ 'grant_type' => 'authorization_code',
+ 'code' => $code,
+ 'client_id' => $oAuthId,
'client_secret' => $oAuthSecret,
- 'redirect_uri' => ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
- 'scope' => 'read'
- )));
- $curl->setopt(CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
+ 'redirect_uri' => $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
+ 'scope' => 'read'
+ ]));
+ $curl->setopt(CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
$curl->setopt(CURLINFO_HEADER_OUT, true);
$curl->setopt(CURLOPT_RETURNTRANSFER, true);
$curl->setopt(CURLOPT_CONNECTTIMEOUT, 30);
@@ -199,8 +177,8 @@ public static function oauth(Client $client, $code, $oAuthId, $oAuthSecret)
if ($response === false) {
throw new \Exception(sprintf('Curl error message: "%s" in %s', $curl->error(), __METHOD__));
}
- $headerSize = $curl->getinfo(CURLINFO_HEADER_SIZE);
- $responseBody = substr($response, $headerSize);
+ $headerSize = $curl->getinfo(CURLINFO_HEADER_SIZE);
+ $responseBody = substr($response, $headerSize);
$responseObject = json_decode($responseBody);
$client->setDebug(
$curl->getinfo(CURLINFO_HEADER_OUT),
@@ -214,4 +192,3 @@ public static function oauth(Client $client, $code, $oAuthId, $oAuthSecret)
return $responseObject;
}
}
-
diff --git a/src/Zendesk/API/HttpClient.php b/src/Zendesk/API/HttpClient.php
new file mode 100644
index 00000000..8882f3ee
--- /dev/null
+++ b/src/Zendesk/API/HttpClient.php
@@ -0,0 +1,431 @@
+guzzle = new \GuzzleHttp\Client();
+ } else {
+ $this->guzzle = $guzzle;
+ }
+
+ $this->subdomain = $subdomain;
+ $this->username = $username;
+ $this->hostname = $hostname;
+ $this->scheme = $scheme;
+ $this->port = $port;
+
+ if (empty($subdomain)) {
+ $this->apiUrl = "$scheme://$hostname:$port/api/{$this->apiVer}/";
+ } else {
+ $this->apiUrl = "$scheme://$subdomain.$hostname:$port/api/{$this->apiVer}/";
+ }
+
+ $this->debug = new Debug();
+ $this->helpCenter = new HelpCenter($this);
+ $this->voice = new Voice($this);
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @return array
+ */
+ public static function getValidSubResources()
+ {
+ return [
+ 'apps' => Apps::class,
+ 'activities' => Activities::class,
+ 'appInstallations' => AppInstallations::class,
+ 'attachments' => Attachments::class,
+ 'auditLogs' => AuditLogs::class,
+ 'autocomplete' => Autocomplete::class,
+ 'automations' => Automations::class,
+ 'bookmarks' => Bookmarks::class,
+ 'brands' => Brands::class,
+ 'customRoles' => CustomRoles::class,
+ 'dynamicContent' => DynamicContent::class,
+ 'groupMemberships' => GroupMemberships::class,
+ 'groups' => Groups::class,
+ 'incremental' => Incremental::class,
+ 'jobStatuses' => JobStatuses::class,
+ 'locales' => Locales::class,
+ 'macros' => Macros::class,
+ 'oauthClients' => OAuthClients::class,
+ 'oauthTokens' => OAuthTokens::class,
+ 'organizationFields' => OrganizationFields::class,
+ 'organizationMemberships' => OrganizationMemberships::class,
+ 'organizations' => Organizations::class,
+ 'organizationSubscriptions' => OrganizationSubscriptions::class,
+ 'pushNotificationDevices' => PushNotificationDevices::class,
+ 'requests' => Requests::class,
+ 'satisfactionRatings' => SatisfactionRatings::class,
+ 'sharingAgreements' => SharingAgreements::class,
+ 'search' => Search::class,
+ 'slaPolicies' => SlaPolicies::class,
+ 'sessions' => Sessions::class,
+ 'supportAddresses' => SupportAddresses::class,
+ 'suspendedTickets' => SuspendedTickets::class,
+ 'tags' => Tags::class,
+ 'targets' => Targets::class,
+ 'tickets' => Tickets::class,
+ 'ticketImports' => TicketImports::class,
+ 'triggers' => Triggers::class,
+ 'twitterHandles' => TwitterHandles::class,
+ 'userFields' => UserFields::class,
+ 'users' => Users::class,
+ 'views' => Views::class,
+ ];
+ }
+
+ /**
+ * @return Auth
+ */
+ public function getAuth()
+ {
+ return $this->auth;
+ }
+
+ /**
+ * Configure the authorization method
+ *
+ * @param $strategy
+ * @param array $options
+ *
+ * @throws AuthException
+ */
+ public function setAuth($strategy, array $options)
+ {
+ $this->auth = new Auth($strategy, $options);
+ }
+
+ public function getUserAgent()
+ {
+ return 'ZendeskAPI PHP ' . self::VERSION;
+ }
+
+ /**
+ * Returns the supplied subdomain
+ *
+ * @return string
+ */
+ public function getSubdomain()
+ {
+ return $this->subdomain;
+ }
+
+ /**
+ * Returns the generated api URL
+ *
+ * @return string
+ */
+ public function getApiUrl()
+ {
+ return $this->apiUrl;
+ }
+
+ /**
+ * Set debug information as an object
+ *
+ * @param mixed $lastRequestHeaders
+ * @param mixed $lastResponseCode
+ * @param string $lastResponseHeaders
+ * @param mixed $lastResponseError
+ */
+ public function setDebug(
+ $lastRequestHeaders,
+ $lastRequestBody,
+ $lastResponseCode,
+ $lastResponseHeaders,
+ $lastResponseError
+ ) {
+ $this->debug->lastRequestHeaders = $lastRequestHeaders;
+ $this->debug->lastRequestBody = $lastRequestBody;
+ $this->debug->lastResponseCode = $lastResponseCode;
+ $this->debug->lastResponseHeaders = $lastResponseHeaders;
+ $this->debug->lastResponseError = $lastResponseError;
+ }
+
+ /**
+ * Returns debug information in an object
+ *
+ * @return Debug
+ */
+ public function getDebug()
+ {
+ return $this->debug;
+ }
+
+ /**
+ * Sideload setter
+ *
+ * @param array|null $fields
+ *
+ * @return HttpClient
+ */
+ public function setSideload(array $fields = null)
+ {
+ $this->sideload = $fields;
+
+ return $this;
+ }
+
+ /**
+ * Sideload getter
+ *
+ * @param array|null $params
+ *
+ * @return array|null
+ */
+ public function getSideload(array $params = null)
+ {
+ if ((isset($params['sideload'])) && (is_array($params['sideload']))) {
+ return $params['sideload'];
+ } else {
+ return $this->sideload;
+ }
+ }
+
+ public function get($endpoint, $queryParams = [])
+ {
+ $sideloads = $this->getSideload($queryParams);
+
+ // TODO: filter allowed query params
+ if (is_array($sideloads)) {
+ $queryParams['include'] = implode(',', $sideloads);
+ unset($queryParams['sideload']);
+ }
+
+ $response = Http::send(
+ $this,
+ $endpoint,
+ ['queryParams' => $queryParams]
+ );
+
+ return $response;
+ }
+
+ /**
+ * This is a helper method to do a post request.
+ *
+ * @param $endpoint
+ * @param array $postData
+ *
+ * @return array
+ * @throws Exceptions\ApiResponseException
+ */
+ public function post($endpoint, $postData = [])
+ {
+ $response = Http::send(
+ $this,
+ $endpoint,
+ [
+ 'postFields' => $postData,
+ 'method' => 'POST'
+ ]
+ );
+
+ return $response;
+ }
+
+ /**
+ * This is a helper method to do a put request.
+ *
+ * @param $endpoint
+ * @param array $putData
+ *
+ * @return array
+ * @throws Exceptions\ApiResponseException
+ */
+ public function put($endpoint, $putData = [])
+ {
+ $response = Http::send(
+ $this,
+ $endpoint,
+ ['postFields' => $putData, 'method' => 'PUT']
+ );
+
+ return $response;
+ }
+
+ /**
+ * This is a helper method to do a delete request.
+ *
+ * @param $endpoint
+ *
+ * @return array
+ * @throws Exceptions\ApiResponseException
+ */
+ public function delete($endpoint)
+ {
+ $response = Http::send(
+ $this,
+ $endpoint,
+ ['method' => 'DELETE']
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/JobStatuses.php b/src/Zendesk/API/JobStatuses.php
deleted file mode 100755
index f8627be5..00000000
--- a/src/Zendesk/API/JobStatuses.php
+++ /dev/null
@@ -1,42 +0,0 @@
-lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('job_statuses/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Locales.php b/src/Zendesk/API/Locales.php
deleted file mode 100755
index 856c728a..00000000
--- a/src/Zendesk/API/Locales.php
+++ /dev/null
@@ -1,121 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific locale
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('locales/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Detect the best locale from the supplied list
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function detectBest(array $params)
- {
- if (!$this->hasKeys($params, array('available_locales'))) {
- throw new MissingParametersException(__METHOD__, array('available_locales'));
- }
- $endPoint = Http::prepare('locales/detect_best_locale.json', null, $params);
- $response = Http::send($this->client, $endPoint, array('available_locales' => $params['available_locales']),
- 'GET');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @throws ResponseException
- *
- * @return mixed
- */
- public function agent()
- {
- return $this->findAll(array('agent' => true));
- }
-
- /**
- * @throws ResponseException
- *
- * @return mixed
- */
- public function current()
- {
- return $this->findAll(array('current' => true));
- }
-
-}
diff --git a/src/Zendesk/API/Macros.php b/src/Zendesk/API/Macros.php
deleted file mode 100755
index d08082f1..00000000
--- a/src/Zendesk/API/Macros.php
+++ /dev/null
@@ -1,184 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific macro
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('macros/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a macro
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('macros.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a macro
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('macros/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a macro
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('macros/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Apply a specific macro
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function apply(array $params = array())
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/macros/' . $params['id'] . '/apply.json' : 'macros/' . $params['id'] . '/apply.json'));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/OAuthClients.php b/src/Zendesk/API/OAuthClients.php
deleted file mode 100755
index 575fdac9..00000000
--- a/src/Zendesk/API/OAuthClients.php
+++ /dev/null
@@ -1,153 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific client
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('oauth/clients/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a client
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('oauth/clients.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a client
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('oauth/clients/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a client
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('oauth/clients/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/OAuthTokens.php b/src/Zendesk/API/OAuthTokens.php
deleted file mode 100755
index 80cac06c..00000000
--- a/src/Zendesk/API/OAuthTokens.php
+++ /dev/null
@@ -1,94 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific token or the current one if no id is specified
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- $endPoint = Http::prepare('oauth/tokens/' . (isset($params['id']) ? $params['id'] : 'current') . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a token
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function revoke(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('oauth/tokens/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/OrganizationFields.php b/src/Zendesk/API/OrganizationFields.php
deleted file mode 100755
index da8fe399..00000000
--- a/src/Zendesk/API/OrganizationFields.php
+++ /dev/null
@@ -1,179 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific organization field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('organization_fields/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new organization field
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('organization_fields.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update an organization field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('organization_fields/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete an organization field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('organization_fields/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Reorder organization fields
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function reorder(array $params)
- {
- if (!$this->hasKeys($params, array('organization_field_ids'))) {
- throw new MissingParametersException(__METHOD__, array('organization_field_ids'));
- }
- $endPoint = Http::prepare('organization_fields/reorder.json');
- $response = Http::send($this->client, $endPoint,
- array('organization_field_ids' => $params['organization_field_ids']), 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Organizations.php b/src/Zendesk/API/Organizations.php
deleted file mode 100755
index 949e475c..00000000
--- a/src/Zendesk/API/Organizations.php
+++ /dev/null
@@ -1,307 +0,0 @@
-client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- $endPoint = Http::prepare((isset($params['user_id']) ? 'users/' . $params['user_id'] . '/organizations.json' : 'organizations.json'),
- $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific organization
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('organizations/' . $params['id'] . '.json', $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new organization
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('organizations.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create multiple new organizations, returns as a job
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function createMany(array $params)
- {
- $endPoint = Http::prepare('organizations/create_many.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME_PLURAL => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update an organization
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('organizations/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete an organization
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('organizations/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Autocomplete a list of organizations
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function autocomplete(array $params = array())
- {
- if (!$this->hasKeys($params, array('name'))) {
- throw new MissingParametersException(__METHOD__, array('name'));
- }
- $endPoint = Http::prepare('organizations/autocomplete.json');
- $response = Http::send($this->client, $endPoint, array('name' => $params['name']), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Get a list of related information
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function related(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('organizations/' . $params['id'] . '/related.json',
- $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Search for organizations
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function search(array $params)
- {
- if (!$this->hasKeys($params, array('external_id'))) {
- throw new MissingParametersException(__METHOD__, array('external_id'));
- }
- $endPoint = Http::prepare('organizations/search.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint, array('external_id' => $params['external_id']), 'GET');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param null $id
- *
- * @return Tickets
- */
- public function tickets($id = null)
- {
- return ($id != null ? $this->client->tickets()->setLastId($id) : $this->client->tickets());
- }
-
- /**
- * @param int $id
- *
- * @return Tickets
- */
- public function ticket($id)
- {
- return $this->client->tickets()->setLastId($id);
- }
-
- /**
- * @param int|null $id
- *
- * @return Tags
- */
- public function tags($id = null)
- {
- return ($id != null ? $this->client->tags()->setLastId($id) : $this->client->tags());
- }
-
- /**
- * @param int $id
- *
- * @return Tags
- */
- public function tag($id)
- {
- return $this->client->tags()->setLastId($id);
- }
-
-}
diff --git a/src/Zendesk/API/PushNotificationDevices.php b/src/Zendesk/API/PushNotificationDevices.php
deleted file mode 100755
index 7a253183..00000000
--- a/src/Zendesk/API/PushNotificationDevices.php
+++ /dev/null
@@ -1,43 +0,0 @@
-client, $endPoint, array("push_notification_devices" => $devices), 'POST');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-}
diff --git a/src/Zendesk/API/RequestComments.php b/src/Zendesk/API/RequestComments.php
deleted file mode 100755
index 9345ebcd..00000000
--- a/src/Zendesk/API/RequestComments.php
+++ /dev/null
@@ -1,81 +0,0 @@
-client->requests()->getLastId() != null) {
- $params['request_id'] = $this->client->requests()->getLastId();
- $this->client->requests()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('request_id'))) {
- throw new MissingParametersException(__METHOD__, array('request_id'));
- }
- $endPoint = Http::prepare('requests/' . $params['request_id'] . '/comments.json', null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific request
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->requests()->getLastId() != null) {
- $params['request_id'] = $this->client->requests()->getLastId();
- $this->client->requests()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'request_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'request_id'));
- }
- $endPoint = Http::prepare('requests/' . $params['request_id'] . '/comments/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Requests.php b/src/Zendesk/API/Requests.php
deleted file mode 100755
index 3c4ea7b8..00000000
--- a/src/Zendesk/API/Requests.php
+++ /dev/null
@@ -1,208 +0,0 @@
-comments = new RequestComments($client);
- }
-
- /**
- * List all requests
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function findAll(array $params = array())
- {
- $endPoint = Http::prepare(
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/requests' :
- (isset($params['user_id']) ? 'users/' . $params['user_id'] . '/requests' :
- (isset($params['ccd']) ? 'requests/ccd' :
- (isset($params['solved']) ? 'requests/solved' :
- (isset($params['open']) ? 'requests/open' : 'requests'))))
- ) . '.json' . (isset($params['status']) ? '?status=' . $params['status'] : ''),
- $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific request
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('requests/' . $params['id'] . '.json', $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new request
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('requests.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a request
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('requests/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param int|null $id
- * @return RequestComments
- */
- public function comments($id = null)
- {
- return ($id != null ? $this->comments->setLastId($id) : $this->comments);
- }
-
- /**
- * @param int $id
- *
- * @return $this
- */
- public function comment($id)
- {
- return $this->comments->setLastId($id);
- }
-
- /**
- * @param array $params
- *
- * @throws ResponseException*
- *
- * @return mixed
- */
- public function open(array $params = array())
- {
- $params['open'] = true;
-
- return $this->findAll($params);
- }
-
- /**
- * @param array $params
- *
- * @throws ResponseException
- *
- * @return mixed
- */
- public function solved(array $params = array())
- {
- $params['solved'] = true;
-
- return $this->findAll($params);
- }
-
- /**
- * @param array $params
- *
- * @throws ResponseException
- *
- * @return mixed
- */
- public function ccd(array $params = array())
- {
- $params['ccd'] = true;
-
- return $this->findAll($params);
- }
-
-}
diff --git a/src/Zendesk/API/Resources/Core/Activities.php b/src/Zendesk/API/Resources/Core/Activities.php
new file mode 100755
index 00000000..adb58c88
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Activities.php
@@ -0,0 +1,17 @@
+setRoute('reorder', "{$this->resourceName}/reorder.json");
+ }
+
+ /**
+ * Creates or updates the relevant Location Installation record with the installation order specified
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function reorder(array $params)
+ {
+ return $this->client->post($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/AppInstallations.php b/src/Zendesk/API/Resources/Core/AppInstallations.php
new file mode 100644
index 00000000..d8c50b2f
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/AppInstallations.php
@@ -0,0 +1,66 @@
+setRoutes([
+ 'jobStatuses' => $this->resourceName . '/job_statuses/{job_id}.json',
+ 'requirements' => $this->resourceName . '/{id}/requirements.json',
+ ]);
+ }
+
+ /**
+ * Queries the requirements installation job status using a job id given from the installation step.
+ *
+ * @param $jobId
+ *
+ * @return mixed
+ */
+ public function jobStatuses($jobId)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__, ['job_id' => $jobId]));
+ }
+
+ /**
+ * Lists all Apps Requirements for an installation.
+ *
+ * @param null $appInstallationId
+ * @param array $params
+ *
+ * @return mixed
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function requirements($appInstallationId = null, array $params = [])
+ {
+ return $this->find($appInstallationId, $params, __FUNCTION__);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/AppLocations.php b/src/Zendesk/API/Resources/Core/AppLocations.php
new file mode 100644
index 00000000..dcf9f3e7
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/AppLocations.php
@@ -0,0 +1,31 @@
+setRoutes([
+ 'upload' => "{$this->resourceName}/uploads.json",
+ 'jobStatus' => "{$this->resourceName}/job_statuses/{id}.json",
+ 'create' => "{$this->resourceName}.json",
+ 'update' => "{$this->resourceName}/{id}.json",
+ 'findAllOwned' => "{$this->resourceName}/owned.json",
+ 'install' => "{$this->resourceName}/installations.json",
+ 'notify' => "{$this->resourceName}/notify.json",
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getUploadName()
+ {
+ return 'uploaded_data';
+ }
+
+ /**
+ * {$@inheritdoc}
+ */
+ public function getUploadRequestMethod()
+ {
+ return 'POST';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getValidSubResources()
+ {
+ return [
+ 'installationLocations' => AppInstallationLocations::class,
+ 'locations' => AppLocations::class,
+ ];
+ }
+
+ /**
+ * Create an app
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function create(array $params)
+ {
+ return $this->client->post(
+ $this->getRoute(__FUNCTION__),
+ $params
+ );
+ }
+
+ /**
+ * Queries the application build job status using a job id given from the job creation step.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function jobStatus(array $params)
+ {
+ if (! isset($params['id'])) {
+ $params = $this->addChainedParametersToParams(['id'], ['id' => self::class]);
+ }
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $route = $this->getRoute(__FUNCTION__, ['id' => $params['id']]);
+
+ return $this->client->get($route, $params);
+ }
+
+ /**
+ * Update an app
+ *
+ * @param null $id
+ * @param array $params
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function update($id = null, array $params = [])
+ {
+ if (empty($id)) {
+ if (isset($params['id'])) {
+ $id = $params['id'];
+ } else {
+ $id = $this->getChainedParameter(self::class, null);
+ }
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->client->put(
+ $this->getRoute(__FUNCTION__, ['id' => $id]),
+ $params
+ );
+ }
+
+ /**
+ * Lists apps owned by the current account.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function findAllOwned(array $params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * The notify endpoint allows you to send messages to currently-open instances of an app.
+ * For example, you could send a message to all logged-in agents telling them to take the day off.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function notify(array $params)
+ {
+ return $this->client->post($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * Installs an App on the account. app_id is required, as is a settings hash containing keys for all required
+ * parameters for the app.
+ * Any values in settings that don't correspond to a parameter that the app declares will be silently ignored.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function install(array $params)
+ {
+ return $this->client->post($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Attachments.php b/src/Zendesk/API/Resources/Core/Attachments.php
new file mode 100755
index 00000000..9c8b1434
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Attachments.php
@@ -0,0 +1,99 @@
+setRoutes([
+ 'upload' => "uploads.json",
+ 'deleteUpload' => "uploads/{token}.json",
+ ]);
+ }
+
+ /**
+ * Upload an attachment
+ * $params must include:
+ * 'file' - an attribute with the absolute local file path on the server
+ * 'type' - the MIME type of the file
+ * Optional:
+ * 'optional_token' - an existing token
+ * 'name' - preferred filename
+ *
+ * @param array $params
+ *
+ * @throws CustomException
+ * @throws MissingParametersException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function upload(array $params)
+ {
+ if (! $this->hasKeys($params, ['file'])) {
+ throw new MissingParametersException(__METHOD__, ['file']);
+ } elseif (! file_exists($params['file'])) {
+ throw new CustomException('File ' . $params['file'] . ' could not be found in ' . __METHOD__);
+ }
+
+ if (! isset($params['name'])) {
+ $params['name'] = basename($params['file']);
+ }
+
+ $queryParams = ['filename' => $params['name']];
+ if (isset($params['token'])) {
+ $queryParams['token'] = $params['token'];
+ }
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ [
+ 'method' => 'POST',
+ 'contentType' => 'application/binary',
+ 'file' => $params['file'],
+ 'queryParams' => $queryParams,
+ ]
+ );
+
+ return $response;
+ }
+
+ /**
+ * Delete a resource
+ *
+ * @param $token
+ *
+ * @return bool
+ * @throws MissingParametersException
+ * @throws \Exception
+ * @throws \Zendesk\API\Exceptions\ResponseException
+ */
+ public function deleteUpload($token)
+ {
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__, ['token' => $token]),
+ ['method' => 'DELETE']
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/AuditLogs.php b/src/Zendesk/API/Resources/Core/AuditLogs.php
new file mode 100755
index 00000000..e3fcf043
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/AuditLogs.php
@@ -0,0 +1,54 @@
+setRoutes([
+ 'findAll' => "{$this->resourceName}.json",
+ 'find' => "{$this->resourceName}/{id}.json",
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function findAll(array $params = [])
+ {
+ $sideloads = $this->client->getSideload($params);
+
+ $extraParams = Http::prepareQueryParams($sideloads, $params);
+ $queryParams = array_filter(array_flip($params), [$this, 'filterParams']);
+ $queryParams = array_flip($queryParams);
+
+ $queryParams = array_merge($queryParams, $extraParams);
+
+ return $this->traitFindAll($queryParams);
+ }
+
+ /**
+ * Filter parameters passed and only allow valid query parameters.
+ */
+ private function filterParams($param)
+ {
+ return preg_match("/^filter[\"[a-zA-Z_]*\"]/", $param);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Autocomplete.php b/src/Zendesk/API/Resources/Core/Autocomplete.php
new file mode 100755
index 00000000..16e86845
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Autocomplete.php
@@ -0,0 +1,32 @@
+setRoute('tags', 'autocomplete/tags.json');
+ }
+
+ /**
+ * Submits a request for matching tags
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ * @return mixed
+ */
+ public function tags(array $params)
+ {
+ $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Automations.php b/src/Zendesk/API/Resources/Core/Automations.php
new file mode 100755
index 00000000..03f338be
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Automations.php
@@ -0,0 +1,37 @@
+setRoute('findActive', "{$this->resourceName}/active.json");
+ }
+
+ /**
+ * List all active Automations
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ * @return mixed
+ */
+ public function findActive(array $params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Bookmarks.php b/src/Zendesk/API/Resources/Core/Bookmarks.php
new file mode 100644
index 00000000..a4d05d73
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Bookmarks.php
@@ -0,0 +1,18 @@
+setRoutes([
+ 'checkHostMapping' => "{$this->resourceName}/check_host_mapping.json",
+ 'updateImage' => "{$this->resourceName}/{id}.json",
+ ]);
+ }
+
+ /**
+ * Check host mapping validity
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function checkHostMapping(array $params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getUploadName()
+ {
+ return 'brand[photo][uploaded_data]';
+ }
+
+ /**
+ * {$@inheritdoc}
+ */
+ public function getUploadRequestMethod()
+ {
+ return 'PUT';
+ }
+
+ /**
+ * Update a brand's image
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+ public function updateImage(array $params = [])
+ {
+ $this->setAdditionalRouteParams(['id' => $this->getChainedParameter(self::class)]);
+
+ return $this->upload($params, __FUNCTION__);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/CustomRoles.php b/src/Zendesk/API/Resources/Core/CustomRoles.php
new file mode 100644
index 00000000..3fa3ccd0
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/CustomRoles.php
@@ -0,0 +1,15 @@
+ DynamicContentItems::class,
+ ];
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/DynamicContentItemVariants.php b/src/Zendesk/API/Resources/Core/DynamicContentItemVariants.php
new file mode 100644
index 00000000..584b9806
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/DynamicContentItemVariants.php
@@ -0,0 +1,61 @@
+setRoutes(
+ [
+ 'findAll' => 'dynamic_content/items/{item_id}/variants.json',
+ 'find' => 'dynamic_content/items/{item_id}/variants/{id}.json',
+ 'create' => 'dynamic_content/items/{item_id}/variants.json',
+ 'delete' => 'dynamic_content/items/{item_id}/variants.json',
+ 'createMany' => 'dynamic_content/items/{item_id}/variants/create_many.json',
+ 'updateMany' => 'dynamic_content/items/{item_id}/variants/update_many.json',
+ ]
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['item_id' => DynamicContentItems::class]);
+
+ return parent::getRoute($name, $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/DynamicContentItems.php b/src/Zendesk/API/Resources/Core/DynamicContentItems.php
new file mode 100644
index 00000000..02014739
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/DynamicContentItems.php
@@ -0,0 +1,43 @@
+ DynamicContentItemVariants::class,
+ ];
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/GroupMemberships.php b/src/Zendesk/API/Resources/Core/GroupMemberships.php
new file mode 100644
index 00000000..66b998bc
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/GroupMemberships.php
@@ -0,0 +1,124 @@
+setRoutes([
+ 'assignable' => "{$this->resourceName}/assignable.json",
+ 'makeDefault' => 'users/{userId}/group_memberships/{id}/make_default.json',
+ ]);
+ }
+
+ /**
+ * Returns a route and replaces tokenized parts of the string with
+ * the passed params
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
+ * based on the parent chain
+ * GET /api/v2/groups.json
+ * GET /api/v2/users/{user_id}/groups.json
+ *
+ * @throws \Exception
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $lastChained = $this->getLatestChainedParameter([self::class]);
+
+ $chainableRoutes = ['findAll', 'find', 'create', 'delete', 'assignable'];
+
+ if ((empty($lastChained)) || ! (in_array($name, $chainableRoutes))) {
+ return parent::getRoute($name, $params);
+ }
+
+ $chainedResourceId = reset($lastChained);
+ $chainedResourceNames = array_keys($lastChained);
+ $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ($name === 'assignable' && $chainedResourceName === 'groups') {
+ return "{$chainedResourceName}/{$chainedResourceId}/memberships/assignable.json";
+ }
+
+ if ($name === 'create' && $chainedResourceName === 'users') {
+ return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
+ }
+
+ if (in_array($name, ['find', 'delete']) && $chainedResourceName === 'users') {
+ return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}/{$params['id']}.json";
+ }
+
+ if ($name === 'findAll') {
+ if ($chainedResourceName === 'groups') {
+ return "{$chainedResourceName}/{$chainedResourceId}/memberships.json";
+ } elseif ($chainedResourceName === 'users') {
+ return "{$chainedResourceName}/{$chainedResourceId}/group_memberships.json";
+ }
+ }
+
+ throw new RouteException('Route not found.');
+ }
+
+ /**
+ * List Assignable Memberships
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+ public function assignable(array $params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * Sets the default group membership of a given user.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ */
+ public function makeDefault($params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => self::class, 'userId' => Users::class]);
+
+ if (! $this->hasKeys($params, ['id', 'userId'])) {
+ throw new MissingParametersException(__METHOD__, ['id', 'userId']);
+ }
+
+ return $this->client->put($this->getRoute(__FUNCTION__, $params));
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Groups.php b/src/Zendesk/API/Resources/Core/Groups.php
new file mode 100644
index 00000000..06748c5e
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Groups.php
@@ -0,0 +1,82 @@
+ GroupMemberships::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUpRoutes()
+ {
+ parent::setUpRoutes();
+ $this->setRoute('assignable', 'groups/assignable.json');
+ }
+
+ /**
+ * Returns a route and replaces tokenized parts of the string with
+ * the passed params
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
+ * based on the parent chain
+ * GET /api/v2/groups.json
+ * GET /api/v2/users/{user_id}/groups.json
+ *
+ * @throws \Exception
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $lastChained = $this->getLatestChainedParameter();
+
+ $chainedResourceNames = array_keys($lastChained);
+
+ if (empty($lastChained) || $name !== 'findAll') {
+ return parent::getRoute($name, $params);
+ } else {
+ $id = reset($lastChained);
+ $resource = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ('users' === $resource) {
+ return "users/$id/groups.json";
+ } else {
+ return 'groups.json';
+ }
+ }
+ }
+
+ /**
+ * Show assignable groups
+ *
+ * @return mixed
+ */
+ public function assignable()
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__));
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Incremental.php b/src/Zendesk/API/Resources/Core/Incremental.php
new file mode 100644
index 00000000..6bef15aa
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Incremental.php
@@ -0,0 +1,77 @@
+setRoutes([
+ 'tickets' => "{$this->resourceName}/tickets.json",
+ 'ticketEvents' => "{$this->resourceName}/ticket_events.json",
+ 'organizations' => "{$this->resourceName}/organizations.json",
+ 'users' => "{$this->resourceName}/users.json",
+ ]);
+ }
+
+ /**
+ * Incremental Ticket Export
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function tickets(array $params)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * The Ticket Events Incremental Export API returns a an stream changes that have occurred on tickets.
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function ticketEvents(array $params)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * Get information about organizations updated since a given point in time
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function organizations(array $params)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * Get information about users updated since a given point in time
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function users(array $params)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/JobStatuses.php b/src/Zendesk/API/Resources/Core/JobStatuses.php
new file mode 100644
index 00000000..e2095d3f
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/JobStatuses.php
@@ -0,0 +1,26 @@
+setRoutes([
+ 'findAllPublic' => "{$this->resourceName}/public.json",
+ 'findAllAgent' => "{$this->resourceName}/agent.json",
+ 'findCurrent' => "{$this->resourceName}/current.json",
+ 'findBest' => "{$this->resourceName}/detect_best_locale.json",
+ ]);
+ }
+
+ /**
+ * This lists the translation locales that are available to all accounts
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function findAllPublic(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+
+ /**
+ * This lists the translation locales that have been localized for agents.
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function findAllAgent(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+
+ /**
+ * This works exactly like show, but instead of taking an id as argument,
+ * it renders the locale of the user performing the request
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function findCurrent(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+
+ /**
+ * Detect best language for user
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function findBest(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Macros.php b/src/Zendesk/API/Resources/Core/Macros.php
new file mode 100755
index 00000000..7e5516df
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Macros.php
@@ -0,0 +1,97 @@
+setRoutes([
+ 'findAllActive' => 'macros/active.json',
+ 'apply' => 'macros/{id}/apply.json',
+ 'applyToTicket' => 'tickets/{ticketId}/macros/{id}/apply.json',
+ ]);
+ }
+
+ /**
+ * Lists all active shared and personal macros available to the current user
+ *
+ * @param array $params
+ *
+ * @throws \Exception
+ * @return mixed
+ */
+ public function findAllActive(array $params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+
+ /**
+ * Returns the changes the macro would make to a ticket.
+ *
+ * @param $id
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Exception
+ * @throws \Zendesk\API\Exceptions\ResponseException
+ */
+ public function apply($id)
+ {
+ if (empty($id)) {
+ $id = $this->getChainedParameter(get_class($this));
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->client->get(
+ $this->getRoute(__FUNCTION__, ['id' => $id])
+ );
+ }
+
+ /**
+ * Returns the full ticket object as it would be after applying the macro to the ticket.
+ *
+ * @param $id
+ * @param $ticketId
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Exception
+ * @throws \Zendesk\API\Exceptions\ResponseException
+ */
+ public function applyToTicket($id, $ticketId)
+ {
+ if (empty($id)) {
+ $id = $this->getChainedParameter(get_class($this));
+ }
+
+ if (empty($ticketId)) {
+ $ticketId = $this->getChainedParameter(Tickets::class);
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id', 'ticketId']);
+ }
+
+ return $this->client->get(
+ $this->getRoute(__FUNCTION__, ['id' => $id, 'ticketId' => $ticketId])
+ );
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/OAuthClients.php b/src/Zendesk/API/Resources/Core/OAuthClients.php
new file mode 100644
index 00000000..8a5855f2
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/OAuthClients.php
@@ -0,0 +1,42 @@
+setRoute('findAllMine', 'users/me/oauth/clients.json');
+ }
+
+ /**
+ * Find all oauth clients belonging to the logged in user.
+ *
+ * @param array $params
+ */
+ public function findAllMine(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/OAuthTokens.php b/src/Zendesk/API/Resources/Core/OAuthTokens.php
new file mode 100644
index 00000000..9db39394
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/OAuthTokens.php
@@ -0,0 +1,61 @@
+setRoute('current', "$this->resourceName/current.json");
+ }
+
+ /**
+ * Wrapper for `delete`, called `revoke` in the API docs.
+ *
+ * @param null $id
+ *
+ * @return bool
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function revoke($id = null)
+ {
+ return $this->delete($id, 'delete');
+ }
+
+ /**
+ * Shows the current token
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function current()
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__));
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/OrganizationFields.php b/src/Zendesk/API/Resources/Core/OrganizationFields.php
new file mode 100755
index 00000000..53703516
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/OrganizationFields.php
@@ -0,0 +1,50 @@
+setRoute('reorder', 'organization_fields/reorder.json');
+ }
+
+ /**
+ * Reorder organization fields
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function reorder(array $params)
+ {
+ if (! $this->hasKeys($params, ['organization_field_ids'])) {
+ throw new MissingParametersException(__METHOD__, ['organization_field_ids']);
+ }
+
+ $putData = ['organization_field_ids' => $params['organization_field_ids']];
+
+ $endpoint = $this->getRoute(__FUNCTION__);
+ $response = $this->client->put($endpoint, $putData);
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/OrganizationMemberships.php b/src/Zendesk/API/Resources/Core/OrganizationMemberships.php
new file mode 100644
index 00000000..7cdd62fa
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/OrganizationMemberships.php
@@ -0,0 +1,100 @@
+setRoute('makeDefault', 'users/{userId}/organization_memberships/{id}/make_default.json');
+ }
+
+ /**
+ * Returns a route and replaces tokenized parts of the string with
+ * the passed params
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
+ * based on the parent chain
+ * GET /api/v2/groups.json
+ * GET /api/v2/users/{user_id}/groups.json
+ *
+ * @throws \Exception
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $lastChained = $this->getLatestChainedParameter([self::class]);
+
+ if ((empty($lastChained)) || ! (in_array($name, ['findAll', 'find', 'create', 'delete']))) {
+ return parent::getRoute($name, $params);
+ }
+
+ $chainedResourceId = reset($lastChained);
+ $chainedResourceNames = array_keys($lastChained);
+ $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ($name === 'findAll') {
+ if (in_array($chainedResourceName, ['users', 'organizations'])) {
+ return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
+ }
+
+ return "{$this->resourceName}.json";
+ } elseif (in_array($name, ['find', 'delete'])) {
+ if ($chainedResourceName === 'users') {
+ return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}/{$params['id']}.json";
+ }
+
+ return "{$this->resourceName}/{$params['id']}.json";
+ } elseif ($name === 'create') {
+ if ($chainedResourceName === 'users') {
+ return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
+ }
+
+ return "{$this->resourceName}.json";
+ }
+
+ }
+
+ /**
+ * Sets the default organization membership of a given user.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ */
+ public function makeDefault($params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => self::class, 'userId' => Users::class]);
+
+ if (! $this->hasKeys($params, ['id', 'userId'])) {
+ throw new MissingParametersException(__METHOD__, ['id', 'userId']);
+ }
+
+ return $this->client->put($this->getRoute(__FUNCTION__, $params));
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/OrganizationSubscriptions.php b/src/Zendesk/API/Resources/Core/OrganizationSubscriptions.php
new file mode 100644
index 00000000..116d9b7a
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/OrganizationSubscriptions.php
@@ -0,0 +1,50 @@
+getLatestChainedParameter();
+
+ if (empty($lastChained) || $name !== 'findAll') {
+ return parent::getRoute($name, $params);
+ } else {
+ $id = reset($lastChained);
+ $chainedResourceNames = array_keys($lastChained);
+ $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ('users' === $chainedResourceName) {
+ return "users/$id/organization_subscriptions.json";
+ } elseif ('organizations' === $chainedResourceName) {
+ return "organizations/$id/subscriptions.json";
+ } else {
+ return 'organization_subscriptions.json';
+ }
+ }
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Organizations.php b/src/Zendesk/API/Resources/Core/Organizations.php
new file mode 100644
index 00000000..4a048aae
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Organizations.php
@@ -0,0 +1,148 @@
+ OrganizationMemberships::class,
+ 'subscriptions' => OrganizationSubscriptions::class,
+ 'requests' => Requests::class,
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function setUpRoutes()
+ {
+ parent::setUpRoutes();
+
+ $this->setRoutes(
+ [
+ 'autocomplete' => $this->resourceName . '/autocomplete.json',
+ 'related' => $this->resourceName . '/{id}/related.json',
+ 'search' => $this->resourceName . '/search.json',
+ ]
+ );
+ }
+
+ /**
+ * Returns a route and replaces tokenized parts of the string with
+ * the passed params
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
+ * based on the parent chain
+ * GET /api/v2/organizations.json
+ * GET /api/v2/users/{user_id}/organizations.json
+ *
+ * @throws \Exception
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $lastChained = $this->getLatestChainedParameter();
+
+ $chainedResourceNames = array_keys($lastChained);
+
+ if (empty($lastChained) || $name !== 'findAll') {
+ return parent::getRoute($name, $params);
+ } else {
+ $id = reset($lastChained);
+ $resource = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ('users' === $resource) {
+ return "users/$id/organizations.json";
+ } else {
+ return 'organizations.json';
+ }
+ }
+ }
+
+ /**
+ * Returns an array of organizations whose name starts with the value specified in the name parameter.
+ * The name must be at least 2 characters in length
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\ApiResponseException
+ * @throws \Zendesk\API\Exceptions\AuthException
+ */
+ public function autocomplete($name, array $params = [])
+ {
+ $sideloads = $this->client->getSideload($params);
+
+ $queryParams = Http::prepareQueryParams($sideloads, $params);
+ $queryParams['name'] = $name;
+
+ return $this->client->get($this->getRoute(__FUNCTION__), $queryParams);
+ }
+
+ /**
+ * Show an organization's related information
+ *
+ * @param $id Organization ID
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\ApiResponseException
+ * @throws \Zendesk\API\Exceptions\AuthException
+ */
+ public function related($id)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__, ['id' => $id]));
+ }
+
+ /**
+ * Seach organizations by external ID
+ *
+ * @param $external_id
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\ApiResponseException
+ * @throws \Zendesk\API\Exceptions\AuthException
+ */
+ public function search($external_id, array $params = [])
+ {
+ $sideloads = $this->client->getSideload($params);
+
+ $queryParams = Http::prepareQueryParams($sideloads, $params);
+ $queryParams['external_id'] = $external_id;
+
+ return $this->client->get($this->getRoute(__FUNCTION__), $queryParams);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/PushNotificationDevices.php b/src/Zendesk/API/Resources/Core/PushNotificationDevices.php
new file mode 100755
index 00000000..995d94fe
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/PushNotificationDevices.php
@@ -0,0 +1,44 @@
+setRoute('deleteMany', 'push_notification_devices/destroy_many.json');
+ }
+
+ /**
+ * Unregisters the mobile devices that are receiving push notifications.
+ * Specify the devices as an array of mobile device tokens.
+ *
+ * @param array $params
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function deleteMany(array $params = [])
+ {
+ if (! isset($params['tokens']) || ! is_array($params['tokens'])) {
+ throw new MissingParametersException(__METHOD__, ['tokens']);
+
+ }
+ $postData = [$this->objectNamePlural => $params['tokens']];
+
+ return $this->client->post($this->getRoute(__FUNCTION__), $postData);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/RequestComments.php b/src/Zendesk/API/Resources/Core/RequestComments.php
new file mode 100755
index 00000000..3f4ca634
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/RequestComments.php
@@ -0,0 +1,68 @@
+setRoutes([
+ 'find' => 'requests/{requestId}/comments/{id}.json',
+ 'findAll' => 'requests/{requestId}/comments.json',
+ ]);
+ }
+
+ public function findAll(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['requestId' => Requests::class]);
+
+ return $this->traitFindAll($params);
+ }
+
+ /**
+ * Find a specific ticket by id or series of ids
+ *
+ * @param $id
+ * @param array $queryParams
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Exception
+ */
+ public function find($id = null, array $queryParams = [])
+ {
+ if (empty($id)) {
+ $id = $this->getChainedParameter(get_class($this));
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ if (! ($requestId = $this->getChainedParameter(Requests::class))) {
+ throw new MissingParametersException(__METHOD__, ['requestId']);
+ }
+
+ $route = $this->getRoute(__FUNCTION__, ['id' => $id, 'requestId' => $requestId]);
+
+ return $this->client->get(
+ $route,
+ $queryParams
+ );
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Requests.php b/src/Zendesk/API/Resources/Core/Requests.php
new file mode 100755
index 00000000..eb4d265d
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Requests.php
@@ -0,0 +1,108 @@
+setRoutes([
+ 'findAllOpen' => "{$this->resourceName}/open.json",
+ 'findAllSolved' => "{$this->resourceName}/solved.json",
+ 'findAllCCd' => "{$this->resourceName}/ccd.json",
+ 'search' => "{$this->resourceName}/search.json",
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getValidSubResources()
+ {
+ return [
+ 'comments' => RequestComments::class,
+ ];
+ }
+
+ /**
+ * {$@inheritdoc}
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $lastChained = $this->getLatestChainedParameter([self::class]);
+
+ if ((empty($lastChained)) || ! (in_array($name, ['findAll']))) {
+ return parent::getRoute($name, $params);
+ }
+
+ $chainedResourceId = reset($lastChained);
+ $chainedResourceNames = array_keys($lastChained);
+ $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ($name === 'findAll') {
+ if (in_array($chainedResourceName, ['users', 'organizations'])) {
+ return "{$chainedResourceName}/{$chainedResourceId}/{$this->resourceName}.json";
+ }
+
+ return "{$this->resourceName}.json";
+ }
+ }
+
+ /**
+ * Find all open requests
+ *
+ * @param array $params
+ */
+ public function findAllOpen(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+
+ /**
+ * Find all open requests
+ *
+ * @param array $params
+ */
+ public function findAllSolved(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+
+ /**
+ * Find all open requests
+ *
+ * @param array $params
+ */
+ public function findAllCCd(array $params = [])
+ {
+ $this->findAll($params, __FUNCTION__);
+ }
+
+ /**
+ * Searching requests
+ *
+ * @param array $queryParams
+ *
+ * @return array
+ */
+ public function search(array $queryParams)
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $queryParams);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/SatisfactionRatings.php b/src/Zendesk/API/Resources/Core/SatisfactionRatings.php
new file mode 100644
index 00000000..4db52ce9
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/SatisfactionRatings.php
@@ -0,0 +1,19 @@
+setRoutes(
+ [
+ 'find' => 'search.json',
+ 'anonymous' => 'portal/search.json'
+ ]
+ );
+ }
+
+ /**
+ *
+ * The search API is a unified search API that returns tickets, users, and organizations. You can define filters to
+ * narrow your search results according to resource type, dates, and object properties, such as ticket requester or
+ * tag.
+ *
+ * @param null $query
+ * @param array $queryParams
+ *
+ * @return array
+ * @throws MissingParametersException
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function find($query = null, array $queryParams = [])
+ {
+ if (empty($query)) {
+ throw new MissingParametersException(__METHOD__, ['query']);
+ }
+
+ $queryParams['query'] = $query;
+
+ return $this->client->get($this->getRoute(__FUNCTION__), $queryParams);
+ }
+
+ /**
+ * This resource behaves the same as /api/v2/search, but lets anonymous users search public forums in the Web
+ * portal. The endpoint searches only articles, not tickets, and returns only articles that
+ * the requesting user is allowed to see.
+ *
+ * @param $query
+ * @param array $queryParams
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function anonymous($query, $queryParams = [])
+ {
+ $queryParams['query'] = $query;
+
+ return $this->client->get($this->getRoute(__FUNCTION__), $queryParams);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Sessions.php b/src/Zendesk/API/Resources/Core/Sessions.php
new file mode 100644
index 00000000..1869d2dd
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Sessions.php
@@ -0,0 +1,120 @@
+setRoutes([
+ 'current' => 'users/me/sessions.json',
+ 'delete' => 'users/{userId}/sessions/{id}.json',
+ 'deleteUserSessions' => 'users/{userId}/sessions.json',
+ 'find' => 'users/{userId}/sessions/{id}.json',
+ 'logout' => 'users/me/logout.json',
+ ]);
+ }
+
+ /**
+ * Returns a route and replaces tokenized parts of the string with
+ * the passed params
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return mixed The default routes, or if $name is set to `findAll`, any of the following formats
+ * based on the parent chain
+ * /api/v2/sessions.json
+ * /api/v2/users/{userId}/sessions.json
+ *
+ * @throws \Exception
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $userId = $this->getChainedParameter(Users::class);
+
+ if (in_array($name, ['delete', 'deleteUserSessionss', 'find', 'findAll']) && ! is_null($userId)) {
+ if ($name === 'findAll') {
+ return "users/{$userId}/sessions.json";
+ }
+
+ $params = $this->addChainedParametersToParams($params, ['userId' => Users::class]);
+ }
+
+ return parent::getRoute($name, $params);
+ }
+
+ /**
+ * Deletes all the sessions for a user.
+ *
+ * @param null $userId
+ *
+ * @return array
+ * @throws CustomException
+ * @throws MissingParametersException
+ * @throws RouteException
+ */
+ public function deleteUserSessions($userId = null)
+ {
+ if (empty($userId)) {
+ $lastChained = $this->getLatestChainedParameter([self::class]);
+
+ $chainedResourceNames = array_keys($lastChained);
+ $chainedResourceName = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ if ($chainedResourceName === 'users') {
+ $userId = reset($lastChained);
+ }
+ }
+
+ if (empty($userId)) {
+ throw new MissingParametersException(__METHOD__, ['userId']);
+ }
+
+ return $this->client->delete($this->getRoute(__FUNCTION__, ['userId' => $userId]));
+ }
+
+ /**
+ * Deletes the current session.
+ *
+ * @return array
+ * @throws CustomException
+ * @throws RouteException
+ */
+ public function logout()
+ {
+ return $this->client->delete($this->getRoute(__FUNCTION__));
+ }
+
+ /**
+ * Shows the currently authenticated session
+ *
+ * @return array
+ * @throws RouteException
+ */
+ public function current()
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__));
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/SharingAgreements.php b/src/Zendesk/API/Resources/Core/SharingAgreements.php
new file mode 100755
index 00000000..188ca61c
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/SharingAgreements.php
@@ -0,0 +1,15 @@
+setRoutes([
+ 'replace' => "{$this->resourceName}/{id}/replace.json",
+ 'reorder' => "{$this->resourceName}/reorder.json",
+ 'definitions' => "{$this->resourceName}/definitions.json",
+ ]);
+ }
+
+ /**
+ * Replace a single SLA Policy
+ *
+ * The replaced SLA policy is versioned. Each time an SLA policy is updated, a new SLA policy is saved.
+ * Altering the title or description of SLA policies doesn't constitute a version change.
+ *
+ * @param null $id
+ * @param array $updateResourceFields
+ *
+ * @return mixed
+ */
+ public function replace($id = null, $updateResourceFields = [])
+ {
+ return $this->update($id, $updateResourceFields, __FUNCTION__);
+ }
+
+ /**
+ * Reorder SLA Policies
+ *
+ * @parama array $ids
+ *
+ * @return mixed
+ */
+ public function reorder($ids = [])
+ {
+ return $this->client->put($this->getRoute(__FUNCTION__), ['sla_policy_ids' => $ids]);
+ }
+
+ /**
+ * Retrieve supported filter definition items
+ *
+ * @parama array $ids
+ *
+ * @return mixed
+ */
+ public function definitions(array $params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/SupportAddresses.php b/src/Zendesk/API/Resources/Core/SupportAddresses.php
new file mode 100644
index 00000000..08545f2e
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/SupportAddresses.php
@@ -0,0 +1,40 @@
+setRoute('verify', "{$this->resourceName}/{id}/verify.json");
+ }
+
+ /**
+ * Verify recipient address
+ *
+ * @param null $recipientAddressId
+ * @param array $updateFields
+ *
+ * @return mixed
+ */
+ public function verify($recipientAddressId = null, array $updateFields = [])
+ {
+ $class = get_class($this);
+ if (empty($recipientAddressId)) {
+ $recipientAddressId = $this->getChainedParameter($class);
+ }
+
+ return $this->client->put($this->getRoute(__FUNCTION__, ['id' => $recipientAddressId]), $updateFields);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/SuspendedTickets.php b/src/Zendesk/API/Resources/Core/SuspendedTickets.php
new file mode 100755
index 00000000..ba21bcf2
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/SuspendedTickets.php
@@ -0,0 +1,85 @@
+setRoutes([
+ 'recover' => "{$this->resourceName}/{id}/recover.json",
+ 'recoverMany' => "{$this->resourceName}/recover_many.json",
+ ]);
+ }
+
+ /**
+ * Recovering suspended tickets.
+ *
+ * @param $id
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ */
+ public function recover($id = null)
+ {
+ if (empty($id)) {
+ $id = $this->getChainedParameter(self::class);
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->client->put($this->getRoute(__FUNCTION__, ['id' => $id]));
+ }
+
+ /**
+ * Recovering suspended tickets.
+ *
+ * @param array $ids
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ * @throws \Zendesk\API\Exceptions\ApiResponseException
+ * @throws \Zendesk\API\Exceptions\RouteException
+ *
+ */
+ public function recoverMany(array $ids)
+ {
+ if (! is_array($ids)) {
+ throw new MissingParametersException(__METHOD__, ['ids']);
+ }
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ [
+ 'method' => 'PUT',
+ 'queryParams' => ['ids' => implode(',', $ids)],
+ ]
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Tags.php b/src/Zendesk/API/Resources/Core/Tags.php
new file mode 100644
index 00000000..21e5da9a
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Tags.php
@@ -0,0 +1,53 @@
+getLatestChainedParameter();
+
+ if (empty($lastChained)) {
+ throw new CustomException('The ' . $name . '() method needs to be called while chaining.');
+ }
+
+ $id = reset($lastChained);
+ $chainedResourceNames = array_keys($lastChained);
+ $resource = (new $chainedResourceNames[0]($this->client))->resourceName;
+
+ return "$resource/$id/tags.json";
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Targets.php b/src/Zendesk/API/Resources/Core/Targets.php
new file mode 100644
index 00000000..5fffb1dc
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Targets.php
@@ -0,0 +1,14 @@
+setRoutes([
+ 'findAll' => 'tickets/{ticket_id}/audits.json',
+ 'find' => 'tickets/{ticket_id}/audits/{id}.json',
+ ]);
+ }
+
+ /**
+ * Returns all audits for a particular ticket
+ *
+ * @param array $params
+ *
+ * @return mixed
+ * @throws MissingParametersException
+ */
+ public function findAll(array $params = [])
+ {
+ $routeParams = $this->addChainedParametersToParams($params, ['ticket_id' => Tickets::class]);
+
+ if (! $this->hasKeys($routeParams, ['ticket_id'])) {
+ throw new MissingParametersException(__METHOD__, ['ticket_id']);
+ }
+
+ $this->setAdditionalRouteParams($routeParams);
+
+ return $this->traitFindAll($params);
+ }
+
+ /**
+ * Show a specific audit record
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function find($id = null, array $params = [])
+ {
+ if (empty($id)) {
+ $id = $this->getChainedParameter(get_class($this));
+ }
+
+ $params = $this->addChainedParametersToParams(
+ $params,
+ [
+ 'ticket_id' => Tickets::class,
+ ]
+ );
+
+ if (! $this->hasKeys($params, ['ticket_id'])) {
+ throw new MissingParametersException(__METHOD__, ['ticket_id']);
+ }
+
+ $this->setAdditionalRouteParams(['ticket_id' => $params['ticket_id']]);
+
+ return $this->traitFind($id);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/TicketComments.php b/src/Zendesk/API/Resources/Core/TicketComments.php
new file mode 100755
index 00000000..1875dc8e
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/TicketComments.php
@@ -0,0 +1,102 @@
+setRoutes(
+ [
+ 'findAll' => 'tickets/{ticket_id}/comments.json',
+ 'makePrivate' => 'tickets/{ticket_id}/comments/{id}/make_private.json'
+ ]
+ );
+ }
+
+ /**
+ * Returns all comments for a particular ticket
+ *
+ * @param array $queryParams
+ *
+ * @throws MissingParametersException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function findAll(array $queryParams = [])
+ {
+ $queryParams = $this->addChainedParametersToParams($queryParams, ['ticket_id' => Tickets::class]);
+
+ if (! $this->hasKeys($queryParams, ['ticket_id'])) {
+ throw new MissingParametersException(__METHOD__, ['ticket_id']);
+ }
+
+ return $this->traitFindAll($queryParams);
+ }
+
+ /**
+ * Make the specified comment private
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function makePrivate(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams(
+ $params,
+ ['id' => get_class($this), 'ticket_id' => Tickets::class]
+ );
+
+ if (! $this->hasKeys($params, ['id', 'ticket_id'])) {
+ throw new MissingParametersException(__METHOD__, ['id', 'ticket_id']);
+ }
+
+ return $this->client->put($this->getRoute(__FUNCTION__, $params), $params);
+ }
+
+ /*
+ * Syntactic sugar methods:
+ * Handy aliases:
+ */
+
+ /**
+ * @param array $params
+ *
+ * @return mixed|void
+ * @throws CustomException
+ */
+ public function find($id = null, array $queryQueryParams = [])
+ {
+ throw new CustomException('Method ' . __METHOD__
+ . ' does not exist. Try $client->ticket(ticket_id)->comments()->findAll() instead.');
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/TicketFields.php b/src/Zendesk/API/Resources/Core/TicketFields.php
new file mode 100755
index 00000000..4f099a87
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/TicketFields.php
@@ -0,0 +1,15 @@
+setRoutes([
+ 'clone' => 'ticket_forms/{id}/clone.json',
+ 'reorder' => 'ticket_forms/reorder.json'
+ ]);
+ }
+
+ /**
+ * Clones an existing ticket form (can't use 'clone' as method name)
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws MissingParametersException
+ * @return mixed
+ */
+ public function cloneForm($id = null)
+ {
+ $class = get_class($this);
+ if (empty($id)) {
+ $id = $this->getChainedParameter($class);
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->client->post($this->getRoute('clone', ['id' => $id]));
+ }
+
+ /**
+ * Reorder Ticket forms
+ *
+ * @param array $ticketFormIds
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function reorder(array $ticketFormIds)
+ {
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ ['postFields' => ['ticket_form_ids' => $ticketFormIds], 'method' => 'PUT']
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/TicketImports.php b/src/Zendesk/API/Resources/Core/TicketImports.php
new file mode 100755
index 00000000..887e7b94
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/TicketImports.php
@@ -0,0 +1,34 @@
+setRoutes([
+ 'create' => 'imports/tickets.json',
+ 'createMany' => 'imports/tickets/create_many.json',
+ ]);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/TicketMetrics.php b/src/Zendesk/API/Resources/Core/TicketMetrics.php
new file mode 100644
index 00000000..9de2ae9d
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/TicketMetrics.php
@@ -0,0 +1,43 @@
+setRoute('findAll', "{$this->resourceName}.json");
+ $this->setRoute('find', "{$this->resourceName}/{id}.json");
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getRoute($name, array $params = [])
+ {
+ if ('find' === $name || 'findAll' === $name) {
+ $lastChained = $this->getChainedParameter(Tickets::class);
+
+ if (! empty($lastChained)) {
+ return "tickets/$lastChained/metrics.json";
+ }
+ }
+
+ return parent::getRoute($name, $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Tickets.php b/src/Zendesk/API/Resources/Core/Tickets.php
new file mode 100755
index 00000000..c9ce91d1
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Tickets.php
@@ -0,0 +1,412 @@
+ TicketComments::class,
+ 'forms' => TicketForms::class,
+ 'tags' => Tags::class,
+ 'audits' => TicketAudits::class,
+ 'attachments' => Attachments::class,
+ 'metrics' => TicketMetrics::class,
+ ];
+ }
+
+ /**
+ * Wrapper for common GET requests
+ *
+ * @param $route
+ * @param array $params
+ *
+ * @return array
+ * @throws ResponseException
+ * @throws \Exception
+ */
+ private function sendGetRequest($route, array $params = [])
+ {
+ $queryParams = Http::prepareQueryParams(
+ $this->client->getSideload($params),
+ $params
+ );
+ $response = Http::send(
+ $this->client,
+ $this->getRoute($route, $params),
+ ['queryParams' => $queryParams]
+ );
+
+ return $response;
+ }
+
+ /**
+ * Declares routes to be used by this resource.
+ */
+ protected function setUpRoutes()
+ {
+ parent::setUpRoutes();
+
+ $this->setRoutes([
+ 'findMany' => 'tickets/show_many.json',
+ 'updateMany' => 'tickets/update_many.json',
+ 'markAsSpam' => 'tickets/{id}/mark_as_spam.json',
+ 'markManyAsSpam' => 'tickets/mark_many_as_spam.json',
+ 'related' => 'tickets/{id}/related.json',
+ 'deleteMany' => 'tickets/destroy_many.json',
+ 'collaborators' => 'tickets/{id}/collaborators.json',
+ 'incidents' => 'tickets/{id}/incidents.json',
+ 'problems' => 'problems.json',
+ 'export' => 'exports/tickets.json',
+ 'problemAutoComplete' => 'problems/autocomplete.json'
+ ]);
+ }
+
+ /**
+ * Find a specific twitter generated ticket by id
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function findTwicket(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+ $endPointBase = 'channels/twitter/tickets/' . $params['id'] . '/statuses.json';
+ $endPoint = Http::prepare(
+ $endPointBase . (is_array($params['comment_ids']) ? '?' . implode(',', $params['comment_ids']) : ''),
+ $this->client->getSideload($params)
+ );
+ $response = Http::send($this->client, $endPoint);
+
+ return $response;
+ }
+
+ /**
+ * Create a ticket
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function create(array $params)
+ {
+ if (count($this->lastAttachments)) {
+ $params['comment']['uploads'] = $this->lastAttachments;
+ $this->lastAttachments = [];
+ }
+
+ return $this->traitCreate($params);
+ }
+
+ /**
+ * Create a ticket from a tweet
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function createFromTweet(array $params)
+ {
+ if ((! $params['twitter_status_message_id']) || (! $params['monitored_twitter_handle_id'])) {
+ throw new MissingParametersException(
+ __METHOD__,
+ ['twitter_status_message_id', 'monitored_twitter_handle_id']
+ );
+ }
+ $endPoint = Http::prepare('channels/twitter/tickets.json');
+ $response = Http::send($this->client, $endPoint, [self::OBJ_NAME => $params], 'POST');
+ $lastResponseCode = $this->client->getDebug()->lastResponseCode;
+ if ((! is_object($response)) || ($lastResponseCode != 201)) {
+ throw new ResponseException(
+ __METHOD__,
+ ($lastResponseCode == 422 ? ' (hint: you can\'t create two tickets from the same tweet)' : '')
+ );
+ }
+
+ return $response;
+ }
+
+ /**
+ * Update a ticket or series of tickets
+ *
+ * @param array $updateResourceFields
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function update($id = null, array $updateResourceFields = [])
+ {
+ if (count($this->lastAttachments)) {
+ $updateResourceFields['comment']['uploads'] = $this->lastAttachments;
+ $this->lastAttachments = [];
+ }
+
+ return $this->traitUpdate($id, $updateResourceFields);
+ }
+
+ /**
+ * Update a ticket or series of tickets
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function updateMany(array $params)
+ {
+ if (count($this->lastAttachments)) {
+ $params['comment']['uploads'] = $this->lastAttachments;
+ $this->lastAttachments = [];
+ }
+
+ return $this->bulkUpdate($params);
+ }
+
+ /**
+ * Mark a ticket as spam and suspend the requester
+ *
+ * @param mixed $id The ticket ID, or an array of ticket ID's to mark as spam
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function markAsSpam($id = null)
+ {
+ $options = ['method' => 'PUT'];
+
+ if (is_array($id)) {
+ $options['queryParams']['ids'] = implode(',', $id);
+ $route = $this->getRoute('markManyAsSpam');
+ } else {
+ $params = $this->addChainedParametersToParams(
+ ['id' => $id],
+ ['id' => get_class($this)]
+ );
+ $route = $this->getRoute('markAsSpam', $params);
+ }
+
+ $response = Http::send(
+ $this->client,
+ $route,
+ $options
+ );
+
+ return $response;
+ }
+
+ /**
+ * Get related ticket information
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function related(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->sendGetRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * List collaborators for a ticket
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function collaborators(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->sendGetRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * List incidents for a ticket
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function incidents(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ return $this->sendGetRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * List all problem tickets
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function problems(array $params = [])
+ {
+ return $this->sendGetRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * Add a problem autocomplete
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function problemAutoComplete(array $params)
+ {
+ if (! $params['text']) {
+ throw new MissingParametersException(__METHOD__, ['text']);
+ }
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute('problemAutoComplete'),
+ [
+ 'method' => 'POST',
+ 'postFields' => ['text' => $params['text']]
+ ]
+ );
+
+ return $response;
+ }
+
+ /**
+ * Incremental ticket exports with a supplied start_time
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function export(array $params)
+ {
+ if (! $params['start_time']) {
+ throw new MissingParametersException(__METHOD__, ['start_time']);
+ }
+
+ $queryParams = ["start_time" => $params["start_time"]];
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute('export'),
+ ["queryParams" => $queryParams]
+ );
+
+ return $response;
+ }
+
+ /**
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @return Tickets
+ */
+ public function attach(array $params = [])
+ {
+ if (! $this->hasKeys($params, ['file'])) {
+ throw new MissingParametersException(__METHOD__, ['file']);
+ }
+
+ $upload = $this->client->attachments()->upload($params);
+
+ if ((! is_object($upload->upload)) || (! $upload->upload->token)) {
+ throw new ResponseException(__METHOD__);
+ }
+ $this->lastAttachments[] = $upload->upload->token;
+
+ return $this;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Triggers.php b/src/Zendesk/API/Resources/Core/Triggers.php
new file mode 100755
index 00000000..590620f8
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Triggers.php
@@ -0,0 +1,34 @@
+setRoute('findActive', "{$this->resourceName}/active.json");
+ }
+
+ /**
+ * Finds all active triggers
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function findActive($params = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $params);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/TwitterHandles.php b/src/Zendesk/API/Resources/Core/TwitterHandles.php
new file mode 100644
index 00000000..3b57d246
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/TwitterHandles.php
@@ -0,0 +1,33 @@
+setRoute('reorder', "{$this->resourceName}/reorder.json");
+ }
+
+ /**
+ * Reorder user fields
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function reorder(array $params)
+ {
+ $postFields = ['user_field_ids' => $params];
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ ['postFields' => $postFields, 'method' => 'PUT']
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/UserIdentities.php b/src/Zendesk/API/Resources/Core/UserIdentities.php
new file mode 100755
index 00000000..af682538
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/UserIdentities.php
@@ -0,0 +1,193 @@
+setRoutes([
+ 'findAll' => "users/{userId}/{$this->resourceName}.json",
+ 'find' => "users/{userId}/{$this->resourceName}/{id}.json",
+ 'update' => "users/{userId}/{$this->resourceName}/{id}.json",
+ 'makePrimary' => "users/{userId}/{$this->resourceName}/{id}/make_primary.json",
+ 'verify' => "users/{userId}/{$this->resourceName}/{id}/verify.json",
+ 'requestVerification' => "users/{userId}/{$this->resourceName}/{id}/request_verification.json",
+ 'delete' => "users/{userId}/{$this->resourceName}/{id}.json",
+ 'create' => "users/{userId}/{$this->resourceName}.json",
+ 'createAsEndUser' => "end_users/{userId}/{$this->resourceName}.json",
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function findAll(array $params = [])
+ {
+ $this->addUserIdToRouteParams($params);
+
+ return $this->traitFindAll($params);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function find($id = null, array $queryParams = [])
+ {
+ $this->addUserIdToRouteParams($queryParams);
+
+ return $this->traitFind($id, $queryParams);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function create(array $params = [])
+ {
+ $this->addUserIdToRouteParams($params);
+
+ return $this->traitCreate($params);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function update($id = null, array $updateResourceFields = [])
+ {
+ $this->addUserIdToRouteParams($updateResourceFields);
+
+ return $this->traitUpdate($id, $updateResourceFields);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function delete($id = null)
+ {
+ $this->addUserIdToRouteParams([]);
+
+ return $this->traitDelete($id);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function createAsEndUser(array $params = [])
+ {
+ $this->addUserIdToRouteParams($params);
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ [
+ 'postFields' => [$this->objectName => $params],
+ 'method' => 'POST'
+ ]
+ );
+
+ return $response;
+ }
+
+ /**
+ * This API method allows you to set an identity to primary.
+ */
+ public function makePrimary(array $params = [])
+ {
+ return $this->makePutRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * This API method only allows you to set an identity as verified. This is allowed only for agents.
+ */
+ public function verify(array $params = [])
+ {
+ return $this->makePutRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * This sends a verification email to the user, asking him to click a link in order to
+ * verify ownership of the email address
+ */
+ public function requestVerification(array $params = [])
+ {
+ return $this->makePutRequest(__FUNCTION__, $params);
+ }
+
+ /**
+ * Get the userId passed as a parameter or as a chained parameter
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ */
+ private function addUserIdToRouteParams(array $params)
+ {
+ if (isset($params['userId'])) {
+ $userId = $params['userId'];
+ } else {
+ $userId = $this->getChainedParameter(Users::class);
+ }
+
+ if (empty($userId)) {
+ throw new MissingParametersException(__METHOD__, ['userId']);
+ }
+
+ $this->setAdditionalRouteParams(['userId' => $userId]);
+ }
+
+ /**
+ * This makes a `PUT` request to the endpoint defined by the $callingMethod parameter.
+ *
+ * @param string $callingMethod
+ * @param array $params
+ *
+ * @return array
+ * @throws MissingParametersException
+ * @throws \Exception
+ * @throws \Zendesk\API\Exceptions\ApiResponseException
+ * @throws \Zendesk\API\Exceptions\AuthException
+ */
+ private function makePutRequest($callingMethod, $params = [])
+ {
+ $this->addUserIdToRouteParams($params);
+
+ if (isset($params['id'])) {
+ $id = $params['id'];
+ } else {
+ $id = $this->getChainedParameter(self::class);
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute($callingMethod, ['id' => $id]),
+ ['method' => 'PUT']
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Users.php b/src/Zendesk/API/Resources/Core/Users.php
new file mode 100755
index 00000000..cdf2389e
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Users.php
@@ -0,0 +1,377 @@
+setRoutes([
+ 'related' => 'users/{id}/related.json',
+ 'merge' => 'users/me/merge.json',
+ 'search' => 'users/search.json',
+ 'autocomplete' => 'users/autocomplete.json',
+ 'setPassword' => 'users/{id}/password.json',
+ 'changePassword' => 'users/{id}/password.json',
+ 'updateMany' => 'users/update_many.json',
+ 'createMany' => 'users/create_many.json',
+ 'updateProfileImageFromFile' => 'users/{id}.json',
+ 'updateProfileImageFromUrl' => 'users/{id}.json',
+ ]);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function getValidSubResources()
+ {
+ return [
+ 'groupMemberships' => GroupMemberships::class,
+ 'groups' => Groups::class,
+ 'identities' => UserIdentities::class,
+ 'organizations' => Organizations::class,
+ 'organizationMemberships' => OrganizationMemberships::class,
+ 'organizationSubscriptions' => OrganizationSubscriptions::class,
+ 'requests' => Requests::class,
+ 'sessions' => Sessions::class
+ ];
+ }
+
+ /**
+ * List all users
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function findAll(array $params = [])
+ {
+ if (isset($params['organization_id'])) {
+ $this->endpoint = "organizations/{$params['organization_id']}/users.json";
+ } elseif (isset($params['group_id'])) {
+ $this->endpoint = 'groups/' . $params['group_id'] . '/users.json';
+ } else {
+ $this->endpoint = 'users.json';
+ }
+
+ return $this->traitFindAll();
+ }
+
+ /**
+ * Find users by ids or external_ids
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function findMany(array $params = [])
+ {
+ if (isset($params['ids']) xor isset($params['external_ids'])) {
+ if (isset($params['ids'])) {
+ $key = 'ids';
+ $ids = $params['ids'];
+ } elseif (isset($params['external_ids'])) {
+ $key = 'external_ids';
+ $ids = $params['external_ids'];
+ }
+ } else {
+ throw new \Exception('Missing parameters ids or external_ids');
+ }
+
+ return $this->traitFindMany($ids, [], $key);
+ }
+
+ /**
+ * Get related information about the user
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function related(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $queryParams = Http::prepareQueryParams($this->client->getSideload($params), $params);
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__, ['id' => $params['id']]),
+ ['queryParams' => $queryParams]
+ );
+
+ return $response;
+ }
+
+ /**
+ * Merge the specified user (???)
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function merge(array $params = [])
+ {
+ $myId = $this->getChainedParameter(get_class($this));
+ $mergeMe = ! isset($myId) || is_null($myId);
+ $hasKeys = $mergeMe ? ['email', 'password'] : ['id'];
+ if (! $this->hasKeys($params, $hasKeys)) {
+ throw new MissingParametersException(__METHOD__, $hasKeys);
+ }
+
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ ['postFields' => [$this->objectName => $params], 'method' => 'PUT']
+ );
+
+ return $response;
+ }
+
+ /**
+ * Update multiple users
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @return mixed
+ */
+ public function suspend(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+ $params['suspended'] = true;
+
+ return $this->update($params['id'], $params);
+ }
+
+ /**
+ * Search for users
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function search(array $params)
+ {
+ $queryParams = isset($params['query']) ? ['query' => $params['query']] : [];
+ $extraParams = Http::prepareQueryParams($this->client->getSideload($params), $params);
+
+ return $this->client->get($this->getRoute(__FUNCTION__), array_merge($extraParams, $queryParams));
+ }
+
+ /**
+ * Requests autocomplete for users
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function autocomplete(array $params)
+ {
+ $response = Http::send(
+ $this->client,
+ $this->getRoute(__FUNCTION__),
+ ['method' => 'POST', 'queryParams' => $params]
+ );
+
+ return $response;
+ }
+
+ /**
+ * {$@inheritdoc}
+ *
+ * @return String
+ */
+ public function getUploadName()
+ {
+ return 'user[photo][uploaded_data]';
+ }
+
+ /**
+ * {$@inheritdoc}
+ *
+ * @return String
+ */
+ public function getUploadRequestMethod()
+ {
+ return 'PUT';
+ }
+
+ /**
+ * Update a user's profile image
+ *
+ * @param array $params
+ *
+ * @throws CustomException
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function updateProfileImageFromFile(array $params)
+ {
+ $this->setAdditionalRouteParams(['id' => $this->getChainedParameter(self::class)]);
+
+ return $this->upload($params, __FUNCTION__);
+ }
+
+ /**
+ * Update a user's profile image
+ *
+ * @param array $params
+ *
+ * @throws CustomException
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function updateProfileImageFromUrl(array $params)
+ {
+ if (! isset($params['id']) || empty($params['id'])) {
+ $params = $this->addChainedParametersToParams($params, ['id' => self::class]);
+ }
+
+ if (! $this->hasKeys($params, ['id', 'url'])) {
+ throw new MissingParametersException(__METHOD__, ['id', 'url']);
+ }
+
+ $endpoint = $this->getRoute(__FUNCTION__, ['id' => $params['id']]);
+
+ $putData = [
+ $this->objectName => [
+ 'remote_photo_url' => $params['url']
+ ]
+ ];
+
+ return $this->client->put($endpoint, $putData);
+ }
+
+ /**
+ * Show the current user
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @return mixed
+ */
+ public function me(array $params = [])
+ {
+ $params['id'] = 'me';
+
+ return $this->find($params['id']);
+ }
+
+ /**
+ * Sets a user's initial password
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function setPassword(array $params)
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+ if (! $this->hasKeys($params, ['id', 'password'])) {
+ throw new MissingParametersException(__METHOD__, ['id', 'password']);
+ }
+ $id = $params['id'];
+ unset($params['id']);
+
+ return $this->client->post($this->getRoute(__FUNCTION__, ['id' => $id]), $params);
+ }
+
+ /**
+ * Change a user's password
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ * @return mixed
+ */
+ public function changePassword(array $params)
+ {
+ $params = $this->addChainedParametersToParams($params, ['id' => get_class($this)]);
+ if (! $this->hasKeys($params, ['id', 'previous_password', 'password'])) {
+ throw new MissingParametersException(__METHOD__, ['id', 'previous_password', 'password']);
+ }
+ $id = $params['id'];
+ unset($params['id']);
+
+ return $this->client->put($this->getRoute(__FUNCTION__, ['id' => $id]), $params);
+
+ }
+}
diff --git a/src/Zendesk/API/Resources/Core/Views.php b/src/Zendesk/API/Resources/Core/Views.php
new file mode 100755
index 00000000..854aa429
--- /dev/null
+++ b/src/Zendesk/API/Resources/Core/Views.php
@@ -0,0 +1,238 @@
+setRoutes([
+ 'findAllActive' => 'views/active.json',
+ 'findAllCompact' => 'views/compact.json',
+ 'export' => 'views/{id}/export.json',
+ 'preview' => 'views/preview.json',
+ 'previewCount' => 'views/preview/count.json',
+ 'execute' => 'views/{id}/execute.json',
+ 'tickets' => 'views/{id}/tickets.json',
+ ]);
+ }
+
+ /**
+ * List all active views
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function findAllActive(array $params = [])
+ {
+ return $this->traitFindAll($params, __FUNCTION__);
+ }
+
+ /**
+ * List all active views
+ *
+ * @param array $params
+ *
+ * @return mixed
+ */
+ public function findAllCompact(array $params = [])
+ {
+ return $this->traitFindAll($params, __FUNCTION__);
+ }
+
+ /**
+ * Show a specific view
+ *
+ * @param int $id
+ * @param array $queryParams
+ *
+ * @return mixed
+ */
+ public function find($id = null, array $queryParams = [])
+ {
+ $queryParams = Http::prepareQueryParams(
+ $this->client->getSideload($queryParams),
+ $queryParams
+ );
+
+ return $this->traitFind($id, $queryParams);
+ }
+
+ /**
+ * Execute a specific view
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function execute(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams(
+ $params,
+ ['id' => get_class($this)]
+ );
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $queryParams = Http::prepareQueryParams(
+ $this->client->getSideload($params),
+ $params
+ );
+
+ return $this->client->get($this->getRoute(__FUNCTION__, ['id' => $params['id']]), $queryParams);
+ }
+
+ /**
+ * Get tickets from a specific view
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function tickets(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams(
+ $params,
+ ['id' => get_class($this)]
+ );
+
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $queryParams = Http::prepareQueryParams(
+ $this->client->getSideload($params),
+ $params
+ );
+
+ return $this->client->get($this->getRoute(__FUNCTION__, ['id' => $params['id']]), $queryParams);
+ }
+
+ /**
+ * Count tickets (estimate) from a specific view or list of views
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function count(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams(
+ $params,
+ ['id' => get_class($this)]
+ );
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $queryParams = $routeParams = [];
+ if (is_array($params['id'])) {
+ $this->setRoute(__FUNCTION__, 'views/count_many.json');
+ $queryParams['ids'] = implode(',', $params['id']);
+ unset($params['id']);
+ } else {
+ $this->setRoute(__FUNCTION__, 'views/{id}/count.json');
+ $routeParams = ['id' => $params['id']];
+ }
+
+ $extraParams = Http::prepareQueryParams(
+ $this->client->getSideload($params),
+ $params
+ );
+
+ return $this->client->get($this->getRoute(__FUNCTION__, $routeParams), array_merge($extraParams, $queryParams));
+ }
+
+ /**
+ * Export a view
+ *
+ * @param array $params
+ *
+ * @throws MissingParametersException
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function export(array $params = [])
+ {
+ $params = $this->addChainedParametersToParams(
+ $params,
+ ['id' => get_class($this)]
+ );
+ if (! $this->hasKeys($params, ['id'])) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ $queryParams = Http::prepareQueryParams(
+ $this->client->getSideload($params),
+ $params
+ );
+
+ return $this->client->get($this->getRoute(__FUNCTION__, ['id' => $params['id']]), $queryParams);
+ }
+
+ /**
+ * Preview a view
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function preview(array $params)
+ {
+ return $this->client->post($this->getRoute(__FUNCTION__), [$this->objectName => $params]);
+ }
+
+ /**
+ * Ticket count for a view preview
+ *
+ * @param array $params
+ *
+ * @throws ResponseException
+ * @throws \Exception
+ *
+ * @return mixed
+ */
+ public function previewCount(array $params)
+ {
+ return $this->client->post($this->getRoute(__FUNCTION__), [$this->objectName => $params]);
+ }
+}
diff --git a/src/Zendesk/API/Resources/HelpCenter.php b/src/Zendesk/API/Resources/HelpCenter.php
new file mode 100644
index 00000000..f563773f
--- /dev/null
+++ b/src/Zendesk/API/Resources/HelpCenter.php
@@ -0,0 +1,42 @@
+client->helpCenter
+ *
+ * @method Categories categories()
+ */
+class HelpCenter
+{
+ use ChainedParametersTrait;
+ use InstantiatorTrait;
+
+ public $client;
+
+ /**
+ * Sets the client to be used
+ *
+ * @param HttpClient $client
+ */
+ public function __construct(HttpClient $client)
+ {
+ $this->client = $client;
+ }
+
+ /**
+ * @inheritdoc
+ * @return array
+ */
+ public static function getValidSubResources()
+ {
+ return [
+ 'categories' => Categories::class
+ ];
+ }
+}
diff --git a/src/Zendesk/API/Resources/HelpCenter/Categories.php b/src/Zendesk/API/Resources/HelpCenter/Categories.php
new file mode 100644
index 00000000..b5fe3eed
--- /dev/null
+++ b/src/Zendesk/API/Resources/HelpCenter/Categories.php
@@ -0,0 +1,98 @@
+setRoute('updateSourceLocale', "{$this->resourceName}/{categoryId}/source_locale.json");
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function getRoute($name, array $params = [])
+ {
+ $routesWithLocale = ['findAll', 'find', 'create', 'update'];
+
+ $locale = $this->getLocale();
+ if (in_array($name, $routesWithLocale) && isset($locale)) {
+ $originalResourceName = $this->resourceName;
+ $this->resourceName = "help_center/{$locale}/categories";
+
+ $route = parent::getRoute($name, $params);
+
+ // Reset resourceName so it doesn't affect succeeding calls
+ $this->resourceName = $originalResourceName;
+
+ return $route;
+ } else {
+ return parent::getRoute($name, $params);
+ }
+ }
+
+ /**
+ * @return string
+ */
+ public function getLocale()
+ {
+ return $this->locale;
+ }
+
+ /**
+ * @param string $locale
+ *
+ * @return Categories
+ */
+ public function setLocale($locale)
+ {
+ if (is_string($locale)) {
+ $this->locale = $locale;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Updates a categories source_locale property
+ *
+ * @param $categoryId The category to update
+ * @param $sourceLocale The new source_locale
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function updateSourceLocale($categoryId, $sourceLocale)
+ {
+ if (empty($categoryId)) {
+ $categoryId = $this->getChainedParameter(get_class($this));
+ }
+
+ return $this->client->put(
+ $this->getRoute(__FUNCTION__, ['categoryId' => $categoryId]),
+ ['category_locale' => $sourceLocale]
+ );
+ }
+}
diff --git a/src/Zendesk/API/Resources/HelpCenter/ResourceAbstract.php b/src/Zendesk/API/Resources/HelpCenter/ResourceAbstract.php
new file mode 100644
index 00000000..55d5413f
--- /dev/null
+++ b/src/Zendesk/API/Resources/HelpCenter/ResourceAbstract.php
@@ -0,0 +1,21 @@
+client = $client;
+
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ if (! isset($this->objectName)) {
+ $this->objectName = Inflect::singularize($this->resourceName);
+ }
+
+ if (! isset($this->objectNamePlural)) {
+ $this->objectNamePlural = Inflect::pluralize($this->resourceName);
+ }
+
+ $this->setUpRoutes();
+ }
+
+ /**
+ * This returns the valid relations of this resource. Definition of what is allowed to chain after this resource.
+ * Make sure to add in this method when adding new sub resources.
+ * Example:
+ * $client->ticket()->comments();
+ * Where ticket would have a comments as a valid sub resource.
+ * The array would look like:
+ * ['comments' => '\Zendesk\API\Resources\TicketComments']
+ *
+ * @return array
+ */
+ public static function getValidSubResources()
+ {
+ return [];
+ }
+
+ /**
+ * Return the resource name using the name of the class (used for endpoints)
+ *
+ * @return string
+ */
+ protected function getResourceNameFromClass()
+ {
+ $namespacedClassName = get_class($this);
+ $resourceName = join('', array_slice(explode('\\', $namespacedClassName), -1));
+
+ // This converts the resource name from camel case to underscore case.
+ // e.g. MyClass => my_class
+ $underscored = strtolower(preg_replace('/(?resourceName;
+ }
+
+ /**
+ * Sets up the available routes for the resource.
+ */
+ protected function setUpRoutes()
+ {
+ }
+
+ /**
+ * Saves an id for future methods in the chain
+ *
+ * @param int $id
+ *
+ * @return $this
+ */
+ public function setLastId($id)
+ {
+ $this->lastId = $id;
+
+ return $this;
+ }
+
+ /**
+ * Saves an id for future methods in the chain
+ *
+ * @return int
+ */
+ public function getLastId()
+ {
+ return $this->lastId;
+ }
+
+ /**
+ * Check that all parameters have been supplied
+ *
+ * @param array $params
+ * @param array $mandatory
+ *
+ * @return bool
+ */
+ public function hasKeys(array $params, array $mandatory)
+ {
+ for ($i = 0; $i < count($mandatory); $i++) {
+ if (! array_key_exists($mandatory[$i], $params)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Check that any parameter has been supplied
+ *
+ * @param array $params
+ * @param array $mandatory
+ *
+ * @return bool
+ */
+ public function hasAnyKey(array $params, array $mandatory)
+ {
+ for ($i = 0; $i < count($mandatory); $i++) {
+ if (array_key_exists($mandatory[$i], $params)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Enable side-loading (beta) - flags until the next chain
+ *
+ * @param array $fields
+ *
+ * @return $this
+ */
+ public function sideload(array $fields = [])
+ {
+ $this->client->setSideload($fields);
+
+ return $this;
+ }
+
+ /**
+ * Wrapper for adding multiple routes via setRoute
+ *
+ * @param array $routes
+ */
+ public function setRoutes(array $routes)
+ {
+ foreach ($routes as $name => $route) {
+ $this->setRoute($name, $route);
+ }
+ }
+
+ /**
+ * Add or override an existing route
+ *
+ * @param $name
+ * @param $route
+ */
+ public function setRoute($name, $route)
+ {
+ $this->routes[$name] = $route;
+ }
+
+ /**
+ * Return all routes for this resource
+ *
+ * @return array
+ */
+ public function getRoutes()
+ {
+ return $this->routes;
+ }
+
+ /**
+ * Returns a route and replaces tokenized parts of the string with
+ * the passed params
+ *
+ * @param $name
+ * @param array $params
+ *
+ * @return mixed
+ * @throws \Exception
+ */
+ public function getRoute($name, array $params = [])
+ {
+ if (! isset($this->routes[$name])) {
+ throw new RouteException('Route not found.');
+ }
+
+ $route = $this->routes[$name];
+
+ $substitutions = array_merge($params, $this->getAdditionalRouteParams());
+ foreach ($substitutions as $name => $value) {
+ if (is_scalar($value)) {
+ $route = str_replace('{' . $name . '}', $value, $route);
+ }
+ }
+
+ return $route;
+ }
+
+ /**
+ * @param array $additionalRouteParams
+ */
+ public function setAdditionalRouteParams($additionalRouteParams)
+ {
+ $this->additionalRouteParams = $additionalRouteParams;
+ }
+
+ /**
+ * @return array
+ */
+ public function getAdditionalRouteParams()
+ {
+ return $this->additionalRouteParams;
+ }
+}
diff --git a/src/Zendesk/API/Resources/Voice.php b/src/Zendesk/API/Resources/Voice.php
new file mode 100644
index 00000000..d34c0624
--- /dev/null
+++ b/src/Zendesk/API/Resources/Voice.php
@@ -0,0 +1,42 @@
+client->helpCenter
+ *
+ * @method PhoneNumbers phoneNumbers()
+ */
+class Voice
+{
+ use ChainedParametersTrait;
+ use InstantiatorTrait;
+
+ public $client;
+
+ /**
+ * Sets the client to be used
+ *
+ * @param HttpClient $client
+ */
+ public function __construct(HttpClient $client)
+ {
+ $this->client = $client;
+ }
+
+ /**
+ * @inheritdoc
+ * @return array
+ */
+ public static function getValidSubResources()
+ {
+ return [
+ 'phoneNumbers' => PhoneNumbers::class,
+ ];
+ }
+}
diff --git a/src/Zendesk/API/Resources/Voice/PhoneNumbers.php b/src/Zendesk/API/Resources/Voice/PhoneNumbers.php
new file mode 100644
index 00000000..c60ae3d2
--- /dev/null
+++ b/src/Zendesk/API/Resources/Voice/PhoneNumbers.php
@@ -0,0 +1,35 @@
+setRoute('search', "{$this->getResourceName()}/search.json");
+ }
+
+ /**
+ * Search for available phone numbers.
+ *
+ * @param array $queryParams
+ *
+ * @return array
+ * @throws \Zendesk\API\Exceptions\RouteException
+ */
+ public function search(array $queryParams = [])
+ {
+ return $this->client->get($this->getRoute(__FUNCTION__), $queryParams);
+ }
+}
diff --git a/src/Zendesk/API/Resources/Voice/ResourceAbstract.php b/src/Zendesk/API/Resources/Voice/ResourceAbstract.php
new file mode 100644
index 00000000..bea1055b
--- /dev/null
+++ b/src/Zendesk/API/Resources/Voice/ResourceAbstract.php
@@ -0,0 +1,20 @@
+client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- $endPoint = Http::prepare('satisfaction_ratings.json', null, $params);
- $allowedFilter = array('score', 'start_time', 'end_time');
- $response = Http::send(
- $this->client,
- $endPoint,
- array_intersect_key($params, array_flip($allowedFilter))
- );
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific satisfaction rating
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('satisfaction_ratings/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new satisfaction rating (authorised end user credentials only please!)
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/satisfaction_rating.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__,
- ($this->client->getDebug()->lastResponseCode == 403 ? ' (hint: you need to authenticate as a verified end user for this method)' : ''));
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Search.php b/src/Zendesk/API/Search.php
deleted file mode 100755
index 3b724215..00000000
--- a/src/Zendesk/API/Search.php
+++ /dev/null
@@ -1,64 +0,0 @@
-hasKeys($params, array('query'))) {
- throw new MissingParametersException(__METHOD__, array('query'));
- }
- $endPoint = Http::prepare('search.json', null, $params);
- $response = Http::send($this->client, $endPoint, $params, 'GET', 'application/json', false);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Perform an anonymous search
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function anonymousSearch(array $params)
- {
- if (!$this->hasKeys($params, array('query'))) {
- throw new MissingParametersException(__METHOD__, array('query'));
- }
- $endPoint = Http::prepare('portal/search.json', null, $params);
- $response = Http::send($this->client, $endPoint, $params, 'GET');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Settings.php b/src/Zendesk/API/Settings.php
deleted file mode 100755
index 7ae6dcc0..00000000
--- a/src/Zendesk/API/Settings.php
+++ /dev/null
@@ -1,59 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update one or more settings
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- $endPoint = Http::prepare('account/settings.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/SharingAgreements.php b/src/Zendesk/API/SharingAgreements.php
deleted file mode 100755
index d1d1b065..00000000
--- a/src/Zendesk/API/SharingAgreements.php
+++ /dev/null
@@ -1,37 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/SuspendedTickets.php b/src/Zendesk/API/SuspendedTickets.php
deleted file mode 100755
index a554acf4..00000000
--- a/src/Zendesk/API/SuspendedTickets.php
+++ /dev/null
@@ -1,131 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific suspended ticket
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('suspended_tickets/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Recover a suspended ticket (or multiple tickets)
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function recover(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare((is_array($id) ? 'suspended_tickets/recover_many.json?ids=' . implode(',',
- $id) : 'suspended_tickets/' . $id . '/recover.json'));
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a suspended ticket or multiple tickets
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare((is_array($id) ? 'suspended_tickets/destroy_many.json?ids=' . implode(',',
- $id) : 'suspended_tickets/' . $id . '.json'));
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Tags.php b/src/Zendesk/API/Tags.php
deleted file mode 100755
index db5017fe..00000000
--- a/src/Zendesk/API/Tags.php
+++ /dev/null
@@ -1,270 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific tag
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->organizations()->getLastId() != null) {
- $params['organization_id'] = $this->client->organizations()->getLastId();
- $this->client->organizations()->setLastId(null);
- }
- if (!$this->hasAnyKey($params, array('ticket_id', 'topic_id', 'organization_id'))) {
- throw new MissingParametersException(__METHOD__, array('ticket_id', 'topic_id', 'organization_id'));
- }
- $endPoint = Http::prepare(
- (isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/tags.json' :
- (isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/tags.json' :
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/tags.json' : '')))
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a tag
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->organizations()->getLastId() != null) {
- $params['organization_id'] = $this->client->organizations()->getLastId();
- $this->client->organizations()->setLastId(null);
- }
- if (!$this->hasAnyKey($params, array('ticket_id', 'topic_id', 'organization_id'))) {
- throw new MissingParametersException(__METHOD__, array('ticket_id', 'topic_id', 'organization_id'));
- }
- if (!$this->hasKeys($params, array('tags'))) {
- throw new MissingParametersException(__METHOD__, array('tags'));
- }
- $endPoint = Http::prepare(
- (isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/tags.json' :
- (isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/tags.json' :
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/tags.json' : '')))
- );
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params['tags']), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a tag
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->organizations()->getLastId() != null) {
- $params['organization_id'] = $this->client->organizations()->getLastId();
- $this->client->organizations()->setLastId(null);
- }
- if (!$this->hasAnyKey($params, array('ticket_id', 'topic_id', 'organization_id'))) {
- throw new MissingParametersException(__METHOD__, array('ticket_id', 'topic_id', 'organization_id'));
- }
- if (!$this->hasKeys($params, array('tags'))) {
- throw new MissingParametersException(__METHOD__, array('tags'));
- }
- $endPoint = Http::prepare(
- (isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/tags.json' :
- (isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/tags.json' :
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/tags.json' : '')))
- );
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params['tags']), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a tag
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function delete(array $params)
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->organizations()->getLastId() != null) {
- $params['organization_id'] = $this->client->organizations()->getLastId();
- $this->client->organizations()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('tags'))) {
- throw new MissingParametersException(__METHOD__, array('tags'));
- }
- if (!$this->hasAnyKey($params, array('ticket_id', 'topic_id', 'organization_id'))) {
- throw new MissingParametersException(__METHOD__, array('ticket_id', 'topic_id', 'organization_id'));
- }
- $endPoint = Http::prepare(
- (isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/tags.json' :
- (isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/tags.json' :
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/tags.json' : '')))
- );
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params['tags']), 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param array $params
- *
- * @throws ResponseException
- *
- * @return mixed
- */
- public function show(array $params = array())
- {
- return $this->findAll($params);
- }
-
- /**
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function set(array $params)
- {
- return $this->create($params);
- }
-
- /**
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function add(array $params)
- {
- return $this->update($params);
- }
-
- /**
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function remove(array $params)
- {
- return $this->delete($params);
- }
-
-}
diff --git a/src/Zendesk/API/Targets.php b/src/Zendesk/API/Targets.php
deleted file mode 100755
index a5a84894..00000000
--- a/src/Zendesk/API/Targets.php
+++ /dev/null
@@ -1,149 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific target
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('targets/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a target
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('targets.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a target
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('targets/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a target
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('targets/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/TicketAudits.php b/src/Zendesk/API/TicketAudits.php
deleted file mode 100755
index 9f659945..00000000
--- a/src/Zendesk/API/TicketAudits.php
+++ /dev/null
@@ -1,115 +0,0 @@
-client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('ticket_id'));
- }
- $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/audits.json',
- $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific audit record
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'ticket_id'));
- }
- $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/audits/' . $params['id'] . '.json',
- $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Mark the specified ticket as trusted
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function markAsTrusted(array $params = array())
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'ticket_id'));
- }
- $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/audits/' . $params['id'] . '/trust.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/TicketComments.php b/src/Zendesk/API/TicketComments.php
deleted file mode 100755
index 1903daba..00000000
--- a/src/Zendesk/API/TicketComments.php
+++ /dev/null
@@ -1,94 +0,0 @@
-client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('ticket_id'));
- }
- $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/comments.json', null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Make the specified comment private
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function makePrivate(array $params = array())
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'ticket_id'));
- }
- $endPoint = Http::prepare('tickets/' . $params['ticket_id'] . '/comments/' . $params['id'] . '/make_private.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__, ' (hint: you can\'t make a private ticket private again)');
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param array $params
- *
- * @throws CustomException
- */
- public function find(array $params = array())
- {
- throw new CustomException('Method ' . __METHOD__ . ' does not exist. Try $client->ticket(ticket_id)->comments()->findAll() instead.');
- }
-
-}
diff --git a/src/Zendesk/API/TicketFields.php b/src/Zendesk/API/TicketFields.php
deleted file mode 100755
index 17eb72bb..00000000
--- a/src/Zendesk/API/TicketFields.php
+++ /dev/null
@@ -1,152 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific ticket field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('ticket_fields/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new ticket field
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('ticket_fields.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a ticket field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('ticket_fields/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a ticket field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('ticket_fields/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/TicketForms.php b/src/Zendesk/API/TicketForms.php
deleted file mode 100755
index 1ec1b6a4..00000000
--- a/src/Zendesk/API/TicketForms.php
+++ /dev/null
@@ -1,223 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific ticket form
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('ticket_forms/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new ticket field
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('ticket_forms.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a ticket field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('ticket_forms/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a ticket field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('ticket_forms/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__,
- ($this->client->getDebug()->lastResponseCode == 422 ? ' (hint: you may need to run $client->ticketForm(id)->deactivate to deactivate the ticket form first)' : ''));
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Reorder fields
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- function reorder(array $params)
- {
- $endPoint = Http::prepare('ticket_forms/reorder.json');
- $response = Http::send($this->client, $endPoint, array('ticket_form_ids' => $params), 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Clones an existing form (can't use 'clone' as method name)
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- function cloneForm(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('ticket_forms/' . $id . '/clone.json');
- $response = Http::send($this->client, $endPoint, null, 'POST');
- if ($this->client->getDebug()->lastResponseCode != 201) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Alias method to deactivate a ticket form
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- function deactivate(array $params = array())
- {
- $params['active'] = false;
-
- return $this->update($params);
- }
-
-}
diff --git a/src/Zendesk/API/TicketImport.php b/src/Zendesk/API/TicketImport.php
deleted file mode 100755
index 6c12c3f1..00000000
--- a/src/Zendesk/API/TicketImport.php
+++ /dev/null
@@ -1,57 +0,0 @@
-client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create multiple new tickets
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function importMany(array $params) {
- $endPoint = Http::prepare('imports/tickets/create_many.json');
- $response = Http::send($this->client, $endPoint, array (self::OBJ_NAME_PLURAL => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/TicketMetrics.php b/src/Zendesk/API/TicketMetrics.php
deleted file mode 100755
index f28aeca0..00000000
--- a/src/Zendesk/API/TicketMetrics.php
+++ /dev/null
@@ -1,76 +0,0 @@
-client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- $endPoint = Http::prepare((isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/metrics.json' : 'ticket_metrics.json'),
- null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific ticket metric
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->tickets()->getLastId() != null) {
- $params['ticket_id'] = $this->client->tickets()->getLastId();
- $this->client->tickets()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasAnyKey($params, array('id', 'ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'ticket_id'));
- }
- $endPoint = Http::prepare((isset($params['ticket_id']) ? 'tickets/' . $params['ticket_id'] . '/metrics.json' : 'ticket_metrics/' . $params['id'] . '.json'));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Tickets.php b/src/Zendesk/API/Tickets.php
deleted file mode 100755
index 9c50fbe2..00000000
--- a/src/Zendesk/API/Tickets.php
+++ /dev/null
@@ -1,634 +0,0 @@
-audits = new TicketAudits($client);
- $this->comments = new TicketComments($client);
- $this->metrics = new TicketMetrics($client);
- $this->import = new TicketImport($client);
- $this->satisfactionRatings = new SatisfactionRatings($client);
- }
-
- /**
- * Returns all recent tickets overall, per user or per organization
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function findAll(array $params = array())
- {
- if ($this->client->organizations()->getLastId() != null) {
- $params['organization_id'] = $this->client->organizations()->getLastId();
- $this->client->organizations()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- $queryParams = array();
- if (isset($params['external_id'])) {
- $queryParams['external_id'] = $params['external_id'];
- }
- $endPoint = Http::prepare(
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/tickets' :
- (isset($params['user_id']) ? 'users/' . $params['user_id'] . '/tickets/' . (isset($params['ccd']) ? 'ccd' : 'requested') :
- (isset($params['recent']) ? 'tickets/recent' : 'tickets'))
- ) . '.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint, $queryParams);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Find a specific ticket by id or series of ids
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((is_array($params['id']) ? 'tickets/show_many.json?ids=' . implode(',',
- $params['id']) : 'tickets/' . $params['id'] . '.json'), $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Find a specific twitter generated ticket by id
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function findTwicket(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('channels/twitter/tickets/' . $params['id'] . '/statuses.json' . (is_array($params['comment_ids']) ? '?' . implode(',',
- $params['comment_ids']) : ''), $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a ticket
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if (count($this->lastAttachments)) {
- $params['comment']['uploads'] = $this->lastAttachments;
- $this->lastAttachments = array();
- }
- $endPoint = Http::prepare('tickets.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create many tickets
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function createMany(array $params)
- {
- $endPoint = Http::prepare('tickets/create_many.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME_PLURAL => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a ticket from a tweet
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function createFromTweet(array $params)
- {
- if ((!$params['twitter_status_message_id']) || (!$params['monitored_twitter_handle_id'])) {
- throw new MissingParametersException(__METHOD__,
- array('twitter_status_message_id', 'monitored_twitter_handle_id'));
- }
- $endPoint = Http::prepare('channels/twitter/tickets.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__,
- ($this->client->getDebug()->lastResponseCode == 422 ? ' (hint: you can\'t create two tickets from the same tweet)' : ''));
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a ticket or series of tickets
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- if (count($this->lastAttachments)) {
- $params['comment']['uploads'] = $this->lastAttachments;
- $this->lastAttachments = array();
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare((is_array($id) ? 'tickets/update_many.json?ids=' . implode(',',
- $id) : 'tickets/' . $id . '.json'));
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__,
- ($this->client->getDebug()->lastResponseCode == 422 ? ' (hint: you can\'t update a closed ticket)' : ''));
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Mark a ticket as spam
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function markAsSpam(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('tickets/' . $id . '/mark_as_spam.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- // Seems to be a bug in the service, it may respond with 422 even when it succeeds
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__,
- ($this->client->getDebug()->lastResponseCode == 422 ? ' (note: there\'s currently a bug in the service so this call may have succeeded; call tickets->find to see if it still exists.)' : ''));
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Get related ticket information
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function related(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('tickets/' . $id . '/related.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a ticket or series of tickets
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare((is_array($id) ? 'tickets/destroy_many.json?ids=' . implode(',',
- $id) : 'tickets/' . $id . '.json'));
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * List collaborators for a ticket
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function collaborators(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('tickets/' . $id . '/collaborators.json', $this->client->getSideload($params),
- $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * List incidents for a ticket
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function incidents(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('tickets/' . $id . '/incidents.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-
- /**
- * List all problem tickets
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function problems(array $params)
- {
- $endPoint = Http::prepare('problems.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Add a problem autocomplete
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function problemAutoComplete(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'text'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'text'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('tickets/' . $id . '/problems/autocomplete.json');
- $response = Http::send($this->client, $endPoint, array('text' => $params['text']), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Incremental ticket exports with a supplied start_time
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function export(array $params)
- {
- if (!$params['start_time']) {
- throw new MissingParametersException(__METHOD__, array('start_time'));
- }
- $endPoint = Http::prepare('exports/tickets.json?start_time=' . $params['start_time']);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * For testing of incremental tickets only
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function exportSample(array $params)
- {
- if (!$params['start_time']) {
- throw new MissingParametersException(__METHOD__, array('start_time'));
- }
- $endPoint = Http::prepare('exports/tickets/sample.json?start_time=' . $params['start_time']);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Generic method to object getter. Since all objects are protected, this method
- * exposes a getter function with the same name as the protected variable, for example
- * $client->tickets can be referenced by $client->tickets()
- *
- * @param $name
- * @param $arguments
- *
- * @throws CustomException
- */
- public function __call($name, $arguments)
- {
- if (isset($this->$name)) {
- return ((isset($arguments[0])) && ($arguments[0] != null) ? $this->$name->setLastId($arguments[0]) : $this->$name);
- }
- $namePlural = $name . 's'; // try pluralize
- if (isset($this->$namePlural)) {
- return $this->$namePlural->setLastId($arguments[0]);
- } else {
- throw new CustomException("No method called $name available in " . __CLASS__);
- }
- }
-
- /**
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param int|null $id
- *
- * @return Tags
- */
- public function tags($id = null)
- {
- return ($id != null ? $this->client->tags()->setLastId($id) : $this->client->tags());
- }
-
- /**
- * @param $id
- *
- * @return Tags
- */
- public function tag($id)
- {
- return $this->client->tags()->setLastId($id);
- }
-
- /**
- * @param array $params
- *
- * @throws ResponseException
- *
- * @return mixed
- */
- public function import(array $params)
- {
- return $this->import->import($params);
- }
-
- /**
- * @param array $params
- *
- * @throws ResponseException
- *
- * @return mixed
- */
- public function importMany(array $params) { return $this->import->importMany($params); }
-
- /**
- * @param array $params
- *
- * @throws CustomException
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return Tickets
- */
- public function attach(array $params = array())
- {
- if (!$this->hasKeys($params, array('file'))) {
- throw new MissingParametersException(__METHOD__, array('file'));
- }
- $upload = $this->client->attachments()->upload($params);
- if ((!is_object($upload->upload)) || (!$upload->upload->token)) {
- throw new ResponseException(__METHOD__);
- }
- $this->lastAttachments[] = $upload->upload->token;
-
- return $this;
- }
-
-}
diff --git a/src/Zendesk/API/TopicComments.php b/src/Zendesk/API/TopicComments.php
deleted file mode 100755
index b65231ae..00000000
--- a/src/Zendesk/API/TopicComments.php
+++ /dev/null
@@ -1,226 +0,0 @@
-client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasAnyKey($params, array('topic_id', 'user_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id', 'user_id'));
- }
- $endPoint = Http::prepare(
- (isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/comments.json' :
- (isset($params['user_id']) ? 'users/' . $params['user_id'] . '/topic_comments.json' : '')),
- $this->client->getSideload($params), $params
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific topic comment
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasAnyKey($params, array('topic_id', 'user_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id', 'user_id'));
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/comments/' . $params['id'] . '.json' : 'users/' . $params['user_id'] . '/topic_comments/' . $params['id'] . '.json'),
- $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new topic comment
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id'));
- }
- $endPoint = Http::prepare('topics/' . $params['topic_id'] . '/comments.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Import a topic comment (same as create but without notifications)
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function import(array $params)
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id'));
- }
- $endPoint = Http::prepare('import/topics/' . $params['topic_id'] . '/comments.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a topic comment
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('id', 'topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'topic_id'));
- }
- $prepare = 'topics/' . $params['topic_id'] . '/comments/' . $params['id'] . '.json';
- unset($params['id']);
- unset($params['topic_id']);
- $endPoint = Http::prepare($prepare);
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a topic comment
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('id', 'topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'topic_id'));
- }
- $endPoint = Http::prepare('topics/' . $params['topic_id'] . '/comments/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/TopicSubscriptions.php b/src/Zendesk/API/TopicSubscriptions.php
deleted file mode 100755
index 96aa0c80..00000000
--- a/src/Zendesk/API/TopicSubscriptions.php
+++ /dev/null
@@ -1,136 +0,0 @@
-client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- $endPoint = Http::prepare((isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/subscriptions.json' : 'topic_subscriptions.json'),
- null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific topic subscription
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('/topic_subscriptions/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new topic subscription
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('topic_id', 'user_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id', 'user_id'));
- }
- $endPoint = Http::prepare('topic_subscriptions.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a topic subscription
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('topic_subscriptions/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/TopicVotes.php b/src/Zendesk/API/TopicVotes.php
deleted file mode 100755
index 3326cb61..00000000
--- a/src/Zendesk/API/TopicVotes.php
+++ /dev/null
@@ -1,152 +0,0 @@
-client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasAnyKey($params, array('topic_id', 'user_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id', 'user_id'));
- }
- $endPoint = Http::prepare((isset($params['topic_id']) ? 'topics/' . $params['topic_id'] . '/votes.json' : 'users/' . $params['user_id'] . '/topic_votes.json'),
- null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Check for a specific topic vote
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id'));
- }
- $endPoint = Http::prepare('/topics/' . $params['topic_id'] . '/vote.json' . (isset($params['user_id']) ? '?user_id=' . $params['user_id'] : ''));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || (($this->client->getDebug()->lastResponseCode != 200) && ($this->client->getDebug()->lastResponseCode != 404))) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new topic vote
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id'));
- }
- $endPoint = Http::prepare('topics/' . $params['topic_id'] . '/vote.json' . (isset($params['user_id']) ? '?user_id=' . $params['user_id'] : ''));
- $response = Http::send($this->client, $endPoint, null, 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a topic vote
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->client->topics()->getLastId() != null) {
- $params['topic_id'] = $this->client->topics()->getLastId();
- $this->client->topics()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('topic_id'))) {
- throw new MissingParametersException(__METHOD__, array('topic_id'));
- }
- $endPoint = Http::prepare('topics/' . $params['topic_id'] . '/vote.json' . (isset($params['user_id']) ? '?user_id=' . $params['user_id'] : ''));
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Topics.php b/src/Zendesk/API/Topics.php
deleted file mode 100755
index a6c25282..00000000
--- a/src/Zendesk/API/Topics.php
+++ /dev/null
@@ -1,259 +0,0 @@
-comments = new TopicComments($client);
- $this->subscriptions = new TopicSubscriptions($client);
- $this->votes = new TopicVotes($client);
- }
-
- /**
- * List all topics
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function findAll(array $params = array())
- {
- if ($this->client->forums()->getLastId() != null) {
- $params['forum_id'] = $this->client->forums()->getLastId();
- $this->client->forums()->setLastId(null);
- }
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- $endPoint = Http::prepare(
- (isset($params['forum_id']) ? 'forums/' . $params['forum_id'] . '/topics.json' :
- (isset($params['user_id']) ? 'users/' . $params['user_id'] . '/topics.json' : 'topics.json')),
- $this->client->getSideload($params), $params
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific topic
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((is_array($params['id']) ? 'topics/show_many.json?ids=' . implode(',',
- $params['id']) : 'topics/' . $params['id'] . '.json'), $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new topic
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->forums()->getLastId() != null) {
- $params['forum_id'] = $this->client->forums()->getLastId();
- $this->client->forums()->setLastId(null);
- }
- $endPoint = Http::prepare('topics.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Import a topic (same as create but without notifications)
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function import(array $params)
- {
- $endPoint = Http::prepare('import/topics.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a topic
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('topics/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a topic
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('topics/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Generic method to object getter
- *
- * @param $name
- * @param $arguments
- *
- * @throws CustomException
- */
- public function __call($name, $arguments)
- {
- if (isset($this->$name)) {
- return ((isset($arguments[0])) && ($arguments[0] != null) ? $this->$name->setLastId($arguments[0]) : $this->$name);
- }
- $namePlural = $name . 's'; // try pluralize
- if (isset($this->$namePlural)) {
- return $this->$namePlural->setLastId($arguments[0]);
- } else {
- throw new CustomException("No method called $name available in " . __CLASS__);
- }
- }
-
- /**
- * @param int|null $id
- *
- * @return Tags
- */
- public function tags($id = null)
- {
- return ($id != null ? $this->client->tags()->setLastId($id) : $this->client->tags());
- }
-
- /**
- * @param $id
- *
- * @return Tags
- */
- public function tag($id)
- {
- return $this->client->tags()->setLastId($id);
- }
-
-}
diff --git a/src/Zendesk/API/Traits/Resource/Create.php b/src/Zendesk/API/Traits/Resource/Create.php
new file mode 100644
index 00000000..c8023f99
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/Create.php
@@ -0,0 +1,35 @@
+getRoute($routeKey, $params);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $route = $this->resourceName . '.json';
+ $this->setRoute(__FUNCTION__, $route);
+ }
+
+ return $this->client->post(
+ $route,
+ [$this->objectName => $params]
+ );
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/CreateMany.php b/src/Zendesk/API/Traits/Resource/CreateMany.php
new file mode 100644
index 00000000..106fe9d7
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/CreateMany.php
@@ -0,0 +1,38 @@
+getRoute(__FUNCTION__);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $route = $this->resourceName . '/create_many.json';
+ $this->setRoute('createMany', $route);
+ }
+
+ return $this->client->post($route, [$this->objectNamePlural => $params]);
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/Defaults.php b/src/Zendesk/API/Traits/Resource/Defaults.php
new file mode 100644
index 00000000..4cc7d3ac
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/Defaults.php
@@ -0,0 +1,17 @@
+getChainedParameters();
+ if (array_key_exists(get_class($this), $chainedParameters)) {
+ $id = $chainedParameters[get_class($this)];
+ }
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ try {
+ $route = $this->getRoute($routeKey, ['id' => $id]);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $this->setRoute(__FUNCTION__, $this->resourceName . '/{id}.json');
+ $route = $this->resourceName . '/' . $id . '.json';
+ }
+
+ return $this->client->delete($route);
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/DeleteMany.php b/src/Zendesk/API/Traits/Resource/DeleteMany.php
new file mode 100644
index 00000000..8fdc2356
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/DeleteMany.php
@@ -0,0 +1,49 @@
+getRoute(__FUNCTION__);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $route = $this->resourceName . '/destroy_many.json';
+ $this->setRoute('', $route);
+ }
+
+ $response = Http::send(
+ $this->client,
+ $route,
+ [
+ 'method' => 'DELETE',
+ 'queryParams' => [$key => implode(',', $ids)]
+ ]
+ );
+
+ $this->client->setSideload(null);
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/Find.php b/src/Zendesk/API/Traits/Resource/Find.php
new file mode 100644
index 00000000..f397d119
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/Find.php
@@ -0,0 +1,46 @@
+getChainedParameter(get_class($this));
+ }
+
+ if (empty($id)) {
+ throw new MissingParametersException(__METHOD__, ['id']);
+ }
+
+ try {
+ $route = $this->getRoute($routeKey, ['id' => $id]);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $this->setRoute(__FUNCTION__, $this->resourceName . '/{id}.json');
+ $route = $this->resourceName . '/' . $id . '.json';
+ }
+
+ return $this->client->get(
+ $route,
+ $queryParams
+ );
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/FindAll.php b/src/Zendesk/API/Traits/Resource/FindAll.php
new file mode 100644
index 00000000..14999bb3
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/FindAll.php
@@ -0,0 +1,36 @@
+getRoute($routeKey, $params);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $route = $this->resourceName . '.json';
+ $this->setRoute(__FUNCTION__, $route);
+ }
+
+ return $this->client->get(
+ $route,
+ $params
+ );
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/FindMany.php b/src/Zendesk/API/Traits/Resource/FindMany.php
new file mode 100644
index 00000000..5b7f3cc0
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/FindMany.php
@@ -0,0 +1,44 @@
+getRoute(__FUNCTION__);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $route = $this->resourceName . '/show_many.json';
+ $this->setRoute('findMany', $route);
+ }
+
+ $queryParams = [];
+
+ if (count($ids) > 0) {
+ $queryParams[$key] = implode(',', $ids);
+ }
+
+ return $this->client->get($route, array_merge($queryParams, $extraParams));
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/MultipartUpload.php b/src/Zendesk/API/Traits/Resource/MultipartUpload.php
new file mode 100644
index 00000000..d1862f15
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/MultipartUpload.php
@@ -0,0 +1,77 @@
+getRoute($routeKey, $params);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $this->setRoute(__FUNCTION__, $this->resourceName . '/uploads.json');
+ $route = $this->resourceName . '/uploads.json';
+ }
+
+ $response = Http::send(
+ $this->client,
+ $route,
+ [
+ 'method' => $this->getUploadRequestMethod(),
+ 'multipart' => [
+ [
+ 'name' => $this->getUploadName(),
+ 'contents' => new LazyOpenStream($params['file'], 'r'),
+ 'filename' => $params['file']
+ ]
+ ]
+ ]
+ );
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/Update.php b/src/Zendesk/API/Traits/Resource/Update.php
new file mode 100644
index 00000000..2068b0e9
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/Update.php
@@ -0,0 +1,42 @@
+getChainedParameter($class);
+ }
+
+ try {
+ $route = $this->getRoute($routeKey, ['id' => $id]);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $this->setRoute(__FUNCTION__, $this->resourceName . '/{id}.json');
+ $route = $this->resourceName . '/' . $id . '.json';
+ }
+
+ return $this->client->put(
+ $route,
+ [$this->objectName => $updateResourceFields]
+ );
+ }
+}
diff --git a/src/Zendesk/API/Traits/Resource/UpdateMany.php b/src/Zendesk/API/Traits/Resource/UpdateMany.php
new file mode 100644
index 00000000..2dc55309
--- /dev/null
+++ b/src/Zendesk/API/Traits/Resource/UpdateMany.php
@@ -0,0 +1,58 @@
+getRoute(__FUNCTION__);
+ } catch (RouteException $e) {
+ if (! isset($this->resourceName)) {
+ $this->resourceName = $this->getResourceNameFromClass();
+ }
+
+ $route = $this->resourceName . '/update_many.json';
+ $this->setRoute('updateMany', $route);
+ }
+
+ $resourceUpdateName = $this->objectNamePlural;
+ $queryParams = [];
+ if (isset($params[$key]) && is_array($params[$key])) {
+ $queryParams[$key] = implode(',', $params[$key]);
+ unset($params[$key]);
+
+ $resourceUpdateName = $this->objectName;
+ }
+
+ $response = Http::send(
+ $this->client,
+ $route,
+ [
+ 'queryParams' => $queryParams,
+ 'postFields' => [$resourceUpdateName => $params],
+ 'method' => 'PUT'
+ ]
+ );
+
+ $this->client->setSideload(null);
+
+ return $response;
+ }
+}
diff --git a/src/Zendesk/API/Traits/Utility/ChainedParametersTrait.php b/src/Zendesk/API/Traits/Utility/ChainedParametersTrait.php
new file mode 100644
index 00000000..c18e564a
--- /dev/null
+++ b/src/Zendesk/API/Traits/Utility/ChainedParametersTrait.php
@@ -0,0 +1,103 @@
+ticket(2)->comments(3)->author();` would create an Author object with
+ * chained parameters (An Array):
+ * [
+ * 'Zendesk\API\Tickets' => 2,
+ * 'Zendesk\API\Comments' => 3
+ * ]
+ * @package Zendesk\API
+ */
+
+trait ChainedParametersTrait
+{
+ /**
+ * @var array
+ */
+ protected $chainedParameters = [];
+
+ /**
+ * Returns the named chained parameter
+ *
+ * @param $name
+ * @param null $default
+ *
+ * @return $this
+ */
+ public function getChainedParameter($name, $default = null)
+ {
+ $chainedParameters = $this->getChainedParameters();
+ if (array_key_exists($name, $chainedParameters)) {
+ return $chainedParameters[$name];
+ }
+
+ return $default;
+ }
+
+ /**
+ * Returns chained parameters
+ * @return $this
+ */
+ public function getChainedParameters()
+ {
+ return $this->chainedParameters;
+ }
+
+ /**
+ * Sets the chained parameters
+ *
+ * @param $params
+ *
+ * @return $this
+ */
+ public function setChainedParameters($params)
+ {
+ $this->chainedParameters = $params;
+
+ return $this;
+ }
+
+ /**
+ * A helper method to add the chained parameters to the existing parameters.
+ *
+ * @param array $params The existing parameters
+ * @param array $map An array describing what parameter key corresponds to which classId
+ * e.g. ['ticket_id' => 'Zendesk\API\Ticket']
+ * normal usage would be ['id' => $this::class]
+ *
+ * @return array
+ */
+ public function addChainedParametersToParams($params, $map)
+ {
+ $chainedParameters = $this->getChainedParameters();
+ foreach ($map as $key => $className) {
+ if (array_key_exists($className, $chainedParameters)) {
+ $params[$key] = $chainedParameters[$className];
+ }
+ }
+
+ return $params;
+ }
+
+ /**
+ * Returns the named chained parameter
+ *
+ * @param array $excludes Pass an array of classnames to exclude from query
+ *
+ * @return array
+ */
+ public function getLatestChainedParameter($excludes = [])
+ {
+ $chainedParameters = $this->getChainedParameters();
+
+ foreach ($excludes as $excludeClass) {
+ unset($chainedParameters[$excludeClass]);
+ }
+
+ return array_slice($chainedParameters, -1, 1);
+ }
+}
diff --git a/src/Zendesk/API/Traits/Utility/InstantiatorTrait.php b/src/Zendesk/API/Traits/Utility/InstantiatorTrait.php
new file mode 100644
index 00000000..8a1d4d47
--- /dev/null
+++ b/src/Zendesk/API/Traits/Utility/InstantiatorTrait.php
@@ -0,0 +1,46 @@
+tickets can be referenced by $client->tickets()
+ *
+ * @param $name
+ * @param $arguments
+ *
+ * @return
+ * @throws \Exception
+ */
+ public function __call($name, $arguments)
+ {
+ if ((array_key_exists($name, $validSubResources = $this::getValidSubResources()))) {
+ $className = $validSubResources[$name];
+ $client = ($this instanceof HttpClient) ? $this : $this->client;
+ $class = new $className($client);
+ } else {
+ throw new \Exception("No method called $name available in " . __CLASS__);
+ }
+
+ $chainedParams = ($this instanceof ResourceAbstract) ? $this->getChainedParameters() : [];
+
+ if ((isset($arguments[0])) && ($arguments[0] != null)) {
+ $chainedParams = array_merge($chainedParams, [get_class($class) => $arguments[0]]);
+ }
+
+ $class = $class->setChainedParameters($chainedParams);
+
+ return $class;
+ }
+}
diff --git a/src/Zendesk/API/Triggers.php b/src/Zendesk/API/Triggers.php
deleted file mode 100755
index b91bb2e1..00000000
--- a/src/Zendesk/API/Triggers.php
+++ /dev/null
@@ -1,159 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific trigger
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('triggers/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a trigger
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('triggers.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a trigger
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('triggers/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a trigger
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('triggers/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * @throws ResponseException
- *
- * @return mixed
- */
- public function active()
- {
- return $this->findAll(array('active' => true));
- }
-
-}
diff --git a/src/Zendesk/API/Twitter.php b/src/Zendesk/API/Twitter.php
deleted file mode 100755
index 6b963641..00000000
--- a/src/Zendesk/API/Twitter.php
+++ /dev/null
@@ -1,67 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Responds with details of a specific handle
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function handleById(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('channels/twitter/monitored_twitter_handles/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/UserFields.php b/src/Zendesk/API/UserFields.php
deleted file mode 100755
index 872c8d5b..00000000
--- a/src/Zendesk/API/UserFields.php
+++ /dev/null
@@ -1,174 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific user field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('user_fields/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new user field
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('user_fields.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a user field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('user_fields/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a user field
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('user_fields/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Reorder user fields
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function reorder(array $params)
- {
- $endPoint = Http::prepare('user_fields/reorder.json');
- $response = Http::send($this->client, $endPoint, array('user_field_ids' => $params), 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/UserIdentities.php b/src/Zendesk/API/UserIdentities.php
deleted file mode 100755
index 2d55bb81..00000000
--- a/src/Zendesk/API/UserIdentities.php
+++ /dev/null
@@ -1,250 +0,0 @@
-client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('user_id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id'));
- }
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/identities.json', null, $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific user identity
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('user_id', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'id'));
- }
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/identities/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new user identity
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if (!$this->hasKeys($params, array('user_id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id'));
- }
- $user_id = $params['user_id'];
- $prepare = (isset($params['end_user']) ? 'end_users' : 'users') . '/' . $user_id . '/identities.json';
- unset($params['user_id']);
- unset($params['end_user']);
- $endPoint = Http::prepare($prepare);
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Mark a user identity as verified
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function markAsVerified(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('user_id', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'id'));
- }
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/identities/' . $params['id'] . '/verify.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Mark a user identity as primary
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function makePrimary(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('user_id', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'id'));
- }
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/identities/' . $params['id'] . '/make_primary.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Request verification
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function requestVerification(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('user_id', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'id'));
- }
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/identities/' . $params['id'] . '/request_verification.json');
- $response = Http::send($this->client, $endPoint, null, 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a user identity
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->client->users()->getLastId() != null) {
- $params['user_id'] = $this->client->users()->getLastId();
- $this->client->users()->setLastId(null);
- }
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('user_id', 'id'))) {
- throw new MissingParametersException(__METHOD__, array('user_id', 'id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('users/' . $params['user_id'] . '/identities/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/Users.php b/src/Zendesk/API/Users.php
deleted file mode 100755
index 810e4148..00000000
--- a/src/Zendesk/API/Users.php
+++ /dev/null
@@ -1,626 +0,0 @@
-identities = new UserIdentities($client);
- }
-
- /**
- * List all users
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function findAll(array $params = array())
- {
- $endPoint = Http::prepare(
- (isset($params['organization_id']) ? 'organizations/' . $params['organization_id'] . '/users' :
- (isset($params['group_id']) ? 'groups/' . $params['group_id'] . '/users' : 'users')
- ) . '.json' . (isset($params['role']) ? (is_array($params['role']) ? '?role[]=' . implode('&role[]=',
- $params['role']) : '?role=' . $params['role']) : '') . (isset($params['permission_set']) ? (isset($params['role']) ? '&' : '?') . 'permission_set=' . $params['permission_set'] : ''),
- $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific user
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare((is_array($params['id']) ? 'users/show_many.json?ids=' . implode(',',
- $params['id']) : 'users/' . $params['id'] . '.json'), $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Find users by ids or external_ids
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function showMany(array $params = array())
- {
- if (isset($params['ids']) && isset($params['external_ids'])) {
- throw new \Exception('Only one parameter of ids or external_ids is allowed');
- } elseif (!isset($params['ids']) && !isset($params['external_ids'])) {
- throw new \Exception('Missing parameters ids or external_ids');
- } elseif (isset($params['ids']) && is_array($params['ids'])) {
- $path = 'users/show_many.json?ids=' . implode(',', $params['ids']);
- } elseif (isset($params['external_ids']) && is_array($params['external_ids'])) {
- $path = 'users/show_many.json?external_ids=' . implode(',', $params['external_ids']);
- } else {
- throw new \Exception('Parameters ids or external_ids must be arrays');
- }
-
- $endPoint = Http::prepare($path, $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Get related information about the user
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function related(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('users/' . $params['id'] . '/related.json', $this->client->getSideload($params),
- $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new user
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('users.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Merge the specified user (???)
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function merge(array $params = array())
- {
- if ($this->lastId != null) {
- $myId = $this->lastId;
- $this->lastId = null;
- }
- $mergeMe = !isset($myId) || is_null($myId);
- $hasKeys = $mergeMe ? array('email', 'password') : array('id');
- if (!$this->hasKeys($params, $hasKeys)) {
- throw new MissingParametersException(__METHOD__, $hasKeys);
- }
- $endPoint = Http::prepare('users/' . ($mergeMe ? 'me' : $myId) . '/merge.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create multiple new users
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function createMany(array $params)
- {
- $endPoint = Http::prepare('users/create_many.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME_PLURAL => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a user
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('users/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update multiple users
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
-
- public function updateMany(array $params)
- {
- if (!$this->hasKeys($params, array('ids'))) {
- throw new MissingParametersException(__METHOD__, array('ids'));
- }
- $ids = $params['ids'];
- unset($params['ids']);
- $endPoint = Http::prepare('users/update_many.json?ids=' . $ids);
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update multiple individual users
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
-
- public function updateManyIndividualUsers(array $params)
- {
- $endPoint = Http::prepare('users/update_many.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME_PLURAL => $params), 'PUT');
-
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-
- /**
- * Suspend a user
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function suspend(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $params['suspended'] = true;
-
- return $this->update($params);
- }
-
- /**
- * Delete a user
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('users/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Search for users
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function search(array $params)
- {
- $endPoint = Http::prepare('users/search.json?' . http_build_query($params), $this->client->getSideload($params),
- $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Requests autocomplete for users
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function autocomplete(array $params)
- {
- $endPoint = Http::prepare('users/autocomplete.json?' . http_build_query($params));
- $response = Http::send($this->client, $endPoint, null, 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a user's profile image
- *
- * @param array $params
- *
- * @throws CustomException
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function updateProfileImage(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'file'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'file'));
- }
- if (!file_exists($params['file'])) {
- throw new CustomException('File ' . $params['file'] . ' could not be found in ' . __METHOD__);
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('users/' . $id . '.json');
- if (function_exists('curl_file_create')) {
- $response = Http::send($this->client, $endPoint, $params['file'], 'PUT',
- (isset($params['type']) ? $params['type'] : 'application/binary'));
- } else {
- $response = Http::send($this->client, $endPoint,
- array('user[photo][uploaded_data]' => '@' . $params['file']), 'PUT',
- (isset($params['type']) ? $params['type'] : 'application/binary'));
- }
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show the current user
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- *
- * @return mixed
- */
- public function me(array $params = array())
- {
- $params['id'] = 'me';
-
- return $this->find($params);
- }
-
- /**
- * Sets a user's initial password
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function setPassword(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'password'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'password'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('users/' . $id . '/password.json');
- $response = Http::send($this->client, $endPoint, $params, 'POST');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Change a user's password
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function changePassword(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'previous_password', 'password'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'previous_password', 'password'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('users/' . $id . '/password.json');
- $response = Http::send($this->client, $endPoint, $params, 'PUT');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /*
- * Syntactic sugar methods:
- * Handy aliases:
- */
-
- /**
- * @param int|null $id
- *
- * @return Tickets
- */
- public function tickets($id = null)
- {
- return ($id != null ? $this->client->tickets()->setLastId($id) : $this->client->tickets());
- }
-
- /**
- * @param int $id
- *
- * @return Tickets
- */
- public function ticket($id)
- {
- return $this->client->tickets()->setLastId($id);
- }
-
- /**
- * @param int|null $id
- *
- * @return UserIdentities
- */
- public function identities($id = null)
- {
- return ($id != null ? $this->identities->setLastId($id) : $this->identities);
- }
-
- /**
- * @param int $id
- *
- * @return UserIdentities
- */
- public function identity($id)
- {
- return $this->identities->setLastId($id);
- }
-
- /**
- * @param int|null $id
- *
- * @return Groups
- */
- public function groups($id = null)
- {
- return ($id != null ? $this->client->groups()->setLastId($id) : $this->client->groups());
- }
-
- /**
- * @param int $id
- *
- * @return Groups
- */
- public function group($id)
- {
- return $this->client->groups()->setLastId($id);
- }
-
- /**
- * @param int|null $id
- *
- * @return GroupMemberships
- */
- public function groupMemberships($id = null)
- {
- return ($id != null ? $this->client->groupMemberships()->setLastId($id) : $this->client->groupMemberships());
- }
-
- /**
- * @param int $id
- *
- * @return GroupMemberships
- */
- public function groupMembership($id)
- {
- return $this->client->groupMemberships()->setLastId($id);
- }
-
-}
diff --git a/src/Zendesk/API/Utilities/Auth.php b/src/Zendesk/API/Utilities/Auth.php
new file mode 100644
index 00000000..a335d597
--- /dev/null
+++ b/src/Zendesk/API/Utilities/Auth.php
@@ -0,0 +1,101 @@
+authStrategy = $strategy;
+
+ if ($strategy == self::BASIC) {
+ if (! array_key_exists('username', $options) || ! array_key_exists('token', $options)) {
+ throw new AuthException('Please supply `username` and `token` for basic auth.');
+ }
+ } elseif ($strategy == self::OAUTH) {
+ if (! array_key_exists('token', $options)) {
+ throw new AuthException('Please supply `token` for oauth.');
+ }
+ }
+
+ $this->authOptions = $options;
+ }
+
+ /**
+ * @param RequestInterface $request
+ * @param array $requestOptions
+ *
+ * @return array
+ * @throws AuthException
+ */
+ public function prepareRequest(RequestInterface $request, array $requestOptions = [])
+ {
+ if ($this->authStrategy === self::BASIC) {
+ $requestOptions = array_merge($requestOptions, [
+ 'auth' => [
+ $this->authOptions['username'] . '/token',
+ $this->authOptions['token'],
+ 'basic'
+ ]
+ ]);
+ } elseif ($this->authStrategy === self::OAUTH) {
+ $oAuthToken = $this->authOptions['token'];
+ $request = $request->withAddedHeader('Authorization', ' Bearer ' . $oAuthToken);
+ } else {
+ throw new AuthException('Please set authentication to send requests.');
+ }
+
+ return [$request, $requestOptions];
+ }
+}
diff --git a/src/Zendesk/API/Views.php b/src/Zendesk/API/Views.php
deleted file mode 100755
index e9b8e857..00000000
--- a/src/Zendesk/API/Views.php
+++ /dev/null
@@ -1,324 +0,0 @@
-client->getSideload($params),
- $params
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific view
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('views/' . $params['id'] . '.json', $this->client->getSideload($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a new view
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('views.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a view
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('views/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a view
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('views/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Execute a specific view
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function execute(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('views/' . $params['id'] . '/execute.json' . (isset($params['sort_by']) ? '?sort_by=' . $params['sort_by'] . (isset($params['sort_order']) ? '&sort_order=' . $params['sort_order'] : '') : ''),
- $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Get tickets from a specific view
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function tickets(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('views/' . $params['id'] . '/tickets.json', $this->client->getSideload($params),
- $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Count tickets (estimate) from a specific view or list of views
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function count(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('views/' . (is_array($params['id']) ? 'count_many.json?ids=' . implode(',',
- $params['id']) : $params['id'] . '/count.json'), $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Export a view
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function export(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('views/' . $params['id'] . '/export.json', $this->client->getSideload($params),
- $params);
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Preview a view
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function preview(array $params)
- {
- $endPoint = Http::prepare('views/preview.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint, array('view' => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Ticket count for a view preview
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function previewCount(array $params)
- {
- $endPoint = Http::prepare('views/preview/count.json', $this->client->getSideload($params), $params);
- $response = Http::send($this->client, $endPoint, array('view' => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/Voice.php b/src/Zendesk/API/Voice.php
deleted file mode 100755
index 320c14b9..00000000
--- a/src/Zendesk/API/Voice.php
+++ /dev/null
@@ -1,75 +0,0 @@
-phoneNumbers = new VoicePhoneNumbers($client);
- $this->greetings = new VoiceGreetings($client);
- $this->stats = new VoiceStats($client);
- $this->agents = new VoiceAgents($client);
- $this->tickets = new VoiceTickets($client);
- }
-
- /**
- * Generic method to object getter. Since all objects are protected, this method
- * exposes a getter function with the same name as the protected variable, for example
- * $client->tickets can be referenced by $client->tickets()
- *
- * @param $name
- * @param $arguments
- *
- * @throws CustomException
- */
- public function __call($name, $arguments)
- {
- if (isset($this->$name)) {
- return ((isset($arguments[0])) && ($arguments[0] != null) ? $this->$name->setLastId($arguments[0]) : $this->$name);
- }
- $namePlural = $name . 's'; // try pluralize
- if (isset($this->$namePlural)) {
- return $this->$namePlural->setLastId($arguments[0]);
- } else {
- throw new CustomException("No method called $name available in " . __CLASS__);
- }
- }
-
-}
diff --git a/src/Zendesk/API/VoiceAgents.php b/src/Zendesk/API/VoiceAgents.php
deleted file mode 100755
index 325fb502..00000000
--- a/src/Zendesk/API/VoiceAgents.php
+++ /dev/null
@@ -1,64 +0,0 @@
-hasKeys($params, array('agent_id', 'user_id'))) {
- throw new MissingParametersException(__METHOD__, array('agent_id', 'user_id'));
- }
- $endPoint = Http::prepare('channels/voice/agents/' . $params['agent_id'] . '/users/' . $params['user_id'] . '/display.json');
- $response = Http::send($this->client, $endPoint, null, 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * Opens a ticket in an agent's browser
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function openTicket(array $params = array())
- {
- if (!$this->hasKeys($params, array('agent_id', 'ticket_id'))) {
- throw new MissingParametersException(__METHOD__, array('agent_id', 'ticket_id'));
- }
- $endPoint = Http::prepare('channels/voice/agents/' . $params['agent_id'] . '/tickets/' . $params['ticket_id'] . '/display.json');
- $response = Http::send($this->client, $endPoint, null, 'POST');
- if (($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/VoiceGreetings.php b/src/Zendesk/API/VoiceGreetings.php
deleted file mode 100755
index 3320d29d..00000000
--- a/src/Zendesk/API/VoiceGreetings.php
+++ /dev/null
@@ -1,183 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific voice greeting
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('channels/voice/greetings/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a voice greeting
- *
- * @param array $params
- *
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- $endPoint = Http::prepare('channels/voice/greetings.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a voice greeting
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('channels/voice/greetings/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a voice greeting
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('channels/voice/greetings/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
- /**
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function upload(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id', 'file'))) {
- throw new MissingParametersException(__METHOD__, array('id', 'file'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('channels/voice/greetings/' . $id . '.json');
- $response = Http::send($this->client, $endPoint,
- array(self::OBJ_NAME => array('uploaded_data' => '@' . $params['file'])), 'POST',
- (isset($params['type']) ? $params['type'] : 'application/binary'));
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/VoicePhoneNumbers.php b/src/Zendesk/API/VoicePhoneNumbers.php
deleted file mode 100755
index 31d111b2..00000000
--- a/src/Zendesk/API/VoicePhoneNumbers.php
+++ /dev/null
@@ -1,182 +0,0 @@
-client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Show a specific voice phone number
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function find(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $endPoint = Http::prepare('channels/voice/phone_numbers/' . $params['id'] . '.json');
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Search for a voice phone number
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function search(array $params)
- {
- if (!$this->hasKeys($params, array('country'))) {
- throw new MissingParametersException(__METHOD__, array('country'));
- }
- $endPoint = Http::prepare('channels/voice/phone_numbers/search.json?' . http_build_query($params));
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Create a voice phone number
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function create(array $params)
- {
- if (!$this->hasKeys($params, array('token'))) {
- throw new MissingParametersException(__METHOD__, array('token'));
- }
- $endPoint = Http::prepare('channels/voice/phone_numbers.json');
- $response = Http::send($this->client, $endPoint, $params, 'POST');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Update a voice phone number
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return mixed
- */
- public function update(array $params)
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- unset($params['id']);
- $endPoint = Http::prepare('channels/voice/phone_numbers/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, array(self::OBJ_NAME => $params), 'PUT');
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
- /**
- * Delete a voice phone number
- *
- * @param array $params
- *
- * @throws MissingParametersException
- * @throws ResponseException
- * @throws \Exception
- *
- * @return bool
- */
- public function delete(array $params = array())
- {
- if ($this->lastId != null) {
- $params['id'] = $this->lastId;
- $this->lastId = null;
- }
- if (!$this->hasKeys($params, array('id'))) {
- throw new MissingParametersException(__METHOD__, array('id'));
- }
- $id = $params['id'];
- $endPoint = Http::prepare('channels/voice/phone_numbers/' . $id . '.json');
- $response = Http::send($this->client, $endPoint, null, 'DELETE');
- if ($this->client->getDebug()->lastResponseCode != 200) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return true;
- }
-
-}
diff --git a/src/Zendesk/API/VoiceStats.php b/src/Zendesk/API/VoiceStats.php
deleted file mode 100755
index bd2a6442..00000000
--- a/src/Zendesk/API/VoiceStats.php
+++ /dev/null
@@ -1,45 +0,0 @@
-hasAnyKey($params, array('current_queue_activity', 'historical_queue_activity', 'agents_activity'))
- ) {
- throw new MissingParametersException(__METHOD__,
- array('current_queue_activity', 'historical_queue_activity', 'agents_activity'));
- }
- $endPoint = Http::prepare(
- (isset($params['current_queue_activity']) ? 'channels/voice/stats/current_queue_activity.json' :
- (isset($params['historical_queue_activity']) ? 'channels/voice/stats/historical_queue_activity.json' :
- (isset($params['agents_activity']) ? 'channels/voice/stats/agents_activity.json' : ''))), null,
- $params
- );
- $response = Http::send($this->client, $endPoint);
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 200)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/src/Zendesk/API/VoiceTickets.php b/src/Zendesk/API/VoiceTickets.php
deleted file mode 100755
index 8fbfda33..00000000
--- a/src/Zendesk/API/VoiceTickets.php
+++ /dev/null
@@ -1,34 +0,0 @@
-client, $endPoint, $params, 'POST'); // note: specify the whole package
- if ((!is_object($response)) || ($this->client->getDebug()->lastResponseCode != 201)) {
- throw new ResponseException(__METHOD__);
- }
- $this->client->setSideload(null);
-
- return $response;
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/ActivityStreamTest.php b/tests/Zendesk/API/LiveTests/ActivityStreamTest.php
deleted file mode 100755
index 7a28be6c..00000000
--- a/tests/Zendesk/API/LiveTests/ActivityStreamTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-subdomain, $username);
- $client_end_user->setAuth('password', $password);
-
- $testTicket = array(
- 'subject' => 'Activity Stream Test',
- 'comment' => array(
- 'body' => 'ce est biche Actions test.'
- ),
- 'priority' => 'normal'
- );
- $request = $client_end_user->requests()->create($testTicket);
- $this->ticket_id = $request->request->id;
- }
-
- public function testAll()
- {
- $activities = $this->client->activities()->findAll();
- $this->assertEquals(is_object($activities), true, 'Should return an object');
- $this->assertEquals(is_array($activities->activities), true,
- 'Should return an array of objects called "activities"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $activity_id = $this->client->activities()->findAll()->activities[0]->id;
- $activity = $this->client->activity($activity_id)->find();
- $this->assertEquals(is_object($activity), true, 'Should return an object');
- $this->assertEquals(is_object($activity->activity), true, 'Should return an objects called "activity"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->client->tickets($this->ticket_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/AppsTest.php b/tests/Zendesk/API/LiveTests/AppsTest.php
deleted file mode 100644
index 078d1d45..00000000
--- a/tests/Zendesk/API/LiveTests/AppsTest.php
+++ /dev/null
@@ -1,142 +0,0 @@
-client);
- if (version_compare(PHP_VERSION, '5.5.0', '<')) {
- $file = ['file' => '@' . getcwd() . '/tests/assets/app.zip'];
- } else {
- $file = ['file' => curl_file_create(getcwd() . '/tests/assets/app.zip')];
- }
-
- $upload = $apps->upload($file);
-
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->assertEquals(is_object($upload), true, 'Should return an object');
- $this->assertEquals(is_integer($upload->id), true, 'Should return an integer called "id"');
- $stack = array($upload);
-
- return $stack;
- }
-
- /**
- * @depends testUploadApps
- */
- public function testCreateApps(array $stack)
- {
- $upload = array_pop($stack);
- $apps = new \Zendesk\API\Apps($this->client);
-
- $create = $apps->create([
- 'name' => 'TESTING APP' . rand(),
- 'short_description' => 'testing',
- 'upload_id' => (string)$upload->id
- ]);
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '202', 'Does not return HTTP code 202');
- $this->assertEquals(is_object($create), true, 'Should return an object');
- $this->assertEquals(is_string($create->job_id), true, 'Should return a string called "job_id"');
- $stack = array($create);
-
- return $stack;
- }
-
- /**
- * @depends testCreateApps
- */
- public function testJobStatusApps(array $stack)
- {
- $jobStatus = array_pop($stack);
- $apps = new \Zendesk\API\Apps($this->client);
-
- $jobStatus = $apps->jobStatus(['id' => (string)$jobStatus->job_id]);
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->assertEquals(is_object($jobStatus), true, 'Should return an object');
- $this->assertEquals(is_string($jobStatus->id), true, 'Should return a string called "job_id"');
- $this->assertEquals(isset($jobStatus->url), true, 'Should return a "url"');
- $this->assertEquals(is_string($jobStatus->status), true, 'Should return a string called "status"');
- $stack = array($jobStatus);
-
- return $stack;
- }
-
- /**
- * @depends testJobStatusApps
- */
- public function testKeepTestingJobStatusUntilDone(array $stack)
- {
- $jobStatus = array_pop($stack);
- $apps = new \Zendesk\API\Apps($this->client);
-
- do {
- $response = $apps->jobStatus(['id' => (string)$jobStatus->id]);
- $status = $response->status;
-
- if ($status === 'failed') {
- throw new \Exception($response->message);
- } elseif ($status === 'queued' || $status === 'working') {
- sleep(5);
- }
- } while ($status === 'queued' || $status === 'working');
-
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals(is_integer($response->app_id), true, 'Should return a string called "app_id"');
-
- $stack = array($response);
-
- return $stack;
- }
-
- /**
- * @depends testKeepTestingJobStatusUntilDone
- */
- public function testUpdateApps(array $stack)
- {
- $jobStatus = array_pop($stack);
- $apps = new \Zendesk\API\Apps($this->client);
-
- if (version_compare(PHP_VERSION, '5.5.0', '<')) {
- $file = ['id' => $jobStatus->app_id, 'file' => '@' . getcwd() . '/tests/assets/app.zip'];
- } else {
- $file = ['id' => $jobStatus->app_id, 'file' => curl_file_create(getcwd() . '/tests/assets/app.zip')];
- }
-
- $upload = $apps->update($file);
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->assertEquals(is_object($upload), true, 'Should return an object');
- $this->assertEquals(is_integer($upload->id), true, 'Should return an integer called "id"');
- $this->assertEquals(is_string($upload->name), true, 'Should return a string called "name"');
- $stack = array($upload);
-
- return $stack;
- }
-
- /**
- * @depends testUpdateApps
- */
- public function testDeleteApps(array $stack)
- {
- $app = array_pop($stack);
- $apps = new \Zendesk\API\Apps($this->client);
-
- $delete = $apps->delete(['id' => $app->id]);
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->assertEquals(is_bool($delete), true, 'Should return an object');
- $this->assertEquals($delete, true, 'Should return true');
- }
-}
diff --git a/tests/Zendesk/API/LiveTests/AttachmentsTest.php b/tests/Zendesk/API/LiveTests/AttachmentsTest.php
deleted file mode 100755
index c7d9695d..00000000
--- a/tests/Zendesk/API/LiveTests/AttachmentsTest.php
+++ /dev/null
@@ -1,77 +0,0 @@
-client->attachments()->upload(array(
- 'file' => getcwd() . '/tests/assets/UK.png',
- 'type' => 'image/png',
- 'name' => 'UK test non-alpha chars.png'
- ));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->assertEquals(is_object($attachment), true, 'Should return an object');
- $this->assertEquals(is_object($attachment->upload), true, 'Should return an object called "upload"');
- $this->assertEquals(($attachment->upload->token != ''), true, 'Should return a token');
- $this->assertEquals(is_array($attachment->upload->attachments), true,
- 'Should return an array called "upload->attachments"');
- $this->assertGreaterThan(0, $attachment->upload->attachments[0]->id,
- 'Returns a non-numeric id for upload->attachments[0]');
- $this->assertGreaterThan(0, $attachment->upload->attachments[0]->size,
- 'returns a file with a greater than nothing filesize');
- $stack = array($attachment);
-
- return $stack;
- }
-
- /**
- * @depends testUploadAttachment
- */
- public function testDeleteAttachment(array $stack)
- {
- $attachment = array_pop($stack);
- $this->assertEquals(($attachment->upload->token != ''), true,
- 'Cannot find a token to test with. Did testUploadAttachment fail?');
- $confirmed = $this->client->attachments()->delete(array(
- 'token' => $attachment->upload->token
- ));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUploadAttachmentBody()
- {
- $body = file_get_contents(getcwd() . '/tests/assets/UK.png');
- $attachment = $this->client->attachments()->uploadWithBody(array(
- 'body' => $body,
- 'type' => 'image/png',
- 'name' => 'UK.png'
- ));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->assertEquals(is_object($attachment), true, 'Should return an object');
- $this->assertEquals(is_object($attachment->upload), true, 'Should return an object called "upload"');
- $this->assertEquals(($attachment->upload->token != ''), true, 'Should return a token');
- $this->assertEquals(is_array($attachment->upload->attachments), true,
- 'Should return an array called "upload->attachments"');
- $this->assertGreaterThan(0, $attachment->upload->attachments[0]->id,
- 'Returns a non-numeric id for upload->attachments[0]');
- $this->assertEquals(strlen($body), $attachment->upload->attachments[0]->size,
- 'returns a file with correct filesize');
- $stack = array($attachment);
-
- return $stack;
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/AuditLogsTest.php b/tests/Zendesk/API/LiveTests/AuditLogsTest.php
deleted file mode 100755
index 833c99a7..00000000
--- a/tests/Zendesk/API/LiveTests/AuditLogsTest.php
+++ /dev/null
@@ -1,65 +0,0 @@
- 'The is for Audit Logs test',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
- );
- $this->ticket = $this->client->tickets()->create($testTicket);
- }
-
- public function tearDown()
- {
- $this->client->tickets($this->ticket->ticket->id)->delete();
- }
-
- public function testAll()
- {
- $auditLogs = $this->client->auditLogs()->findAll(array(
- 'filter' => array(
- 'source_type' => 'rule'
- )
- ));
- $this->assertEquals(is_object($auditLogs), true, 'Should return an object');
- $this->assertEquals(is_array($auditLogs->audit_logs), true,
- 'Should return an object containing an array called "audit_logs"');
- $this->assertGreaterThan(0, $auditLogs->audit_logs[0]->id, 'Returns a non-numeric id for audit_logs[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $auditLog_id = $this->client->auditLogs()->findAll()->audit_logs[0]->id;
- $auditLog = $this->client->auditLog($auditLog_id)->find(); // don't delete audit log #24000361
- $this->assertEquals(is_object($auditLog), true, 'Should return an object');
- $this->assertGreaterThan(0, $auditLog->audit_log->id, 'Returns a non-numeric id for audit_log');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/AuthTest.php b/tests/Zendesk/API/LiveTests/AuthTest.php
new file mode 100755
index 00000000..e9acb815
--- /dev/null
+++ b/tests/Zendesk/API/LiveTests/AuthTest.php
@@ -0,0 +1,29 @@
+client->setAuth('basic', ['username' => $this->username, 'token' => $this->token]);
+ $users = $this->client->users()->findAll();
+ $this->assertTrue(isset($users->users), 'Should return a valid user object.');
+ }
+
+ /**
+ * Test the use of basic test
+ */
+ public function testOAuth()
+ {
+ $this->client->setAuth('oauth', ['token' => $this->oAuthToken]);
+ $users = $this->client->users()->findAll();
+ $this->assertTrue(isset($users->users), 'Should return a valid user object.');
+ }
+}
diff --git a/tests/Zendesk/API/LiveTests/AutocompleteTest.php b/tests/Zendesk/API/LiveTests/AutocompleteTest.php
deleted file mode 100755
index 92101555..00000000
--- a/tests/Zendesk/API/LiveTests/AutocompleteTest.php
+++ /dev/null
@@ -1,33 +0,0 @@
-client->autocomplete()->tags(array(
- 'name' => 'att'
- ));
- $this->assertEquals(is_object($tags), true, 'Should return an object');
- $this->assertEquals(is_array($tags->tags), true, 'Should return an object containing an array called "tags"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/AutomationsTest.php b/tests/Zendesk/API/LiveTests/AutomationsTest.php
deleted file mode 100755
index 34f45477..00000000
--- a/tests/Zendesk/API/LiveTests/AutomationsTest.php
+++ /dev/null
@@ -1,102 +0,0 @@
-client->automations()->create(array(
- 'title' => 'Roger Wilco',
- 'all' => array(
- array(
- 'field' => 'status',
- 'operator' => 'is',
- 'value' => 'open'
- ),
- array(
- 'field' => 'priority',
- 'operator' => 'less_than',
- 'value' => 'high'
- )
- ),
- 'actions' => array(
- array(
- 'field' => 'priority',
- 'value' => 'high'
- )
- )
- ));
- $this->assertEquals(is_object($automation), true, 'Should return an object');
- $this->assertEquals(is_object($automation->automation), true, 'Should return an object called "automation"');
- $this->assertGreaterThan(0, $automation->automation->id, 'Returns a non-numeric id for automation');
- $this->assertEquals($automation->automation->title, 'Roger Wilco', 'Name of test automation does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $automation->automation->id;
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a automation id to test with. Did setUP fail?');
- $topic = $this->client->automation($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAll()
- {
- $automations = $this->client->automations()->findAll();
- $this->assertEquals(is_object($automations), true, 'Should return an object');
- $this->assertEquals(is_array($automations->automations), true,
- 'Should return an object containing an array called "automations"');
- $this->assertGreaterThan(0, $automations->automations[0]->id, 'Returns a non-numeric id for automations[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testActive()
- {
- $automations = $this->client->automations()->findAll(array('active' => true));
- $this->assertEquals(is_object($automations), true, 'Should return an object');
- $this->assertEquals(is_array($automations->automations), true,
- 'Should return an object containing an array called "automations"');
- $this->assertGreaterThan(0, $automations->automations[0]->id, 'Returns a non-numeric id for automations[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $automation = $this->client->automations($this->id)->find();
- $this->assertEquals(is_object($automation), true, 'Should return an object');
- $this->assertGreaterThan(0, $automation->automation->id, 'Returns a non-numeric id for automation');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $automation = $this->client->automation($this->id)->update(array(
- 'title' => 'Roger Wilco II'
- ));
- $this->assertEquals(is_object($automation), true, 'Should return an object');
- $this->assertEquals(is_object($automation->automation), true, 'Should return an object called "automation"');
- $this->assertGreaterThan(0, $automation->automation->id, 'Returns a non-numeric id for automation');
- $this->assertEquals($automation->automation->title, 'Roger Wilco II', 'Name of test automation does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-}
diff --git a/tests/Zendesk/API/LiveTests/BasicTest.php b/tests/Zendesk/API/LiveTests/BasicTest.php
index 70006efe..8e436caf 100644
--- a/tests/Zendesk/API/LiveTests/BasicTest.php
+++ b/tests/Zendesk/API/LiveTests/BasicTest.php
@@ -2,94 +2,83 @@
namespace Zendesk\API\LiveTests;
-use Zendesk\API\Client;
+use Zendesk\API\HttpClient;
/**
* Basic test class
*/
abstract class BasicTest extends \PHPUnit_Framework_TestCase
{
- use \InterNations\Component\HttpMock\PHPUnit\HttpMockTrait;
-
+ /**
+ * @var HttpClient
+ */
protected $client;
+ /**
+ * @var string
+ */
protected $subdomain;
+ /**
+ * @var string
+ */
protected $password;
+ /**
+ * @var string
+ */
protected $token;
+ /**
+ * @var string
+ */
protected $oAuthToken;
+ /**
+ * @var string
+ */
protected $hostname;
+ /**
+ * @var string
+ */
protected $scheme;
+ /**
+ * @var string
+ */
protected $port;
+ /**
+ * @var array
+ */
+ protected $mockedTransactionsContainer = [];
- public function __construct()
- {
- $this->subdomain = getenv('SUBDOMAIN');
- $this->username = getenv('USERNAME');
- $this->password = getenv('PASSWORD');
- $this->token = getenv('TOKEN');
- $this->oAuthToken = getenv('OAUTH_TOKEN');
- $this->scheme = getenv('SCHEME');
- $this->hostname = getenv('HOSTNAME');
- $this->port = getenv('PORT');
-
- $this->client = new Client($this->subdomain, $this->username, $this->scheme, $this->hostname, $this->port);
- $this->client->setAuth('token', $this->token);
- }
-
- protected function mockApiCall($httpMethod, $path, $response, $options = array())
- {
- $options = array_merge(array(
- 'code' => 200,
- 'timesCalled' => 1
- ), $options);
-
- $this->http->mock
- ->exactly($options['timesCalled'])
- ->when()
- ->methodIs($httpMethod)
- ->pathIs('/api/v2' . $path)
- ->then()
- ->body(json_encode($response))
- ->statusCode($options['code'])
- ->end();
- $this->http->setUp();
- }
-
- public function setUp()
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct($name = null, array $data = [], $dataName = '')
{
- $this->setUpHttpMock();
- parent::setUp();
- }
+ $this->subdomain = getenv('SUBDOMAIN');
+ $this->username = getenv('USERNAME');
+ $this->password = getenv('PASSWORD');
+ $this->token = getenv('TOKEN');
+ $this->oAuthToken = getenv('OAUTH_TOKEN');
+ $this->scheme = getenv('SCHEME');
+ $this->hostname = getenv('HOSTNAME');
+ $this->port = getenv('PORT');
+ $this->authStrategy = getenv('AUTH_STRATEGY');
- public function tearDown()
- {
- $this->tearDownHttpMock();
- parent::tearDown();
+ parent::__construct($name, $data, $dataName);
}
- public static function setUpBeforeClass()
+ /**
+ * Sets up the fixture, for example, open a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
{
- static::setUpHttpMockBeforeClass(getenv("PORT"), getenv("HOSTNAME"));
- parent::setUpBeforeClass();
- }
+ $this->client = new HttpClient($this->subdomain, $this->username, $this->scheme, $this->hostname, $this->port);
- public static function tearDownAfterClass()
- {
- static::tearDownHttpMockAfterClass();
- parent::tearDownAfterClass();
- }
+ $authOptions['username'] = $this->username;
+ if ($this->authStrategy === 'basic') {
+ $authOptions['token'] = $this->token;
+ } else {
+ $authOptions['token'] = $this->oAuthToken;
+ }
- public function authTokenTest()
- {
- $tickets = $this->client->tickets()->findAll();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function credentialsTest()
- {
- $this->assertNotEmpty($this->subdomain,
- 'Expecting $this->subdomain parameter; does phpunit.xml exist?');
- $this->assertNotEmpty($this->token, 'Expecting $this->token parameter; does phpunit.xml exist?');
- $this->assertNotEmpty($this->username,
- 'Expecting $this->username parameter; does phpunit.xml exist?');
+ $this->client->setAuth($this->authStrategy, $authOptions);
}
}
diff --git a/tests/Zendesk/API/LiveTests/CategoriesTest.php b/tests/Zendesk/API/LiveTests/CategoriesTest.php
deleted file mode 100755
index 38c9fb4d..00000000
--- a/tests/Zendesk/API/LiveTests/CategoriesTest.php
+++ /dev/null
@@ -1,99 +0,0 @@
-client->categories()->create(array(
- 'name' => 'My Category'
- ));
- $this->assertEquals(is_object($category), true, 'Should return an object');
- $this->assertEquals(is_object($category->category), true, 'Should return an object called "category"');
- $this->assertGreaterThan(0, $category->category->id, 'Returns a non-numeric id for category');
- $this->assertEquals($category->category->name, 'My Category', 'Name of test category does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $id = $category->category->id;
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreate
- */
- public function testAll($stack)
- {
- $categories = $this->client->categories()->findAll();
- $this->assertEquals(is_object($categories), true, 'Should return an object');
- $this->assertEquals(is_array($categories->categories), true,
- 'Should return an object containing an array called "categories"');
- $this->assertGreaterThan(0, $categories->categories[0]->id, 'Returns a non-numeric id for categories[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- return $stack;
- }
-
- /**
- * @depends testCreate
- */
- public function testFind($stack)
- {
- $id = array_pop($stack);
- $category = $this->client->category($id)->find();
- $this->assertEquals(is_object($category), true, 'Should return an object');
- $this->assertGreaterThan(0, $category->category->id, 'Returns a non-numeric id for category');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreate
- */
- public function testUpdate(array $stack)
- {
- $id = array_pop($stack);
- $category = $this->client->category($id)->update(array(
- 'name' => 'My Category II'
- ));
- $this->assertEquals(is_object($category), true, 'Should return an object');
- $this->assertEquals(is_object($category->category), true, 'Should return an object called "category"');
- $this->assertGreaterThan(0, $category->category->id, 'Returns a non-numeric id for category');
- $this->assertEquals($category->category->name, 'My Category II', 'Name of test category does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreate
- */
- public function testDelete(array $stack)
- {
- $id = array_pop($stack);
- $this->assertGreaterThan(0, $id, 'Cannot find a category id to test with. Did testCreate fail?');
- $view = $this->client->category($id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/CustomRolesTest.php b/tests/Zendesk/API/LiveTests/CustomRolesTest.php
deleted file mode 100755
index a45fc2fa..00000000
--- a/tests/Zendesk/API/LiveTests/CustomRolesTest.php
+++ /dev/null
@@ -1,33 +0,0 @@
-client->customRoles()->findAll();
- $this->assertEquals(is_object($customRoles), true, 'Should return an object');
- $this->assertEquals(is_array($customRoles->custom_roles), true,
- 'Should return an object containing an array called "custom_roles"');
- $this->assertGreaterThan(0, $customRoles->custom_roles[0]->id, 'Returns a non-numeric id for custom_roles[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/DynamicContentTest.php b/tests/Zendesk/API/LiveTests/DynamicContentTest.php
deleted file mode 100755
index d6dbb28f..00000000
--- a/tests/Zendesk/API/LiveTests/DynamicContentTest.php
+++ /dev/null
@@ -1,58 +0,0 @@
-client->dynamicContent()->create(array(
- 'name' => "Test Content Name {$number}",
- 'content' => "test content content",
- 'default_locale_id' => 1176
- ));
- $this->assertEquals(is_object($dynamicContent), true, 'Should return an object');
- $this->assertEquals(is_object($dynamicContent->item), true, 'Should return an object called "item"');
- $this->assertGreaterThan(0, $dynamicContent->item->id, 'Returns a non-numeric id for item');
- $this->assertEquals($dynamicContent->item->name, "Test Content Name {$number}",
- 'Name of test item does not match');
- $this->assertEquals('201', $this->client->getDebug()->lastResponseCode, 'Does not return HTTP code 201');
- $this->id = $dynamicContent->item->id;
- }
-
- public function testFindAll()
- {
- $dynamicContents = $this->client->dynamicContent()->findAll();
- $this->assertEquals(is_object($dynamicContents), true, 'Should return an object');
- $this->assertEquals(is_array($dynamicContents->items), true,
- 'Should return an object containing an array called "items"');
- $this->assertGreaterThan(0, $dynamicContents->items[0]->id, 'Returns a non-numeric id for items[0]');
- $this->assertEquals('200', $this->client->getDebug()->lastResponseCode, 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a item id to test with. Did setUp fail?');
- $dynamicContent = $this->client->dynamicContent($this->id)->delete();
- $this->assertEquals('200', $this->client->getDebug()->lastResponseCode, 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/ForumSubscriptionsTest.php b/tests/Zendesk/API/LiveTests/ForumSubscriptionsTest.php
deleted file mode 100755
index 13584bf0..00000000
--- a/tests/Zendesk/API/LiveTests/ForumSubscriptionsTest.php
+++ /dev/null
@@ -1,83 +0,0 @@
-client->forums()->create(array(
- 'name' => 'My Forum',
- 'forum_type' => 'articles',
- 'access' => 'logged-in users',
- ));
-
- $this->forum_id = $forum->forum->id;
-
- $this->user_id = $this->client->users()->findAll()->users[0]->id;
-
- $forumSubscription = $this->client->forum($this->forum_id)->subscriptions()->create(array(
- 'user_id' => $this->user_id
- ));
-
- $this->assertEquals(is_object($forumSubscription), true, 'Should return an object');
- $this->assertEquals(is_object($forumSubscription->forum_subscription), true,
- 'Should return an object called "forum_subscription"');
- $this->assertGreaterThan(0, $forumSubscription->forum_subscription->id,
- 'Returns a non-numeric id for forum_subscription');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $forumSubscription->forum_subscription->id;
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a forum subscription id to test with. Did setUp fail?');
- $view = $this->client->forums()->subscription($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- $this->client->forum($this->forum_id)->delete();
- }
-
- public function testAll()
- {
- $forumSubscriptions = $this->client->forums()->subscriptions()->findAll();
- $this->assertEquals(is_object($forumSubscriptions), true, 'Should return an object');
- $this->assertEquals(is_array($forumSubscriptions->forum_subscriptions), true,
- 'Should return an object containing an array called "forum_subscriptions"');
- $this->assertGreaterThan(0, $forumSubscriptions->forum_subscriptions[0]->id,
- 'Returns a non-numeric id for forum_subscriptions[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $forumSubscription = $this->client->forums()->subscription($this->id)->find(); // find the one we just created
- $this->assertEquals(is_object($forumSubscription), true, 'Should return an object');
- $this->assertGreaterThan(0, $forumSubscription->forum_subscription->id,
- 'Returns a non-numeric id for forum_subscription');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-}
diff --git a/tests/Zendesk/API/LiveTests/ForumsTest.php b/tests/Zendesk/API/LiveTests/ForumsTest.php
deleted file mode 100755
index b6cfe8cc..00000000
--- a/tests/Zendesk/API/LiveTests/ForumsTest.php
+++ /dev/null
@@ -1,77 +0,0 @@
-client->forums()->create(array(
- 'name' => 'My Forum',
- 'forum_type' => 'articles',
- 'access' => 'logged-in users'
- ));
- $this->assertEquals(is_object($forum), true, 'Should return an object');
- $this->assertEquals(is_object($forum->forum), true, 'Should return an object called "forum"');
- $this->assertGreaterThan(0, $forum->forum->id, 'Returns a non-numeric id for forum');
- $this->assertEquals($forum->forum->name, 'My Forum', 'Name of test forum does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $forum->forum->id;
- }
-
- public function testAll()
- {
- $forums = $this->client->forums()->findAll();
- $this->assertEquals(is_object($forums), true, 'Should return an object');
- $this->assertEquals(is_array($forums->forums), true,
- 'Should return an object containing an array called "forums"');
- $this->assertGreaterThan(0, $forums->forums[0]->id, 'Returns a non-numeric id for forums[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $forum = $this->client->forum($this->id)->find();
- $this->assertEquals(is_object($forum), true, 'Should return an object');
- $this->assertGreaterThan(0, $forum->forum->id, 'Returns a non-numeric id for forum');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $forum = $this->client->forum($this->id)->update(array(
- 'name' => 'My Forum II'
- ));
- $this->assertEquals(is_object($forum), true, 'Should return an object');
- $this->assertEquals(is_object($forum->forum), true, 'Should return an object called "forum"');
- $this->assertGreaterThan(0, $forum->forum->id, 'Returns a non-numeric id for forum');
- $this->assertEquals($forum->forum->name, 'My Forum II', 'Name of test forum does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a forum id to test with. Did setUp fail?');
- $view = $this->client->forum($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/GroupMembershipsTest.php b/tests/Zendesk/API/LiveTests/GroupMembershipsTest.php
deleted file mode 100755
index 05da214e..00000000
--- a/tests/Zendesk/API/LiveTests/GroupMembershipsTest.php
+++ /dev/null
@@ -1,121 +0,0 @@
-number = strval(rand(1, 1000));
- /*
- * First start by creating a topic (we'll delete it later)
- */
- $group = $this->client->groups()->create(array(
- 'name' => 'New Group'
- ));
- $this->group_id = $group->group->id;
-
- $user = $this->client->users()->create(array(
- 'name' => 'Roger Wilco' . $this->number,
- 'email' => 'roge' . $this->number . '@example.org',
- 'role' => 'agent',
- 'verified' => true
- ));
- $this->user_id = $user->user->id;
-
- $groupMembership = $this->client->groupMemberships()->create(array(
- 'group_id' => $this->group_id,
- 'user_id' => $this->user_id
- ));
-
- $this->assertEquals(is_object($groupMembership), true, 'Should return an object');
- $this->assertEquals(is_object($groupMembership->group_membership), true,
- 'Should return an object called "group_membership"');
- $this->assertGreaterThan(0, $groupMembership->group_membership->id,
- 'Returns a non-numeric id for group_membership');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $groupMembership->group_membership->id;
- }
-
- public function testAll()
- {
- $groupMemberships = $this->client->groupMemberships()->findAll();
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAllByUser()
- {
- $groupMemberships = $this->client->user($this->user_id)->groupMemberships()->findAll();
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAllByGroup()
- {
- $groupMemberships = $this->client->group($this->group_id)->members()->findAll();
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $groupMembership = $this->client->groupMembership($this->id)->find(); // don't delete group membership #22534232
- $this->assertEquals(is_object($groupMembership), true, 'Should return an object');
- $this->assertGreaterThan(0, $groupMembership->group_membership->id, 'Returns a non-numeric id for group');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testMakeDefault()
- {
- $groupMemberships = $this->client->user($this->user_id)->groupMembership($this->id)->makeDefault();
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a group membership id to test with. Did setUP fail?');
- $view = $this->client->groupMembership($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- /*
- * Clean-up
- */
- $this->client->group($this->group_id)->delete();
- $this->client->user($this->user_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/GroupsTest.php b/tests/Zendesk/API/LiveTests/GroupsTest.php
deleted file mode 100755
index 8014b85f..00000000
--- a/tests/Zendesk/API/LiveTests/GroupsTest.php
+++ /dev/null
@@ -1,85 +0,0 @@
-client->groups()->create(array(
- 'name' => 'New Group'
- ));
- $this->assertEquals(is_object($group), true, 'Should return an object');
- $this->assertEquals(is_object($group->group), true, 'Should return an object called "group"');
- $this->assertGreaterThan(0, $group->group->id, 'Returns a non-numeric id for group');
- $this->assertEquals($group->group->name, 'New Group', 'Name of test group does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $group->group->id;
- }
-
- public function testAll()
- {
- $groups = $this->client->groups()->findAll();
- $this->assertEquals(is_object($groups), true, 'Should return an object');
- $this->assertEquals(is_array($groups->groups), true,
- 'Should return an object containing an array called "groups"');
- $this->assertGreaterThan(0, $groups->groups[0]->id, 'Returns a non-numeric id for groups[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAssignable()
- {
- $groups = $this->client->groups()->findAll(array('assignable' => true));
- $this->assertEquals(is_object($groups), true, 'Should return an object');
- $this->assertEquals(is_array($groups->groups), true,
- 'Should return an object containing an array called "groups"');
- $this->assertGreaterThan(0, $groups->groups[0]->id, 'Returns a non-numeric id for groups[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $group = $this->client->group($this->id)->find();
- $this->assertEquals(is_object($group), true, 'Should return an object');
- $this->assertGreaterThan(0, $group->group->id, 'Returns a non-numeric id for group');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $group = $this->client->group($this->id)->update(array(
- 'name' => 'New Group II'
- ));
- $this->assertEquals(is_object($group), true, 'Should return an object');
- $this->assertEquals(is_object($group->group), true, 'Should return an object called "group"');
- $this->assertGreaterThan(0, $group->group->id, 'Returns a non-numeric id for group');
- $this->assertEquals($group->group->name, 'New Group II', 'Name of test group does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a group id to test with. Did setUP fail?');
- $view = $this->client->group($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/JobStatusesTest.php b/tests/Zendesk/API/LiveTests/JobStatusesTest.php
deleted file mode 100755
index 82420a07..00000000
--- a/tests/Zendesk/API/LiveTests/JobStatusesTest.php
+++ /dev/null
@@ -1,52 +0,0 @@
- 'The quick brown fox jumps over the lazy dog',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
- );
- $ticket = $this->client->tickets()->create($testTicket);
- $ticket2 = $this->client->tickets()->create($testTicket);
-
- $testUpdateTicket['id'] = array($ticket->ticket->id, $ticket2->ticket->id);
- $testUpdateTicket['subject'] = 'Updated subject';
- $testUpdateTicket['priority'] = 'urgent';
-
- $testJobStatus = $this->client->tickets()->update($testUpdateTicket);
-
- $id = $testJobStatus->job_status->id;
- $jobStatus = $this->client->jobStatus($id)->find();
- $this->assertEquals(is_object($jobStatus), true, 'Should return an object');
- $this->assertNotEmpty($jobStatus->job_status->id, 'Returns no id value for job_status');
- // $this->assertEquals($jobStatus->job_status->status, 'working', 'Returns an incorrect status for job_status');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- $ticket = $this->client->ticket($ticket->ticket->id)->delete();
- $ticket = $this->client->ticket($ticket2->ticket->id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/LocalesTest.php b/tests/Zendesk/API/LiveTests/LocalesTest.php
deleted file mode 100755
index 1baf7d42..00000000
--- a/tests/Zendesk/API/LiveTests/LocalesTest.php
+++ /dev/null
@@ -1,68 +0,0 @@
-client->locales()->findAll();
- $this->assertEquals(is_object($locales), true, 'Should return an object');
- $this->assertEquals(is_array($locales->locales), true, 'Should return an array of objects called "locales"');
- $this->assertGreaterThan(0, $locales->locales[0]->id, 'Returns a non-numeric id for locales');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAgent()
- {
- $locales = $this->client->locales()->agent();
- $this->assertEquals(is_object($locales), true, 'Should return an object');
- $this->assertEquals(is_array($locales->locales), true, 'Should return an array of objects called "locales"');
- $this->assertGreaterThan(0, $locales->locales[0]->id, 'Returns a non-numeric id for locales');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testCurrent()
- {
- $locale = $this->client->locales()->current();
- $this->assertEquals(is_object($locale), true, 'Should return an object');
- $this->assertEquals(is_object($locale->locale), true, 'Should return an object called "locale"');
- $this->assertGreaterThan(0, $locale->locale->id, 'Returns a non-numeric id for locale');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $locale = $this->client->locale(1)->find();
- $this->assertEquals(is_object($locale), true, 'Should return an object');
- $this->assertEquals(is_object($locale->locale), true, 'Should return an object called "locale"');
- $this->assertGreaterThan(0, $locale->locale->id, 'Returns a non-numeric id for locale');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testDetectBest()
- {
- $locale = $this->client->locales()->detectBest(array('available_locales' => array('en', 'js', 'es')));
- $this->assertEquals(is_object($locale), true, 'Should return an object');
- $this->assertEquals(is_object($locale->locale), true, 'Should return an object called "locale"');
- $this->assertGreaterThan(0, $locale->locale->id, 'Returns a non-numeric id for locale');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/MacrosTest.php b/tests/Zendesk/API/LiveTests/MacrosTest.php
deleted file mode 100755
index d819fff3..00000000
--- a/tests/Zendesk/API/LiveTests/MacrosTest.php
+++ /dev/null
@@ -1,91 +0,0 @@
-client->macros()->create(array(
- 'title' => 'Roger Wilco',
- 'actions' => array(
- array(
- 'field' => 'status',
- 'value' => 'solved'
- )
- )
- ));
- $this->assertEquals(is_object($macro), true, 'Should return an object');
- $this->assertEquals(is_object($macro->macro), true, 'Should return an object called "macro"');
- $this->assertGreaterThan(0, $macro->macro->id, 'Returns a non-numeric id for macro');
- $this->assertEquals($macro->macro->title, 'Roger Wilco', 'Name of test macro does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $macro->macro->id;
- }
-
- public function testAll()
- {
- $macros = $this->client->macros()->findAll();
- $this->assertEquals(is_object($macros), true, 'Should return an object');
- $this->assertEquals(is_array($macros->macros), true,
- 'Should return an object containing an array called "macros"');
- $this->assertGreaterThan(0, $macros->macros[0]->id, 'Returns a non-numeric id for macros[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testActive()
- {
- $macros = $this->client->macros()->findAll(array('active' => true));
- $this->assertEquals(is_object($macros), true, 'Should return an object');
- $this->assertEquals(is_array($macros->macros), true,
- 'Should return an object containing an array called "macros"');
- $this->assertGreaterThan(0, $macros->macros[0]->id, 'Returns a non-numeric id for macros[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $macro = $this->client->macros($this->id)->find();
- $this->assertEquals(is_object($macro), true, 'Should return an object');
- $this->assertGreaterThan(0, $macro->macro->id, 'Returns a non-numeric id for macro');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $macro = $this->client->macro($this->id)->update(array(
- 'title' => 'Roger Wilco II'
- ));
- $this->assertEquals(is_object($macro), true, 'Should return an object');
- $this->assertEquals(is_object($macro->macro), true, 'Should return an object called "macro"');
- $this->assertGreaterThan(0, $macro->macro->id, 'Returns a non-numeric id for macro');
- $this->assertEquals($macro->macro->title, 'Roger Wilco II', 'Name of test macro does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a macro id to test with. Did setUp fail?');
- $topic = $this->client->macro($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/OAuthClientsTest.php b/tests/Zendesk/API/LiveTests/OAuthClientsTest.php
deleted file mode 100755
index faaadbfd..00000000
--- a/tests/Zendesk/API/LiveTests/OAuthClientsTest.php
+++ /dev/null
@@ -1,89 +0,0 @@
-number = strval(time());
- $user = $this->client->users()->create(array(
- 'name' => 'Roger Wilco' . $this->number,
- 'email' => 'roge' . $this->number . '@example.org',
- 'role' => 'agent',
- 'verified' => true
- ));
- $this->user_id = $user->user->id;
-
- $client = $this->client->oauthClients()->create(array(
- 'name' => 'Test Client' . $this->number,
- 'identifier' => md5(time()),
- 'user_id' => $this->user_id
- ));
- $this->assertEquals(is_object($client), true, 'Should return an object');
- $this->assertEquals(is_object($client->client), true, 'Should return an object called "client"');
- $this->assertGreaterThan(0, $client->client->id, 'Returns a non-numeric id for client');
- $this->assertEquals($client->client->name, 'Test Client' . $this->number, 'Name of test client does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $client->client->id;
- }
-
- public function testAll()
- {
- $clients = $this->client->oauthClients()->findAll();
- $this->assertEquals(is_object($clients), true, 'Should return an object');
- $this->assertEquals(is_array($clients->clients), true,
- 'Should return an object containing an array called "clients"');
- $this->assertGreaterThan(0, $clients->clients[0]->id, 'Returns a non-numeric id for clients[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $client = $this->client->oauthClient($this->id)->find();
- $this->assertEquals(is_object($client), true, 'Should return an object');
- $this->assertGreaterThan(0, $client->client->id, 'Returns a non-numeric id for client');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $client = $this->client->oauthClient($this->id)->update(array(
- 'name' => 'New Client Name' . $this->number
- ));
- $this->assertEquals(is_object($client), true, 'Should return an object');
- $this->assertEquals(is_object($client->client), true, 'Should return an object called "client"');
- $this->assertGreaterThan(0, $client->client->id, 'Returns a non-numeric id for client');
- $this->assertEquals($client->client->name, 'New Client Name' . $this->number,
- 'Name of test client does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a client id to test with. Did setUp fail?');
- $topic = $this->client->oauthClient($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- $this->client->user($this->user_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/OAuthTokensTest.php b/tests/Zendesk/API/LiveTests/OAuthTokensTest.php
deleted file mode 100755
index 72990d95..00000000
--- a/tests/Zendesk/API/LiveTests/OAuthTokensTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-markTestSkipped(
- 'Since there\'s no way to create a token programmatically, we can\'t test testAll'
- );
- $tokens = $this->client->oauthTokens()->findAll();
- $this->assertEquals(is_object($tokens), true, 'Should return an object');
- $this->assertEquals(is_array($tokens->tokens), true,
- 'Should return an object containing an array called "tokens"');
- $this->assertGreaterThan(0, $tokens->tokens[0]->id, 'Returns a non-numeric id for tokens[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- /**
- * @depends testAuthToken
- */
- public function testFind()
- {
- $this->markTestSkipped(
- 'Since there\'s no way to create a token programmatically, we can\'t test testFind'
- );
- $id = 941; // don't delete this token
- $token = $this->client->oauthToken($id)->find();
- $this->assertEquals(is_object($token), true, 'Should return an object');
- $this->assertGreaterThan(0, $token->token->id, 'Returns a non-numeric id for token');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- /**
- * @depends testAuthToken
- */
- public function testRevoke()
- {
- $this->markTestSkipped(
- 'Since there\'s no way to create a token programmatically, we can\'t test revoke'
- );
- $id = '123';
- $topic = $this->client->oauthClient($id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/OrganizationFieldsTest.php b/tests/Zendesk/API/LiveTests/OrganizationFieldsTest.php
deleted file mode 100755
index 1dac6056..00000000
--- a/tests/Zendesk/API/LiveTests/OrganizationFieldsTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-client->organizationFields()->create(array(
- 'type' => 'text',
- 'title' => 'Support description',
- 'description' => 'This field describes the support plan this user has',
- 'position' => 0,
- 'active' => true,
- 'key' => 'support_description' . date("YmdHis")
- ));
- $this->assertEquals(is_object($organizationFields), true, 'Should return an object');
- $this->assertEquals(is_object($organizationFields->organization_field), true,
- 'Should return an object called "organization_field"');
- $this->assertGreaterThan(0, $organizationFields->organization_field->id,
- 'Returns a non-numeric id for organization_field');
- $this->assertEquals($organizationFields->organization_field->title, 'Support description',
- 'Name of test organization field does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $organizationFields->organization_field->id;
- }
-
- public function testAll()
- {
- $organizationFields = $this->client->organizationFields()->findAll();
- $this->assertEquals(is_object($organizationFields), true, 'Should return an object');
- $this->assertEquals(is_array($organizationFields->organization_fields), true,
- 'Should return an object containing an array called "organization_fields"');
- $this->assertGreaterThan(0, $organizationFields->organization_fields[0]->id,
- 'Returns a non-numeric id for organization_fields[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $organizationField = $this->client->organizationField($this->id)->find();
- $this->assertEquals(is_object($organizationField), true, 'Should return an object');
- $this->assertGreaterThan(0, $organizationField->organization_field->id,
- 'Returns a non-numeric id for organization_field');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $organizationField = $this->client->organizationField($this->id)->update(array(
- 'title' => 'Roger Wilco II'
- ));
- $this->assertEquals(is_object($organizationField), true, 'Should return an object');
- $this->assertEquals(is_object($organizationField->organization_field), true,
- 'Should return an object called "organization_field"');
- $this->assertGreaterThan(0, $organizationField->organization_field->id,
- 'Returns a non-numeric id for organization_field');
- $this->assertEquals($organizationField->organization_field->title, 'Roger Wilco II',
- 'Title of test organization field does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testReorder()
- {
- $result = $this->client->organizationFields()->reorder(array('organization_field_ids' => array(14382, 14342)));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find an organization field id to test with. Did setUp fail?');
- $organizationField = $this->client->organizationField($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/OrganizationsTest.php b/tests/Zendesk/API/LiveTests/OrganizationsTest.php
deleted file mode 100755
index 338270d1..00000000
--- a/tests/Zendesk/API/LiveTests/OrganizationsTest.php
+++ /dev/null
@@ -1,108 +0,0 @@
-number = strval(time());
- $organization = $this->client->organizations()->create(array(
- 'name' => 'My New Organization' . $this->number
- ));
- $this->assertEquals(is_object($organization), true, 'Should return an object');
- $this->assertEquals(is_object($organization->organization), true,
- 'Should return an object called "organization"');
- $this->assertGreaterThan(0, $organization->organization->id, 'Returns a non-numeric id for organization');
- $this->assertEquals($organization->organization->name, 'My New Organization' . $this->number,
- 'Name of test organization does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $organization->organization->id;
- }
-
- public function testAll()
- {
- $organizations = $this->client->organizations()->findAll();
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertGreaterThan(0, $organizations->organizations[0]->id,
- 'Returns a non-numeric id for organizations[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $organization = $this->client->organization($this->id)->find();
- $this->assertEquals(is_object($organization), true, 'Should return an object');
- $this->assertGreaterThan(0, $organization->organization->id, 'Returns a non-numeric id for organization');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $organization = $this->client->organization($this->id)->update(array(
- 'name' => 'My Organization II'
- ));
- $this->assertEquals(is_object($organization), true, 'Should return an object');
- $this->assertEquals(is_object($organization->organization), true,
- 'Should return an object called "organization"');
- $this->assertGreaterThan(0, $organization->organization->id, 'Returns a non-numeric id for organization');
- $this->assertEquals($organization->organization->name, 'My Organization II',
- 'Name of test organization does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testRelated()
- {
- $organizationRelated = $this->client->organization($this->id)->related();
- $this->assertEquals(is_object($organizationRelated), true, 'Should return an object');
- $this->assertEquals(is_object($organizationRelated->organization_related), true,
- 'Should return an object containing an array called "organization_related"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testSearch()
- {
- $organizations = $this->client->organizations()->search(array('external_id' => 'my'));
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAutocomplete()
- {
- $organizations = $this->client->organizations()->autocomplete(array('name' => 'rog'));
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find an organization id to test with. Did setUp fail?');
- $organization = $this->client->organization($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/PushNotificationDevicesTest.php b/tests/Zendesk/API/LiveTests/PushNotificationDevicesTest.php
deleted file mode 100644
index 532be6b3..00000000
--- a/tests/Zendesk/API/LiveTests/PushNotificationDevicesTest.php
+++ /dev/null
@@ -1,20 +0,0 @@
-client->push_notification_devices()->delete($devices);
- $this->assertEquals(true, $deleted, 'Returns true on success');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/RequestsTest.php b/tests/Zendesk/API/LiveTests/RequestsTest.php
deleted file mode 100755
index e2b58952..00000000
--- a/tests/Zendesk/API/LiveTests/RequestsTest.php
+++ /dev/null
@@ -1,103 +0,0 @@
-client->requests()->create(array(
- 'subject' => 'Help!',
- 'comment' => array(
- 'body' => 'My printer is on fire!'
- )
- ));
- $this->assertEquals(is_object($request), true, 'Should return an object');
- $this->assertEquals(is_object($request->request), true, 'Should return an object called "request"');
- $this->assertGreaterThan(0, $request->request->id, 'Returns a non-numeric id for request');
- $this->assertEquals($request->request->subject, 'Help!', 'Subject of test request does not match');
- $this->assertEquals($request->request->description, 'My printer is on fire!',
- 'Description of test request does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $request->request->id;
- }
-
- public function testAll()
- {
- $requests = $this->client->requests()->findAll();
- $this->assertEquals(is_object($requests), true, 'Should return an object');
- $this->assertEquals(is_array($requests->requests), true,
- 'Should return an object containing an array called "requests"');
- $this->assertGreaterThan(0, $requests->requests[0]->id, 'Returns a non-numeric id for requests[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $request = $this->client->request($this->id)->find();
- $this->assertEquals(is_object($request), true, 'Should return an object');
- $this->assertEquals(is_object($request->request), true, 'Should return an object called "request"');
- $this->assertGreaterThan(0, $request->request->id, 'Returns a non-numeric id for request');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $request = $this->client->request($this->id)->update(array(
- 'comment' => array(
- 'body' => 'Thanks!'
- )
- ));
- $new_comment = array_pop($this->client->request($this->id)->comments()->findAll()->comments)->body;
- $this->assertEquals(is_object($request), true, 'Should return an object');
- $this->assertEquals(is_object($request->request), true, 'Should return an object called "request"');
- $this->assertGreaterThan(0, $request->request->id, 'Returns a non-numeric id for request');
- $this->assertEquals($request->request->subject, 'Help!', 'Name of test request does not match');
- $this->assertEquals($new_comment, 'Thanks!', 'Comment of test request does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testComments()
- {
- $comments = $this->client->request($this->id)->comments()->findAll();
- $this->assertEquals(is_object($comments), true, 'Should return an object');
- $this->assertEquals(is_array($comments->comments), true,
- 'Should return an object containing an array called "comments"');
- $this->assertGreaterThan(0, $comments->comments[0]->id, 'Returns a non-numeric id for comments[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFindComment()
- {
- $comment_id = $this->client->request($this->id)->comments()->findAll()->comments[0]->id;
- $comment = $this->client->request($this->id)->comment($comment_id)->find();
- $this->assertEquals(is_object($comment), true, 'Should return an object');
- $this->assertEquals(is_object($comment->comment), true, 'Should return an object called "comment"');
- $this->assertGreaterThan(0, $comment->comment->id, 'Returns a non-numeric id for comment');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->client->ticket($this->id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/SatisfactionRatingsTest.php b/tests/Zendesk/API/LiveTests/SatisfactionRatingsTest.php
deleted file mode 100755
index a93931c7..00000000
--- a/tests/Zendesk/API/LiveTests/SatisfactionRatingsTest.php
+++ /dev/null
@@ -1,82 +0,0 @@
-subdomain, $username);
- $client_end_user->setAuth('password', $password);
-
- $testTicket = array(
- 'subject' => 'Satisfaction Ratings Test',
- 'comment' => array(
- 'body' => 'Dette er for tilfredshed ratings test.'
- ),
- 'priority' => 'normal'
- );
- $request = $client_end_user->requests()->create($testTicket);
- $this->ticket_id = $request->request->id;
-
- // Agent set ticket status to be solved
- $testTicket['status'] = 'solved';
- $this->client->ticket($this->ticket_id)->update($testTicket);
-
- $rating = $client_end_user->ticket($this->ticket_id)->satisfactionRatings()->create(array(
- 'score' => 'good',
- 'comment' => 'Awesome support'
- ));
- $this->assertEquals(is_object($rating), true, 'Should return an object');
- $this->assertEquals(is_object($rating->satisfaction_rating), true,
- 'Should return an object called "satisfaction_rating"');
- $this->assertGreaterThan(0, $rating->satisfaction_rating->id,
- 'Returns a non-numeric id for satisfaction_rating');
- $this->assertEquals($rating->satisfaction_rating->score, 'good', 'Score of test rating does not match');
- $this->assertEquals($client_end_user->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->id = $rating->satisfaction_rating->id;
- }
-
- public function testAll()
- {
- $ratings = $this->client->ticket($this->ticket_id)->satisfactionRatings()->findAll();
- $this->assertEquals(is_object($ratings), true, 'Should return an object');
- $this->assertEquals(is_array($ratings->satisfaction_ratings), true,
- 'Should return an object containing an array called "satisfaction_ratings"');
- $this->assertGreaterThan(0, $ratings->satisfaction_ratings[0]->id,
- 'Returns a non-numeric id for satisfaction_ratings[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $rating = $this->client->ticket($this->ticket_id)->satisfactionRating($this->id)->find();
- $this->assertEquals(is_object($rating), true, 'Should return an object');
- $this->assertGreaterThan(0, $rating->satisfaction_rating->id,
- 'Returns a non-numeric id for satisfaction_rating');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->client->ticket($this->ticket_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/SearchTest.php b/tests/Zendesk/API/LiveTests/SearchTest.php
old mode 100755
new mode 100644
index 8d313b8c..cbaf45db
--- a/tests/Zendesk/API/LiveTests/SearchTest.php
+++ b/tests/Zendesk/API/LiveTests/SearchTest.php
@@ -2,56 +2,12 @@
namespace Zendesk\API\LiveTests;
-use Zendesk\API\Client;
-
-/**
- * Search test class
- */
class SearchTest extends BasicTest
{
-
- protected $ticket_id;
-
- public function testCredentials()
- {
- parent::credentialsTest();
- }
-
- public function testAuthToken()
- {
- parent::authTokenTest();
- }
-
- /*
- * Needs an existed ticket with the specified query keyword to test all Search functions
- */
- public function testSearch()
+ public function testSearchQueryString()
{
- $results = $this->client->search(array('query' => 'hello'));
- $this->assertEquals(is_object($results), true, 'Should return an object');
- $this->assertEquals(is_array($results->results), true,
- 'Should return an object containing an array called "results"');
- $this->assertGreaterThan(0, $results->results[0]->id, 'Returns a non-numeric id for results[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
+ $response = $this->client->search()->find('type:ticket status:open', ['sort_by' => 'updated_at']);
- public function testComplexSearch()
- {
- $results = $this->client->search(array('query' => 'statusassertEquals(is_object($results), true, 'Should return an object');
- $this->assertEquals(is_array($results->results), true,
- 'Should return an object containing an array called "results"');
- $this->assertGreaterThan(0, $results->results[0]->id, 'Returns a non-numeric id for results[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAnonymousSearch()
- {
- $results = $this->client->anonymousSearch(array('query' => 'hello'));
- $this->assertEquals(is_object($results), true, 'Should return an object');
- $this->assertEquals(is_array($results->results), true,
- 'Should return an object containing an array called "results"');
- $this->assertGreaterThan(0, $results->results[0]->id, 'Returns a non-numeric id for results[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
+ $this->assertTrue(isset($response->results), 'Should contain a property called `results`');
}
}
diff --git a/tests/Zendesk/API/LiveTests/SettingsTest.php b/tests/Zendesk/API/LiveTests/SettingsTest.php
deleted file mode 100755
index 9799c6a0..00000000
--- a/tests/Zendesk/API/LiveTests/SettingsTest.php
+++ /dev/null
@@ -1,43 +0,0 @@
-client->settings()->findAll();
- $this->assertEquals(is_object($settings), true, 'Should return an object');
- $this->assertEquals(is_object($settings->settings), true, 'Should return an object called "settings"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $settings = $this->client->settings()->update(array(
- 'lotus' => array(
- 'prefer_lotus' => false
- )
- ));
- $this->assertEquals(is_object($settings), true, 'Should return an object');
- $this->assertEquals(is_object($settings->settings), true, 'Should return an object called "settings"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/SharingAgreementsTest.php b/tests/Zendesk/API/LiveTests/SharingAgreementsTest.php
deleted file mode 100755
index 4cf360a0..00000000
--- a/tests/Zendesk/API/LiveTests/SharingAgreementsTest.php
+++ /dev/null
@@ -1,32 +0,0 @@
-client->sharingAgreements()->findAll();
- $this->assertEquals(is_object($agreements), true, 'Should return an object');
- $this->assertEquals(is_array($agreements->sharing_agreements), true,
- 'Should return an array of objects called "sharing_agreements"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/SuspendedTicketsTest.php b/tests/Zendesk/API/LiveTests/SuspendedTicketsTest.php
deleted file mode 100755
index 956081d3..00000000
--- a/tests/Zendesk/API/LiveTests/SuspendedTicketsTest.php
+++ /dev/null
@@ -1,69 +0,0 @@
-client->suspendedTickets()->findAll();
- $this->assertEquals(is_object($tickets), true, 'Should return an object');
- $this->assertEquals(is_array($tickets->suspended_tickets), true,
- 'Should return an object containing an array called "suspended_tickets"');
- $this->assertGreaterThan(0, $tickets->suspended_tickets[0]->id,
- 'Returns a non-numeric id for suspended_tickets[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $id = $this->client->suspendedTickets()->findAll()->suspended_tickets[0]->id;
- $ticket = $this->client->suspendedTicket($id)->find();
- $this->assertEquals(is_object($ticket), true, 'Should return an object');
- $this->assertEquals(is_object($ticket->suspended_ticket), true,
- 'Should return an object called "suspended_ticket"');
- $this->assertGreaterThan(0, $ticket->suspended_ticket->id, 'Returns a non-numeric id for view');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testRecover()
- {
- $this->markTestSkipped(
- 'The only way to recover a ticket is to suspend it first (but that would result in a suspended user too)'
- );
- $ticket = $this->client->suspendedTicket(256155729)->recover();
- $this->assertEquals(is_object($ticket), true, 'Should return an object');
- $this->assertEquals(is_object($ticket->ticket), true, 'Should return an object called "ticket"');
- $this->assertGreaterThan(0, $ticket->ticket->id, 'Returns a non-numeric id for ticket');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testDelete()
- {
- $this->markTestSkipped(
- 'The only way to delete a suspended ticket is to suspend it first (but that would result in a suspended user too)'
- );
- $ticket = $this->client->suspendedTicket(256155729)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TagsTest.php b/tests/Zendesk/API/LiveTests/TagsTest.php
deleted file mode 100755
index 7dfd62e4..00000000
--- a/tests/Zendesk/API/LiveTests/TagsTest.php
+++ /dev/null
@@ -1,89 +0,0 @@
- 'This is for tag test',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
- );
- $ticket = $this->client->tickets()->create($testTicket);
- $this->ticket_id = $ticket->ticket->id;
- /*
- * Continue with the rest of the test...
- */
- $tags = $this->client->ticket($this->ticket_id)->tags()->create(array('tags' => array('important')));
- $this->assertEquals(is_object($tags), true, 'Should return an object');
- $this->assertEquals(is_array($tags->tags), true, 'Should return an array called "tags"');
- $this->assertEquals(in_array('important', $tags->tags), true, 'Added tag does not exist');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- }
-
- public function testAll()
- {
- $tags = $this->client->tags()->findAll();
- $this->assertEquals(is_object($tags), true, 'Should return an object');
- $this->assertEquals(is_array($tags->tags), true, 'Should return an array called "tags"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $tags = $this->client->ticket($this->ticket_id)->tags()->update(array('tags' => array('customer')));
- $this->assertEquals(is_object($tags), true, 'Should return an object');
- $this->assertEquals(is_array($tags->tags), true, 'Should return an array called "tags"');
- $this->assertEquals(in_array('customer', $tags->tags), true, 'Added tag does not exist');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $tags = $this->client->ticket($this->ticket_id)->tags()->find();
- $this->assertEquals(is_object($tags), true, 'Should return an object');
- $this->assertEquals(is_array($tags->tags), true, 'Should return an array called "tags"');
- $this->assertEquals(in_array('important', $tags->tags), true, 'Added tag does not exist');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $tags = $this->client->ticket($this->ticket_id)->tags()->delete(array('tags' => 'customer'));
- $this->assertEquals(is_object($tags), true, 'Should return an object');
- $this->assertEquals(is_array($tags->tags), true, 'Should return an array called "tags"');
- $this->assertEquals(in_array('important', $tags->tags), true, 'Added tag does not exist');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- /*
- * Clean-up
- */
- $this->client->ticket($this->ticket_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TargetsTest.php b/tests/Zendesk/API/LiveTests/TargetsTest.php
deleted file mode 100755
index 28ced932..00000000
--- a/tests/Zendesk/API/LiveTests/TargetsTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-client->targets()->create(array(
- 'type' => 'email_target',
- 'title' => 'Test Email Target',
- 'email' => 'hello@example.com',
- 'subject' => 'Test Target'
- ));
- $this->assertEquals(is_object($target), true, 'Should return an object');
- $this->assertEquals(is_object($target->target), true, 'Should return an object called "target"');
- $this->assertGreaterThan(0, $target->target->id, 'Returns a non-numeric id for target');
- $this->assertEquals($target->target->title, 'Test Email Target', 'Title of test target does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $target->target->id;
- }
-
- public function testAll()
- {
- $targets = $this->client->targets()->findAll();
- $this->assertEquals(is_object($targets), true, 'Should return an object');
- $this->assertEquals(is_array($targets->targets), true,
- 'Should return an object containing an array called "targets"');
- $this->assertGreaterThan(0, $targets->targets[0]->id, 'Returns a non-numeric id for targets[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $target = $this->client->target($this->id)->find();
- $this->assertEquals(is_object($target), true, 'Should return an object');
- $this->assertGreaterThan(0, $target->target->id, 'Returns a non-numeric id for target');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $target = $this->client->target($this->id)->update(array(
- 'email' => 'roger@example.com'
- ));
- $this->assertEquals(is_object($target), true, 'Should return an object');
- $this->assertEquals(is_object($target->target), true, 'Should return an object called "target"');
- $this->assertGreaterThan(0, $target->target->id, 'Returns a non-numeric id for target');
- $this->assertEquals($target->target->email, 'roger@example.com', 'Email of test target does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a target id to test with. Did setUp fail?');
- $result = $this->client->target($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketAuditsTest.php b/tests/Zendesk/API/LiveTests/TicketAuditsTest.php
deleted file mode 100755
index 893cc409..00000000
--- a/tests/Zendesk/API/LiveTests/TicketAuditsTest.php
+++ /dev/null
@@ -1,123 +0,0 @@
- '12345',
- 'subject' => 'The quick brown fox jumps over the lazy dog',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
- );
-
- $this->ticket_id = $testTicket['id'];
-
- parent::setUp();
- }
-
- public function testAll()
- {
- $this->mockApiCall('GET', '/tickets/12345/audits.json?',
- array(
- 'audits' => array(
- array(
- 'id' => '1'
- )
- )
- )
- );
-
- $audits = $this->client->ticket($this->ticket_id)->audits()->findAll();
- $this->assertEquals(is_object($audits), true, 'Should return an object');
- $this->assertEquals(is_array($audits->audits), true,
- 'Should return an object containing an array called "audits"');
- $this->assertGreaterThan(0, $audits->audits[0]->id, 'Returns a non-numeric id in first audit');
- }
-
- public function testAllSideLoadedMethod()
- {
- $this->mockApiCall('GET', '/tickets/12345/audits.json?include=users%2Cgroups&',
- array(
- 'audits' => array(),
- 'users' => array(),
- 'groups' => array(),
- )
- );
-
- $audits = $this->client->ticket($this->ticket_id)->sideload(array('users', 'groups'))->audits()->findAll();
- $this->assertEquals(is_object($audits), true, 'Should return an object');
- $this->assertEquals(is_array($audits->users), true,
- 'Should return an object containing an array called "users"');
- $this->assertEquals(is_array($audits->groups), true,
- 'Should return an object containing an array called "groups"');
- }
-
- public function testAllSideLoadedParameter()
- {
- $this->mockApiCall('GET', '/tickets/12345/audits.json?include=users%2Cgroups&',
- array(
- 'audits' => array(),
- 'users' => array(),
- 'groups' => array(),
- )
- );
-
- $audits = $this->client->ticket($this->ticket_id)->audits()->findAll(array(
- 'sideload' => array(
- 'users',
- 'groups'
- )
- ));
- $this->assertEquals(is_object($audits), true, 'Should return an object');
- $this->assertEquals(is_array($audits->users), true,
- 'Should return an object containing an array called "users"');
- $this->assertEquals(is_array($audits->groups), true,
- 'Should return an object containing an array called "groups"');
- }
-
- public function testFind()
- {
- $this->mockApiCall('GET', '/tickets/12345/audits.json?',
- array(
- 'audits' => array(
- array(
- 'id' => '1'
- )
- )
- )
- );
- $audit_id = $this->client->ticket($this->ticket_id)->audits()->findAll()->audits[0]->id;
-
- $this->mockApiCall('GET', '/tickets/12345/audits/1.json?',
- array(
- 'audit' => array(
- 'id' => '1'
- )
- )
- );
- $audits = $this->client->ticket($this->ticket_id)->audit($audit_id)->find();
- $this->assertEquals(is_object($audits), true, 'Should return an object');
- $this->assertEquals(is_object($audits->audit), true,
- 'Should return an object containing an array called "audit"');
- $this->assertEquals($audit_id, $audits->audit->id, 'Returns an incorrect id in audit object');
- }
-
- /*
- * Test mark as trusted. Need a voice comment or Facebook comment for this test
- */
- // public function testMarkAsTrusted() {
- // $audits = $this->client->ticket(2)->audit(16317679361)->markAsTrusted();
- // $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- // }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketCommentsTest.php b/tests/Zendesk/API/LiveTests/TicketCommentsTest.php
deleted file mode 100755
index 80e3452a..00000000
--- a/tests/Zendesk/API/LiveTests/TicketCommentsTest.php
+++ /dev/null
@@ -1,66 +0,0 @@
-testTicket = array(
- 'id' => "12345",
- 'subject' => 'Ticket comment test',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
- );
- $this->ticket_id = $this->testTicket['id'];
-
- parent::setUp();
- }
-
- public function testAll()
- {
- $this->mockApiCall('GET', '/tickets/12345/comments.json?',
- array(
- 'comments' => array(
- array(
- 'id' => 1
- )
- )
- )
- );
-
- $comments = $this->client->ticket($this->ticket_id)->comments()->findAll();
- $this->assertEquals(is_object($comments), true, 'Should return an object');
- $this->assertEquals(is_array($comments->comments), true,
- 'Should return an object containing an array called "comments"');
- $this->assertGreaterThan(0, $comments->comments[0]->id, 'Returns a non-numeric id in first audit');
- }
-
- /*
- * Test make private
- */
- public function testMakePrivate()
- {
- $this->mockApiCall('GET', '/tickets/12345/comments.json?',
- array(
- 'comments' => array(
- array(
- 'id' => 1
- )
- )
- )
- );
- $comment_id = $this->client->ticket($this->ticket_id)->comments()->findAll()->comments[0]->id;
-
- $this->mockApiCall('PUT', '/tickets/12345/comments/1/make_private.json', array());
- $this->client->ticket($this->ticket_id)->comments($comment_id)->makePrivate();
- }
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketFieldsTest.php b/tests/Zendesk/API/LiveTests/TicketFieldsTest.php
deleted file mode 100755
index 5389a641..00000000
--- a/tests/Zendesk/API/LiveTests/TicketFieldsTest.php
+++ /dev/null
@@ -1,78 +0,0 @@
-client->ticketFields()->create(array(
- 'type' => 'text',
- 'title' => 'Age'
- ));
- $this->assertEquals(is_object($field), true, 'Should return an object');
- $this->assertEquals(is_object($field->ticket_field), true, 'Should return an object called "ticket_field"');
- $this->assertGreaterThan(0, $field->ticket_field->id, 'Returns a non-numeric id for ticket_field');
- $this->assertEquals($field->ticket_field->type, 'text', 'Type of test ticket field does not match');
- $this->assertEquals($field->ticket_field->title, 'Age', 'Title of test ticket field does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $field->ticket_field->id;
- }
-
- public function testAll()
- {
- $fields = $this->client->ticketFields()->findAll();
- $this->assertEquals(is_object($fields), true, 'Should return an object');
- $this->assertEquals(is_array($fields->ticket_fields), true,
- 'Should return an object containing an array called "ticket_fields"');
- $this->assertGreaterThan(0, $fields->ticket_fields[0]->id, 'Returns a non-numeric id in first ticket field');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $fields = $this->client->ticketField($this->id)->find();
- $this->assertEquals(is_object($fields), true, 'Should return an object');
- $this->assertEquals(is_object($fields->ticket_field), true, 'Should return an object called "ticket_field"');
- $this->assertEquals($this->id, $fields->ticket_field->id, 'Returns an incorrect id in ticket field object');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $field = $this->client->ticketField($this->id)->update(array(
- 'title' => 'Another value'
- ));
- $this->assertEquals(is_object($field), true, 'Should return an object');
- $this->assertEquals(is_object($field->ticket_field), true, 'Should return an object called "ticket_field"');
- $this->assertGreaterThan(0, $field->ticket_field->id, 'Returns a non-numeric id for ticket_field');
- $this->assertEquals($field->ticket_field->type, 'text', 'Type of test ticket field does not match');
- $this->assertEquals($field->ticket_field->title, 'Another value', 'Title of test ticket field does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $field = $this->client->ticketField($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketFormsTest.php b/tests/Zendesk/API/LiveTests/TicketFormsTest.php
deleted file mode 100755
index 36c161c1..00000000
--- a/tests/Zendesk/API/LiveTests/TicketFormsTest.php
+++ /dev/null
@@ -1,125 +0,0 @@
-client->ticketForms()->create(array(
- 'name' => 'Snowboard Problem',
- 'end_user_visible' => true,
- 'display_name' => 'Snowboard Damage',
- 'position' => 2,
- 'active' => true,
- 'default' => false
- ));
- $this->assertEquals(is_object($form), true, 'Should return an object');
- $this->assertEquals(is_object($form->ticket_form), true, 'Should return an object called "ticket_form"');
- $this->assertGreaterThan(0, $form->ticket_form->id, 'Returns a non-numeric id for ticket_form');
- $this->assertEquals($form->ticket_form->name, 'Snowboard Problem', 'Name of test ticket form does not match');
- $this->assertEquals($form->ticket_form->display_name, 'Snowboard Damage',
- 'Display name of test ticket form does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $form->ticket_form->id;
- }
-
- public function tearDown()
- {
- /*
- * First deactivate, then delete
- */
- $response = $this->client->ticketForm($this->id)->deactivate();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200',
- 'Deactivate does not return HTTP code 200');
- $form = $this->client->ticketForm($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Delete does not return HTTP code 200');
- }
-
- public function testAll()
- {
- $forms = $this->client->ticketForms()->findAll();
- $this->assertEquals(is_object($forms), true, 'Should return an object');
- $this->assertEquals(is_array($forms->ticket_forms), true,
- 'Should return an object containing an array called "ticket_forms"');
- $this->assertGreaterThan(0, $forms->ticket_forms[0]->id, 'Returns a non-numeric id in first ticket form');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $forms = $this->client->ticketForm($this->id)->find(); // ticket form #9881 must never be deleted
- $this->assertEquals(is_object($forms), true, 'Should return an object');
- $this->assertEquals(is_object($forms->ticket_form), true, 'Should return an object called "ticket_form"');
- $this->assertEquals($this->id, $forms->ticket_form->id, 'Returns an incorrect id in ticket form object');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $form = $this->client->ticketForm($this->id)->update(array(
- 'name' => 'Snowboard Fixed',
- 'display_name' => 'Snowboard has been fixed'
- ));
- $this->assertEquals(is_object($form), true, 'Should return an object');
- $this->assertEquals(is_object($form->ticket_form), true, 'Should return an object called "ticket_form"');
- $this->assertGreaterThan(0, $form->ticket_form->id, 'Returns a non-numeric id for ticket_form');
- $this->assertEquals($form->ticket_form->name, 'Snowboard Fixed', 'Name of test ticket form does not match');
- $this->assertEquals($form->ticket_form->display_name, 'Snowboard has been fixed',
- 'Display name of test ticket form does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $id = $form->ticket_form->id;
- $stack = array($id);
-
- return $stack;
- }
-
- public function testReorder()
- {
- $allForms = $this->client->ticketForms()->findAll();
- $allIds = array();
- while (list($k, $form) = each($allForms->ticket_forms)) {
- $allIds[] = $form->id;
- }
- array_unshift($allIds, array_pop($allIds));
- $form = $this->client->ticketForms()->reorder($allIds);
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testClone()
- {
- $form = $this->client->ticketForm($this->id)->cloneForm();
- $this->assertEquals(is_object($form), true, 'Should return an object');
- $this->assertEquals(is_object($form->ticket_form), true, 'Should return an object called "ticket_form"');
- $this->assertGreaterThan(0, $form->ticket_form->id, 'Returns a non-numeric id for ticket_form');
- $this->assertEquals($form->ticket_form->name, 'Snowboard Problem', 'Name of test ticket form does not match');
- $this->assertEquals($form->ticket_form->display_name, 'Snowboard Damage',
- 'Display name of test ticket form does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $id = $form->ticket_form->id;
- $response = $this->client->ticketForm($id)->deactivate();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200',
- 'Deactivate does not return HTTP code 200');
- $form = $this->client->ticketForm($id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Delete does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketImportTest.php b/tests/Zendesk/API/LiveTests/TicketImportTest.php
deleted file mode 100755
index f9c7399c..00000000
--- a/tests/Zendesk/API/LiveTests/TicketImportTest.php
+++ /dev/null
@@ -1,54 +0,0 @@
-client->users()->create(array(
- 'name' => 'Roger Wilco',
- 'email' => 'roge@example.org',
- 'role' => 'agent',
- 'verified' => true
- ));
- $author_id = $user->user->id;
-
- $confirm = $this->client->tickets()->import(array(
- 'subject' => 'Help',
- 'description' => 'A description',
- 'comments' => array(
- array('author_id' => $author_id, 'value' => 'This is a author comment') // 454094082 is me
- )
- ));
- $this->assertEquals(is_object($confirm), true, 'Should return an object');
- $this->assertEquals(is_object($confirm->ticket), true, 'Should return an object called "ticket"');
- $this->assertGreaterThan(0, $confirm->ticket->id, 'Returns a non-numeric id for ticket');
- $this->assertEquals($confirm->ticket->subject, 'Help', 'Subject of test ticket does not match');
- $this->assertEquals($confirm->ticket->description, 'A description',
- 'Description of test ticket does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
-
- $this->client->user($author_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketMetricsTest.php b/tests/Zendesk/API/LiveTests/TicketMetricsTest.php
deleted file mode 100755
index 3454d8dc..00000000
--- a/tests/Zendesk/API/LiveTests/TicketMetricsTest.php
+++ /dev/null
@@ -1,63 +0,0 @@
- 'Ticket Metrics test',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal'
- );
- $ticket = $this->client->tickets()->create($testTicket);
- $this->ticket_id = $ticket->ticket->id;
- }
-
- public function tearDown()
- {
- $this->client->ticket($this->ticket_id)->delete();
- }
-
- public function testAll()
- {
- $metrics = $this->client->tickets()->metrics()->findAll();
- $this->assertEquals(is_object($metrics), true, 'Should return an object');
- $this->assertEquals(is_array($metrics->ticket_metrics), true,
- 'Should return an object containing an array called "ticket_metrics"');
- $this->assertGreaterThan(0, $metrics->ticket_metrics[0]->id, 'Returns a non-numeric id for ticket_metrics[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $metrics_id = $this->client->tickets()->metrics()->findAll()->ticket_metrics[0]->id;
- $metric = $this->client->tickets()->metric($metrics_id)->find();
- $this->assertEquals(is_object($metric), true, 'Should return an object');
- $this->assertEquals(is_object($metric->ticket_metric), true, 'Should return an object called "ticket_metric"');
- $this->assertGreaterThan(0, $metric->ticket_metric->id, 'Returns a non-numeric id for ticket_metric');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TicketsTest.php b/tests/Zendesk/API/LiveTests/TicketsTest.php
index d68f2285..51c99fd3 100755
--- a/tests/Zendesk/API/LiveTests/TicketsTest.php
+++ b/tests/Zendesk/API/LiveTests/TicketsTest.php
@@ -2,170 +2,275 @@
namespace Zendesk\API\LiveTests;
-use Zendesk\API\Client;
-use Zendesk\API\ResponseException;
+use Faker\Factory;
/**
* Tickets test class
*/
class TicketsTest extends BasicTest
{
- protected $testTicket;
-
- public function setUp()
+ /**
+ * Test creating of ticket
+ */
+ public function testCreateTicket()
{
- $this->testTicket = array(
- 'subject' => 'The quick brown fox jumps over the lazy dog',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
+ $faker = Factory::create();
+ $ticketParams = [
+ 'subject' => $faker->sentence(5),
+ 'comment' => [
+ 'body' => $faker->sentence(10),
+ ],
'priority' => 'normal',
- 'id' => "12345"
- );
-
- parent::setUp();
+ ];
+ $response = $this->client->tickets()->create($ticketParams);
+ $this->assertTrue(property_exists($response, 'ticket'));
+ $ticket = $response->ticket;
+ $this->assertEquals($ticketParams['subject'], $ticket->subject);
+ $this->assertEquals($ticketParams['comment']['body'], $ticket->description);
+ $this->assertEquals($ticketParams['priority'], $ticket->priority);
+ $this->assertNotNull($ticket->id);
+
+ return $ticket;
}
- public function testAll()
+ /**
+ * Tests if the client can call and build the tickets endpoint with the proper sideloads
+ *
+ * @depends testCreateTicket
+ */
+ public function testFindAll($ticket)
{
- $this->mockApiCall("GET", "/tickets.json?", array("tickets" => [$this->testTicket]));
-
- $tickets = $this->client->tickets()->findAll();
-
- $this->assertEquals(is_array($tickets->tickets), true,
- 'Should return an object containing an array called "tickets"');
- $this->assertEquals($this->testTicket['id'], $tickets->tickets[0]->id, 'Includes the id of the first ticket');
+ $response = $this->client->tickets()->findAll();
+ $this->assertTrue(property_exists($response, 'tickets'));
+ $this->assertGreaterThan(0, count($response->tickets));
}
- public function testAllSideLoadedMethod()
+ /**
+ * Tests if the client can call and build the find ticket endpoint
+ *
+ * @depends testCreateTicket
+ */
+ public function testFindSingle($ticket)
{
- $this->mockApiCall("GET", "/tickets.json?include=users%2Cgroups&",
- array(
- "tickets" => [$this->testTicket],
- "groups" => [],
- "users" => []
- ));
+ $response = $this->client->tickets()->find($ticket->id);
+ foreach (['id', 'subject', 'description', 'priority'] as $property) {
+ $this->assertTrue(property_exists($response->ticket, $property));
+ $this->assertEquals($ticket->$property, $response->ticket->$property);
+ }
+ }
- $tickets = $this->client->tickets()->sideload(array('users', 'groups'))->findAll();
+ /**
+ * Tests if the client can call and build the show many tickets endpoint with the correct IDs
+ *
+ * @depends testCreateTicket
+ */
+ public function testFindMultiple($ticket)
+ {
+ $ticket2 = $this->createTestTicket();
- $this->assertEquals(is_array($tickets->users), true,
- 'Should return an object containing an array called "users"');
- $this->assertEquals(is_array($tickets->groups), true,
- 'Should return an object containing an array called "groups"');
+ $response = $this->client->tickets()->findMany([$ticket->id, $ticket2->id]);
+ $this->assertTrue(property_exists($response, 'tickets'));
+ $this->assertEquals(2, count($response->tickets));
+ $this->assertEquals(2, $response->count);
}
- public function testAllSideLoadedParameter()
+ /**
+ * Tests if the client can update tickets
+ *
+ * @depends testCreateTicket
+ */
+ public function testUpdate($ticket)
{
- $this->mockApiCall("GET", "/tickets.json?include=users%2Cgroups&",
- array(
- "tickets" => [$this->testTicket],
- "groups" => [],
- "users" => []
- ));
-
- $tickets = $this->client->tickets()->findAll(array('sideload' => array('users', 'groups')));
- $this->assertEquals(is_array($tickets->users), true,
- 'Should return an object containing an array called "users"');
- $this->assertEquals(is_array($tickets->groups), true,
- 'Should return an object containing an array called "groups"');
+ $faker = factory::create();
+ $ticketParams = [
+ 'subject' => $faker->sentence(3),
+ 'priority' => 'high',
+ ];
+ $updatedTicket = $this->client->tickets()->update($ticket->id, $ticketParams);
+ $this->assertEquals(
+ $ticketParams['subject'],
+ $updatedTicket->ticket->subject,
+ 'Should have updated ticket subject.'
+ );
+ $this->assertEquals(
+ $ticketParams['priority'],
+ $updatedTicket->ticket->priority,
+ 'Should have updated ticket priority.'
+ );
}
- public function testFindSingle()
+ /**
+ * Tests if the client can call and build the create ticket witch attachment endpoint and initiate the file upload
+ * headers and POST data
+ */
+ public function testCreateWithAttachment()
{
- $this->mockApiCall("GET", '/tickets/' . $this->testTicket['id'] . ".json?",
- array("ticket" => $this->testTicket));
+ $attachmentData = [
+ 'file' => getcwd() . '/tests/assets/UK.png',
+ 'name' => 'UK test non-alpha chars.png'
+ ];
+
+ $faker = factory::create();
+ $ticketParams = [
+ 'subject' => $faker->sentence(5),
+ 'comment' => [
+ 'body' => $faker->sentence(10),
+ ],
+ 'priority' => 'normal',
+ ];
+
+ $response = $this->client->tickets()->attach($attachmentData)->create($ticketParams);
- $tickets = $this->client->ticket($this->testTicket['id'])->find();
+ $this->assertNotNull($ticket = $response->ticket);
+ $this->assertEquals($ticketParams['subject'], $ticket->subject);
+ $this->assertEquals($ticketParams['comment']['body'], $ticket->description);
+ $this->assertEquals($ticketParams['priority'], $ticket->priority);
- $this->assertEquals(is_object($tickets->ticket), true, 'Should return an object called "ticket"');
- $this->assertEquals($tickets->ticket->id, $this->testTicket['id'],
- 'Should return an object with the right ticket ID');
+ $attachmentFound = false;
+ foreach ($response->audit->events as $event) {
+ if (property_exists($event, 'attachments')) {
+ $attachmentFound = true;
+ break;
+ }
+ }
+ $this->assertTrue($attachmentFound, 'Should have attachment in ticket audits.');
+
+ return $ticket;
}
- public function testFindMultiple()
+ /**
+ * Tests if the client can call and build the update many tickets endpoint with the correct IDS and POST fields
+ *
+ * @depends testCreateTicket
+ */
+ public function testUpdateManyWithQueryParams($ticket)
{
- $testTicket2 = array(
- 'subject' => 'The second ticket',
- 'comment' => array(
- 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
- ),
- 'priority' => 'normal',
- 'id' => '4321'
- );
+ $ticket2 = $this->createTestTicket();
- $this->mockApiCall("GET", "/tickets/show_many.json?ids={$this->testTicket['id']},{$testTicket2['id']}&",
- array("tickets" => array($this->testTicket, $testTicket2)));
+ $ticketIds = [$ticket->id, $ticket2->id];
- $tickets = $this->client->tickets(array($this->testTicket['id'], $testTicket2['id']))->find();
+ $updatedTickets = $this->client->tickets()->updateMany(
+ [
+ 'ids' => $ticketIds,
+ 'status' => 'solved'
+ ]
+ );
- $this->assertEquals($tickets->tickets[0]->id, $this->testTicket['id']);
- $this->assertEquals($tickets->tickets[1]->id, $testTicket2['id']);
+ $this->assertTrue(property_exists($updatedTickets, 'job_status'));
+ $this->assertEquals(
+ 'queued',
+ $updatedTickets->job_status->status,
+ 'Should have queued the multiple update task'
+ );
}
- public function testUpdate()
+ /**
+ * Tests if the client can call and build the related tickets endpoint with the correct ID
+ *
+ * @depends testCreateTicket
+ */
+ public function testRelated($ticket)
{
- $this->mockApiCall("PUT", "/tickets/" . $this->testTicket['id'] . ".json", array("tickets" => $this->testTicket));
-
- $this->client->tickets()->update($this->testTicket);
+ $response = $this->client->tickets($ticket->id)->related();
+
+ $properties = [
+ 'url',
+ 'topic_id',
+ 'jira_issue_ids',
+ 'followup_source_ids',
+ 'from_archive',
+ 'incidents',
+ 'twitter'
+ ];
+ foreach ($properties as $property) {
+ $this->assertTrue(
+ property_exists($response->ticket_related, $property),
+ 'Should have property ' . $property
+ );
+ }
}
- public function testDeleteMultiple()
+ /**
+ * Tests if the client can call and build the ticket collaborators endpoint with the correct ID
+ *
+ * @depends testCreateTicket
+ */
+ public function testCollaborators($ticket)
{
- $this->mockApiCall("DELETE", "/tickets/destroy_many.json?ids=123,321&", array("tickets" => []));
-
- $this->client->tickets(array(123, 321))->delete();
+ $collaborators = $this->client->tickets()->collaborators(['id' => $ticket->id]);
+ $this->assertTrue(property_exists($collaborators, 'users'), 'Should find the collaborators on a ticket.');
}
- public function testCreateWithAttachment()
+ /**
+ * Tests if the client can call and build the tickets incidents endpoint with the correct ID
+ */
+ public function testIncidents()
{
- $this->mockApiCall("POST", "/uploads.json?filename=UK+test+non-alpha+chars.png", array("upload" => array("token" => "asdf")),
- array('code' => 201));
-
- $this->mockApiCall("POST", "/tickets.json", array("ticket" => array("id" => "123")), array('code' => 201));
-
- $ticket = $this->client->tickets()->attach(array(
- 'file' => getcwd() . '/tests/assets/UK.png',
- 'name' => 'UK test non-alpha chars.png'
- ))->create($this->testTicket);
+ $problemTicket = $this->createTestTicket(['type' => 'problem']);
+ $incidentTicket = $this->createTestTicket(['type' => 'incident', 'problem_id' => $problemTicket->id]);
+ $incidents = $this->client->tickets($problemTicket->id)->incidents();
+ $this->assertTrue(
+ property_exists($incidents, 'tickets'),
+ 'Should find the incident tickets associated to a problem ticket.'
+ );
- $contentType = $this->http->requests->first()->getHeader("Content-Type")->toArray()[0];
- $this->assertEquals($contentType, "application/binary");
+ $this->assertNotNull($incident = $incidents->tickets[0]);
+ $this->assertEquals($incidentTicket->id, $incident->id);
+ $this->assertEquals($incidentTicket->subject, $incident->subject);
}
- public function testExport()
+ /**
+ * Tests if the client can call and build the delete tickets endpoint
+ * This will throw an exception if it fails
+ *
+ * @depends testCreateWithAttachment
+ */
+ public function testDelete($ticket)
{
- $this->mockApiCall("GET", "/exports/tickets.json?start_time=1332034771&", array("results" => []));
- $tickets = $this->client->tickets()->export(array('start_time' => '1332034771'));
- $this->assertEquals(is_object($tickets), true, 'Should return an object');
- $this->assertEquals(is_array($tickets->results), true,
- 'Should return an object containing an array called "results"');
+ $this->client->tickets($ticket->id)->delete();
+ $this->assertEquals(200, $this->client->getDebug()->lastResponseCode);
+ $this->assertNull($this->client->getDebug()->lastResponseError);
}
- public function testCreateFromTweet()
+ /**
+ * Tests if the client can call and build the delete many tickets endpoint with the correct IDs
+ *
+ * @depends testCreateTicket
+ */
+ public function testDeleteMultiple($ticket)
{
- $this->markTestSkipped(
- 'Skipped for now because it requires a new (unique) twitter id for each test'
- );
- $twitter_id = $this->client->twitter()->handles()->monitored_twitter_handles[0]->id;
- $params = array(
- 'monitored_twitter_handle_id' => $twitter_id,
- 'twitter_status_message_id' => '419191717649473536'
+ $ticket2 = $this->createTestTicket();
+
+ $response = $this->client->tickets()->deleteMany([$ticket->id, $ticket2->id]);
+
+ $this->assertTrue(property_exists($response, 'job_status'));
+ $this->assertEquals(
+ 'queued',
+ $response->job_status->status,
+ 'Should have queued the multiple delete task'
);
- $ticket = $this->client->tickets()->createFromTweet($params);
- $this->assertEquals(is_object($ticket), true, 'Should return an object');
- $this->assertEquals(is_object($ticket->ticket), true, 'Should return an object called "ticket"');
- $this->assertGreaterThan(0, $ticket->ticket->id, 'Returns a non-numeric id for ticket');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Create does not return HTTP code 201');
- $this->client->tickets()->delete(array('id' => $ticket->ticket->id));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Delete does not return HTTP code 200');
}
- public function tearDown()
+ /**
+ * Create a test ticket
+ *
+ * @param array $extraParams
+ *
+ * @return mixed
+ */
+ private function createTestTicket($extraParams = [])
{
- $testTicket = $this->testTicket;
- $this->assertGreaterThan(0, $testTicket['id'], 'Cannot find a ticket id to test with. Did setUp fail?');
- parent::tearDown();
+ $faker = Factory::create();
+ $ticketParams = array_merge([
+ 'subject' => $faker->sentence(5),
+ 'comment' => [
+ 'body' => $faker->sentence(10),
+ ],
+ 'priority' => 'low',
+ ], $extraParams);
+ $response = $this->client->tickets()->create($ticketParams);
+
+ return $response->ticket;
}
-
}
diff --git a/tests/Zendesk/API/LiveTests/TopicCommentsTest.php b/tests/Zendesk/API/LiveTests/TopicCommentsTest.php
deleted file mode 100755
index 7cb92ec7..00000000
--- a/tests/Zendesk/API/LiveTests/TopicCommentsTest.php
+++ /dev/null
@@ -1,104 +0,0 @@
-client->forums()->create(array(
- 'name' => 'My Forum',
- 'forum_type' => 'articles',
- 'access' => 'logged-in users'
- ));
- $this->forum_id = $forum->forum->id;
-
- $topic = $this->client->topics()->create(array(
- 'forum_id' => $this->forum_id,
- 'title' => 'My Topic',
- 'body' => 'This is a test topic'
- ));
- $this->topic_id = $topic->topic->id;
- /*
- * Continue with the rest of the test...
- */
- $topicComment = $this->client->topic($this->topic_id)->comments()->create(array(
- 'body' => 'A man walks into a bar'
- ));
- $this->assertEquals(is_object($topicComment), true, 'Should return an object');
- $this->assertEquals(is_object($topicComment->topic_comment), true,
- 'Should return an object called "topic_comment"');
- $this->assertGreaterThan(0, $topicComment->topic_comment->id, 'Returns a non-numeric id for topic_comment');
- $this->assertEquals($topicComment->topic_comment->body, 'A man walks into a bar',
- 'Body of test comment does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $topicComment->topic_comment->id;
- }
-
- public function testAll()
- {
- $topicComments = $this->client->topic($this->topic_id)->comments()->findAll();
- $this->assertEquals(is_object($topicComments), true, 'Should return an object');
- $this->assertEquals(is_array($topicComments->topic_comments), true,
- 'Should return an object containing an array called "topic_comments"');
- $this->assertGreaterThan(0, $topicComments->topic_comments[0]->id,
- 'Returns a non-numeric id for topic_comments[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $topicComment = $this->client->topic($this->topic_id)->comment($this->id)->find();
- $this->assertEquals(is_object($topicComment), true, 'Should return an object');
- $this->assertGreaterThan(0, $topicComment->topic_comment->id, 'Returns a non-numeric id for topic');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $topicComment = $this->client->topic($this->topic_id)->comment($this->id)->update(array(
- 'body' => 'A man walks into a different bar'
- ));
- $this->assertEquals(is_object($topicComment), true, 'Should return an object');
- $this->assertEquals(is_object($topicComment->topic_comment), true,
- 'Should return an object called "topic_comment"');
- $this->assertGreaterThan(0, $topicComment->topic_comment->id, 'Returns a non-numeric id for topic_comment');
- $this->assertEquals($topicComment->topic_comment->body, 'A man walks into a different bar',
- 'Name of test topic does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function teardown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a topic comment id to test with. Did setUp fail?');
- $view = $this->client->topic($this->topic_id)->comment($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- /*
- * Clean-up
- */
- $topic = $this->client->forum($this->forum_id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TopicSubscriptionsTest.php b/tests/Zendesk/API/LiveTests/TopicSubscriptionsTest.php
deleted file mode 100755
index ea6abdb2..00000000
--- a/tests/Zendesk/API/LiveTests/TopicSubscriptionsTest.php
+++ /dev/null
@@ -1,98 +0,0 @@
-number = strval(time());
- $forum = $this->client->forums()->create(array(
- 'name' => 'My Forum',
- 'forum_type' => 'articles',
- 'access' => 'logged-in users'
- ));
- $this->forum_id = $forum->forum->id;
-
- $user = $this->client->users()->create(array(
- 'name' => 'Roger Wilco' . $this->number,
- 'email' => 'roge' . $this->number . '@example.org',
- 'verified' => true
- ));
- $this->user_id = $user->user->id;
-
- $topic = $this->client->topics()->create(array(
- 'forum_id' => $this->forum_id,
- 'title' => 'My Topic',
- 'body' => 'This is a test topic'
- ));
- $this->topic_id = $topic->topic->id;
- /*
- * Continue with the rest of the test...
- */
- $topicSubscription = $this->client->topic($topic->topic->id)->subscriptions()->create(array(
- 'user_id' => $this->user_id
- ));
- $this->assertEquals(is_object($topicSubscription), true, 'Should return an object');
- $this->assertEquals(is_object($topicSubscription->topic_subscription), true,
- 'Should return an object called "topic_subscription"');
- $this->assertGreaterThan(0, $topicSubscription->topic_subscription->id,
- 'Returns a non-numeric id for topic_subscription');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $topicSubscription->topic_subscription->id;
- }
-
- public function testAll()
- {
- $topicSubscriptions = $this->client->topic($this->topic_id)->subscriptions()->findAll();
- $this->assertEquals(is_object($topicSubscriptions), true, 'Should return an object');
- $this->assertEquals(is_array($topicSubscriptions->topic_subscriptions), true,
- 'Should return an object containing an array called "topic_subscriptions"');
- $this->assertGreaterThan(0, $topicSubscriptions->topic_subscriptions[0]->id,
- 'Returns a non-numeric id for topic_subscriptions[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $topicSubscription = $this->client->topic($this->topic_id)->subscription($this->id)->find();
- $this->assertEquals(is_object($topicSubscription), true, 'Should return an object');
- $this->assertGreaterThan(0, $topicSubscription->topic_subscription->id, 'Returns a non-numeric id for topic');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function teardown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a topic subscription id to test with. Did setUp fail?');
- $topicSubscription = $this->client->topic($this->topic_id)->subscription($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- /*
- * Clean-up
- */
- $topic = $this->client->topic($this->topic_id)->delete();
- $forum = $this->client->forum($this->forum_id)->delete();
- $user = $this->client->user($this->user_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TopicVotesTest.php b/tests/Zendesk/API/LiveTests/TopicVotesTest.php
deleted file mode 100755
index 8a005d1f..00000000
--- a/tests/Zendesk/API/LiveTests/TopicVotesTest.php
+++ /dev/null
@@ -1,87 +0,0 @@
-client->forums()->create(array(
- 'name' => 'My Forum',
- 'forum_type' => 'articles',
- 'access' => 'logged-in users'
- ));
- $this->forum_id = $forum->forum->id;
-
- $topic = $this->client->topics()->create(array(
- 'forum_id' => $this->forum_id,
- 'title' => 'My Topic',
- 'body' => 'This is a test topic'
- ));
- $this->topic_id = $topic->topic->id;
- $this->assertEquals(is_object($topic), true, 'Should return an object');
- $this->assertEquals(is_object($topic->topic), true, 'Should return an object called "topic"');
- $this->assertGreaterThan(0, $this->topic_id, 'Returns a non-numeric id for topic');
- /*
- * Continue with the rest of the test...
- */
- $topicVote = $this->client->topic($this->topic_id)->votes()->create(array(// 'user_id' => $user_id
- ));
- $this->assertEquals(is_object($topicVote), true, 'Should return an object');
- $this->assertEquals(is_object($topicVote->topic_vote), true, 'Should return an object called "topic_vote"');
- $this->assertGreaterThan(0, $topicVote->topic_vote->id, 'Returns a non-numeric id for topic_vote');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $topicVote->topic_vote->id;
- }
-
- public function testAll()
- {
- $topicVotes = $this->client->topic($this->topic_id)->votes()->findAll();
- $this->assertEquals(is_object($topicVotes), true, 'Should return an object');
- $this->assertEquals(is_array($topicVotes->topic_votes), true,
- 'Should return an object containing an array called "topic_votes"');
- $this->assertGreaterThan(0, $topicVotes->topic_votes[0]->id, 'Returns a non-numeric id for topic_votes[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $topicVote = $this->client->topic($this->topic_id)->vote($this->id)->find();
- $this->assertEquals(is_object($topicVote), true, 'Should return an object');
- $this->assertGreaterThan(0, $topicVote->topic_vote->id, 'Returns a non-numeric id for topic_vote');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a topic vote id to test with. Did setUp fail?');
- $topicSubscription = $this->client->topic($this->topic_id)->votes()->delete(); // oddly enough, delete works by topic_id not vote_id
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- /*
- * Clean-up
- */
- $forum = $this->client->forum($this->forum_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TopicsTest.php b/tests/Zendesk/API/LiveTests/TopicsTest.php
deleted file mode 100755
index 462492af..00000000
--- a/tests/Zendesk/API/LiveTests/TopicsTest.php
+++ /dev/null
@@ -1,94 +0,0 @@
-client->forums()->create(array(
- 'name' => 'My Forum',
- 'forum_type' => 'articles',
- 'access' => 'logged-in users'
- ));
- $this->forum_id = $forum->forum->id;
- /*
- * Continue with the rest of the test...
- */
- $topic = $this->client->topics()->create(array(
- 'forum_id' => $this->forum_id,
- 'title' => 'My Topic',
- 'body' => 'This is a test topic'
- ));
- $this->assertEquals(is_object($topic), true, 'Should return an object');
- $this->assertEquals(is_object($topic->topic), true, 'Should return an object called "topic"');
- $this->assertGreaterThan(0, $topic->topic->id, 'Returns a non-numeric id for topic');
- $this->assertEquals($topic->topic->title, 'My Topic', 'Name of test topic does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $topic->topic->id;
- }
-
- public function testAll()
- {
- $topics = $this->client->topics()->findAll();
- $this->assertEquals(is_object($topics), true, 'Should return an object');
- $this->assertEquals(is_array($topics->topics), true,
- 'Should return an object containing an array called "topics"');
- $this->assertGreaterThan(0, $topics->topics[0]->id, 'Returns a non-numeric id for topics[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $topic = $this->client->topic($this->id)->find();
- $this->assertEquals(is_object($topic), true, 'Should return an object');
- $this->assertGreaterThan(0, $topic->topic->id, 'Returns a non-numeric id for topic');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $topic = $this->client->topic($this->id)->update(array(
- 'title' => 'My Topic II'
- ));
- $this->assertEquals(is_object($topic), true, 'Should return an object');
- $this->assertEquals(is_object($topic->topic), true, 'Should return an object called "topic"');
- $this->assertGreaterThan(0, $topic->topic->id, 'Returns a non-numeric id for topic');
- $this->assertEquals($topic->topic->title, 'My Topic II', 'Name of test topic does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a topic id to test with. Did setUp fail?');
- $topic = $this->client->topic($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- /*
- * Clean-up
- */
- $topic = $this->client->forum($this->forum_id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TriggersTest.php b/tests/Zendesk/API/LiveTests/TriggersTest.php
deleted file mode 100755
index d2388583..00000000
--- a/tests/Zendesk/API/LiveTests/TriggersTest.php
+++ /dev/null
@@ -1,112 +0,0 @@
-client->groups()->create(array(
- 'name' => 'New Group'
- ));
- $this->group_id = $group->group->id;
-
- $trigger = $this->client->triggers()->create(array(
- 'title' => 'Roger Wilco',
- 'all' => array(
- array(
- 'field' => 'status',
- 'operator' => 'is',
- 'value' => 'open'
- ),
- array(
- 'field' => 'priority',
- 'operator' => 'less_than',
- 'value' => 'high'
- )
- ),
- 'actions' => array(
- array(
- 'field' => 'group_id',
- 'value' => $this->group_id
- )
- )
- ));
- $this->assertEquals(is_object($trigger), true, 'Should return an object');
- $this->assertEquals(is_object($trigger->trigger), true, 'Should return an object called "trigger"');
- $this->assertGreaterThan(0, $trigger->trigger->id, 'Returns a non-numeric id for trigger');
- $this->assertEquals($trigger->trigger->title, 'Roger Wilco', 'Title of test trigger does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $trigger->trigger->id;
- }
-
- public function testAll()
- {
- $triggers = $this->client->triggers()->findAll();
- $this->assertEquals(is_object($triggers), true, 'Should return an object');
- $this->assertEquals(is_array($triggers->triggers), true,
- 'Should return an object containing an array called "triggers"');
- $this->assertGreaterThan(0, $triggers->triggers[0]->id, 'Returns a non-numeric id for triggers[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testActive()
- {
- $triggers = $this->client->triggers()->active();
- $this->assertEquals(is_object($triggers), true, 'Should return an object');
- $this->assertEquals(is_array($triggers->triggers), true,
- 'Should return an object containing an array called "triggers"');
- $this->assertGreaterThan(0, $triggers->triggers[0]->id, 'Returns a non-numeric id for triggers[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $trigger = $this->client->trigger($this->id)->find();
- $this->assertEquals(is_object($trigger), true, 'Should return an object');
- $this->assertGreaterThan(0, $trigger->trigger->id, 'Returns a non-numeric id for trigger');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $trigger = $this->client->trigger($this->id)->update(array(
- 'title' => 'Roger Wilco II'
- ));
- $this->assertEquals(is_object($trigger), true, 'Should return an object');
- $this->assertEquals(is_object($trigger->trigger), true, 'Should return an object called "trigger"');
- $this->assertGreaterThan(0, $trigger->trigger->id, 'Returns a non-numeric id for trigger');
- $this->assertEquals($trigger->trigger->title, 'Roger Wilco II', 'Title of test trigger does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a trigger id to test with. Did setUp fail?');
- $result = $this->client->trigger($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200',
- 'Delete trigger does not return HTTP code 200');
- // Clean-up
- $result = $this->client->group($this->group_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/TwitterTest.php b/tests/Zendesk/API/LiveTests/TwitterTest.php
deleted file mode 100755
index 79da166c..00000000
--- a/tests/Zendesk/API/LiveTests/TwitterTest.php
+++ /dev/null
@@ -1,39 +0,0 @@
-client->twitter()->handles();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->assertEquals(is_object($handles), true, 'Should return an object');
- $this->assertEquals(is_array($handles->monitored_twitter_handles), true,
- 'Should return an array called "monitored_twitter_handles"');
- }
-
- public function testGetHandleById()
- {
- $id = $this->client->twitter()->handles()->monitored_twitter_handles[0]->id;
- $handles = $this->client->twitter()->handleById(array(
- 'id' => $id
- ));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $this->assertEquals(is_object($handles), true, 'Should return an object');
- $this->assertEquals(is_object($handles->monitored_twitter_handle), true,
- 'Should return an object called "monitored_twitter_handles"');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/UserFieldsTest.php b/tests/Zendesk/API/LiveTests/UserFieldsTest.php
deleted file mode 100755
index 1ad7cc36..00000000
--- a/tests/Zendesk/API/LiveTests/UserFieldsTest.php
+++ /dev/null
@@ -1,90 +0,0 @@
-number = strval(time());
- $userField = $this->client->userFields()->create(array(
- 'type' => 'text',
- 'title' => 'Support description' . $this->number,
- 'description' => 'This field describes the support plan this user has',
- 'position' => 0,
- 'active' => true,
- 'key' => 'support_description' . date("YmdHis")
- ));
- $this->assertEquals(is_object($userField), true, 'Should return an object');
- $this->assertEquals(is_object($userField->user_field), true, 'Should return an object called "user field"');
- $this->assertGreaterThan(0, $userField->user_field->id, 'Returns a non-numeric id for user field');
- $this->assertEquals($userField->user_field->title, 'Support description' . $this->number,
- 'Title of test user field does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $userField->user_field->id;
- }
-
- public function testAll()
- {
- $userFields = $this->client->userFields()->findAll();
- $this->assertEquals(is_object($userFields), true, 'Should return an object');
- $this->assertEquals(is_array($userFields->user_fields), true,
- 'Should return an object containing an array called "user_fields"');
- $this->assertGreaterThan(0, $userFields->user_fields[0]->id, 'Returns a non-numeric id for user_fields[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $userField = $this->client->userField($this->id)->find();
- $this->assertEquals(is_object($userField), true, 'Should return an object');
- $this->assertEquals(is_object($userField->user_field), true, 'Should return an object called "view"');
- $this->assertGreaterThan(0, $userField->user_field->id, 'Returns a non-numeric id for view');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testUpdate()
- {
- $userField = $this->client->userField($this->id)->update(array(
- 'title' => 'Support description II' . $this->number
- ));
- $this->assertEquals(is_object($userField), true, 'Should return an object');
- $this->assertEquals(is_object($userField->user_field), true, 'Should return an object called "user_field"');
- $this->assertGreaterThan(0, $userField->user_field->id, 'Returns a non-numeric id for user_field');
- $this->assertEquals($userField->user_field->title, 'Support description II' . $this->number,
- 'Name of test user field does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testReorder()
- {
- $view = $this->client->userFields()->reorder(array($this->id));
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a user field id to test with. Did setUp fail?');
- $view = $this->client->userField($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/UserIdentitiesTest.php b/tests/Zendesk/API/LiveTests/UserIdentitiesTest.php
deleted file mode 100755
index da5dec12..00000000
--- a/tests/Zendesk/API/LiveTests/UserIdentitiesTest.php
+++ /dev/null
@@ -1,125 +0,0 @@
-number = strval(time());
-
- $user = $this->client->users()->create(array(
- 'name' => 'Roger Wilco' . $this->number,
- 'email' => 'roge' . $this->number . '@example.org',
- 'role' => 'agent',
- 'verified' => true
- ));
- $this->user_id = $user->user->id;
-
- $identity = $this->client->user($this->user_id)->identities()->create(array(
- 'type' => 'email',
- 'value' => 'devaris.brown' . $this->number . '@zendesk.com'
- ));
- $this->assertEquals(is_object($identity), true, 'Should return an object');
- $this->assertEquals(is_object($identity->identity), true, 'Should return an object called "identity"');
- $this->assertGreaterThan(0, $identity->identity->id, 'Returns a non-numeric id for user field');
- $this->assertEquals($identity->identity->value, 'devaris.brown' . $this->number . '@zendesk.com',
- 'Title of test identity does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->id = $identity->identity->id;
- }
-
- public function testCreateAsEndUser()
- {
-
- $user = $this->client->users()->create(array(
- 'name' => 'Roger EndUser' . $this->number,
- 'email' => 'roge2@example.org',
- 'role' => 'end-user',
- 'verified' => true
- ));
-
- $this->username = "roge2@example.org";
- $identity = $this->client->user($user->user->id)->identities()->create(array(
- 'type' => 'email',
- 'value' => 'foo@bar.com'
- ));
- $this->assertEquals(is_object($identity), true, 'Should return an object');
- $this->assertEquals(is_object($identity->identity), true, 'Should return an object called "identity"');
- $this->assertGreaterThan(0, $identity->identity->id, 'Returns a non-numeric id for user field');
- $this->assertEquals($identity->identity->value, 'foo@bar.com', 'Title of test identity does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $this->username = getenv('USERNAME');
-
- $this->client->user($user->user->id)->delete();
- }
-
- public function testAll()
- {
- $identities = $this->client->user($this->user_id)->identities()->findAll();
- $this->assertEquals(is_object($identities), true, 'Should return an object');
- $this->assertEquals(is_array($identities->identities), true,
- 'Should return an object containing an array called "identities"');
- $this->assertGreaterThan(0, $identities->identities[0]->id, 'Returns a non-numeric id for identities[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testFind()
- {
- $identity = $this->client->user($this->user_id)->identity($this->id)->find();
- $this->assertEquals(is_object($identity), true, 'Should return an object');
- $this->assertGreaterThan(0, $identity->identity->id, 'Returns a non-numeric id for identity');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testMarkAsVerified()
- {
- $identity = $this->client->user($this->user_id)->identity($this->id)->markAsVerified();
- $this->assertEquals(is_object($identity), true, 'Should return an object');
- $this->assertGreaterThan(0, $identity->identity->id, 'Returns a non-numeric id for identity');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testMakePrimary()
- {
- $identities = $this->client->user($this->user_id)->identity($this->id)->makePrimary();
- $this->assertEquals(is_object($identities), true, 'Should return an object');
- $this->assertGreaterThan(0, $identities->identities[0]->id, 'Returns a non-numeric id for identities[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $id = $identities->identities[0]->id;
- }
-
- public function testRequestVerification()
- {
- $identity = $this->client->user($this->user_id)->identity($this->id)->requestVerification();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function tearDown()
- {
- $this->assertGreaterThan(0, $this->id, 'Cannot find a identity id to test with. Did setUp fail?');
- $view = $this->client->user($this->user_id)->identity($this->id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- $this->client->user($this->user_id)->delete();
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/UsersTest.php b/tests/Zendesk/API/LiveTests/UsersTest.php
index fe679b2c..de336d8b 100755
--- a/tests/Zendesk/API/LiveTests/UsersTest.php
+++ b/tests/Zendesk/API/LiveTests/UsersTest.php
@@ -1,269 +1,168 @@
'12345',
- 'name' => 'Roger Wilco',
- 'email' => 'roge@example.org',
- 'role' => 'agent',
+ $faker = Factory::create();
+ $userFields = [
+ 'name' => $faker->name,
+ 'email' => $faker->safeEmail,
'verified' => true,
- 'external_id' => '3000'
- );
-
- $this->mockApiCall('POST', '/users.json', array('user' => $testUser), array('code' => 201));
-
- $user = $this->client->users()->create($testUser);
-
- $this->assertEquals(is_object($user), true, 'Should return an object');
- $this->assertEquals(is_object($user->user), true, 'Should return an object called "user"');
- $this->assertGreaterThan(0, $user->user->id, 'Returns a non-numeric id for user');
- }
-
- public function testDelete()
- {
- $this->mockApiCall('DELETE', '/users/12345.json?', array());
- $this->client->users(12345)->delete();
- }
-
- public function testAll()
- {
- $this->mockApiCall('GET', '/users.json?', array('users' => array(array('id' => 12345))));
-
- $users = $this->client->users()->findAll();
- $this->assertEquals(is_object($users), true, 'Should return an object');
- $this->assertEquals(is_array($users->users), true,
- 'Should return an object containing an array called "users"');
-
- $this->assertGreaterThan(0, $users->users[0]->id, 'Returns a non-numeric id for requests[0]');
- }
-
- public function testFind()
- {
- $this->mockApiCall('GET', '/users/12345.json?', array('user' => array('id' => 12345)));
-
- $user = $this->client->user(12345)->find();
- $this->assertEquals(is_object($user), true, 'Should return an object');
- $this->assertEquals(is_object($user->user), true, 'Should return an object called "user"');
- $this->assertGreaterThan(0, $user->user->id, 'Returns a non-numeric id for user');
- }
-
- public function testFindMultiple()
- {
- $findIds = array(12345, 80085);
- $response = array('users' => array(
- array('id' => $findIds[0]),
- array('id' => $findIds[1]),
- )
- );
+ ];
+ $response = $this->client->users()->create($userFields);
+ $this->assertTrue(property_exists($response, 'user'));
+ $this->assertEquals($userFields['name'], $response->user->name);
+ $this->assertEquals(strtolower($userFields['email']), $response->user->email);
+ $this->assertEquals($userFields['verified'], $response->user->verified);
- $this->mockApiCall('GET', '/users/show_many.json?ids=' . implode(',', $findIds) . '&', $response);
-
- $users = $this->client->users($findIds)->find();
- $this->assertEquals(is_object($users), true, 'Should return an object');
- $this->assertEquals(is_array($users->users), true, 'Should return an array called "users"');
- $this->assertEquals($users->users[0]->id, $findIds[0]);
- $this->assertEquals($users->users[1]->id, $findIds[1]);
+ return $response->user;
}
- public function testShowManyUsingIds()
- {
- $findIds = array(12345, 80085);
- $response = array('users' => array(
- array('id' => $findIds[0]),
- array('id' => $findIds[1]),
- )
- );
-
- $this->mockApiCall('GET', '/users/show_many.json?ids=' . implode(',', $findIds) . '&', $response);
-
- $users = $this->client->users()->showMany(array('ids' => $findIds));
- $this->assertEquals(is_object($users), true, 'Should return an object');
- $this->assertEquals(is_array($users->users), true, 'Should return an array called "users"');
- $this->assertEquals(is_object($users->users[0]), true,
- 'Should return an object as first "users" array element');
- }
-
- public function testShowManyUsingExternalIds()
+ /**
+ * Tests listing of users
+ *
+ * @depends testCreate
+ */
+ public function testFindAll($user)
{
- $findIds = array(12345, 80085);
- $response = array('users' => array(
- array('id' => $findIds[0]),
- array('id' => $findIds[1]),
- )
- );
-
- $this->mockApiCall('GET', '/users/show_many.json?external_ids=' . implode(',', $findIds) . '&', $response);
-
- $users = $this->client->users()->showMany(array('external_ids' => $findIds));
-
- $this->assertEquals(is_object($users), true, 'Should return an object');
- $this->assertEquals(is_array($users->users), true, 'Should return an array called "users"');
- $this->assertEquals(is_object($users->users[0]), true,
- 'Should return an object as first "users" array element');
+ $response = $this->client->users()->findAll();
+ $this->assertTrue(property_exists($response, 'users'));
+ $this->assertGreaterThan(0, count($response->users));
}
- public function testRelated()
+ /**
+ * Tests find a single user
+ *
+ * @depends testCreate
+ */
+ public function testFind($user)
{
- $this->mockApiCall('GET', '/users/12345/related.json?', array('user_related' => array('requested_tickets' => 1)));
-
- $related = $this->client->user(12345)->related();
- $this->assertEquals(is_object($related), true, 'Should return an object');
- $this->assertEquals(is_object($related->user_related), true, 'Should return an object called "user_related"');
- $this->assertGreaterThan(0, $related->user_related->requested_tickets,
- 'Returns a non-numeric requested_tickets for user');
+ $response = $this->client->users($user->id)->find();
+ $this->assertTrue(property_exists($response, 'user'));
+ $this->assertEquals($user->id, $response->user->id);
}
- public function testMerge()
+ /**
+ * Tests search for a user
+ *
+ * @depends testCreate
+ */
+ public function testSearch($user)
{
- $this->mockApiCall('PUT', '/users/me/merge.json', array('user' => array('id' => 12345)));
- $this->client->user('me')->merge(array('id' => 12345));
+ $response = $this->client->users()->search(['query' => $user->name]);
+ $this->assertTrue(property_exists($response, 'users'));
+ $this->assertNotNull($foundUser = $response->users[0]);
+ $this->assertEquals($user->email, $foundUser->email);
+ $this->assertEquals($user->name, $foundUser->name);
}
- public function testCreateMany()
+ /**
+ * Tests find a single user
+ *
+ * @depends testCreate
+ */
+ public function testGetRelatedInformation($user)
{
- $this->mockApiCall('POST', '/users/create_many.json', array('job_status' => array('id' => 1)));
- $jobStatus = $this->client->users()->createMany(array(
- array(
- 'name' => 'Roger Wilco 3',
- 'email' => 'roge3@example.org',
- 'verified' => true
- ),
- array(
- 'name' => 'Roger Wilco 4',
- 'email' => 'roge4@example.org',
- 'verified' => true
- )
- )
- );
- $this->assertEquals(is_object($jobStatus), true, 'Should return an object');
- $this->assertEquals(is_object($jobStatus->job_status), true, 'Should return an object called "job_status"');
- $this->assertGreaterThan(0, $jobStatus->job_status->id, 'Returns a non-numeric id for users[0]');
+ $response = $this->client->users($user->id)->related();
+ $this->assertTrue(property_exists($response, 'user_related'));
}
- public function testUpdate()
+ /**
+ * Tests update
+ *
+ * @depends testCreate
+ */
+ public function testUpdate($user)
{
- $this->mockApiCall('PUT', '/users/12345.json', array('user' => array()));
- $user = $this->client->user(12345)->update(array(
- 'name' => 'Joe Soap'
- ));
- }
+ $faker = Factory::create();
+ $userFields = [
+ 'name' => $faker->name,
+ ];
- public function testUpdateMany()
- {
- $updateIds = array(12345, 80085);
- $this->mockApiCall('PUT', '/users/update_many.json?ids=' . implode(',', $updateIds), array('job_status' => array('id' => 1)));
- $jobStatus = $this->client->users()->updateMany(array(
- 'ids' => implode(',', $updateIds),
- 'phone' => '1234567890'
- ));
- $this->assertEquals(is_object($jobStatus), true, 'Should return an array');
- $this->assertEquals(is_object($jobStatus->job_status), true, 'Should return an object called "job_status"');
- $this->assertGreaterThan(0, $jobStatus->job_status->id, 'Returns a non-numeric id for users[0]');
- }
+ $response = $this->client->users()->update($user->id, $userFields);
- public function testUpdateManyIndividualUsers()
- {
- $this->mockApiCall('PUT', '/users/update_many.json', array('job_status' => array('id' => 1)));
- $jobStatus = $this->client->users()->updateManyIndividualUsers(array(
- array(
- 'id' => 12345,
- 'phone' => '1234567890'
- ),
- array(
- 'id' => 80085,
- 'phone' => '0987654321'
- )
- ));
- $this->assertEquals(is_object($jobStatus), true, 'Should return an array');
- $this->assertEquals(is_object($jobStatus->job_status), true, 'Should return an object called "job_status"');
- $this->assertGreaterThan(0, $jobStatus->job_status->id, 'Returns a non-numeric id for users[0]');
+ $this->assertEquals($userFields['name'], $response->user->name);
}
- public function testSuspend()
+ /**
+ * Tests if the client can upload a file to update the profile photo
+ *
+ * @depends testCreate
+ */
+ public function testUpdateProfileImageFromFile($user)
{
- $this->mockApiCall('PUT', '/users/12345.json', array('user' => array('id' => 12345)));
- $user = $this->client->user(12345)->suspend();
- $this->assertEquals(is_object($user), true, 'Should return an object');
- $this->assertEquals(is_object($user->user), true, 'Should return an object called "user"');
- $this->assertGreaterThan(0, $user->user->id, 'Returns a non-numeric id for request');
+ $params = [
+ 'file' => getcwd() . '/tests/assets/UK.png'
+ ];
+ $response = $this->client->users($user->id)->updateProfileImageFromFile($params);
+ $this->assertTrue(property_exists($response->user, 'photo'));
+ $this->assertEquals('UK.png', $response->user->photo->file_name);
}
- public function testSearch()
+ /**
+ * Tests if the client can call the users/me.json endpoint
+ */
+ public function testAuthenticatedUser()
{
- $this->mockApiCall('GET', '/users/search.json?query=Roger&', array('users' => array(array('id' => 12345))));
- $users = $this->client->users()->search(array('query' => 'Roger'));
- $this->assertEquals(is_object($users), true, 'Should return an object');
- $this->assertEquals(is_array($users->users), true,
- 'Should return an object containing an array called "users"');
- $this->assertGreaterThan(0, $users->users[0]->id, 'Returns a non-numeric id for user');
+ $response = $this->client->users()->me();
+ $this->assertTrue(property_exists($response, 'user'));
+ $this->assertEquals($this->username, $response->user->email);
}
- /*
- * Needs an existed User with specified query 'name' keyword to run this function
+ /**
+ * Tests if the setPassword function calls the correct endpoint and passes the correct POST data
+ *
+ * @depends testCreate
*/
- public function testAutocomplete()
+ public function testSetPassword($user)
{
- $this->mockApiCall('POST', '/users/autocomplete.json?name=joh', array('users' => array(array('id' => 12345))));
+ $postFields = ['password' => 'aBc12345'];
- $users = $this->client->users()->autocomplete(array('name' => 'joh'));
+ $this->client->users($user->id)->setPassword($postFields);
+ $this->assertEquals(200, $this->client->getDebug()->lastResponseCode);
+ $this->assertNull($this->client->getDebug()->lastResponseError);
- $this->assertEquals(is_object($users), true, 'Should return an object');
- $this->assertEquals(is_array($users->users), true,
- 'Should return an object containing an array called "users"');
- $this->assertGreaterThan(0, $users->users[0]->id, 'Returns a non-numeric id for user');
+ return $user;
}
- public function testUpdateProfileImage()
+ /**
+ * Tests if the changePassword function calls the correct endpoint and passes the correct PUT data
+ *
+ * @depends testSetPassword
+ */
+ public function testChangePassword($user)
{
- $this->mockApiCall('GET', '/users/12345.json?', array('id' => 12345));
- $this->mockApiCall('PUT', '/users/12345.json', array('user' => array('id' => 12345)));
-
- $user = $this->client->user(12345)->updateProfileImage(array(
- 'file' => getcwd() . '/tests/assets/UK.png'
- ));
-
- $contentType = $this->http->requests->first()->getHeader("Content-Type")->toArray()[0];
- $this->assertEquals($contentType, "application/binary");
-
- $this->assertEquals(is_object($user), true, 'Should return an object');
- $this->assertEquals(is_object($user->user), true, 'Should return an object called "user"');
- $this->assertGreaterThan(0, $user->user->id, 'Returns a non-numeric id for request');
- }
+ $this->client->setAuth('basic', ['username' => $user->email, 'token' => $this->token]);
- public function testAuthenticatedUser()
- {
- $this->mockApiCall('GET', '/users/me.json?', array('user' => array('id' => 12345)));
- $user = $this->client->users()->me();
- $this->assertEquals(is_object($user), true, 'Should return an object');
- $this->assertEquals(is_object($user->user), true, 'Should return an object called "user"');
- $this->assertGreaterThan(0, $user->user->id, 'Returns a non-numeric id for request');
- }
+ $postFields = [
+ 'previous_password' => 'aBc12345',
+ 'password' => '12345'
+ ];
- public function testSetPassword()
- {
- $this->mockApiCall('POST', '/users/12345/password.json', array());
- $user = $this->client->user(12345)->setPassword(array('password' => "aBc12345"));
+ $this->client->users($user->id)->changePassword($postFields);
+ $this->assertEquals(200, $this->client->getDebug()->lastResponseCode);
+ $this->assertNull($this->client->getDebug()->lastResponseError);
}
- public function testChangePassword()
+ /**
+ * Tests delete user
+ *
+ * @depends testCreate
+ */
+ public function testDelete($user)
{
- $this->mockApiCall('PUT', '/users/421450109/password.json', array());
- $user = $this->client->user(421450109)->changePassword(array(
- 'previous_password' => '12346',
- 'password' => '12345'
- ));
+ $this->client->users()->delete($user->id);
+ $this->assertEquals(200, $this->client->getDebug()->lastResponseCode);
+ $this->assertNull($this->client->getDebug()->lastResponseError);
}
-
}
diff --git a/tests/Zendesk/API/LiveTests/ViewsTest.php b/tests/Zendesk/API/LiveTests/ViewsTest.php
deleted file mode 100755
index 83902559..00000000
--- a/tests/Zendesk/API/LiveTests/ViewsTest.php
+++ /dev/null
@@ -1,189 +0,0 @@
-mockApiCall('POST', '/views.json', array('view' => array('id' => $this->id, 'title' => 'Roger Wilco')), array('code' => 201));
-
- $view = $this->client->views()->create(array(
- 'title' => 'Roger Wilco',
- 'active' => true,
- 'all' => array(
- array(
- 'field' => 'status',
- 'operator' => 'is',
- 'value' => 'open'
- ),
- array(
- 'field' => 'priority',
- 'operator' => 'less_than',
- 'value' => 'high'
- )
- ),
- 'any' => array(
- array(
- 'field' => 'current_tags',
- 'operator' => 'includes',
- 'value' => 'hello'
- )
- )
- ));
- $this->assertEquals(is_object($view), true, 'Should return an object');
- $this->assertEquals(is_object($view->view), true, 'Should return an object called "view"');
- $this->assertGreaterThan(0, $view->view->id, 'Returns a non-numeric id for view');
- $this->assertEquals($view->view->title, 'Roger Wilco', 'Title of test view does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- }
-
- public function testAll()
- {
- $this->mockApiCall('GET', '/views.json?', array('views' => array(array('id' => $this->id))));
-
- $views = $this->client->views()->findAll();
- $this->assertEquals(is_object($views), true, 'Should return an object');
- $this->assertEquals(is_array($views->views), true,
- 'Should return an object containing an array called "views"');
- $this->assertGreaterThan(0, $views->views[0]->id, 'Returns a non-numeric id for views[0]');
- }
-
- public function testActive()
- {
- $this->mockApiCall('GET', '/views/active.json?', array('views' => array(array('id' => $this->id))));
-
- $views = $this->client->views()->findAll(array('active' => true));
- $this->assertEquals(is_object($views), true, 'Should return an object');
- $this->assertEquals(is_array($views->views), true,
- 'Should return an object containing an array called "views"');
- $this->assertGreaterThan(0, $views->views[0]->id, 'Returns a non-numeric id for views[0]');
- }
-
- public function testCompact()
- {
- $this->mockApiCall('GET', '/views/compact.json?', array('views' => array(array('id' => $this->id))));
- $views = $this->client->views()->findAll(array('compact' => true));
- $this->assertEquals(is_object($views), true, 'Should return an object');
- $this->assertEquals(is_array($views->views), true,
- 'Should return an object containing an array called "views"');
- $this->assertGreaterThan(0, $views->views[0]->id, 'Returns a non-numeric id for views[0]');
- }
-
- public function testFind()
- {
- $this->mockApiCall('GET', '/views/' . $this->id . '.json?', array('view' => array('id' => $this->id)));
- $view = $this->client->view($this->id)->find();
- $this->assertEquals(is_object($view), true, 'Should return an object');
- $this->assertEquals(is_object($view->view), true, 'Should return an object called "view"');
- $this->assertGreaterThan(0, $view->view->id, 'Returns a non-numeric id for view');
- }
-
- public function testUpdate()
- {
- $this->mockApiCall('PUT', '/views/' . $this->id . '.json', array('view' => array('id' => $this->id, 'title' => 'Roger Wilco II')));
-
- $view = $this->client->view($this->id)->update(array(
- 'title' => 'Roger Wilco II'
- ));
- $this->assertEquals(is_object($view), true, 'Should return an object');
- $this->assertEquals(is_object($view->view), true, 'Should return an object called "view"');
- $this->assertGreaterThan(0, $view->view->id, 'Returns a non-numeric id for view');
- $this->assertEquals($view->view->title, 'Roger Wilco II', 'Name of test view does not match');
- }
-
- public function testExecute()
- {
- $this->mockApiCall('GET', '/views/' . $this->id . '/execute.json?', array('view' => array('id' => $this->id)));
-
- $view = $this->client->view($this->id)->execute();
- $this->assertEquals(is_object($view), true, 'Should return an object');
- $this->assertEquals(is_object($view->view), true, 'Should return an object called "view"');
- $this->assertGreaterThan(0, $view->view->id, 'Returns a non-numeric id for view');
- }
-
- public function testCount()
- {
- $this->mockApiCall('GET', '/views/' . $this->id . '/count.json?', array('view_count' => array('view_id' => $this->id)));
-
- $counts = $this->client->view($this->id)->count();
- $this->assertEquals(is_object($counts), true, 'Should return an object');
- $this->assertEquals(is_object($counts->view_count), true, 'Should return an object called "view_count"');
- $this->assertGreaterThan(0, $counts->view_count->view_id, 'Returns a non-numeric view_id for view_count');
- }
-
- public function testCountMany()
- {
- $this->mockApiCall('GET', '/views/count_many.json?ids=' . implode(',', array($this->id, 80085)) . '&', array('view_counts' => array(array('view_id' => $this->id))));
-
- $counts = $this->client->view(array($this->id, 80085))->count();
- $this->assertEquals(is_object($counts), true, 'Should return an object');
- $this->assertEquals(is_array($counts->view_counts), true,
- 'Should return an array of objects called "view_counts"');
- $this->assertGreaterThan(0, $counts->view_counts[0]->view_id,
- 'Returns a non-numeric view_id for view_counts[0]');
- }
-
- public function testExport()
- {
- $this->mockApiCall('GET', '/views/' . $this->id . '/export.json?', array('export' => array('view_id' => $this->id)));
-
- $export = $this->client->view($this->id)->export();
- $this->assertEquals(is_object($export), true, 'Should return an object');
- $this->assertGreaterThan(0, $export->export->view_id, 'Returns a non-numeric view_id for export');
- }
-
- public function testPreview()
- {
- $this->mockApiCall('POST', '/views/preview.json', array('rows' => array(), 'columns' => array()));
-
- $preview = $this->client->views()->preview(array(
- 'all' => array(
- array(
- 'operator' => 'is',
- 'value' => 'open',
- 'field' => 'status'
- )
- ),
- 'output' => array(
- 'columns' => array('subject')
- )
- ));
- $this->assertEquals(is_object($preview), true, 'Should return an object');
- $this->assertEquals(is_array($preview->rows), true, 'Should return an array of objects called "rows"');
- $this->assertEquals(is_array($preview->columns), true, 'Should return an array of objects called "columns"');
- }
-
- public function testPreviewCount()
- {
- $this->mockApiCall('POST', '/views/preview/count.json', array('view_count' => (new \stdClass())));
-
- $preview = $this->client->views()->previewCount(array(
- 'all' => array(
- array(
- 'operator' => 'is',
- 'value' => 'open',
- 'field' => 'status'
- )
- ),
- 'output' => array(
- 'columns' => array('subject')
- )
- ));
- $this->assertEquals(is_object($preview), true, 'Should return an object');
- $this->assertEquals(is_object($preview->view_count), true, 'Should return an object called "view_count"');
- }
-
- public function testDelete()
- {
- $this->mockApiCall('DELETE', '/views/' . $this->id . '.json?', array());
- $this->client->views($this->id)->delete();
- }
-}
diff --git a/tests/Zendesk/API/LiveTests/VoiceIntegrationTest.php b/tests/Zendesk/API/LiveTests/VoiceIntegrationTest.php
deleted file mode 100755
index 8e03cb54..00000000
--- a/tests/Zendesk/API/LiveTests/VoiceIntegrationTest.php
+++ /dev/null
@@ -1,85 +0,0 @@
-client->voice()->agents()->openUserProfile(array(
- // 'agent_id' => '1',
- // 'user_id' => '1'
- // ));
- // $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- // }
-
- // public function testOpenTicket() {
- // $result = $this->client->voice()->agents()->openTicket(array(
- // 'agent_id' => '1',
- // 'ticket_id' => '1'
- // ));
- // $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- // }
-
- public function testCreateVoiceTicket()
- {
- $ticket = $this->client->voice()->tickets()->create(array(
- 'ticket' => array(
- 'via_id' => 44,
- 'subject' => 'My printer is on fire!',
- 'comment' => array(
- 'body' => 'The smoke is very colorful'
- ),
- 'priority' => 'urgent'
- )
- ));
- $this->assertEquals(is_object($ticket), true, 'Should return an object');
- $this->assertEquals(is_object($ticket->ticket), true, 'Should return an object called "ticket"');
- $this->assertGreaterThan(0, $ticket->ticket->id, 'Returns a non-numeric id for ticket');
- $this->assertEquals($ticket->ticket->subject, 'My printer is on fire!',
- 'Subject of test ticket does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- }
-
- public function testCreateVoicemailTicket()
- {
- $ticket = $this->client->voice()->tickets()->create(array(
- 'ticket' => array(
- 'via_id' => 45,
- 'description' => 'Incoming phone call from: +16617480240',
- 'voice_comment' => array(
- 'from' => '+16617480240',
- 'to' => '+16617480123',
- 'recording_url' => 'http://yourdomain.com/recordings/1.mp3',
- 'started_at' => '2013-07-11 15:31:44 +0000',
- 'call_duration' => 40,
- 'answered_by_id' => 28,
- 'transcription_text' => 'The transcription of the call',
- 'location' => 'Dublin, Ireland'
- )
- )
- ));
- $this->assertEquals(is_object($ticket), true, 'Should return an object');
- $this->assertEquals(is_object($ticket->ticket), true, 'Should return an object called "ticket"');
- $this->assertGreaterThan(0, $ticket->ticket->id, 'Returns a non-numeric id for ticket');
- $this->assertEquals($ticket->ticket->description, 'Incoming phone call from: +16617480240',
- 'Description of test voicemail does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- }
-
-}
diff --git a/tests/Zendesk/API/LiveTests/VoiceTest.php b/tests/Zendesk/API/LiveTests/VoiceTest.php
deleted file mode 100755
index aeefaa6e..00000000
--- a/tests/Zendesk/API/LiveTests/VoiceTest.php
+++ /dev/null
@@ -1,232 +0,0 @@
-client->voice()->phoneNumbers()->search(array(
- 'country' => 'US'
- ));
- $this->assertEquals(is_object($numbers), true, 'Should return an object');
- $this->assertEquals(is_array($numbers->phone_numbers), true,
- 'Should return an object containing an array called "phone_numbers"');
- $this->assertEquals(is_string($numbers->phone_numbers[0]->token), true,
- 'No string token found for first phone number');
- // Now we assign it to our account
- $number = $this->client->voice()->phoneNumbers()->create(array(
- 'token' => $numbers->phone_numbers[0]->token
- ));
- $this->assertEquals(is_object($number), true, 'Should return an object');
- $this->assertEquals(is_object($number->phone_number), true, 'Should return an object called "phone_number"');
- $this->assertGreaterThan(0, $number->phone_number->id, 'Returns a non-numeric id for trigger');
- $this->assertEquals($number->phone_number->number, $numbers->phone_numbers[0]->number,
- 'Value of test phone number does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $id = $number->phone_number->id;
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreatePhoneNumber
- */
- public function testAllPhoneNumber($stack)
- {
- $numbers = $this->client->voice()->phoneNumbers()->findAll();
- $this->assertEquals(is_object($numbers), true, 'Should return an object');
- $this->assertEquals(is_array($numbers->phone_numbers), true,
- 'Should return an object containing an array called "phone_numbers"');
- $this->assertGreaterThan(0, $numbers->phone_numbers[0]->id, 'Returns a non-numeric id for phone_numbers[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- return $stack;
- }
-
- /**
- * @depends testCreatePhoneNumber
- */
- public function testSearchPhoneNumber($stack)
- {
- $numbers = $this->client->voice()->phoneNumbers()->search(array('country' => 'US'));
- $this->assertEquals(is_object($numbers), true, 'Should return an object');
- $this->assertEquals(is_array($numbers->phone_numbers), true,
- 'Should return an object containing an array called "phone_numbers"');
- $this->assertEquals(is_string($numbers->phone_numbers[0]->token), true,
- 'No string token found for first phone number');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- return $stack;
- }
-
- /**
- * @depends testCreatePhoneNumber
- */
- public function testFindPhoneNumber($stack)
- {
- $id = array_pop($stack);
- $number = $this->client->voice()->phoneNumber($id)->find();
- $this->assertGreaterThan(0, $number->phone_number->id, 'Returns a non-numeric id for phone_number');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreatePhoneNumber
- */
- public function testUpdatePhoneNumber(array $stack)
- {
- $id = array_pop($stack);
- $number = $this->client->voice()->phoneNumber($id)->update(array(
- 'nickname' => 'Awesome support line'
- ));
- $this->assertEquals(is_object($number), true, 'Should return an object');
- $this->assertEquals(is_object($number->phone_number), true, 'Should return an object called "phone_number"');
- $this->assertGreaterThan(0, $number->phone_number->id, 'Returns a non-numeric id for phone_number');
- $this->assertEquals($number->phone_number->nickname, 'Awesome support line',
- 'Nickname of test phone number does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreatePhoneNumber
- */
- public function testDeletePhoneNumber(array $stack)
- {
- $id = array_pop($stack);
- $this->assertGreaterThan(0, $id, 'Cannot find a phone number id to test with. Did testCreate fail?');
- $result = $this->client->voice()->phoneNumber($id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200',
- 'Delete trigger does not return HTTP code 200');
- }
-
- public function testCreateGreeting()
- {
- $greeting = $this->client->voice()->greetings()->create(array(
- 'name' => 'Hello',
- 'type' => 'Voicemail',
- 'category_id' => 1
- ));
- $this->assertEquals(is_object($greeting), true, 'Should return an object');
- $this->assertEquals(is_object($greeting->greeting), true, 'Should return an object called "greeting"');
- $this->assertGreaterThan(0, $greeting->greeting->id, 'Returns a non-numeric id for greeting');
- $this->assertEquals($greeting->greeting->name, 'Hello', 'Name of test greeting does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '201', 'Does not return HTTP code 201');
- $id = $greeting->greeting->id;
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreateGreeting
- */
- public function testAllGreeting($stack)
- {
- $greetings = $this->client->voice()->greetings()->findAll();
- $this->assertEquals(is_object($greetings), true, 'Should return an object');
- $this->assertEquals(is_array($greetings->greetings), true,
- 'Should return an object containing an array called "greetings"');
- $this->assertGreaterThan(0, $greetings->greetings[0]->id, 'Returns a non-numeric id for greetings[0]');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
-
- return $stack;
- }
-
- /**
- * @depends testCreateGreeting
- */
- public function testFindGreeting($stack)
- {
- $id = array_pop($stack);
- $greeting = $this->client->voice()->greeting($id)->find();
- $this->assertGreaterThan(0, $greeting->greeting->id, 'Returns a non-numeric id for greeting');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreateGreeting
- */
- public function testUpdateGreeting(array $stack)
- {
- $id = array_pop($stack);
- $greeting = $this->client->voice()->greeting($id)->update(array(
- 'name' => 'Premium support'
- ));
- $this->assertEquals(is_object($greeting), true, 'Should return an object');
- $this->assertEquals(is_object($greeting->greeting), true, 'Should return an object called "greeting"');
- $this->assertGreaterThan(0, $greeting->greeting->id, 'Returns a non-numeric id for greeting');
- $this->assertEquals($greeting->greeting->name, 'Premium support', 'Name of test greeting does not match');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- $stack = array($id);
-
- return $stack;
- }
-
- /**
- * @depends testCreateGreeting
- */
- public function testDeleteGreeting(array $stack)
- {
- $id = array_pop($stack);
- $this->assertGreaterThan(0, $id, 'Cannot find a greeting id to test with. Did testCreate fail?');
- $result = $this->client->voice()->greeting($id)->delete();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200',
- 'Delete trigger does not return HTTP code 200');
- }
-
- public function testCurrentQueueActivity()
- {
- $stats = $this->client->voice()->stats()->findAll(array('current_queue_activity' => true));
- $this->assertEquals(is_object($stats), true, 'Should return an object');
- $this->assertEquals(is_object($stats->current_queue_activity), true,
- 'Should return an object called "current_queue_activity"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testHistoricalQueueActivity()
- {
- $stats = $this->client->voice()->stats()->findAll(array('historical_queue_activity' => true));
- $this->assertEquals(is_object($stats), true, 'Should return an object');
- $this->assertEquals(is_object($stats->historical_queue_activity), true,
- 'Should return an object called "historical_queue_activity"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
- public function testAgentsActivity()
- {
- $stats = $this->client->voice()->stats()->findAll(array('agents_activity' => true));
- $this->assertEquals(is_object($stats), true, 'Should return an object');
- $this->assertEquals(is_array($stats->agents_activity), true,
- 'Should return an object containing an array called "agents_activity"');
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
- }
-
-}
diff --git a/tests/Zendesk/API/MockTests/TOUCH b/tests/Zendesk/API/MockTests/TOUCH
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/Zendesk/API/UnitTests/BasicTest.php b/tests/Zendesk/API/UnitTests/BasicTest.php
index 27551e13..1208ef43 100644
--- a/tests/Zendesk/API/UnitTests/BasicTest.php
+++ b/tests/Zendesk/API/UnitTests/BasicTest.php
@@ -2,43 +2,209 @@
namespace Zendesk\API\UnitTests;
-use Zendesk\API\Client;
+use GuzzleHttp\Client;
+use GuzzleHttp\Handler\MockHandler;
+use GuzzleHttp\HandlerStack;
+use GuzzleHttp\Middleware;
+use GuzzleHttp\Psr7\LazyOpenStream;
+use GuzzleHttp\Psr7\MultipartStream;
+use GuzzleHttp\Psr7\Response;
+use PHPUnit_Framework_TestCase;
+use Zendesk\API\HttpClient;
/**
* Basic test class
*/
abstract class BasicTest extends \PHPUnit_Framework_TestCase
{
-
+ /**
+ * @var HttpClient
+ */
protected $client;
+ /**
+ * @var string
+ */
protected $subdomain;
+ /**
+ * @var string
+ */
protected $password;
+ /**
+ * @var string
+ */
protected $token;
+ /**
+ * @var string
+ */
protected $oAuthToken;
+ /**
+ * @var string
+ */
+ protected $hostname;
+ /**
+ * @var string
+ */
+ protected $scheme;
+ /**
+ * @var string
+ */
+ protected $port;
+ /**
+ * @var array
+ */
+ protected $mockedTransactionsContainer = [];
- public function __construct()
+ /**
+ * {@inheritdoc}
+ */
+ public function __construct($name = null, array $data = [], $dataName = '')
{
- $this->subdomain = getenv('SUBDOMAIN');
- $this->username = getenv('USERNAME');
- $this->password = getenv('PASSWORD');
- $this->token = getenv('TOKEN');
+ $this->subdomain = getenv('SUBDOMAIN');
+ $this->username = getenv('USERNAME');
+ $this->token = getenv('TOKEN');
$this->oAuthToken = getenv('OAUTH_TOKEN');
- $this->client = new Client($this->subdomain, $this->username);
- $this->client->setAuth('token', $this->token);
+ $this->scheme = getenv('SCHEME');
+ $this->hostname = getenv('HOSTNAME');
+ $this->port = getenv('PORT');
+
+ parent::__construct($name, $data, $dataName);
}
- public function authTokenTest()
+ /**
+ * Sets up the fixture, for example, open a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
{
- $tickets = $this->client->tickets()->findAll();
- $this->assertEquals($this->client->getDebug()->lastResponseCode, '200', 'Does not return HTTP code 200');
+ $this->client = new HttpClient($this->subdomain, $this->username, $this->scheme, $this->hostname, $this->port);
+ $this->client->setAuth('oauth', ['token' => $this->oAuthToken]);
}
- public function credentialsTest()
+ /**
+ * This will mock the next responses sent via guzzle
+ *
+ * @param array $responses
+ * An array of GuzzleHttp\Psr7\Response objects
+ */
+ protected function mockApiResponses($responses = [])
{
- $this->assertEquals($this->subdomain != '', true,
- 'Expecting $this->subdomain parameter; does phpunit.xml exist?');
- $this->assertEquals($this->token != '', true, 'Expecting $this->token parameter; does phpunit.xml exist?');
- $this->assertEquals($this->username != '', true,
- 'Expecting $this->username parameter; does phpunit.xml exist?');
+ if (empty($responses)) {
+ return;
+ } elseif (! is_array($responses)) {
+ $responses = [$responses];
+ }
+
+ $history = Middleware::history($this->mockedTransactionsContainer);
+ $mock = new MockHandler($responses);
+ $handler = HandlerStack::create($mock);
+ $handler->push($history);
+
+ $this->client->guzzle = new Client(['handler' => $handler]);
+
+ }
+
+ /**
+ * This checks the last request sent
+ *
+ * @param $options
+ */
+ public function assertLastRequestIs($options)
+ {
+ $this->assertRequestIs($options, count($this->mockedTransactionsContainer) - 1);
+ }
+
+ /**
+ * This checks the response with the given index
+ *
+ * @param $options
+ * @param int $index
+ */
+ public function assertRequestIs($options, $index = 0)
+ {
+ $this->assertArrayHasKey($index, $this->mockedTransactionsContainer, 'Should have made an API call.');
+ $transaction = $this->mockedTransactionsContainer[$index];
+ $request = $transaction['request'];
+ $response = $transaction['response'];
+
+ $options = array_merge(
+ [
+ 'statusCode' => 200,
+ 'headers' => [
+ 'Accept' => 'application/json',
+ 'Content-Type' => 'application/json'
+ ]
+ ],
+ $options
+ );
+
+ $this->assertEquals($options['statusCode'], $response->getStatusCode());
+
+ if (isset($options['multipart'])) {
+ $body = $request->getBody();
+ $this->assertInstanceOf(MultipartStream::class, $body);
+ $this->assertGreaterThan(0, $body->getSize());
+ $this->assertNotEmpty($header = $request->getHeaderLine('Content-Type'));
+ $this->assertContains('multipart/form-data', $header);
+ unset($options['headers']['Content-Type']);
+ }
+
+ if (isset($options['file'])) {
+ $body = $request->getBody();
+ $this->assertInstanceOf(LazyOpenStream::class, $body);
+ $this->assertGreaterThan(0, $body->getSize());
+ $this->assertEquals($options['file'], $body->getMetadata('uri'));
+ $this->assertNotEmpty($header = $request->getHeaderLine('Content-Type'));
+ $this->assertEquals('application/binary', $header);
+ unset($options['headers']['Content-Type']);
+ }
+
+ if (isset($options['headers']) && is_array($options['headers'])) {
+ foreach ($options['headers'] as $headerKey => $value) {
+ $this->assertNotEmpty($header = $request->getHeaderLine($headerKey));
+ $this->assertEquals($value, $header);
+ }
+ }
+
+ if (isset($options['method'])) {
+ $this->assertEquals($options['method'], $request->getMethod());
+ }
+
+ if (isset($options['endpoint'])) {
+ // Truncate the `/api/v2` part of the target
+ $endpoint = str_replace('/api/v2/', '', $request->getUri()->getPath());
+ $this->assertEquals($options['endpoint'], $endpoint);
+ }
+
+ if (isset($options['queryParams'])) {
+ $expectedQueryParams = urldecode(http_build_query($options['queryParams']));
+ $this->assertEquals($expectedQueryParams, $request->getUri()->getQuery());
+ }
+
+ if (isset($options['postFields'])) {
+ $this->assertEquals(json_encode($options['postFields']), $request->getBody()->getContents());
+ }
+ }
+
+ /**
+ * Test for the endpoint using the given method and endpoint
+ *
+ * @param $userFunction
+ * @param $endpoint - An array containing [request method, endpoint path]
+ * @param string $method
+ */
+ protected function assertEndpointCalled($userFunction, $endpoint, $method = 'GET', $additionalAsserts = [])
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ call_user_func($userFunction);
+
+ $this->assertLastRequestIs(
+ array_merge($additionalAsserts, [
+ 'method' => $method,
+ 'endpoint' => $endpoint,
+ ])
+ );
}
}
diff --git a/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php b/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php
new file mode 100644
index 00000000..a1320e48
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AppInstallationLocationsTest.php
@@ -0,0 +1,37 @@
+assertTrue(method_exists($this->client->apps()->installationLocations(), 'find'));
+ $this->assertTrue(method_exists($this->client->apps()->installationLocations(), 'findAll'));
+ }
+
+ /**
+ * Test the reorder method
+ *
+ */
+ public function testReorder()
+ {
+ $postFields = [
+ 'installations' => [82, 56],
+ 'location_name' => 'nav_bar'
+ ];
+
+ $this->assertEndpointCalled(function () use ($postFields) {
+ $this->client->apps()->installationLocations()->reorder($postFields);
+ }, 'apps/location_installations/reorder.json', 'POST', ['postFields' => $postFields]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php b/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php
new file mode 100644
index 00000000..a710f3d0
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AppInstallationsTest.php
@@ -0,0 +1,59 @@
+assertEndpointCalled(function () use ($resourceId) {
+ $this->client->appInstallations()->find($resourceId);
+ }, "apps/installations/{$resourceId}.json");
+
+ $postParams = [
+ 'settings' => [
+ 'name' => 'Helpful App - Updated',
+ 'api_token' => '659323ngt4ut9an'
+ ]
+ ];
+
+ $this->assertEndpointCalled(function () use ($postParams) {
+ $this->client->appInstallations()->create($postParams);
+ }, 'apps/installations.json', 'POST', ['postFields' => ['installation' => $postParams]]);
+
+ }
+
+ /**
+ * Tests if the client calls the correct endpoint for App Installation job statuses
+ */
+ public function testJobStatuses()
+ {
+ $resourceId = 1;
+ $this->assertEndpointCalled(function () use ($resourceId) {
+ $this->client->appInstallations()->jobStatuses($resourceId);
+ }, "apps/installations/job_statuses/{$resourceId}.json");
+ }
+
+ /**
+ * Tests if the client calls the correct endpoint and adds query parameters for App Installation requirements
+ */
+ public function testRequirements()
+ {
+ $queryParams = ['per_page' => 50];
+ $resourceId = 2727;
+
+ $this->assertEndpointCalled(function () use ($resourceId, $queryParams) {
+ $this->client->appInstallations()->requirements($resourceId, $queryParams);
+ }, "apps/installations/{$resourceId}/requirements.json", 'GET', ['queryParams' => $queryParams]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AppLocationsTest.php b/tests/Zendesk/API/UnitTests/Core/AppLocationsTest.php
new file mode 100644
index 00000000..81bd2b18
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AppLocationsTest.php
@@ -0,0 +1,31 @@
+assertTrue(method_exists($this->client->apps()->locations(), 'find'));
+ $this->assertTrue(method_exists($this->client->apps()->locations(), 'findAll'));
+ }
+
+ /**
+ * Test if the methods can be called via apps()
+ */
+ public function testMethodsCallable()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->apps()->locations()->findAll(['per_page' => 20]);
+ }, 'apps/locations.json', 'GET', ['queryParams' => ['per_page' => 20]]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AppsTest.php b/tests/Zendesk/API/UnitTests/Core/AppsTest.php
new file mode 100644
index 00000000..c9192fbd
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AppsTest.php
@@ -0,0 +1,187 @@
+mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $postFields = ['file' => getcwd() . '/tests/assets/app.zip'];
+
+ $this->client->apps()->upload($postFields);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'apps/uploads.json',
+ 'multipart' => true,
+ ]
+ );
+ }
+
+ /**
+ * Test creating of app from upload
+ */
+ public function testCreateApp()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $uploadId = 'diid22';
+ $postFields = [
+ 'name' => 'TESTING APP' . rand(),
+ 'short_description' => 'testing',
+ 'upload_id' => (string) $uploadId
+ ];
+
+ $this->client->apps()->create($postFields);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'apps.json',
+ 'postFields' => $postFields,
+ ]
+ );
+ }
+
+ /**
+ * Test getting of the upload status.
+ */
+ public function testJobStatusApp()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $resourceId = 'asdfg';
+
+ $this->client->apps()->jobStatus(['id' => $resourceId]);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'GET',
+ 'endpoint' => "apps/job_statuses/{$resourceId}.json",
+ ]
+ );
+ }
+
+ /**
+ * Test updating of app
+ */
+ public function testUpdateApp()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $resourceId = 82827;
+
+ $putData = [
+ 'name' => 'updated Name',
+ 'short_description' => 'update short desription',
+ 'upload_id' => '263858'
+ ];
+
+ $this->client->apps()->update($resourceId, $putData);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'PUT',
+ 'endpoint' => "apps/{$resourceId}.json",
+ 'postData' => $putData,
+ ]
+ );
+ }
+
+ /**
+ * Test finding all of the user's owned apps.
+ */
+ public function testFindAllOwned()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $this->client->apps()->findAllOwned();
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'GET',
+ 'endpoint' => 'apps/owned.json',
+ ]
+ );
+ }
+
+ /**
+ * Test endpoint to notify app users
+ */
+ public function testNotify()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $postFields = [
+ 'app_id' => 375,
+ 'event' => 'updateUsersPhoneNumber',
+ 'body' => '61455534512',
+ 'agent_id' => 534,
+ ];
+
+ $this->client->apps()->notify($postFields);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'apps/notify.json',
+ 'postFields' => $postFields,
+ ]
+ );
+ }
+
+ /**
+ * Test install an app
+ */
+ public function testInstall()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $postFields = [
+ 'app_id' => '225',
+ 'settings' =>
+ [
+ 'name' => 'Helpful App',
+ 'api_token' => '53xjt93n6tn4321p',
+ 'use_ssl' => true,
+ ],
+ ];
+
+ $this->client->apps()->install($postFields);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'apps/installations.json',
+ 'postFields' => $postFields,
+ ]
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php b/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php
new file mode 100755
index 00000000..a9dc5311
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AttachmentsTest.php
@@ -0,0 +1,71 @@
+ getcwd() . '/tests/assets/UK.png',
+ 'type' => 'image/png',
+ 'name' => 'UK test non-alpha chars.png'
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($attachmentData) {
+ $this->client->attachments()->upload($attachmentData);
+ },
+ 'uploads.json',
+ 'POST',
+ [
+ 'queryParams' => ['filename' => rawurlencode($attachmentData['name'])],
+ 'file' => $attachmentData['file'],
+ ]
+ );
+ }
+
+ /**
+ * Test upload of file
+ */
+ public function testUploadAttachmentWithNoName()
+ {
+ $attachmentData = [
+ 'file' => getcwd() . '/tests/assets/UK.png',
+ 'type' => 'image/png',
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($attachmentData) {
+ $this->client->attachments()->upload($attachmentData);
+ },
+ 'uploads.json',
+ 'POST',
+ [
+ 'queryParams' => ['filename' => 'UK.png'], // Taken from file path
+ 'file' => $attachmentData['file'],
+ ]
+ );
+ }
+
+ /**
+ * Test delete uploaded file
+ */
+ public function testDeleteAttachment()
+ {
+ $token = 'validToken';
+
+ $this->assertEndpointCalled(function () use ($token) {
+ $this->client->attachments()->deleteUpload($token);
+ }, "uploads/{$token}.json", 'DELETE');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AuditLogsTest.php b/tests/Zendesk/API/UnitTests/Core/AuditLogsTest.php
new file mode 100755
index 00000000..ecebb297
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AuditLogsTest.php
@@ -0,0 +1,43 @@
+ 'rule',
+ 'filter["valid"]' => 'somerule',
+ 'invalid' => 'invalidrule',
+ ];
+
+ // We expect invalid parameters are removed.
+ // We also expect url encoded keys and values
+ $expectedQueryParams = [];
+ foreach ($queryParams as $key => $value) {
+ if ($key == 'invalid') {
+ continue;
+ }
+
+ $expectedQueryParams = array_merge($expectedQueryParams, [urlencode($key) => urlencode($value)]);
+ }
+
+ $this->assertEndpointCalled(
+ function () use ($queryParams) {
+ $this->client->auditLogs()->findAll($queryParams);
+ },
+ 'audit_logs.json',
+ 'GET',
+ ['queryParams' => $expectedQueryParams]
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AuthTest.php b/tests/Zendesk/API/UnitTests/Core/AuthTest.php
new file mode 100755
index 00000000..cd7a9910
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AuthTest.php
@@ -0,0 +1,57 @@
+client->setAuth('basic', ['username' => $this->username, 'token' => $this->token]);
+
+ $currentRequest = new Request('GET', 'http://www.endpoint.com/test.json');
+ $currentRequestOptions = ['existing' => 'option'];
+
+ list ($request, $requestOptions) = $this->client->getAuth()->prepareRequest(
+ $currentRequest,
+ $currentRequestOptions
+ );
+
+ $this->assertInstanceOf(Request::class, $request, 'Should have returned a request');
+
+ $this->assertArrayHasKey('existing', $requestOptions);
+ $this->assertArrayHasKey('auth', $requestOptions);
+ $this->assertEquals($this->username . '/token', $requestOptions['auth'][0]);
+ $this->assertEquals($this->token, $requestOptions['auth'][1]);
+ $this->assertEquals(Auth::BASIC, $requestOptions['auth'][2]);
+ }
+
+ /**
+ * Test the preparing of a request for oauth authentication.
+ */
+ public function testPrepareOAuth()
+ {
+ $this->client->setAuth('oauth', ['token' => $this->oAuthToken]);
+
+ $currentRequest = new Request('GET', 'http://www.endpoint.com/test.json');
+ $currentRequestOptions = ['existing' => 'option'];
+
+ list ($request, $requestOptions) = $this->client->getAuth()->prepareRequest(
+ $currentRequest,
+ $currentRequestOptions
+ );
+
+ $this->assertEquals($currentRequestOptions, $requestOptions);
+ $this->assertNotEmpty($authHeader = $request->getHeader('Authorization'));
+ $this->assertEquals('Bearer ' . $this->oAuthToken, $authHeader[0]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AutocompleteTest.php b/tests/Zendesk/API/UnitTests/Core/AutocompleteTest.php
new file mode 100755
index 00000000..27bca202
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AutocompleteTest.php
@@ -0,0 +1,36 @@
+mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $queryParams = [
+ 'name' => 'att'
+ ];
+
+ $this->client->autocomplete()->tags($queryParams);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'GET',
+ 'endpoint' => 'autocomplete/tags.json',
+ 'queryParams' => $queryParams,
+ ]
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php b/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php
new file mode 100755
index 00000000..5ed9d516
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/AutomationsTest.php
@@ -0,0 +1,22 @@
+assertEndpointCalled(function () {
+ $this->client->automations()->findActive();
+ }, 'automations/active.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/BookmarksTest.php b/tests/Zendesk/API/UnitTests/Core/BookmarksTest.php
new file mode 100644
index 00000000..26c5eb20
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/BookmarksTest.php
@@ -0,0 +1,22 @@
+assertTrue(method_exists($this->client->bookmarks(), 'findAll'));
+ $this->assertTrue(method_exists($this->client->bookmarks(), 'create'));
+ $this->assertTrue(method_exists($this->client->bookmarks(), 'delete'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/BrandsTest.php b/tests/Zendesk/API/UnitTests/Core/BrandsTest.php
new file mode 100755
index 00000000..a916f456
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/BrandsTest.php
@@ -0,0 +1,54 @@
+assertTrue(method_exists($this->client->brands(), 'create'));
+ $this->assertTrue(method_exists($this->client->brands(), 'delete'));
+ $this->assertTrue(method_exists($this->client->brands(), 'find'));
+ $this->assertTrue(method_exists($this->client->brands(), 'findAll'));
+ $this->assertTrue(method_exists($this->client->brands(), 'update'));
+ }
+
+ /**
+ * Test endpoint to check host mapping is available
+ */
+ public function testCheckHostMapping()
+ {
+ $queryParams = [
+ 'host_mapping' => 'test.com',
+ 'subdomain' => 'test',
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->brands()->checkHostMapping($queryParams);
+ }, 'brands/check_host_mapping.json', 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Test updateImage method
+ */
+ public function testUpdateProfileImageFromFile()
+ {
+ $id = 915987427;
+
+ $params = [
+ 'file' => getcwd() . '/tests/assets/UK.png'
+ ];
+
+ $this->assertEndpointCalled(function () use ($id, $params) {
+ $this->client->brands($id)->updateImage($params);
+ }, "brands/{$id}.json", 'PUT', ['multipart' => true]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/CustomRolesTest.php b/tests/Zendesk/API/UnitTests/Core/CustomRolesTest.php
new file mode 100644
index 00000000..f6c14ef8
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/CustomRolesTest.php
@@ -0,0 +1,13 @@
+assertTrue(method_exists($this->client->customRoles(), 'findAll'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/DummyResource.php b/tests/Zendesk/API/UnitTests/Core/DummyResource.php
new file mode 100644
index 00000000..fe62c089
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/DummyResource.php
@@ -0,0 +1,53 @@
+assertEndpointCalled(function () use ($itemId) {
+ $this->client->dynamicContent()->items($itemId)->variants()->findAll();
+ }, "dynamic_content/items/{$itemId}/variants.json");
+
+ }
+
+ /**
+ * Test variant id is added to route.
+ *
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testItemIdVariantIdIsAddedToRoute()
+ {
+ $itemId = 12345;
+ $variantId = 3332;
+ $this->assertEndpointCalled(function () use ($itemId, $variantId) {
+ $this->client->dynamicContent()->items($itemId)->variants()->find($variantId);
+ }, "dynamic_content/items/{$itemId}/variants/{$variantId}.json");
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/GroupMembershipsTest.php b/tests/Zendesk/API/UnitTests/Core/GroupMembershipsTest.php
new file mode 100644
index 00000000..c6907407
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/GroupMembershipsTest.php
@@ -0,0 +1,222 @@
+mockAPIResponses([
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ ]);
+
+ // GET /api/v2/groups/{group_id}/memberships.json
+ $this->client->groups(123)->memberships()->findAll();
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'groups/123/memberships.json',
+ ]);
+
+ // GET /api/v2/group_memberships.json
+ $this->client->groupMemberships()->findAll();
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'group_memberships.json',
+ ]);
+
+ // GET /api/v2/users/{user_id}/group_memberships.json
+ $this->client->users(123)->groupMemberships()->findAll();
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'users/123/group_memberships.json',
+ ]);
+ }
+
+ /**
+ * Test the assignable endpoint, since this resource involves chaining
+ */
+ public function testAssignableEndpoint()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ ]);
+
+ $queryParams = ['per_page' => 20];
+
+ // GET /api/v2/groups/{group_id}/memberships/assignable.json
+ $this->client->groups(123)->memberships()->assignable($queryParams);
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'groups/123/memberships/assignable.json',
+ 'queryParams' => $queryParams
+ ]);
+
+ // GET /api/v2/group_memberships/assignable.json
+ $this->client->groupMemberships()->assignable($queryParams);
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'group_memberships/assignable.json',
+ 'queryParams' => $queryParams
+ ]);
+ }
+
+ /**
+ * Test the show endpoint, since this resource involves chaining
+ */
+ public function testFindEndpoint()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ ]);
+
+ // GET /api/v2/users/{user_id}/group_memberships/{id}.json
+ $this->client->users(123)->groupMemberships()->find(456);
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'users/123/group_memberships/456.json',
+ ]);
+
+ // GET /api/v2/users/{user_id}/group_memberships/{id}.json
+ $this->client->users(123)->groupMemberships(456)->find();
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'users/123/group_memberships/456.json',
+ ]);
+
+ // GET /api/v2/group_memberships/{id}.json
+ $this->client->groupMemberships()->find(123);
+
+ $this->assertLastRequestIs([
+ 'method' => 'GET',
+ 'endpoint' => 'group_memberships/123.json',
+ ]);
+ }
+
+ /**
+ * Test the create endpoint, since this resource involves chaining
+ */
+ public function testCreateEndpoint()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ ]);
+
+ $postData = ['user_id' => 72, 'group_id' => 88];
+
+ // POST /api/v2/users/{user_id}/group_memberships.json
+ $this->client->users(123)->groupMemberships()->create($postData);
+
+ $this->assertLastRequestIs([
+ 'method' => 'POST',
+ 'endpoint' => 'users/123/group_memberships.json',
+ 'postFields' => ['group_membership' => $postData]
+ ]);
+
+ // POST /api/v2/group_memberships/{id}.json
+ $this->client->groupMemberships()->create($postData);
+
+ $this->assertLastRequestIs([
+ 'method' => 'POST',
+ 'endpoint' => 'group_memberships.json',
+ 'postFields' => ['group_membership' => $postData]
+ ]);
+ }
+
+
+ /**
+ * Test the delete endpoint, since this resource involves chaining
+ */
+ public function testDeleteEndpoint()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ new Response(200, [], ''),
+ ]);
+
+ // DELETE api/v2/users/{user_id}/group_memberships/{id}.json
+ $this->client->users(123)->groupMemberships()->delete(456);
+
+ $this->assertLastRequestIs([
+ 'method' => 'DELETE',
+ 'endpoint' => 'users/123/group_memberships/456.json',
+ ]);
+
+ // DELETE /api/v2/group_memberships/{id}.json
+ $this->client->groupMemberships()->delete(123);
+
+ $this->assertLastRequestIs([
+ 'method' => 'DELETE',
+ 'endpoint' => 'group_memberships/123.json'
+ ]);
+
+ // DELETE /api/v2/group_memberships/{id}.json
+ $this->client->groupMemberships()->deleteMany([1, 2, 3]);
+
+ $this->assertLastRequestIs([
+ 'method' => 'DELETE',
+ 'endpoint' => 'group_memberships/destroy_many.json',
+ 'queryParams' => ['ids' => '1,2,3']
+ ]);
+ }
+
+ public function testMakeDefault()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $params = [
+ 'id' => 1122,
+ 'userId' => 2341,
+ ];
+
+ $this->client->groupMemberships()->makeDefault($params);
+
+ $this->assertLastRequestIs([
+ 'method' => 'PUT',
+ 'endpoint' => "users/{$params['userId']}/group_memberships/{$params['id']}/make_default.json",
+ ]);
+ }
+
+ public function testMakeDefaultChained()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $params = [
+ 'id' => 1122,
+ 'userId' => 2341,
+ ];
+
+ $this->client->users($params['userId'])->groupMemberships($params['id'])->makeDefault();
+
+ $this->assertLastRequestIs([
+ 'method' => 'PUT',
+ 'endpoint' => "users/{$params['userId']}/group_memberships/{$params['id']}/make_default.json",
+ ]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/GroupsTest.php b/tests/Zendesk/API/UnitTests/Core/GroupsTest.php
new file mode 100644
index 00000000..824354e0
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/GroupsTest.php
@@ -0,0 +1,41 @@
+assertEndpointCalled(function () {
+ $this->client->groups()->assignable();
+ }, 'groups/assignable.json');
+ }
+
+ /**
+ * Test finding of user groups
+ */
+ public function testFindUserGroups()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(123)->groups()->findAll();
+ }, 'users/123/groups.json');
+ }
+
+ /**
+ * Tests if the default findAll route is still accessible
+ */
+ public function testFindAllGroups()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->groups()->findAll();
+ }, 'groups.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/IncrementalExportsTest.php b/tests/Zendesk/API/UnitTests/Core/IncrementalExportsTest.php
new file mode 100644
index 00000000..3e5a3535
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/IncrementalExportsTest.php
@@ -0,0 +1,68 @@
+ 1332034771,
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->incremental()->tickets($queryParams);
+ }, 'incremental/tickets.json', 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Test get incremental export for ticket events
+ *
+ */
+ public function testTicketEvents()
+ {
+ $queryParams = [
+ 'start_time' => 1332034771,
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->incremental()->ticketEvents($queryParams);
+ }, 'incremental/ticket_events.json', 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Test get incremental export for organizations
+ */
+ public function testOrganizations()
+ {
+ $queryParams = [
+ 'start_time' => 1332034771,
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->incremental()->organizations($queryParams);
+ }, 'incremental/organizations.json', 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Test get incremental export for users
+ */
+ public function testUsers()
+ {
+ $queryParams = [
+ 'start_time' => 1332034771,
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->incremental()->users($queryParams);
+ }, 'incremental/users.json', 'GET', ['queryParams' => $queryParams]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/LocalesTest.php b/tests/Zendesk/API/UnitTests/Core/LocalesTest.php
new file mode 100755
index 00000000..33c17fab
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/LocalesTest.php
@@ -0,0 +1,51 @@
+assertEndpointCalled(function () {
+ $this->client->locales()->findAllPublic();
+ }, 'locales/public.json');
+ }
+
+ /**
+ * Test findAllAgent method
+ */
+ public function testFindAllAgent()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->locales()->findAllAgent();
+ }, 'locales/agent.json');
+ }
+
+ /**
+ * Test findCurrent method
+ */
+ public function testFindCurrent()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->locales()->findCurrent();
+ }, 'locales/current.json');
+ }
+
+ /**
+ * Test findBest method
+ */
+ public function testFindBest()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->locales()->findBest();
+ }, 'locales/detect_best_locale.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/MacrosTest.php b/tests/Zendesk/API/UnitTests/Core/MacrosTest.php
new file mode 100755
index 00000000..3f17c0f4
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/MacrosTest.php
@@ -0,0 +1,50 @@
+assertEndpointCalled(function () {
+ $this->client->macros()->findAllActive();
+ }, 'macros/active.json');
+ }
+
+ /**
+ * Test the `GET /api/v2/macros/{id}/apply.json` endpoint
+ * Shows the changes to the ticket
+ */
+ public function testApply()
+ {
+ $id = 1;
+
+ $this->assertEndpointCalled(function () use ($id) {
+ $this->client->macros()->apply($id);
+ }, "macros/{$id}/apply.json");
+ }
+
+ /**
+ * Test the `GET /api/v2/tickets/{ticket_id}/macros/{id}/apply.json` endpoint
+ * Shows the ticket after the macro changes
+ */
+ public function testApplyToTicket()
+ {
+ $id = 1;
+ $ticketId = 3;
+
+ $this->assertEndpointCalled(function () use ($id, $ticketId) {
+ $this->client->macros()->applyToTicket($id, $ticketId);
+ }, "tickets/{$ticketId}/macros/{$id}/apply.json");
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/OAuthClientsTest.php b/tests/Zendesk/API/UnitTests/Core/OAuthClientsTest.php
new file mode 100755
index 00000000..f8fa7fc9
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/OAuthClientsTest.php
@@ -0,0 +1,33 @@
+assertTrue(method_exists($this->client->oauthClients(), 'create'));
+ $this->assertTrue(method_exists($this->client->oauthClients(), 'delete'));
+ $this->assertTrue(method_exists($this->client->oauthClients(), 'find'));
+ $this->assertTrue(method_exists($this->client->oauthClients(), 'findAll'));
+ $this->assertTrue(method_exists($this->client->oauthClients(), 'update'));
+ }
+
+ /**
+ * Test findAllMine method
+ */
+ public function testFindAllMine()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->oauthClients()->findAllMine();
+ }, 'users/me/oauth/clients.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/OAuthTokensTest.php b/tests/Zendesk/API/UnitTests/Core/OAuthTokensTest.php
new file mode 100644
index 00000000..29deb91a
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/OAuthTokensTest.php
@@ -0,0 +1,32 @@
+assertEndpointCalled(function () use ($resourceId) {
+ $this->client->oauthTokens()->revoke($resourceId);
+ }, "oauth/tokens/{$resourceId}.json", 'DELETE');
+ }
+
+ /**
+ * Test for current method
+ */
+ public function testCurrentEndpoint()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->oauthTokens()->current();
+ }, 'oauth/tokens/current.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/OrganizationFieldsTest.php b/tests/Zendesk/API/UnitTests/Core/OrganizationFieldsTest.php
new file mode 100755
index 00000000..e0f3a4f8
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/OrganizationFieldsTest.php
@@ -0,0 +1,23 @@
+ [14382, 14342]];
+
+ $this->assertEndpointCalled(function () use ($postFields) {
+ $this->client->organizationFields()->reorder($postFields);
+ }, 'organization_fields/reorder.json', 'PUT', ['postFields' => $postFields]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php b/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php
new file mode 100644
index 00000000..107d4c26
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/OrganizationMembershipsTest.php
@@ -0,0 +1,257 @@
+assertEndpointCalled(function () use ($resourceId) {
+ $this->client->organizationMemberships($resourceId)->find();
+ }, "organization_memberships/{$resourceId}.json");
+ }
+
+ /**
+ * Test find method with chained user
+ */
+ public function testFindUserOrganizationMemberships()
+ {
+ $resourceId = 299283;
+ $userId = 28261;
+
+ $this->assertEndpointCalled(function () use ($resourceId, $userId) {
+ $this->client->users($userId)->organizationMemberships()->find($resourceId);
+ }, "users/{$userId}/organization_memberships/{$resourceId}.json");
+ }
+
+ /**
+ * Test find with organization memberships is passed when instantiating the resource.
+ */
+ public function testFindUserOrganizationMembershipsChained()
+ {
+ $resourceId = 299283;
+ $userId = 28261;
+
+ $this->assertEndpointCalled(function () use ($userId, $resourceId) {
+ $this->client->users($userId)->organizationMemberships($resourceId)->find();
+ }, "users/{$userId}/organization_memberships/{$resourceId}.json");
+ }
+
+ /**
+ * Test findAll method
+ */
+ public function testFindAll()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->organizationMemberships()->findAll();
+ }, 'organization_memberships.json');
+ }
+
+ /**
+ * Test findAll with user resource chained
+ */
+ public function testFindAllUserOrganizationMemberships()
+ {
+ $userId = 123;
+
+ $this->assertEndpointCalled(function () use ($userId) {
+ $this->client->users($userId)->organizationMemberships()->findAll();
+ }, "users/{$userId}/organization_memberships.json");
+
+ }
+
+ /**
+ * Test findAll with organizations chained
+ */
+ public function testFindAllOrganizationMemberships()
+ {
+ $resourceId = 123;
+ $this->assertEndpointCalled(function () use ($resourceId) {
+ $this->client->organizations($resourceId)->memberships()->findAll();
+ }, "organizations/{$resourceId}/organization_memberships.json");
+ }
+
+ /**
+ * Test create endpoint
+ */
+ public function testCreateOrganizationMemberships()
+ {
+ $postFields = [
+ 'id' => 461,
+ 'user_id' => 72,
+ 'organization_id' => 88,
+ 'default' => true,
+ 'created_at' => '2012-04-03T12:34:01Z',
+ 'updated_at' => '2012-04-03T12:34:01Z'
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($postFields) {
+ $this->client->organizationMemberships()->create($postFields);
+ },
+ 'organization_memberships.json',
+ 'POST',
+ [
+ 'postFields' => ['organization_membership' => $postFields],
+ ]
+ );
+ }
+
+ /**
+ * Test create endpoint with user resource chained
+ */
+ public function testCreateUserOrganizationMemberships()
+ {
+ $userId = 282;
+ $postFields = [
+ 'id' => 461,
+ 'user_id' => 72,
+ 'organization_id' => 88,
+ 'default' => true,
+ 'created_at' => '2012-04-03T12:34:01Z',
+ 'updated_at' => '2012-04-03T12:34:01Z'
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($userId, $postFields) {
+ $this->client->users($userId)->organizationMemberships()->create($postFields);
+ },
+ "users/{$userId}/organization_memberships.json",
+ 'POST',
+ [
+ 'postFields' => ['organization_membership' => $postFields],
+ ]
+ );
+
+ }
+
+ /**
+ * Test createMany method
+ */
+ public function testCreateMany()
+ {
+ $postFields = [
+ [
+ 'user_id' => 72,
+ 'organization_id' => 88,
+ ],
+ [
+ 'user_id' => 28,
+ 'organization_id' => 88,
+ ],
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($postFields) {
+ $this->client->organizationMemberships()->createMany($postFields);
+ },
+ 'organization_memberships/create_many.json',
+ 'POST',
+ [
+ 'postFields' => ['organization_memberships' => $postFields],
+ ]
+ );
+
+ }
+
+ /**
+ * Test delete method
+ */
+ public function testDelete()
+ {
+ $resourceId = 299283;
+
+ $this->assertEndpointCalled(function () use ($resourceId) {
+ $this->client->organizationMemberships($resourceId)->delete();
+ }, "organization_memberships/{$resourceId}.json", 'DELETE');
+ }
+
+ /**
+ * Test delete method with chained user resource
+ */
+ public function testDeleteUserOrganizationMemberships()
+ {
+ $resourceId = 299283;
+ $userId = 28261;
+
+ $this->assertEndpointCalled(function () use ($userId, $resourceId) {
+ $this->client->users($userId)->organizationMemberships()->delete($resourceId);
+ }, "users/{$userId}/organization_memberships/{$resourceId}.json", 'DELETE');
+ }
+
+ /**
+ * Test delete with chained user resource and passing the membership id when instantiating.
+ */
+ public function testDeleteUserOrganizationMembershipsChained()
+ {
+ $resourceId = 299283;
+ $userId = 28261;
+
+ $this->assertEndpointCalled(function () use ($resourceId, $userId) {
+ $this->client->users($userId)->organizationMemberships($resourceId)->delete();
+ }, "users/{$userId}/organization_memberships/{$resourceId}.json", 'DELETE');
+ }
+
+ /**
+ * Test delete many method
+ */
+ public function testDeleteMany()
+ {
+ $resourceIds = [299283, 2331];
+
+ $this->assertEndpointCalled(
+ function () use ($resourceIds) {
+ $this->client->organizationMemberships()->deleteMany($resourceIds);
+ },
+ "organization_memberships/destroy_many.json",
+ 'DELETE',
+ [
+ 'queryParams' => ['ids' => implode(',', $resourceIds)],
+ ]
+ );
+ }
+
+ /**
+ * Test for make default method
+ */
+ public function testMakeDefault()
+ {
+ $params = [
+ 'id' => 1122,
+ 'userId' => 2341,
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($params) {
+ $this->client->organizationMemberships()->makeDefault($params);
+ },
+ "users/{$params['userId']}/organization_memberships/{$params['id']}/make_default.json",
+ 'PUT'
+ );
+ }
+
+ /**
+ * Test for make default method using chaining
+ */
+ public function testMakeDefaultChained()
+ {
+ $params = [
+ 'id' => 1122,
+ 'userId' => 2341,
+ ];
+
+ $this->assertEndpointCalled(function () use ($params) {
+ $this->client->users($params['userId'])->organizationMemberships($params['id'])->makeDefault();
+ }, "users/{$params['userId']}/organization_memberships/{$params['id']}/make_default.json", 'PUT');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/OrganizationSubscriptionsTest.php b/tests/Zendesk/API/UnitTests/Core/OrganizationSubscriptionsTest.php
new file mode 100644
index 00000000..2b664dc9
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/OrganizationSubscriptionsTest.php
@@ -0,0 +1,57 @@
+client->organizationSubscriptions()->getResourceName();
+
+ $this->assertEquals(
+ 'organization_subscriptions',
+ $resourceName,
+ 'Should return `organization_subscriptions` as resource name'
+ );
+ }
+
+ /**
+ * Test find method with chained user resource
+ */
+ public function testFindUserOrganizations()
+ {
+ $userId = 82828;
+ $this->assertEndpointCalled(function () use ($userId) {
+ $this->client->users($userId)->organizationSubscriptions()->findAll();
+ }, "users/{$userId}/organization_subscriptions.json");
+ }
+
+ /**
+ * Test find method with chained organization resource
+ */
+ public function testFindOrganizationSubscriptions()
+ {
+ $organizationId = 9393;
+ $this->assertEndpointCalled(function () use ($organizationId) {
+ $this->client->organizations($organizationId)->subscriptions()->findAll();
+ }, "organizations/{$organizationId}/subscriptions.json");
+ }
+
+ /**
+ * Tests if the default findAll route is still accessible
+ */
+ public function testFindAllOrganizationSubscriptions()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->organizationSubscriptions()->findAll();
+ }, 'organization_subscriptions.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php b/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php
new file mode 100644
index 00000000..ef753946
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/OrganizationsTest.php
@@ -0,0 +1,64 @@
+assertEndpointCalled(function () use ($userId) {
+ $this->client->users($userId)->organizations()->findAll();
+ }, "users/{$userId}/organizations.json");
+ }
+
+ /**
+ * Tests if the default findAll route is still accessible
+ */
+ public function testFindAllOrganizations()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->organizations()->findAll();
+ }, 'organizations.json');
+ }
+
+ /**
+ * Test for autocomplete method
+ */
+ public function testAutocomplete()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->organizations()->autocomplete('foo');
+ }, 'organizations/autocomplete.json', 'GET', ['queryParams' => ['name' => 'foo']]);
+ }
+
+ /**
+ * Test related method
+ */
+ public function testRelated()
+ {
+ $resourceId = 123;
+ $this->assertEndpointCalled(function () use ($resourceId) {
+ $this->client->organizations()->related($resourceId);
+ }, "organizations/{$resourceId}/related.json");
+ }
+
+ /**
+ * Test for search method
+ */
+ public function testSearchByExternalId()
+ {
+ $externalId = 123;
+ $this->assertEndpointCalled(function () use ($externalId) {
+ $this->client->organizations()->search($externalId);
+ }, 'organizations/search.json', 'GET', ['queryParams' => ['external_id' => 123]]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/PushNotificationDevicesTest.php b/tests/Zendesk/API/UnitTests/Core/PushNotificationDevicesTest.php
new file mode 100755
index 00000000..d121f270
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/PushNotificationDevicesTest.php
@@ -0,0 +1,29 @@
+ ['token1', 'token2']];
+ $this->assertEndpointCalled(
+ function () use ($postFields) {
+ $this->client->pushNotificationDevices()->deleteMany($postFields);
+ },
+ 'push_notification_devices/destroy_many.json',
+ 'POST',
+ [
+ 'postFields' => ['push_notification_devices' => $postFields['tokens']]
+ ]
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/RequestCommentsTest.php b/tests/Zendesk/API/UnitTests/Core/RequestCommentsTest.php
new file mode 100755
index 00000000..2a5dd890
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/RequestCommentsTest.php
@@ -0,0 +1,36 @@
+assertEndpointCalled(function () use ($requestId) {
+ $this->client->requests($requestId)->comments()->findAll();
+ }, "requests/{$requestId}/comments.json");
+ }
+
+ /**
+ * Test find method
+ */
+ public function testFind()
+ {
+ $resourceId = 3838;
+ $requestId = 19192;
+
+ $this->assertEndpointCalled(function () use ($requestId, $resourceId) {
+ $this->client->requests($requestId)->comments()->find($resourceId);
+ }, "requests/{$requestId}/comments/{$resourceId}.json");
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/RequestsTest.php b/tests/Zendesk/API/UnitTests/Core/RequestsTest.php
new file mode 100755
index 00000000..8ed12b21
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/RequestsTest.php
@@ -0,0 +1,90 @@
+assertEndpointCalled(function () {
+ $this->client->requests()->findAll();
+ }, 'requests.json');
+ }
+
+ /**
+ * Test findAllOpen method
+ */
+ public function testFindAllOpen()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->requests()->findAllOpen();
+ }, 'requests/open.json');
+ }
+
+ /**
+ * Test findAllSolved method
+ */
+ public function testFindAllSolved()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->requests()->findAllSolved();
+ }, 'requests/solved.json');
+ }
+
+ /**
+ * Test findAllCCd method
+ */
+ public function testFindAllCCd()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->requests()->findAllCCd();
+ }, 'requests/ccd.json');
+ }
+
+ /**
+ * Test findAll method with a chained user
+ */
+ public function testFindAllChainedUser()
+ {
+ $userId = 8373;
+
+ $this->assertEndpointCalled(function () use ($userId) {
+ $this->client->users($userId)->requests()->findAll();
+ }, "users/{$userId}/requests.json");
+ }
+
+ /**
+ * Test findAll method with chained organization
+ */
+ public function testFindAllChainedOrganization()
+ {
+ $organizationId = 8373;
+
+ $this->assertEndpointCalled(function () use ($organizationId) {
+ $this->client->organizations($organizationId)->requests()->findAll();
+ }, "organizations/{$organizationId}/requests.json");
+ }
+
+ /**
+ * Test search method
+ */
+ public function testSearch()
+ {
+ $queryParams = [
+ 'query' => 'camera',
+ 'organization_id' => 1,
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->requests()->search($queryParams);
+ }, 'requests/search.json', 'GET', ['queryParams' => $queryParams]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/ResourceTest.php b/tests/Zendesk/API/UnitTests/Core/ResourceTest.php
new file mode 100644
index 00000000..b39b5f19
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/ResourceTest.php
@@ -0,0 +1,275 @@
+dummyResource = new DummyResource($this->client);
+ }
+
+ /**
+ * Test findAll method
+ */
+ public function testFindAll()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->dummyResource->findAll();
+ }, 'dummy_resource.json');
+ }
+
+ /**
+ * Test find method
+ */
+ public function testFind()
+ {
+ $resourceId = 8282;
+ $this->assertEndpointCalled(function () use ($resourceId) {
+ $this->dummyResource->find($resourceId);
+ }, "dummy_resource/{$resourceId}.json");
+ }
+
+ /**
+ * Test we can set the iterator parameters
+ */
+ public function testCanSetIteratorParams()
+ {
+ $iterators = ['per_page' => 1, 'page' => 2, 'sort_order' => 'desc', 'sort_by' => 'date'];
+
+ $this->assertEndpointCalled(function () use ($iterators) {
+ $this->dummyResource->findAll($iterators);
+ }, 'dummy_resource.json', 'GET', ['queryParams' => $iterators]);
+ }
+
+ /**
+ * Test create method
+ */
+ public function testCreate()
+ {
+ $postFields = ['foo' => 'test body'];
+
+ $this->assertEndpointCalled(
+ function () use ($postFields) {
+ $this->dummyResource->create($postFields);
+ },
+ 'dummy_resource.json',
+ 'POST',
+ ['postFields' => ['dummy' => $postFields]]
+ );
+ }
+
+ /**
+ * Test update method
+ */
+ public function testUpdate()
+ {
+ $resourceId = 39392;
+ $postFields = ['foo' => 'test body'];
+ $this->assertEndpointCalled(
+ function () use ($resourceId, $postFields) {
+ $this->dummyResource->update($resourceId, $postFields);
+ },
+ "dummy_resource/{$resourceId}.json",
+ 'PUT',
+ ['postFields' => ['dummy' => $postFields]]
+ );
+ }
+
+ /**
+ * Test delete method
+ */
+ public function testDelete()
+ {
+
+ $resourceId = 292;
+ $this->assertEndpointCalled(function () use ($resourceId) {
+ $this->dummyResource->delete($resourceId);
+ }, "dummy_resource/{$resourceId}.json", 'DELETE');
+ }
+
+ /**
+ * Test setting of sideloads
+ */
+ public function testSideLoad()
+ {
+ $sideloads = ['foo', 'bar', 'hello', 'world'];
+
+ $this->assertEndpointCalled(function () use ($sideloads) {
+ $this->dummyResource->sideload($sideloads);
+ $this->dummyResource->findAll();
+ }, 'dummy_resource.json', 'GET', ['queryParams' => ['include' => implode(',', $sideloads)]]);
+ }
+
+ /**
+ * Test createMany method
+ */
+ public function testCreateMany()
+ {
+ $postFields = [['foo' => 'test body'], ['foo2' => 'test body 2'], ['foo3' => 'test body3']];
+
+ $this->assertEndpointCalled(
+ function () use ($postFields) {
+ $this->dummyResource->createMany($postFields);
+ },
+ 'dummy_resource/create_many.json',
+ 'POST',
+ ['postFields' => ['dummies' => $postFields]]
+ );
+ }
+
+ /**
+ * Test findMany method
+ */
+ public function testFindMany()
+ {
+ $ids = [1, 2, 3, 4, 5];
+ $this->assertEndpointCalled(function () use ($ids) {
+ $this->dummyResource->findMany($ids);
+ }, 'dummy_resource/show_many.json', 'GET', ['queryParams' => ['ids' => implode(',', $ids)]]);
+ }
+
+ /**
+ * Test updateMany with the same data
+ */
+ public function testUpdateManySameData()
+ {
+ $ids = [1, 2, 3, 4, 5];
+ $postFields = ['foo' => 'test body'];
+
+ $this->assertEndpointCalled(
+ function () use ($ids, $postFields) {
+ $this->dummyResource->updateMany(array_merge(['ids' => $ids], $postFields));
+ },
+ 'dummy_resource/update_many.json',
+ 'PUT',
+ [
+ 'queryParams' => ['ids' => implode(',', $ids)],
+ 'postFields' => ['dummy' => $postFields],
+ ]
+ );
+
+ }
+
+ /**
+ * Test updateMany with different data
+ */
+ public function testUpdateManyDifferentData()
+ {
+ $postFields = [
+ ['id' => 1, 'foo' => 'bar', 'hello' => 'world'],
+ ['id' => 2, 'foo' => 'bar', 'hello' => 'world'],
+ ['id' => 3, 'foo' => 'bar', 'hello' => 'world'],
+ ['id' => 4, 'foo' => 'bar', 'hello' => 'world']
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($postFields) {
+ $this->dummyResource->updateMany($postFields);
+ },
+ 'dummy_resource/update_many.json',
+ 'PUT',
+ ['postFields' => ['dummies' => $postFields]]
+ );
+
+ }
+
+ /**
+ * Test delete many
+ */
+ public function testDeleteMany()
+ {
+ $ids = [1, 2, 3, 4, 5];
+
+ $this->assertEndpointCalled(
+ function () use ($ids) {
+ $this->dummyResource->deleteMany($ids);
+ },
+ 'dummy_resource/destroy_many.json',
+ 'DELETE',
+ ['queryParams' => ['ids' => implode(',', $ids)]]
+ );
+ }
+
+ /**
+ * Test multipost upload trait creates an upload method.
+ */
+ public function testUpload()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $params = [
+ 'file' => getcwd() . '/tests/assets/UK.png'
+ ];
+
+ $this->dummyResource->upload($params);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'dummy_resource/uploads.json',
+ 'multipart' => true,
+ ]
+ );
+ }
+
+ /**
+ * Test we can handle server exceptions
+ *
+ * @expectedException Zendesk\API\Exceptions\ApiResponseException
+ * @expectedExceptionMessage Zendesk may be experiencing internal issues or undergoing scheduled maintenance.
+ */
+ public function testHandlesServerException()
+ {
+ $this->mockApiResponses(
+ new Response(500, [], '')
+ );
+
+ $this->dummyResource->create(['foo' => 'bar']);
+ }
+
+ /**
+ * Test we can handle api exceptions
+ *
+ * @expectedException Zendesk\API\Exceptions\ApiResponseException
+ * @expectedExceptionMessage Unprocessable Entity
+ */
+ public function testHandlesApiException()
+ {
+ $this->mockApiResponses(
+ new Response(422, [], '')
+ );
+
+ $this->dummyResource->create(['foo' => 'bar']);
+ }
+
+ /**
+ * Test if the correct User-Agent header is passed method
+ */
+ public function testUserAgent()
+ {
+ $this->mockApiResponses([
+ new Response(200, [], '')
+ ]);
+
+ $this->dummyResource->findAll();
+
+ $transaction = $this->mockedTransactionsContainer[0];
+ $request = $transaction['request'];
+
+ $this->assertRegExp('/ZendeskAPI PHP/', $request->getHeaderLine('User-Agent'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php b/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php
new file mode 100755
index 00000000..38a24240
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SatisfactionRatingsTest.php
@@ -0,0 +1,21 @@
+assertTrue(method_exists($this->client->satisfactionRatings(), 'create'));
+ $this->assertTrue(method_exists($this->client->satisfactionRatings(), 'find'));
+ $this->assertTrue(method_exists($this->client->satisfactionRatings(), 'findAll'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SearchTest.php b/tests/Zendesk/API/UnitTests/Core/SearchTest.php
new file mode 100644
index 00000000..66cc77a0
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SearchTest.php
@@ -0,0 +1,52 @@
+ 'updated_at'];
+ $this->assertEndpointCalled(
+ function () use ($searchString, $queryParams) {
+ $this->client->search()->find($searchString, $queryParams);
+ },
+ 'search.json',
+ 'GET',
+ [
+ 'queryParams' => [
+ 'sort_by' => 'updated_at',
+ // replace colons, the colons are a special case in this endpoint so let's do the replacement
+ // for this test only
+ 'query' => str_replace('%3A', ':', rawurlencode($searchString))
+ ]
+ ]
+ );
+ }
+
+ /**
+ * @return array
+ */
+ public function basicQueryStrings()
+ {
+ return [
+ [3245227],
+ ['Greenbriar'],
+ ['type:user "Jane Doe"'],
+ ['type:ticket status:open'],
+ ['type:organization created<2015-05-01'],
+ ['created>2012-07-17 type:ticket organization:"MD Photo"'],
+ ];
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SessionsTest.php b/tests/Zendesk/API/UnitTests/Core/SessionsTest.php
new file mode 100644
index 00000000..27c8f791
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SessionsTest.php
@@ -0,0 +1,79 @@
+assertEndpointCalled(function () {
+ $this->client->users()->sessions()->deleteUserSessions(12345);
+ }, 'users/12345/sessions.json', 'DELETE');
+ }
+
+ /**
+ * Tests if the delete user session endpoint is accessible if chained via the Users resource
+ */
+ public function testBulkDeleteRouteWithChaining()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(12345)->sessions()->deleteUserSessions();
+ }, 'users/12345/sessions.json', 'DELETE');
+ }
+
+ /**
+ * Tests if the delete route can be chained and called properly
+ */
+ public function testDeleteRoute()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(12345)->sessions()->delete(67890);
+ }, 'users/12345/sessions/67890.json', 'DELETE');
+ }
+
+ /**
+ * Tests if the find session route can be chained and called properly
+ */
+ public function testFindRoute()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(12345)->sessions()->find(67890);
+ }, 'users/12345/sessions/67890.json', 'GET');
+ }
+
+ /**
+ * Tests if the list sessions route can be called properly
+ */
+ public function testFindAllViaSessionsRoute()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->sessions()->findAll();
+ }, 'sessions.json', 'GET');
+ }
+
+ /**
+ * Tests if the list sessions route can be chained and called properly
+ */
+ public function testFindAllSessionsWithChaining()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(12345)->sessions()->findAll();
+ }, 'users/12345/sessions.json', 'GET');
+ }
+
+ /**
+ * Tests if the find route can be chained and called properly
+ */
+ public function testFindSession()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(12345)->sessions()->find(67890);
+ }, 'users/12345/sessions/67890.json', 'GET');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php b/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php
new file mode 100755
index 00000000..124c64a1
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SharingAgreementsTest.php
@@ -0,0 +1,20 @@
+assertTrue(method_exists($this->client->sharingAgreements(), 'findAll'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SlaPoliciesTest.php b/tests/Zendesk/API/UnitTests/Core/SlaPoliciesTest.php
new file mode 100755
index 00000000..53486b50
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SlaPoliciesTest.php
@@ -0,0 +1,116 @@
+assertTrue(method_exists($this->client->slaPolicies(), 'findAll'));
+ $this->assertTrue(method_exists($this->client->slaPolicies(), 'create'));
+ $this->assertTrue(method_exists($this->client->slaPolicies(), 'find'));
+ $this->assertTrue(method_exists($this->client->slaPolicies(), 'delete'));
+ $this->assertTrue(method_exists($this->client->slaPolicies(), 'update'));
+ }
+
+ /**
+ * Test that the resource was overridden
+ */
+ public function testResourceName()
+ {
+ $this->assertEquals('slas/policies', $this->client->slaPolicies()->getResourceName());
+ }
+
+ /**
+ * Test the replace method
+ */
+ public function testReplace()
+ {
+ $resourceId = 91918;
+ $updateFields = [
+ 'title' => 'Incidents',
+ 'description' => 'For urgent incidents, we will respond to tickets in 10 minutes',
+ 'position' => 3,
+ 'filter' =>
+ [
+ 'all' =>
+ [
+ 0 =>
+ [
+ 'field' => 'type',
+ 'operator' => 'is',
+ 'value' => 'incident',
+ ],
+ ],
+ 'any' =>
+ [
+ ],
+ ],
+ 'policy_metrics' =>
+ [
+ 0 =>
+ [
+ 'priority' => 'normal',
+ 'metric' => 'first_reply_time',
+ 'target' => 30,
+ 'business_hours' => false,
+ ],
+ 1 =>
+ [
+ 'priority' => 'urgent',
+ 'metric' => 'first_reply_time',
+ 'target' => 10,
+ 'business_hours' => false,
+ ],
+ ],
+ ];
+
+ $this->assertEndpointCalled(
+ function () use ($resourceId, $updateFields) {
+ $this->client->slaPolicies()->replace($resourceId, $updateFields);
+ },
+ "slas/policies/{$resourceId}/replace.json",
+ 'PUT',
+ ['postFields' => ['sla_policy' => $updateFields]]
+ );
+ }
+
+ /**
+ * Test the reorder method
+ */
+ public function testReorder()
+ {
+ $resourceIds = [12, 55];
+ $this->assertEndpointCalled(
+ function () use ($resourceIds) {
+ $this->client->slaPolicies()->reorder($resourceIds);
+ },
+ "slas/policies/reorder.json",
+ 'PUT',
+ ['postFields' => ['sla_policy_ids' => $resourceIds]]
+ );
+ }
+
+ /**
+ * Test the definitions method
+ */
+ public function testDefinitions()
+ {
+ $this->assertEndpointCalled(
+ function () {
+ $this->client->slaPolicies()->definitions();
+ },
+ "slas/policies/definitions.json",
+ 'GET'
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SupportAddressesTest.php b/tests/Zendesk/API/UnitTests/Core/SupportAddressesTest.php
new file mode 100644
index 00000000..b92dbd0a
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SupportAddressesTest.php
@@ -0,0 +1,32 @@
+ 'forwarding'];
+
+ $this->assertEndpointCalled(function () use ($updateData) {
+ $this->client->supportAddresses()->verify(123, $updateData);
+ }, 'recipient_addresses/123/verify.json', 'PUT', ['postFields' => $updateData]);
+ }
+
+ /**
+ * Tests if the client can build the verify support address endpoint and pass the update fields
+ */
+ public function testCreate()
+ {
+ $updateData = ['type' => 'forwarding'];
+
+ $this->assertEndpointCalled(function () use ($updateData) {
+ $this->client->supportAddresses()->create($updateData);
+ }, 'recipient_addresses.json', 'POST', ['postFields' => ['recipient_address' => $updateData]]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/SuspendedTicketsTest.php b/tests/Zendesk/API/UnitTests/Core/SuspendedTicketsTest.php
new file mode 100644
index 00000000..dede7ec4
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/SuspendedTicketsTest.php
@@ -0,0 +1,47 @@
+assertTrue(method_exists($this->client->suspendedTickets(), 'delete'));
+ $this->assertTrue(method_exists($this->client->suspendedTickets(), 'find'));
+ $this->assertTrue(method_exists($this->client->suspendedTickets(), 'findAll'));
+ $this->assertTrue(method_exists($this->client->suspendedTickets(), 'deleteMany'));
+ }
+
+ public function testRecover()
+ {
+ $resourceId = 233;
+ $this->assertEndpointCalled(
+ function () use ($resourceId) {
+ $this->client->suspendedTickets($resourceId)->recover();
+ },
+ "suspended_tickets/{$resourceId}/recover.json",
+ 'PUT'
+ );
+ }
+
+ public function testRecoverMany()
+ {
+ $resourceIds = [233, 232];
+ $this->assertEndpointCalled(
+ function () use ($resourceIds) {
+ $this->client->suspendedTickets()->recoverMany($resourceIds);
+ },
+ "suspended_tickets/recover_many.json",
+ 'PUT',
+ ['queryParams' => ['ids' => implode(',', $resourceIds)]]
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TagsTest.php b/tests/Zendesk/API/UnitTests/Core/TagsTest.php
new file mode 100644
index 00000000..fc9e73ed
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TagsTest.php
@@ -0,0 +1,41 @@
+client->tickets(12345)->tags()->getRoute('find', ['id' => 12345]);
+ $this->assertEquals('tickets/12345/tags.json', $route);
+ }
+
+ /**
+ * @expectedException Zendesk\API\Exceptions\CustomException
+ */
+ public function testFindUnchained()
+ {
+ $this->client->tags()->find(1);
+ }
+
+ /**
+ * @expectedException Zendesk\API\Exceptions\CustomException
+ */
+ public function testFindNoChainedParameter()
+ {
+ $this->client->tickets()->tags()->find(1);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketAuditsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketAuditsTest.php
new file mode 100755
index 00000000..46681e81
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketAuditsTest.php
@@ -0,0 +1,40 @@
+ 1];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->tickets($this->ticketId)->audits()->findAll($queryParams);
+ }, "tickets/{$this->ticketId}/audits.json", 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Test find with chained resources
+ */
+ public function testFindWithChainedParams()
+ {
+ $auditId = 1;
+
+ $this->assertEndpointCalled(function () use ($auditId) {
+ $this->client->tickets($this->ticketId)->audits($auditId)->find();
+ }, "tickets/{$this->ticketId}/audits/{$auditId}.json");
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketCommentsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketCommentsTest.php
new file mode 100755
index 00000000..6e8b155b
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketCommentsTest.php
@@ -0,0 +1,36 @@
+assertEndpointCalled(function () use ($ticketId) {
+ $this->client->tickets($ticketId)->comments()->findAll();
+ }, "tickets/{$ticketId}/comments.json");
+
+ }
+
+ /**
+ * Test make private
+ */
+ public function testMakePrivate()
+ {
+ $ticketId = 12345;
+ $commentId = 123;
+ $this->assertEndpointCalled(function () use ($ticketId, $commentId) {
+ $this->client->tickets($ticketId)->comments($commentId)->makePrivate();
+ }, "tickets/{$ticketId}/comments/{$commentId}/make_private.json", 'PUT');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php
new file mode 100755
index 00000000..b6355fe3
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketFieldsTest.php
@@ -0,0 +1,23 @@
+client);
+
+ $this->assertEquals('ticket_fields', $ticketFields->getResourceName());
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketFormsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketFormsTest.php
new file mode 100644
index 00000000..39170a60
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketFormsTest.php
@@ -0,0 +1,86 @@
+mockAPIResponses([
+ new Response(422, [], '')
+ ]);
+
+ $this->client->tickets()->forms(1)->delete();
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'DELETE',
+ 'endpoint' => 'ticket_forms/1.json'
+ ]
+ );
+ }
+
+ public function testCloneForm()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $this->client->tickets()->forms(1)->cloneForm();
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'ticket_forms/1/clone.json'
+ ]
+ );
+ }
+
+ /**
+ * Tests if an exception is thrown when a ticket form ID could not be retrieved from
+ * the method call.
+ *
+ * @expectedException Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testCloneFormThrowsException()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $this->client->tickets(1)->forms()->cloneForm();
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'ticket_forms/1/clone.json'
+ ]
+ );
+ }
+
+ public function testReorder()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], '')
+ ]);
+
+ $this->client->tickets()->forms()->reorder([3, 4, 5, 1]);
+
+ $this->assertLastRequestIs(
+ [
+ 'method' => 'PUT',
+ 'endpoint' => 'ticket_forms/reorder.json',
+ 'postFields' => ['ticket_form_ids' => [3, 4, 5, 1]]
+ ]
+ );
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketImportsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketImportsTest.php
new file mode 100755
index 00000000..94488ed9
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketImportsTest.php
@@ -0,0 +1,32 @@
+client->ticketImports()->getRoutes();
+
+ $this->assertEquals('imports/tickets.json', $routes['create']);
+ $this->assertEquals('imports/tickets/create_many.json', $routes['createMany']);
+ $this->assertEquals(2, count($routes), 'Should only have routes for create and createMany');
+ }
+
+ /**
+ * Test that the trait methods exists
+ */
+ public function testTraitMethods()
+ {
+ $this->assertTrue(method_exists($this->client->ticketImports(), 'create'));
+ $this->assertTrue(method_exists($this->client->ticketImports(), 'createMany'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketMetricsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketMetricsTest.php
new file mode 100644
index 00000000..7f10fa9c
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketMetricsTest.php
@@ -0,0 +1,33 @@
+client->tickets(12345)->metrics()->getRoute('find', ['id' => 12345]);
+ $this->assertEquals('tickets/12345/metrics.json', $route);
+
+ $route = $this->client->tickets()->metrics(12345)->getRoute('find', ['id' => 12345]);
+ $this->assertEquals('ticket_metrics/12345.json', $route);
+
+ $route = $this->client->tickets()->metrics()->getRoute('findAll');
+ $this->assertEquals('ticket_metrics.json', $route);
+
+ $route = $this->client->tickets(12345)->metrics()->getRoute('findAll');
+ $this->assertEquals('tickets/12345/metrics.json', $route);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TicketsTest.php b/tests/Zendesk/API/UnitTests/Core/TicketsTest.php
new file mode 100755
index 00000000..16bf0ea7
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TicketsTest.php
@@ -0,0 +1,298 @@
+testTicket = [
+ 'subject' => 'The quick brown fox jumps over the lazy dog',
+ 'comment' => [
+ 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor'
+ . ' incididunt ut labore et dolore magna aliqua.'
+ ],
+ 'priority' => 'normal',
+ 'id' => '12345'
+ ];
+
+ $this->testTicket2 = [
+ 'subject' => 'The second ticket',
+ 'comment' => [
+ 'body' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor'
+ . ' incididunt ut labore et dolore magna aliqua.'
+ ],
+ 'priority' => 'normal',
+ 'id' => '4321'
+ ];
+
+ parent::setUp();
+ }
+
+ /**
+ * Tests if the client can call and build the tickets endpoint with the proper sideloads
+ */
+ public function testAllSideLoadedMethod()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->sideload(['users', 'groups'])->findAll();
+ }, 'tickets.json', 'GET', ['queryParams' => ['include' => 'users,groups']]);
+
+ $this->assertNull($this->client->getSideload());
+ }
+
+ /**
+ * Tests if the client can call and build the tickets endpoint with the proper sideloads
+ */
+ public function testAllSideLoadedParameter()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->findAll(['sideload' => ['users', 'groups']]);
+ }, 'tickets.json', 'GET', ['queryParams' => ['include' => 'users,groups']]);
+ }
+
+ /**
+ * Tests if the client can call and build the find ticket endpoint
+ */
+ public function testFindSingle()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->find($this->testTicket['id']);
+ }, 'tickets/' . $this->testTicket['id'] . '.json');
+ }
+
+ /**
+ * Tests if the client can call and build the find ticket endpoint while chaining
+ */
+ public function testFindSingleChainPattern()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets($this->testTicket['id'])->find();
+ }, 'tickets/' . $this->testTicket['id'] . '.json');
+ }
+
+ /**
+ * Tests if the client can call and build the show many tickets endpoint with the correct IDs
+ */
+ public function testFindMultiple()
+ {
+ $this->assertEndpointCalled(
+ function () {
+ $this->client->tickets()->findMany([$this->testTicket['id'], $this->testTicket2['id']]);
+ },
+ 'tickets/show_many.json',
+ 'GET',
+ [
+ 'queryParams' => [
+ 'ids' => implode(',', [$this->testTicket['id'], $this->testTicket2['id']])
+ ]
+ ]
+ );
+ }
+
+ /**
+ * Tests if the client can call and build the show many tickets endpoint with the proper sideloads and correct IDs
+ */
+ public function testFindMultipleWithSideload()
+ {
+ $this->assertEndpointCalled(
+ function () {
+ $this->client->tickets()->findMany(
+ [$this->testTicket['id'], $this->testTicket2['id']],
+ ['sideload' => ['users', 'groups'], 'per_page' => 20],
+ 'ids'
+ );
+ },
+ 'tickets/show_many.json',
+ 'GET',
+ [
+ 'queryParams' => [
+ 'ids' => implode(',', [$this->testTicket['id'], $this->testTicket2['id']]),
+ 'per_page' => 20,
+ 'include' => 'users,groups'
+ ]
+ ]
+ );
+ }
+
+ /**
+ * Tests if the client can call and build the delete many tickets endpoint with the correct IDs
+ */
+ public function testDeleteMultiple()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->deleteMany([123, 321]);
+ }, 'tickets/destroy_many.json', 'DELETE', ['queryParams' => ['ids' => implode(',', [123, 321])]]);
+ }
+
+ /**
+ * Tests if the client can call and build the create ticket witch attachment endpoint and initiate the file upload
+ * headers and POST data
+ */
+ public function testCreateWithAttachment()
+ {
+ $this->mockAPIResponses([
+ new Response(200, [], json_encode(['upload' => ['token' => 'asdf']])),
+ new Response(200, [], json_encode(['ticket' => ['id' => '123']])),
+ ]);
+
+ $attachmentData = [
+ 'file' => getcwd() . '/tests/assets/UK.png',
+ 'name' => 'UK test non-alpha chars.png'
+ ];
+
+ $this->client->tickets()->attach($attachmentData)->create($this->testTicket);
+
+ $this->assertRequestIs(
+ [
+ 'method' => 'POST',
+ 'endpoint' => 'uploads.json',
+ 'queryParams' => ['filename' => rawurlencode($attachmentData['name'])],
+ 'file' => $attachmentData['file'],
+ ],
+ 0
+ );
+
+ $postFields = [
+ 'ticket' => [
+ 'subject' => $this->testTicket['subject'],
+ 'comment' => array_merge($this->testTicket['comment'], ['uploads' => ['asdf']]),
+ 'priority' => $this->testTicket['priority'],
+ 'id' => $this->testTicket['id'],
+
+ ]
+ ];
+ array_merge([$this->testTicket, ['uploads' => ['asdf']]]);
+ $this->assertLastRequestIs([
+ 'method' => 'POST',
+ 'endpoint' => 'tickets.json',
+ 'postFields' => $postFields,
+ ]);
+ }
+
+ /**
+ * Tests if the client can call and build the export tickets endpoint with the proper pagination query
+ */
+ public function testExport()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->export(['start_time' => '1332034771']);
+ }, 'exports/tickets.json', 'GET', ['queryParams' => ['start_time' => '1332034771']]);
+ }
+
+ /**
+ * Tests if the client can call and build the update many tickets endpoint with the correct IDS and POST fields
+ */
+ public function testUpdateManyWithQueryParams()
+ {
+ $ticketIds = [$this->testTicket['id'], $this->testTicket2['id']];
+
+ $this->assertEndpointCalled(
+ function () use ($ticketIds) {
+ $this->client->tickets()->updateMany(
+ [
+ 'ids' => $ticketIds,
+ 'status' => 'solved'
+ ]
+ );
+ },
+ 'tickets/update_many.json',
+ 'PUT',
+ [
+ 'queryParams' => ['ids' => implode(',', $ticketIds)],
+ 'postFields' => ['ticket' => ['status' => 'solved']]
+ ]
+ );
+ }
+
+ /**
+ * Tests if the client can call and build the update many tickets endpoint with the correct IDS and POST fields
+ */
+ public function testUpdateMany()
+ {
+ $tickets = [$this->testTicket, $this->testTicket2];
+
+ $this->assertEndpointCalled(function () use ($tickets) {
+ $this->client->tickets()->updateMany($tickets);
+ }, 'tickets/update_many.json', 'PUT', ['postFields' => ['tickets' => $tickets]]);
+ }
+
+ /**
+ * Tests if the client can call and build the related tickets endpoint with the correct ID
+ */
+ public function testRelated()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets(12345)->related();
+ }, 'tickets/12345/related.json');
+ }
+
+ /**
+ * Tests if the client can call and build the ticket collaborators endpoint with the correct ID
+ */
+ public function testCollaborators()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->collaborators(['id' => 12345]);
+ }, 'tickets/12345/collaborators.json');
+ }
+
+ /**
+ * Tests if the client can call and build the tickets incidents endpoint with the correct ID
+ */
+ public function testIncidents()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->incidents(['id' => 12345]);
+ }, 'tickets/12345/incidents.json');
+ }
+
+ /**
+ * Tests if the client can call and build the problem tickets endpoint
+ */
+ public function testProblems()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->problems();
+ }, 'problems.json');
+ }
+
+ /**
+ * Tests if the client can call and build the problem autocomplete endpoint
+ */
+ public function testProblemAutoComplete()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->problemAutoComplete(['text' => 'foo']);
+ }, 'problems/autocomplete.json', 'POST', ['postFields' => ['text' => 'foo']]);
+ }
+
+ /**
+ * Tests if the client can call and build the mark ticket as spam endpoint with the correct ID
+ */
+ public function testMarkAsSpam()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets(12345)->markAsSpam();
+ }, 'tickets/12345/mark_as_spam.json', 'PUT');
+ }
+
+ /**
+ * Tests if the client can call and build the mark many tickets as spam endpoint with the correct IDs
+ */
+ public function testMarkManyAsSpam()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->tickets()->markAsSpam([12345, 54321]);
+ }, 'tickets/mark_many_as_spam.json', 'PUT', ['queryParams' => ['ids' => '12345,54321']]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TriggersTest.php b/tests/Zendesk/API/UnitTests/Core/TriggersTest.php
new file mode 100755
index 00000000..c045823b
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TriggersTest.php
@@ -0,0 +1,21 @@
+assertEndpointCalled(function () {
+ $this->client->triggers()->findActive();
+ }, 'triggers/active.json');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/TwitterHandlesTest.php b/tests/Zendesk/API/UnitTests/Core/TwitterHandlesTest.php
new file mode 100644
index 00000000..f536afcb
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/TwitterHandlesTest.php
@@ -0,0 +1,32 @@
+assertEndpointCalled(function () {
+ $this->client->twitterHandles()->findAll();
+ }, 'channels/twitter/monitored_twitter_handles.json');
+
+ $this->assertEndpointCalled(function () {
+ $this->client->twitterHandles()->find(1);
+ }, 'channels/twitter/monitored_twitter_handles/1.json');
+ }
+
+ /**
+ * Test that only find and findAll are present
+ */
+ public function testMethods()
+ {
+ $this->assertFalse(method_exists($this->client->twitterHandles(), 'create'));
+ $this->assertFalse(method_exists($this->client->twitterHandles(), 'delete'));
+ $this->assertFalse(method_exists($this->client->twitterHandles(), 'update'));
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/UserFieldsTest.php b/tests/Zendesk/API/UnitTests/Core/UserFieldsTest.php
new file mode 100755
index 00000000..b9ce825b
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/UserFieldsTest.php
@@ -0,0 +1,23 @@
+assertEndpointCalled(function () use ($ids) {
+ $this->client->userFields()->reorder($ids);
+ }, 'user_fields/reorder.json', 'PUT', ['postFields' => ['user_field_ids' => $ids]]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php b/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php
new file mode 100755
index 00000000..518a9adb
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/UserIdentitiesTest.php
@@ -0,0 +1,123 @@
+assertEquals(
+ "users/{$userId}/identities.json",
+ $this->client->users($userId)->identities()->getRoute(
+ 'findAll',
+ ['userId' => $userId]
+ )
+ );
+
+ // Create
+ $this->assertEquals(
+ "users/{$userId}/identities.json",
+ $this->client->users($userId)->identities()->getRoute(
+ 'create',
+ ['userId' => $userId]
+ )
+ );
+
+ // Find
+ $this->assertEquals(
+ "users/{$userId}/identities/{$id}.json",
+ $this->client->users($userId)->identities($id)->getRoute(
+ 'find',
+ ['id' => $id, 'userId' => $userId]
+ )
+ );
+
+ // Delete
+ $this->assertEquals(
+ "users/{$userId}/identities/{$id}.json",
+ $this->client->users($userId)->identities($id)->getRoute(
+ 'delete',
+ ['id' => $id, 'userId' => $userId]
+ )
+ );
+
+ // Update
+ $this->assertEquals(
+ "users/{$userId}/identities/{$id}.json",
+ $this->client->users($userId)->identities($id)->getRoute(
+ 'update',
+ ['id' => $id, 'userId' => $userId]
+ )
+ );
+ }
+
+ /**
+ * Tests if the client can POST to the identities end point
+ */
+ public function testCreateAsEndUser()
+ {
+ $userId = 3124;
+
+ $postFields = [
+ 'type' => 'email',
+ 'value' => 'thecustomer@domain.com'
+ ];
+
+ $this->assertEndpointCalled(function () use ($userId, $postFields) {
+ $this->client->users($userId)->identities()->createAsEndUser($postFields);
+ }, "end_users/{$userId}/identities.json", 'POST', ['postFields' => ['identity' => $postFields]]);
+ }
+
+ /**
+ * Tests if the client can call and build the verify endpoint
+ */
+ public function testVerify()
+ {
+ $userId = 3124;
+ $id = 123;
+
+ $this->assertEndpointCalled(function () use ($userId, $id) {
+ $this->client->users($userId)->identities($id)->verify();
+ }, "users/{$userId}/identities/{$id}/verify.json", 'PUT');
+ }
+
+ /**
+ * Tests if the client can call and build the make primary endpoint
+ */
+ public function testMakePrimary()
+ {
+ $userId = 3124;
+ $id = 123;
+
+ $this->assertEndpointCalled(function () use ($id, $userId) {
+ $this->client->users($userId)->identities($id)->makePrimary();
+ }, "users/$userId/identities/$id/make_primary.json", 'PUT');
+ }
+
+ /**
+ * Tests if the client can call and build the request verification endpoint
+ */
+ public function testRequestVerification()
+ {
+ $userId = 3124;
+ $id = 123;
+
+ $this->assertEndpointCalled(function () use ($id, $userId) {
+ $this->client->users($userId)->identities($id)->requestVerification();
+ }, "users/{$userId}/identities/{$id}/request_verification.json", 'PUT');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/UsersTest.php b/tests/Zendesk/API/UnitTests/Core/UsersTest.php
new file mode 100755
index 00000000..46e44968
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/UsersTest.php
@@ -0,0 +1,161 @@
+assertEndpointCalled(function () use ($findIds) {
+ $this->client->users()->findMany(['external_ids' => $findIds]);
+ }, 'users/show_many.json', 'GET', ['queryParams' => ['external_ids' => implode(',', $findIds)]]);
+ }
+
+ /**
+ * Tests if the related enpoint can be called by the client and is passed the correct ID
+ */
+ public function testRelated()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users(12345)->related();
+ }, 'users/12345/related.json');
+ }
+
+ /**
+ * Tests if the nerge enpoint can be called by the client and is passed the correct data
+ */
+ public function testMerge()
+ {
+ $postFields = ['id' => 12345];
+
+ $this->assertEndpointCalled(function () use ($postFields) {
+ $this->client->users('me')->merge($postFields);
+ }, 'users/me/merge.json', 'PUT', ['postFields' => ['user' => $postFields]]);
+ }
+
+ /**
+ * Tests if the suspend enpoint can be called by the client and is passed the correct ID
+ */
+ public function testSuspend()
+ {
+ $userId = 12345;
+
+ $this->assertEndpointCalled(
+ function () use ($userId) {
+ $this->client->users($userId)->suspend();
+ },
+ 'users/12345.json',
+ 'PUT',
+ [
+ 'postFields' => ['user' => ['id' => $userId, 'suspended' => true]]
+ ]
+ );
+ }
+
+ /**
+ * Tests if the search enpoint can be called by the client and is passed the correct query
+ */
+ public function testSearch()
+ {
+ $queryParams = ['query' => 'Roger'];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->users()->search($queryParams);
+ }, 'users/search.json', 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /*
+ * Needs an existed User with specified query 'name' keyword to run this function
+ */
+ public function testAutocomplete()
+ {
+ $queryParams = ['name' => 'joh'];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->users()->autocomplete($queryParams);
+ }, 'users/autocomplete.json', 'POST', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Tests if the client can perform the update profile functionality
+ */
+ public function testUpdateProfileImageFromFile()
+ {
+ $id = 915987427;
+
+ $this->assertEndpointCalled(function () use ($id) {
+ $params = [
+ 'file' => getcwd() . '/tests/assets/UK.png'
+ ];
+ $this->client->users($id)->updateProfileImageFromFile($params);
+ }, "users/{$id}.json", 'PUT', ['multipart' => true]);
+ }
+
+ /**
+ * Tests if the client can perform the update profile image functionality
+ */
+ public function testUpdateProfileImageFromUrl()
+ {
+ $id = 915987427;
+
+ $params = [
+ 'url' => 'http://www.test.com/profile.png'
+ ];
+
+ $this->assertEndpointCalled(function () use ($id, $params) {
+ $this->client->users($id)->updateProfileImageFromUrl($params);
+ }, "users/{$id}.json", 'PUT', ['postFields' => ['user' => ['remote_photo_url' => $params['url']]]]);
+ }
+
+ /**
+ * Tests if the client can call the users/me.json endpoint
+ */
+ public function testAuthenticatedUser()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->users()->me();
+ }, 'users/me.json');
+ }
+
+ /**
+ * Tests if the setPassword function calls the correct endpoint and passes the correct POST data
+ */
+ public function testSetPassword()
+ {
+ $postFields = ['password' => 'aBc12345'];
+
+ $this->assertEndpointCalled(function () use ($postFields) {
+ $this->client->users(12345)->setPassword($postFields);
+ }, 'users/12345/password.json', 'POST', ['postFields' => $postFields]);
+ }
+
+ /**
+ * Tests if the changePassword function calls the correct endpoint and passes the correct PUT data
+ */
+ public function testChangePassword()
+ {
+ $postFields = [
+ 'previous_password' => '12346',
+ 'password' => '12345'
+ ];
+
+ $userId = 421450109;
+
+ $this->assertEndpointCalled(function () use ($postFields, $userId) {
+ $this->client->users($userId)->changePassword($postFields);
+ }, "users/{$userId}/password.json", 'PUT');
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/Core/ViewsTest.php b/tests/Zendesk/API/UnitTests/Core/ViewsTest.php
new file mode 100755
index 00000000..66c58ac2
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Core/ViewsTest.php
@@ -0,0 +1,143 @@
+assertEndpointCalled(function () {
+ $this->client->views()->findAllActive();
+ }, 'views/active.json');
+ }
+
+ /**
+ * Test getting compact list of views
+ */
+ public function testCompact()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->views()->findAllCompact();
+ }, 'views/compact.json');
+ }
+
+ /**
+ * Test execution of views
+ *
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testExecute()
+ {
+ $queryParams = ['per_page' => 1];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->views($this->id)->execute($queryParams);
+ }, "views/{$this->id}/execute.json", 'GET', ['queryParams' => $queryParams]);
+ }
+
+ /**
+ * Test getting of view counts
+ *
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testCount()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->views($this->id)->count();
+ }, "views/{$this->id}/count.json");
+ }
+
+ /**
+ * Test counting many views
+ *
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testCountMany()
+ {
+ $queryIds = [$this->id, 80085];
+
+ $this->assertEndpointCalled(function () use ($queryIds) {
+ $this->client->views($queryIds)->count();
+ }, 'views/count_many.json', 'GET', ['queryParams' => ['ids' => implode(',', $queryIds)]]);
+ }
+
+ /**
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testExport()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->views($this->id)->export();
+ }, "views/{$this->id}/export.json", 'GET');
+ }
+
+ /**
+ * Test previewing of views
+ */
+ public function testPreview()
+ {
+ $postFields = [
+ 'all' => [
+ [
+ 'operator' => 'is',
+ 'value' => 'open',
+ 'field' => 'status'
+ ]
+ ],
+ 'output' => [
+ 'columns' => ['subject']
+ ]
+ ];
+
+ $this->assertEndpointCalled(function () use ($postFields) {
+ $this->client->views()->preview($postFields);
+ }, 'views/preview.json', 'POST', ['postFields' => ['view' => $postFields]]);
+ }
+
+ /**
+ * Test getting the count of a view preview
+ */
+ public function testPreviewCount()
+ {
+ $postFields = [
+ 'all' => [
+ [
+ 'operator' => 'is',
+ 'value' => 'open',
+ 'field' => 'status'
+ ]
+ ],
+ 'output' => [
+ 'columns' => ['subject']
+ ]
+ ];
+
+ $this->assertEndpointCalled(function () use ($postFields) {
+ $this->client->views()->previewCount($postFields);
+ }, 'views/preview/count.json', 'POST', ['postFields' => ['view' => $postFields]]);
+ }
+
+ /**
+ * @throws \Zendesk\API\Exceptions\MissingParametersException
+ */
+ public function testGetTickets()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->views($this->id)->tickets();
+ }, "views/{$this->id}/tickets.json");
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/GroupMembershipsTest.php b/tests/Zendesk/API/UnitTests/GroupMembershipsTest.php
deleted file mode 100644
index 3394d1dd..00000000
--- a/tests/Zendesk/API/UnitTests/GroupMembershipsTest.php
+++ /dev/null
@@ -1,125 +0,0 @@
-user_id = 123456;
- $membership_mock_object->group_id = 123456;
- $membership_mock_object->id = 123456;
-
- // Create Group Membership Mock Object for Find/Create/MakeDefault Method
- $find_membership_mock_object = new \stdClass();
- $find_membership_mock_object->group_membership = $membership_mock_object;
-
- // Create Group Memberships Mock Object
- $memberships_mock_object = new \stdClass();
- $memberships_mock_object->group_memberships = Array($membership_mock_object);
-
- // Set Variables that will be used in tests
- $this->mock = $this->getMock('GroupMemberships', array('findAll', 'find', 'create', 'delete', 'makeDefault'));
- $this->group_memberships = $memberships_mock_object;
- $this->group_membership = $membership_mock_object;
- $this->find_membership = $find_membership_mock_object;
- }
-
- public function testFindAll()
- {
- // Test for FindAll Method - optionally accepts User_id, Group_id, or assignable as parameter
- $this->mock->expects($this->any())->method('findAll')->withConsecutive(array(), array($this->greaterThan(0)),
- array($this->greaterThan(0)),
- array($this->arrayHasKey('assignable')))->will($this->returnValue($this->group_memberships));
-
- // Run Test with No parameter
- $groupMemberships = $this->mock->findAll();
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
-
- // Run Test with User ID parameter set
- $groupMemberships = $this->mock->findAll($this->group_membership->user_id);
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
-
- // Run Test with Group ID parameter set
- $groupMemberships = $this->mock->findAll($this->group_membership->group_id);
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
-
- // Run Test with Assignable parameter set
- $groupMemberships = $this->mock->findAll(array("assignable" => true));
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
- }
-
- public function testFind()
- {
- // Test for Find Method
- $this->mock->expects($this->any())->method('find')->with($this->greaterThan(0))->will($this->returnValue($this->find_membership));
-
- $groupMembership = $this->mock->find($this->find_membership->group_membership->id);
- $this->assertEquals(is_object($groupMembership), true, 'Should return an object');
- $this->assertEquals(is_object($groupMembership->group_membership), true,
- 'Should return an object containing an object called "group_membership"');
- $this->assertGreaterThan(0, $groupMembership->group_membership->id, 'Returns a non-numeric id for group');
- }
-
- public function create()
- {
- // Test for Create Method
- $this->mock->expects($this->any())->method('create')->with($this->greaterThan(0),
- $this->greaterThan(0))->will($this->returnValue($this->group_membership));
-
- $groupMembership = $this->mock->create($this->group_membership->user_id, $this->group_membership->group_id);
- $this->assertEquals(is_object($groupMembership), true, 'Should return an object');
- $this->assertEquals(is_object($groupMembership->group_membership), true,
- 'Should return an object called "group_membership"');
- $this->assertGreaterThan(0, $groupMembership->group_membership->id,
- 'Returns a non-numeric id for group_membership');
- }
-
- public function testDelete()
- {
- // Test for Delete Method
- $this->mock->expects($this->any())->method('delete')->with($this->greaterThan(0))->will($this->returnValue(null));
-
- $groupMembership = $this->mock->delete($this->group_membership->id);
- $this->assertEquals(null, $groupMembership, 'Does not return a null object');
- }
-
- public function testMakeDefault()
- {
- // Test for MakeDefault Method
- $this->mock->expects($this->any())->method('makeDefault')->with($this->greaterThan(0),
- $this->greaterThan(0))->will($this->returnValue($this->group_memberships));
-
- $groupMemberships = $this->mock->makeDefault($this->group_membership->user_id, $this->group_membership->id);
- $this->assertEquals(is_object($groupMemberships), true, 'Should return an object');
- $this->assertEquals(is_array($groupMemberships->group_memberships), true,
- 'Should return an object containing an array called "group_memberships"');
- $this->assertGreaterThan(0, $groupMemberships->group_memberships[0]->id,
- 'Returns a non-numeric id for groups[0]');
- }
-}
diff --git a/tests/Zendesk/API/UnitTests/GroupsTest.php b/tests/Zendesk/API/UnitTests/GroupsTest.php
deleted file mode 100644
index e5e6834e..00000000
--- a/tests/Zendesk/API/UnitTests/GroupsTest.php
+++ /dev/null
@@ -1,92 +0,0 @@
-group = new \stdClass();
- $group_mock_object->group->name = 'New Group';
- $group_mock_object->group->id = 123456;
-
- // Set Variables that will be used in other tests
- $this->mock = $this->getMock('Groups', array('create', 'findAll', 'find', 'update', 'delete'));
- $this->group = $group_mock_object;
- }
-
- public function create()
- {
- // Test for Create Method
- $this->mock->expects($this->any())->method('create')->will($this->returnValue($this->returnArgument(0)));
- $group = $this->mock->create($this->group);
-
- $this->assertEquals(is_object($group), true, 'Should return an object');
- $this->assertEquals(is_object($group->group), true, 'Should return an object called "group"');
- $this->assertGreaterThan(0, $group->group->id, 'Returns a non-numeric id for group');
- $this->assertEquals($group->group->name, 'New Group', 'Name of test group does not match');
- }
-
- public function testAll()
- {
- // Test for FindAll Method
- $this->mock->expects($this->any())->method('findAll')->will($this->returnValue($this->group));
- $groups = $this->mock->findAll();
-
- $this->assertEquals(is_object($groups), true, 'Should return an object');
- $this->assertEquals(is_object($groups->group), true, 'Should return an object called "group"');
- $this->assertGreaterThan(0, $groups->group->id, 'Returns a non-numeric id for groups[0]');
- }
-
- public function testAssignable()
- {
- // Test for FindAll Method with 'assignable' parameter
- $this->mock->expects($this->any())->method('findAll')->will($this->returnValue($this->group));
- $groups = $this->mock->findAll(array('assignable' => true));
-
- $this->assertEquals(is_object($groups), true, 'Should return an object');
- $this->assertEquals(is_object($groups->group), true,
- 'Should return an object containing an array called "groups"');
- $this->assertGreaterThan(0, $groups->group->id, 'Returns a non-numeric id for groups[0]');
- }
-
- public function testFind()
- {
- // Test for Find Method
- $this->mock->expects($this->any())->method('find')->will($this->returnValue($this->group));
- $group = $this->mock->find($this->group->group->id);
-
- $this->assertEquals(is_object($group), true, 'Should return an object');
- $this->assertGreaterThan(0, $group->group->id, 'Returns a non-numeric id for group');
- }
-
- public function testUpdate()
- {
- // Test for Update Method
- $this->mock->expects($this->any())->method('update')->will($this->returnArgument(0));
- $this->group->group->name = "New Group II";
- $group = $this->mock->update($this->group);
-
- $this->assertEquals(is_object($group), true, 'Should return an object');
- $this->assertEquals(is_object($group->group), true, 'Should return an object called "group"');
- $this->assertGreaterThan(0, $group->group->id, 'Returns a non-numeric id for group');
- $this->assertEquals($group->group->name, 'New Group II', 'Name of test group does not match');
- }
-
- public function tearDown()
- {
- // Test for Delete Method
- $this->mock->expects($this->any())->method('delete')->will($this->returnValue(null));
- $group = $this->mock->delete($this->group->group->id);
-
- $this->assertEquals(null, $group, 'Does not return a null object');
- }
-}
diff --git a/tests/Zendesk/API/UnitTests/HelpCenter/CategoriesTest.php b/tests/Zendesk/API/UnitTests/HelpCenter/CategoriesTest.php
new file mode 100644
index 00000000..928f32a9
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/HelpCenter/CategoriesTest.php
@@ -0,0 +1,71 @@
+client->helpCenter->categories();
+ $categoriesResource->setLocale('en-US');
+
+ $this->assertEndpointCalled(function () use ($categoriesResource) {
+ $categoriesResource->findAll();
+ }, 'help_center/en-US/categories.json');
+
+ $this->assertEndpointCalled(function () use ($categoriesResource) {
+ $categoriesResource->find(1);
+ }, 'help_center/en-US/categories/1.json');
+
+ $postFields = [
+ 'position' => 2,
+ 'locale' => 'en-us',
+ 'name' => 'Super Hero Tricks',
+ 'description' => 'This category contains a collection of super hero tricks',
+ ];
+
+ $this->assertEndpointCalled(function () use ($categoriesResource, $postFields) {
+ $categoriesResource->create($postFields);
+ }, 'help_center/en-US/categories.json', 'POST', ['postFields' => ['category' => $postFields]]);
+
+ $this->assertEndpointCalled(function () use ($categoriesResource, $postFields) {
+ $categoriesResource->update(1, $postFields);
+ }, 'help_center/en-US/categories/1.json', 'PUT', ['postFields' => ['category' => $postFields]]);
+ }
+
+ /**
+ * Tests if the route can be generated
+ */
+ public function testRouteWithoutLocale()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->helpCenter->categories()->findAll();
+ }, 'help_center/categories.json');
+ }
+
+ /**
+ * Tests if the Update category source locale endpoint can be called and passed the correct params
+ */
+ public function testUpdateCategorySourceLocale()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->helpCenter->categories()->updateSourceLocale(1, 'fr');
+ }, 'help_center/categories/1/source_locale.json', 'PUT', ['postFields' => ['category_locale' => 'fr']]);
+ }
+
+ /**
+ * Tests if the Update category source locale endpoint can be called and passed the correct params
+ */
+ public function testUpdateCategorySourceLocaleNoId()
+ {
+ $this->assertEndpointCalled(function () {
+ $this->client->helpCenter->categories(1)->updateSourceLocale(null, 'fr');
+ }, 'help_center/categories/1/source_locale.json', 'PUT', ['postFields' => ['category_locale' => 'fr']]);
+ }
+}
diff --git a/tests/Zendesk/API/UnitTests/HttpTest.php b/tests/Zendesk/API/UnitTests/HttpTest.php
deleted file mode 100644
index 21599f75..00000000
--- a/tests/Zendesk/API/UnitTests/HttpTest.php
+++ /dev/null
@@ -1,157 +0,0 @@
-client, 'tickets.json');
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json') . '?',
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'GET', 'Should be a GET');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testGetRequestWithQuery()
- {
- $response = Http::send($this->client, 'tickets.json', ['check' => 1]);
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL},
- $this->client->getApiUrl() . Http::prepare('tickets.json') . '?check=1', 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'GET', 'Should be a GET');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testGetRequestWithContentType()
- {
- $response = Http::send($this->client, 'tickets.json', [], 'GET', 'application/x-www-form-urlencoded');
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json') . '?',
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'GET', 'Should be a GET');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/x-www-form-urlencoded', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testPostRequest()
- {
- $response = Http::send($this->client, 'tickets.json', [], 'POST');
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'),
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_POST}, true, 'Should be a POST');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testPostRequestWithData()
- {
- $response = Http::send($this->client, 'tickets.json', ['check' => 1], 'POST');
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'),
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_POST}, true, 'Should be a POST');
- $this->assertEquals($response->{CURLOPT_POSTFIELDS}, '{"check":1}', 'Should have POST data');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testPostRequestWithContentType()
- {
- $response = Http::send($this->client, 'tickets.json', ['check' => 1], 'POST',
- 'application/x-www-form-urlencoded');
-
- $data = new \StdClass;
- $data->check = 1;
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'),
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_POST}, true, 'Should be a POST');
- $this->assertEquals($response->{CURLOPT_POSTFIELDS}, $data, 'Should have POST data');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/x-www-form-urlencoded', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testPutRequest()
- {
- $response = Http::send($this->client, 'tickets.json', [], 'PUT');
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'),
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'PUT', 'Should be a PUT');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testPutRequestWithData()
- {
- $response = Http::send($this->client, 'tickets.json', ['check' => 1], 'PUT');
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'),
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'PUT', 'Should be a PUT');
- $this->assertEquals($response->{CURLOPT_POSTFIELDS}, '{"check":1}', 'Should have PUT data');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-
- public function testPutRequestWithContentType()
- {
- $response = Http::send($this->client, 'tickets.json', ['check' => 1], 'PUT',
- 'application/x-www-form-urlencoded');
-
- $data = new \StdClass;
- $data->check = 1;
-
- $this->assertEquals(is_object($response), true, 'Should return an object');
- $this->assertEquals($response->{CURLOPT_URL}, $this->client->getApiUrl() . Http::prepare('tickets.json'),
- 'Should be the correct url');
- $this->assertEquals($response->{CURLOPT_CUSTOMREQUEST}, 'PUT', 'Should be a PUT');
- $this->assertEquals($response->{CURLOPT_POSTFIELDS}, $data, 'Should have POST data');
- $this->assertContains('Accept: application/json', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Accept header');
- $this->assertContains('Content-Type: application/x-www-form-urlencoded', $response->{CURLOPT_HTTPHEADER},
- 'Should contain a Content-Type header');
- }
-}
diff --git a/tests/Zendesk/API/UnitTests/MockCurlRequest.php b/tests/Zendesk/API/UnitTests/MockCurlRequest.php
deleted file mode 100644
index 268a37e1..00000000
--- a/tests/Zendesk/API/UnitTests/MockCurlRequest.php
+++ /dev/null
@@ -1,204 +0,0 @@
-constants[constant($k)] = $k;
- }
- $this->handle = curl_init($url);
- }
-
- public function close()
- {
- return curl_close($this->handle);
- }
-
- public function copy_handle()
- {
- return curl_copy_handle($this->handle);
- }
-
- public function errno()
- {
- return curl_errno($this->handle);
- }
-
- public function error()
- {
- return curl_error($this->handle);
- }
-
- public function escape($str)
- {
- return curl_escape($this->handle, $str);
- }
-
- public function exec()
- {
- return json_encode($this->getopt_array());
- }
-
- public function file_create($filename, $mimetype = null, $postname = null)
- {
- return curl_file_create($filename, $mimetype, $postname);
- }
-
- public function getinfo($opt = 0)
- {
- return curl_getinfo($this->handle, $opt);
- }
-
- public function pause($bitmask)
- {
- return curl_pause($this->handle, $bitmask);
- }
-
- public function reset()
- {
- return curl_reset($this->handle);
- }
-
- public function setopt_array($options)
- {
- $this->options = $options;
-
- return curl_setopt_array($this->handle, $options);
- }
-
- public function setopt($option, $value)
- {
- //$this->options[ (isset($this->constants[$option]) ? $this->constants[$option] : $option) ] = $value;
- $this->options[$option] = $value;
-
- return curl_setopt($this->handle, $option, $value);
- }
-
- public function getopt_array()
- {
- return $this->options;
- }
-
- public function strerror($errornum)
- {
- return curl_strerror($errornum);
- }
-
- public function unescape($str)
- {
- return curl_unescape($this->handle, $str);
- }
-
- public function version($age = CURLVERSION_NOW)
- {
- return curl_version($age);
- }
-}
diff --git a/tests/Zendesk/API/UnitTests/OrganizationsTest.php b/tests/Zendesk/API/UnitTests/OrganizationsTest.php
deleted file mode 100644
index 511e3e1f..00000000
--- a/tests/Zendesk/API/UnitTests/OrganizationsTest.php
+++ /dev/null
@@ -1,195 +0,0 @@
-organization = new \stdClass();
- $organization_mock_object->organization->name = 'New Organization';
- $organization_mock_object->organization->id = 123456;
- $organization_mock_object->organization_related = new \stdClass();
- $organization_mock_object->job_status = new \stdClass();
- $organization_mock_object->job_status->id = 123456;
- $organization_mock_object->organizations = Array(
- $organization_mock_object->organization,
- clone $organization_mock_object->organization
- );
-
- // Set Variables that will be used in other tests
- $this->mock = $this->getMock('Organizations',
- array('findAll', 'find', 'create', 'createMany', 'update', 'delete', 'autocomplete', 'related', 'search'));
- $this->organizations = $organization_mock_object;
- }
-
- public function testFindAll()
- {
- // Test for FindAll Method - optionally accepts User_id as parameter
- $this->mock->expects($this->any())
- ->method('findAll')
- ->withConsecutive(array(), array($this->greaterThan(0)))
- ->will($this->returnValue($this->organizations));
-
- // Run Test with No parameter
- $organizations = $this->mock->findAll();
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertGreaterThan(0, $organizations->organizations[0]->id,
- 'Returns a non-numeric id for organizations[0]');
-
- // Run Test with User ID parameter
- $organizations = $this->mock->findAll(123456);
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertGreaterThan(0, $organizations->organizations[0]->id,
- 'Returns a non-numeric id for organizations[0]');
- }
-
- public function testFind()
- {
- // Test for Find Method - requires an Organization ID as parameter
- $this->mock->expects($this->any())
- ->method('find')
- ->with($this->greaterThan(0))
- ->will($this->returnValue($this->organizations));
-
- // Run Test with Organization ID parameter
- $organization = $this->mock->find(123456);
- $this->assertEquals(is_object($organization), true, 'Should return an object');
- $this->assertEquals(is_object($organization->organization), true,
- 'Should return an object containing an object called "organization"');
- $this->assertGreaterThan(0, $organization->organization->id, 'Returns a non-numeric id for organization');
- }
-
- public function testCreate()
- {
- // Test for Create Method - requires an Organization Name as parameter
- $this->mock->expects($this->any())
- ->method('create')
- ->with($this->isType('string'))
- ->will($this->returnCallback(function ($name) {
- $this->organizations->organization->name = $name;
-
- return $this->organizations;
- }));
-
- $organization = $this->mock->create('Test Organization');
- $this->assertEquals(is_object($organization), true, 'Should return an object');
- $this->assertEquals(is_object($organization->organization), true,
- 'Should return an object containing an object called "organization"');
- $this->assertGreaterThan(0, $organization->organization->id, 'Returns a non-numeric id for organization');
- $this->assertEquals($organization->organization->name, 'Test Organization',
- 'Name of test organization does not match');
-
- }
-
- public function testCreateMany()
- {
- // Test for CreateMany Method - requires an Organization Name as parameter and should return a job status rather than an Organization object
- $this->mock->expects($this->any())
- ->method('createMany')
- ->with($this->isType('string'), $this->isType('string'))
- ->will($this->returnValue($this->organizations));
-
- $organizations = $this->mock->createMany('Organization I', 'Organization II');
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_object($organizations->job_status), true,
- 'Should return an object containing an object called job_status"');
- $this->assertGreaterThan(0, $organizations->job_status->id,
- 'Should return a non-numeric id for job status object');
- }
-
- public function testUpdate()
- {
- // Test for Update Method - requires an Organization ID and another value as parameters
- // Create a clone of the original object to ensure that the change results in a different object than the original
- $this->mock->expects($this->any())
- ->method('update')
- ->with($this->greaterThan(0), $this->isType('string'))
- ->will($this->returnCallback(function ($name) {
- $update_organization = clone $this->organizations->organization;
- $update_organization->name = $name;
-
- return $update_organization;
- }));
-
- $organization = $this->mock->update(123456, "Test Organization II");
- $this->assertEquals(is_object($organization), true, 'Should return an object');
- $this->assertEquals(is_object($organization), true,
- 'Should return an object containing an object called "organization"');
- $this->assertGreaterThan(0, $organization->id, 'Returns a non-numeric id for organization');
- $this->assertNotEquals($this->organizations->organization, $organization,
- 'Should return an organization that is not the same as the original');
- }
-
- public function testDelete()
- {
- // Test for Delete Method - requires an Organization ID as parameter
- $this->mock->expects($this->any())
- ->method('delete')
- ->with($this->greaterThan(0))
- ->will($this->returnValue(null));
-
- $organization = $this->mock->delete(123456);
- $this->assertEquals(null, $organization, 'Does not return a null object');
- }
-
- public function testAutocomplete()
- {
- // Test for Autocomplete Method - requires a partial Organization Name as parameter
- $this->mock->expects($this->any())
- ->method('autocomplete')
- ->with($this->isType('string'))
- ->will($this->returnValue($this->organizations));
-
- $organizations = $this->mock->autocomplete('New');
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertGreaterThan(0, $organizations->organizations[0]->id, 'Returns a non-numeric id for organization');
- $this->assertContains('New', $organizations->organizations[0]->name,
- 'Should return an string that contains the search term for organization name');
- }
-
- public function testRelated()
- {
- // Test for Related Method - requires an Organization ID as parameter
- $this->mock->expects($this->any())
- ->method('related')
- ->with($this->greaterThan(0))
- ->will($this->returnValue($this->organizations));
-
- $organization_related = $this->mock->related(123456);
- $this->assertEquals(is_object($organization_related), true, 'Should return an object');
- $this->assertEquals(is_object($organization_related->organization_related), true,
- 'Should return an object containing an object called "organization_related"');
- }
-
- public function testSearch()
- {
- // Test for Search Method - requires an Organization External ID as parameter
- $this->mock->expects($this->any())
- ->method('search')
- ->with($this->isType('string'))
- ->will($this->returnValue($this->organizations));
-
- $organizations = $this->mock->search('12ef');
- $this->assertEquals(is_object($organizations), true, 'Should return an object');
- $this->assertEquals(is_array($organizations->organizations), true,
- 'Should return an object containing an array called "organizations"');
- $this->assertGreaterThan(0, $organizations->organizations[0]->id,
- 'Returns a non-numeric id for organizations[0]');
- }
-
-}
diff --git a/tests/Zendesk/API/UnitTests/Voice/PhoneNumbersTest.php b/tests/Zendesk/API/UnitTests/Voice/PhoneNumbersTest.php
new file mode 100644
index 00000000..0ca21f04
--- /dev/null
+++ b/tests/Zendesk/API/UnitTests/Voice/PhoneNumbersTest.php
@@ -0,0 +1,25 @@
+ 'US',
+ 'area_code' => 410,
+ 'contains' => 'pizza',
+ 'toll_free' => 1,
+ ];
+
+ $this->assertEndpointCalled(function () use ($queryParams) {
+ $this->client->voice->phoneNumbers()->search($queryParams);
+ }, 'channels/voice/phone_numbers/search.json', 'GET', ['queryParams' => $queryParams]);
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 55a14d5f..fc3e16c5 100755
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,6 +1,6 @@