1: <?php
2:
3: namespace Crowdsdom\Labor\Models;
4:
5: use Crowdsdom\Client\Client;
6: use GuzzleHttp\Psr7\Response;
7:
8: abstract class Model
9: {
10: const ENDPOINT = "";
11:
12: /**
13: * @var Client
14: */
15: protected $client;
16:
17: /**
18: * @var Response
19: */
20: protected $response;
21:
22: /**
23: * @return Response
24: */
25: public function getResponse()
26: {
27: return $this->response;
28: }
29:
30: /**
31: * Model constructor.
32: * @param Client $client
33: */
34: public function __construct(Client $client)
35: {
36: $this->client = $client;
37: }
38:
39: /**
40: * @param array $data
41: * @return array|null
42: */
43: public function create(array $data)
44: {
45: $this->response = $this->client->getGuzzle()->request('POST', static::ENDPOINT, [
46: 'json' => $data
47: ]);
48: return json_decode($this->response->getBody()->getContents(), true);
49: }
50:
51: /**
52: * @return array|null
53: * @throws \RuntimeException
54: */
55: public function find()
56: {
57: $this->response = $this->client->getGuzzle()->request('GET', static::ENDPOINT);
58: return json_decode($this->response->getBody()->getContents(), true);
59: }
60:
61: /**
62: * @param string $id
63: * @return array|null
64: * @throws \RuntimeException
65: */
66: public function findById($id)
67: {
68: $this->response = $this->client->getGuzzle()->request('GET', static::ENDPOINT . "/$id");
69: return json_decode($this->response->getBody()->getContents(), true);
70: }
71: }
72: