mirovit/ionic-platform-sdk

View on GitHub
src/Endpoints/Traits/CreatesResource.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Mirovit\IonicPlatformSDK\Endpoints\Traits;

use Mirovit\IonicPlatformSDK\Exceptions\MissingArgumentException;
use Mirovit\IonicPlatformSDK\Response\Response;

trait CreatesResource
{
    /**
     * @param array $data
     * @throws MissingArgumentException
     */
    abstract protected function validateCreate(array $data);

    /**
     * Creates a new resource.
     *
     * @param array $data
     * @return Response
     */
    public function create(array $data)
    {
        $this->validateCreate($data);

        $response = $this->client->post($this->getEndpoint(), [
            'body' => json_encode($data),
        ]);

        return $this->toResponse($response);
    }
}