1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace JulianoBailao\DomusApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use JulianoBailao\DomusApi\Contracts\CreationContract; |
6
|
|
|
use JulianoBailao\DomusApi\Contracts\GetContract; |
7
|
|
|
use JulianoBailao\DomusApi\Core\Endpoint; |
8
|
|
|
use JulianoBailao\DomusApi\Data\ProductData; |
9
|
|
|
|
10
|
|
|
class Products extends Endpoint implements GetContract, CreationContract |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* Get a page of products list. |
14
|
|
|
* |
15
|
|
|
* @param array $query the request query string. |
16
|
|
|
* |
17
|
|
|
* @return stdObject |
18
|
|
|
*/ |
19
|
3 |
|
public function paginate(array $query = []) |
20
|
|
|
{ |
21
|
3 |
|
return $this->page('operacional/produtos', $query); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Get a specific product. |
26
|
|
|
* |
27
|
|
|
* @param int $id the product id. |
28
|
|
|
* |
29
|
|
|
* @return stdObject |
30
|
|
|
*/ |
31
|
3 |
|
public function get($id) |
32
|
|
|
{ |
33
|
3 |
|
return $this->run('GET', 'operacional/produtos/'.$id); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Create a new product. |
38
|
|
|
* |
39
|
|
|
* @return ProductData |
40
|
|
|
*/ |
41
|
3 |
|
public function create() |
42
|
|
|
{ |
43
|
3 |
|
return new ProductData($this); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Update a existing product. |
48
|
|
|
* |
49
|
|
|
* @return ProductData |
50
|
|
|
*/ |
51
|
3 |
|
public function update($id) |
52
|
|
|
{ |
53
|
3 |
|
return new ProductData($this, $id); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Send the save request. |
58
|
|
|
* |
59
|
|
|
* @param PersonData $data |
60
|
|
|
* |
61
|
|
|
* @return stdClass |
62
|
|
|
*/ |
63
|
6 |
View Code Duplication |
public function save(ProductData $data) |
|
|
|
|
64
|
|
|
{ |
65
|
6 |
|
$id = $data->getId(); |
66
|
|
|
|
67
|
6 |
|
return $this->run( |
68
|
6 |
|
$id == null ? 'POST' : 'PUT', |
69
|
6 |
|
'operacional/produtos'.($id > 0 ? '/'.$id : null), |
70
|
6 |
|
['json' => $data->toArray()] |
71
|
6 |
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Delete a product. |
76
|
|
|
* |
77
|
|
|
* @param int $id |
78
|
|
|
* |
79
|
|
|
* @return bool |
80
|
|
|
*/ |
81
|
3 |
|
public function delete($id) |
82
|
|
|
{ |
83
|
3 |
|
return $this->run('DELETE', 'operacional/produtos/'.$id); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the product price table info. |
88
|
|
|
* |
89
|
|
|
* @return ProductPriceTable |
90
|
|
|
*/ |
91
|
|
|
public function priceTableInfo() |
92
|
|
|
{ |
93
|
|
|
return new ProductPriceTable($this->client); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.