1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Guapa\TimeChimp; |
4
|
|
|
|
5
|
|
|
class CustomersRequest extends AbstractRequest |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Get all customers. |
9
|
|
|
* |
10
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customers/get-all-customers |
11
|
|
|
* |
12
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
13
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
14
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
15
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
16
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
17
|
|
|
*/ |
18
|
|
|
public function getAll(): \Psr\Http\Message\ResponseInterface |
19
|
|
|
{ |
20
|
|
|
return $this->execute('get', 'customers'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Update a customer. |
25
|
|
|
* |
26
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customers/update-customer |
27
|
|
|
* |
28
|
|
|
* @param array $parameters |
29
|
|
|
* |
30
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
31
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
32
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
33
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
34
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
35
|
|
|
*/ |
36
|
|
|
public function update(array $parameters): \Psr\Http\Message\ResponseInterface |
37
|
|
|
{ |
38
|
|
|
if (! isset($parameters['json'])) { |
39
|
|
|
$parameters = [ |
40
|
|
|
'json' => $parameters, |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->execute('put', 'customers', $parameters); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a customer. |
49
|
|
|
* |
50
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customers/create-new-customer |
51
|
|
|
* |
52
|
|
|
* @param array $parameters |
53
|
|
|
* |
54
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
55
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
56
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
57
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
58
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
59
|
|
|
*/ |
60
|
|
|
public function create(array $parameters): \Psr\Http\Message\ResponseInterface |
61
|
|
|
{ |
62
|
|
|
if (! isset($parameters['json'])) { |
63
|
|
|
$parameters = [ |
64
|
|
|
'json' => $parameters, |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this->execute('post', 'customers', $parameters); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get a customer by relation id. |
73
|
|
|
* |
74
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customersrelationidrelationid/get-customer-by-relation-id |
75
|
|
|
* |
76
|
|
|
* @param mixed $id |
77
|
|
|
* |
78
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
79
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
80
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
81
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
82
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
83
|
|
|
*/ |
84
|
|
|
public function getByRelationId($id): \Psr\Http\Message\ResponseInterface |
85
|
|
|
{ |
86
|
|
|
return $this->execute('get', "customers/relationid/{$id}"); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Get a customer by name. |
91
|
|
|
* |
92
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customersnamename/get-customer-by-name |
93
|
|
|
* |
94
|
|
|
* @param string $name |
95
|
|
|
* |
96
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
97
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
98
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
99
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
100
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
101
|
|
|
*/ |
102
|
|
|
public function getByName(string $name): \Psr\Http\Message\ResponseInterface |
103
|
|
|
{ |
104
|
|
|
return $this->execute('get', "customers/name/{$name}"); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Get a customer. |
109
|
|
|
* |
110
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customersid/get-customer |
111
|
|
|
* |
112
|
|
|
* @param mixed $id |
113
|
|
|
* |
114
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
115
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
116
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
117
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
118
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
119
|
|
|
*/ |
120
|
|
|
public function get($id): \Psr\Http\Message\ResponseInterface |
121
|
|
|
{ |
122
|
|
|
return $this->execute('get', "customers/{$id}"); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Delete a customer. |
127
|
|
|
* |
128
|
|
|
* @see https://timechimp.docs.apiary.io/#reference/customers/v1customersid/delete-customer |
129
|
|
|
* |
130
|
|
|
* @param mixed $id |
131
|
|
|
* |
132
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
133
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\ClientException |
134
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\NotFoundException |
135
|
|
|
* @throws \Guapa\TimeChimp\Exceptions\UnauthorizedException |
136
|
|
|
* @throws \GuzzleHttp\Exception\GuzzleException |
137
|
|
|
*/ |
138
|
|
|
public function delete($id) |
139
|
|
|
{ |
140
|
|
|
return $this->execute('delete', "customers/{$id}"); |
141
|
|
|
} |
142
|
|
|
} |