Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Expose organization createOrUpdate method #522

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Zendesk/API/Resources/Core/Organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Zendesk\API\Resources\ResourceAbstract;
use Zendesk\API\Traits\Resource\CreateMany;
use Zendesk\API\Traits\Resource\CreateOrUpdate;
use Zendesk\API\Traits\Resource\Defaults;
use Zendesk\API\Traits\Resource\DeleteMany;
use Zendesk\API\Traits\Resource\FindMany;
Expand All @@ -25,6 +26,7 @@ class Organizations extends ResourceAbstract
use Defaults;

use CreateMany;
use CreateOrUpdate;
use DeleteMany;
use FindMany;
use UpdateMany;
Expand Down
41 changes: 41 additions & 0 deletions src/Zendesk/API/Traits/Resource/CreateOrUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Zendesk\API\Traits\Resource;

use Zendesk\API\Exceptions\RouteException;

/**
* Allows resources to call a createOrUpdate endpoint.
*/
trait CreateOrUpdate
{

/**
* Update resource
*
* @param array $params
*
* @return \stdClass | null
*/
public function createOrUpdate(array $params)
{
try {
$route = $this->getRoute(__FUNCTION__, $params);
} catch (RouteException $e) {
if (! isset($this->resourceName)) {
$this->resourceName = $this->getResourceNameFromClass();
}

$route = $this->resourceName . '/create_or_update.json';
$this->setRoute(__FUNCTION__, $route);
}


$response = $this->client->post(
$route,
[$this->objectName => $params]
);

return $response;
}
}