|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Streak\Endpoint; |
|
4
|
|
|
|
|
5
|
|
|
class Field extends PipelineEndpoint |
|
6
|
|
|
{ |
|
7
|
|
|
const ENDPOINT = 'fields'; |
|
8
|
|
|
|
|
9
|
|
|
const TYPE_TEXT = 'TEXT_INPUT'; |
|
10
|
|
|
const TYPE_PERSON = 'PERSON'; |
|
11
|
|
|
const TYPE_DATE = 'DATE'; |
|
12
|
|
|
|
|
13
|
|
|
public function findAll() |
|
14
|
|
|
{ |
|
15
|
|
|
return $this->client->get(sprintf('pipelines/%s/%s', $this->pipelineKey, self::ENDPOINT)); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function find($fieldKey) |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->client->get(sprintf('pipelines/%s/%s/%s', $this->pipelineKey, self::ENDPOINT, $fieldKey)); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function create($name, $type) |
|
24
|
|
|
{ |
|
25
|
|
|
if (!in_array($type, [self::TYPE_TEXT, self::TYPE_PERSON, self::TYPE_DATE])) { |
|
26
|
|
|
throw new \InvalidArgumentException('Invalid Field type.'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
return $this->client->put(sprintf('pipelines/%s/%s', $this->pipelineKey, self::ENDPOINT), [ |
|
30
|
|
|
'form_params' => [ |
|
31
|
|
|
'name' => $name, |
|
32
|
|
|
'type' => $type, |
|
33
|
|
|
], |
|
34
|
|
|
]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function delete($fieldKey) |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->client->delete(sprintf('pipelines/%s/%s/%s', $this->pipelineKey, self::ENDPOINT, $fieldKey)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function edit($fieldKey, $name) |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->client->post(sprintf('pipelines/%s/%s/%s', $this->pipelineKey, self::ENDPOINT, $fieldKey), [ |
|
45
|
|
|
'json' => [ |
|
46
|
|
|
'name' => $name, |
|
47
|
|
|
], |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function values($boxKey) |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->client->get(sprintf('boxes/%s/%s', $boxKey, self::ENDPOINT)); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getValue($boxKey, $fieldKey) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->client->get(sprintf('boxes/%s/%s/%s', $boxKey, self::ENDPOINT, $fieldKey)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function setValue($boxKey, $fieldKey, $value) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->client->post(sprintf('boxes/%s/%s/%s', $boxKey, self::ENDPOINT, $fieldKey), [ |
|
64
|
|
|
'json' => [ |
|
65
|
|
|
'value' => $value, |
|
66
|
|
|
], |
|
67
|
|
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|