1
|
|
|
<?php |
2
|
|
|
namespace Datatrics\API\Modules; |
3
|
|
|
|
4
|
|
View Code Duplication |
class Template extends Base |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
/** |
7
|
|
|
* Private constructor so only the client can create this |
8
|
|
|
* @param string $apikey |
9
|
|
|
* @param string $projectid |
10
|
|
|
*/ |
11
|
|
|
public function __construct($apikey, $projectid) |
12
|
|
|
{ |
13
|
|
|
parent::__construct($apikey, "/project/" . $projectid . "/template"); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Get one or multiple templates |
18
|
|
|
* @param string template id, leave null for list of boxes |
19
|
|
|
* @param object Containing query arguments |
20
|
|
|
* @return object Result of the request |
21
|
|
|
*/ |
22
|
|
|
public function Get($templateId = null, $args = array("limit" => 50)) |
23
|
|
|
{ |
24
|
|
|
return $templateId == null ? $this->request(self::HTTP_GET, "?".http_build_query($args)) : $this->request(self::HTTP_GET, "/".$templateId."?".http_build_query($args)); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create new template |
29
|
|
|
* @param object Containing all the information of a template |
30
|
|
|
* @return object Result of the request |
31
|
|
|
*/ |
32
|
|
|
public function Create($template) |
33
|
|
|
{ |
34
|
|
|
return $this->request(self::HTTP_POST, "", $template); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Create new template |
39
|
|
|
* @param id of the template |
40
|
|
|
* @param object Containing all the information of a template |
41
|
|
|
* @return object Result of the request |
42
|
|
|
*/ |
43
|
|
|
public function Update($templateId, $template) |
44
|
|
|
{ |
45
|
|
|
return $this->request(self::HTTP_PUT, "/".$templateId, $template); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Delete a template object by template id |
50
|
|
|
* @param string Id of the template |
51
|
|
|
* @return object Result of the request |
52
|
|
|
*/ |
53
|
|
|
public function Delete($templateId) |
54
|
|
|
{ |
55
|
|
|
return $this->request(self::HTTP_DELETE, "/".$templateId); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
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.