forked from SeunMatt/fstackapi_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSField.php
More file actions
77 lines (65 loc) · 2.2 KB
/
FSField.php
File metadata and controls
77 lines (65 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Created by PhpStorm.
* User: smatt
* Date: 26/06/2017
* Time: 01:51 PM
*/
namespace FormStack;
use FSExceptions\FSException;
class FSField extends FSClient {
public function __construct($token = null, $baseUrl = null, $xmlResponseType = false) {
parent::__construct($token, $baseUrl, $xmlResponseType);
}
/*
* Get all the fields of a form
* */
public function all($formId) {
$this->validateId($formId);
$uri = "form/".$formId."/field";
$response = $this->client->get($uri);
return json_decode($response->getBody(), true);
}
/*
* Get the details of a particular field
* */
public function get($fieldId) {
$this->validateId($fieldId);
$uri = "field/".$fieldId;
$response = $this->client->get($uri);
return json_decode($response->getBody(), true);
}
/*
* This will create new field
* */
public function newField($formId, $param) {
$this->validateId($formId);
if(is_null($param) || !array_key_exists("field_type", $param) || !array_key_exists("label", $param)) {
throw new FSException("The param supplied is missing required fields: 'field_type', 'label' ");
}
$uri = "form/".$formId."/field";
$response = $this->client->post($uri, ["json" => $param]);
return json_decode($response->getBody(), true);
}
/*
* This will update the details of a field
* */
public function update($fieldId, $param) {
$this->validateId($fieldId);
if(is_null($param) || !array_key_exists("field_type", $param) || !array_key_exists("label", $param)) {
throw new FSException("The param supplied is missing required fields: 'field_type', 'label' ");
}
$uri = "field/".$fieldId;
$response = $this->client->put($uri, ["json" => $param]);
return json_decode($response->getBody(), true);
}
/*
* This will delete the form field
* */
public function delete($fieldId) {
$this->validateId($fieldId);
$uri = "field/".$fieldId;
$response = $this->client->delete($uri);
return json_decode($response->getBody(), true);
}
}