Skip to content

Commit bcd82c1

Browse files
authored
Merge pull request #7 from basekit/section-api-fixes
New sections api endpoints, image upload endpoints, bug fixes
2 parents 89efb9a + 1e7449e commit bcd82c1

File tree

7 files changed

+195
-8
lines changed

7 files changed

+195
-8
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ $createSite = $client->getCommand(
3737
$client->execute($createSite);
3838
```
3939

40+
A more detailed example script is [available here](https://github.com/basekit/php-api-client-example) including account and site creation and populating a site with content using the API.
41+
4042
## Testing
4143

4244
Feed an optional `handler` into the config of `clientFactory` to control the responses from the http client.

service/basekit.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"plugins/blogs.json",
3939
"plugins/blogs/categories.json",
4040
"plugins/blogs/posts.json",
41-
"plugins/users/blogs.json"
41+
"plugins/users/blogs.json",
42+
"sections.json"
4243
]
4344
}

service/profiles.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"required": true,
2929
"type": "integer"
3030
}
31-
},
31+
},
3232
"summary": "Delete profile with the specified reference. The delete method must be permitted by the caller.",
3333
"uri": "/users/{userRef}/profiles/{profileRef}"
3434
},
@@ -78,8 +78,14 @@
7878
"location": "uri",
7979
"required": true,
8080
"type": "integer"
81+
},
82+
"fields": {
83+
"description": "Profile fields in name value pairs.",
84+
"location": "json",
85+
"required": true,
86+
"type": "array"
8187
}
82-
},
88+
},
8389
"summary": "Update profile data with the specified profile reference. The update method must be permitted by the caller.",
8490
"uri": "/users/{userRef}/profiles/{profileRef}"
8591
}

service/sections.json

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
{
2+
"operations": {
3+
"AddSection": {
4+
"summary": "Add a section to a given site page",
5+
"uri": "/sites/{siteRef}/pages/{pageRef}/sections",
6+
"httpMethod": "POST",
7+
"parameters": {
8+
"siteRef": {
9+
"description": "Site reference to retrieve site.",
10+
"location": "uri",
11+
"required": true,
12+
"type": "integer"
13+
},
14+
"pageRef": {
15+
"description": "Page reference for adding a new section.",
16+
"location": "uri",
17+
"required": true,
18+
"type": "integer"
19+
},
20+
"template": {
21+
"description": "ID of the row template to use eg image_text_2a",
22+
"location": "json",
23+
"required": true,
24+
"type": "string"
25+
},
26+
"siblingRef": {
27+
"description": "The sectionRef of the section that the new section is to be positioned relative to. If blank the new section will be added to the end of the main content.",
28+
"location": "json",
29+
"required": false,
30+
"type": "string"
31+
},
32+
"position": {
33+
"description": "Relative position to the sibling section, above or below.",
34+
"location": "json",
35+
"required": false,
36+
"type": "string"
37+
}
38+
}
39+
},
40+
"GetSections": {
41+
"summary": "Retrieve a list of sections on a given page",
42+
"uri": "/sites/{siteRef}/pages/{pageRef}/sections",
43+
"httpMethod": "GET",
44+
"parameters": {
45+
"siteRef": {
46+
"description": "Site reference to retrieve site.",
47+
"location": "uri",
48+
"required": true,
49+
"type": "integer"
50+
},
51+
"pageRef": {
52+
"description": "Page reference for getting all sections.",
53+
"location": "uri",
54+
"required": true,
55+
"type": "integer"
56+
}
57+
}
58+
},
59+
"DeleteSection": {
60+
"summary": "Delete a section, and its child widgets, by the section's sectionRef",
61+
"uri": "/sites/{siteRef}/pages/{pageRef}/sections/{sectionRef}",
62+
"httpMethod": "DELETE",
63+
"parameters": {
64+
"siteRef": {
65+
"description": "Site reference to retrieve site.",
66+
"location": "uri",
67+
"required": true,
68+
"type": "integer"
69+
},
70+
"pageRef": {
71+
"description": "Page containing the section to be deleted.",
72+
"location": "uri",
73+
"required": true,
74+
"type": "integer"
75+
},
76+
"sectionRef": {
77+
"description": "Section reference returned from the AddSection or GetSections calls.",
78+
"location": "uri",
79+
"required": true,
80+
"type": "string"
81+
}
82+
}
83+
},
84+
"UpdateSectionWidget": {
85+
"summary": "Update the data in a widget contained within a section",
86+
"uri": "/sites/{siteRef}/pages/{pageRef}/sections/{sectionRef}/widgets/{widgetRef}",
87+
"httpMethod": "PUT",
88+
"parameters": {
89+
"siteRef": {
90+
"description": "Site reference to retrieve site.",
91+
"location": "uri",
92+
"required": true,
93+
"type": "integer"
94+
},
95+
"pageRef": {
96+
"description": "Page containing the section widget to be updated.",
97+
"location": "uri",
98+
"required": true,
99+
"type": "integer"
100+
},
101+
"sectionRef": {
102+
"description": "Section reference returned from the AddSection or GetSections calls containing the widget to update.",
103+
"location": "uri",
104+
"required": true,
105+
"type": "string"
106+
},
107+
"widgetRef": {
108+
"description": "Widget ref to update, returned from the AddSection call.",
109+
"location": "uri",
110+
"required": true,
111+
"type": "integer"
112+
}
113+
},
114+
"additionalParameters": {
115+
"location": "json"
116+
}
117+
}
118+
}
119+
}

service/users.json

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"operations": {
33
"AddSite": {
4-
"httpMethod": "POST",
4+
"httpMethod": "POST",
55
"parameters": {
66
"siteRef": {
77
"description": "Site reference to be associated with the user.",
@@ -277,8 +277,19 @@
277277
"location": "json",
278278
"required": true,
279279
"type": "string"
280+
},
281+
"entryFlowComplete": {
282+
"default": 0,
283+
"description": "Set to 1 to bypass BaseKit onboarding process",
284+
"enum": [
285+
"0",
286+
"1"
287+
],
288+
"location": "json",
289+
"required": false,
290+
"type": "numeric"
280291
}
281-
},
292+
},
282293
"summary": "Create a new user. You need to specify the brand in which to create the user.",
283294
"uri": "/users"
284295
},
@@ -1539,6 +1550,50 @@
15391550
"type": "integer"
15401551
}
15411552
}
1553+
},
1554+
"CreateUploadToken": {
1555+
"httpMethod": "POST",
1556+
"parameters": {
1557+
"userRef": {
1558+
"description": "Account holder user reference",
1559+
"location": "uri",
1560+
"required": true,
1561+
"type": "integer"
1562+
}
1563+
},
1564+
"summary": "Creates a one use file upload token for use with CreateAsset",
1565+
"uri": "/users/{userRef}/upload-tokens"
1566+
},
1567+
"CreateAsset": {
1568+
"httpMethod": "POST",
1569+
"parameters": {
1570+
"userRef": {
1571+
"description": "Account holder user reference",
1572+
"location": "uri",
1573+
"required": true,
1574+
"type": "integer"
1575+
},
1576+
"siteRef": {
1577+
"description": "Site ref",
1578+
"location": "multipart",
1579+
"required": true,
1580+
"type": "integer"
1581+
},
1582+
"token": {
1583+
"description": "One use upload token obtained from calling the CreateUploadToken command",
1584+
"location": "multipart",
1585+
"required": true,
1586+
"type": "string"
1587+
},
1588+
"file": {
1589+
"description": "Stream of the file to upload, eg fopen('image.jpg', 'r'); ",
1590+
"location": "multipart",
1591+
"required": true,
1592+
"type": "any"
1593+
}
1594+
},
1595+
"summary": "Upload a file asset",
1596+
"uri": "/users/{userRef}/assets"
15421597
}
15431598
}
15441599
}

service/widgets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@
319319
"location": "json",
320320
"required": false,
321321
"type": "string"
322-
},
322+
},
323323
"values": {
324324
"description": "Optional widget values for setup (JSON Encoded key => value).",
325325
"location": "json",
326326
"required": false,
327-
"type": "string"
327+
"type": "array"
328328
},
329329
"widgetRef": {
330330
"description": "Widget reference to be updated.",

src/ClientFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,12 @@ private static function createGuzzleClient(array $config, string $authType): Guz
5959
ResponseInterface $response,
6060
RequestInterface $request
6161
): ResultInterface {
62+
$body = (string) $response->getBody();
63+
if (!empty($body)) {
64+
$body = Utils::jsonDecode($body, true);
65+
}
6266
return new Result([
63-
'response' => Utils::jsonDecode((string) $response->getBody(), true)
67+
'response' => $body
6468
]);
6569
}
6670
);

0 commit comments

Comments
 (0)