forked from SeunMatt/fstackapi_php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSForm.php
More file actions
94 lines (80 loc) · 2.93 KB
/
FSForm.php
File metadata and controls
94 lines (80 loc) · 2.93 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Created by PhpStorm.
* User: smatt
* Date: 23/06/2017
* Time: 11:09 AM
*/
namespace FormStack;
class FSForm extends FSClient {
public function __construct($token = null, $baseUrl = null, $xmlResponseType = false) {
parent::__construct($token, $baseUrl, $xmlResponseType);
}
/*
* Returns all the forms available for the authenticated user
* */
public function all() {
$uri = "form";
$response = $this->client->get($uri);
return json_decode($response->getBody(), true);
}
/*
* Get details of a particular form
* @param $id of the existing form
* @return assoc array of API response
* */
public function get($id) {
if(is_null($id) || strlen($id) <= 0) {
throw new FSException("The supplied form id should not be null and empty");
}
$uri = "form/".$id;
$response = $this->client->get($uri);
return json_decode($response->getBody(), true);
}
/*
* creates a new form
* @param $param: an assoc array of params.
* Check https://developers.formstack.com/docs/form-post for more info
* Note: the param should at least have a name
* @return assoc array of API response
* */
public function create($param) {
if(!array_key_exists("name", $param) || is_null($param['name']) ) {
throw new FSException("The supplied param assoc array must have a 'name' entry with a non-null key");
}
$uri = "form";
$response = $this->client->post($uri, ["json" => $param]);
return json_decode($response->getBody(), true);
}
/*
* update the details of an existing form. Like the number of columns and others details. See more at
* https://developers.formstack.com/docs/form-id-put
* @param $id of the form to be updated
* @param $param - an assoc array of the form properties
* @return assoc array of API response
* */
public function update($id, $param) {
if(!array_key_exists("name", $param) || is_null($param['name']) ) {
throw new FSException("The supplied param assoc array must have a 'name' entry with a non-null key");
}
if(is_null($id) || strlen($id) <= 0) {
throw new FSException("The supplied form id should not be null and empty");
}
$uri = "form/".$id;
$response = $this->client->put($uri, ["json" => $param]);
return json_decode($response->getBody(), true);
}
/*
* Delete a particular form on FormStack
* @param $id of the form to be deleted
* @return assoc array of API response
* */
public function delete($id){
if(is_null($id) || strlen($id) <= 0) {
throw new FSException("The supplied form id should not be null and empty");
}
$uri = "form/".$id;
$response = $this->client->delete($uri);
return json_decode($response->getBody(), true);
}
}