Skip to content

Commit

Permalink
Merge pull request #7 from basekit/section-api-fixes
Browse files Browse the repository at this point in the history
New sections api endpoints, image upload endpoints, bug fixes
  • Loading branch information
markjeffries authored Jun 28, 2023
2 parents 89efb9a + 1e7449e commit bcd82c1
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ $createSite = $client->getCommand(
$client->execute($createSite);
```

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.

## Testing

Feed an optional `handler` into the config of `clientFactory` to control the responses from the http client.
Expand Down
3 changes: 2 additions & 1 deletion service/basekit.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"plugins/blogs.json",
"plugins/blogs/categories.json",
"plugins/blogs/posts.json",
"plugins/users/blogs.json"
"plugins/users/blogs.json",
"sections.json"
]
}
10 changes: 8 additions & 2 deletions service/profiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"required": true,
"type": "integer"
}
},
},
"summary": "Delete profile with the specified reference. The delete method must be permitted by the caller.",
"uri": "/users/{userRef}/profiles/{profileRef}"
},
Expand Down Expand Up @@ -78,8 +78,14 @@
"location": "uri",
"required": true,
"type": "integer"
},
"fields": {
"description": "Profile fields in name value pairs.",
"location": "json",
"required": true,
"type": "array"
}
},
},
"summary": "Update profile data with the specified profile reference. The update method must be permitted by the caller.",
"uri": "/users/{userRef}/profiles/{profileRef}"
}
Expand Down
119 changes: 119 additions & 0 deletions service/sections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"operations": {
"AddSection": {
"summary": "Add a section to a given site page",
"uri": "/sites/{siteRef}/pages/{pageRef}/sections",
"httpMethod": "POST",
"parameters": {
"siteRef": {
"description": "Site reference to retrieve site.",
"location": "uri",
"required": true,
"type": "integer"
},
"pageRef": {
"description": "Page reference for adding a new section.",
"location": "uri",
"required": true,
"type": "integer"
},
"template": {
"description": "ID of the row template to use eg image_text_2a",
"location": "json",
"required": true,
"type": "string"
},
"siblingRef": {
"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.",
"location": "json",
"required": false,
"type": "string"
},
"position": {
"description": "Relative position to the sibling section, above or below.",
"location": "json",
"required": false,
"type": "string"
}
}
},
"GetSections": {
"summary": "Retrieve a list of sections on a given page",
"uri": "/sites/{siteRef}/pages/{pageRef}/sections",
"httpMethod": "GET",
"parameters": {
"siteRef": {
"description": "Site reference to retrieve site.",
"location": "uri",
"required": true,
"type": "integer"
},
"pageRef": {
"description": "Page reference for getting all sections.",
"location": "uri",
"required": true,
"type": "integer"
}
}
},
"DeleteSection": {
"summary": "Delete a section, and its child widgets, by the section's sectionRef",
"uri": "/sites/{siteRef}/pages/{pageRef}/sections/{sectionRef}",
"httpMethod": "DELETE",
"parameters": {
"siteRef": {
"description": "Site reference to retrieve site.",
"location": "uri",
"required": true,
"type": "integer"
},
"pageRef": {
"description": "Page containing the section to be deleted.",
"location": "uri",
"required": true,
"type": "integer"
},
"sectionRef": {
"description": "Section reference returned from the AddSection or GetSections calls.",
"location": "uri",
"required": true,
"type": "string"
}
}
},
"UpdateSectionWidget": {
"summary": "Update the data in a widget contained within a section",
"uri": "/sites/{siteRef}/pages/{pageRef}/sections/{sectionRef}/widgets/{widgetRef}",
"httpMethod": "PUT",
"parameters": {
"siteRef": {
"description": "Site reference to retrieve site.",
"location": "uri",
"required": true,
"type": "integer"
},
"pageRef": {
"description": "Page containing the section widget to be updated.",
"location": "uri",
"required": true,
"type": "integer"
},
"sectionRef": {
"description": "Section reference returned from the AddSection or GetSections calls containing the widget to update.",
"location": "uri",
"required": true,
"type": "string"
},
"widgetRef": {
"description": "Widget ref to update, returned from the AddSection call.",
"location": "uri",
"required": true,
"type": "integer"
}
},
"additionalParameters": {
"location": "json"
}
}
}
}
59 changes: 57 additions & 2 deletions service/users.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"operations": {
"AddSite": {
"httpMethod": "POST",
"httpMethod": "POST",
"parameters": {
"siteRef": {
"description": "Site reference to be associated with the user.",
Expand Down Expand Up @@ -277,8 +277,19 @@
"location": "json",
"required": true,
"type": "string"
},
"entryFlowComplete": {
"default": 0,
"description": "Set to 1 to bypass BaseKit onboarding process",
"enum": [
"0",
"1"
],
"location": "json",
"required": false,
"type": "numeric"
}
},
},
"summary": "Create a new user. You need to specify the brand in which to create the user.",
"uri": "/users"
},
Expand Down Expand Up @@ -1539,6 +1550,50 @@
"type": "integer"
}
}
},
"CreateUploadToken": {
"httpMethod": "POST",
"parameters": {
"userRef": {
"description": "Account holder user reference",
"location": "uri",
"required": true,
"type": "integer"
}
},
"summary": "Creates a one use file upload token for use with CreateAsset",
"uri": "/users/{userRef}/upload-tokens"
},
"CreateAsset": {
"httpMethod": "POST",
"parameters": {
"userRef": {
"description": "Account holder user reference",
"location": "uri",
"required": true,
"type": "integer"
},
"siteRef": {
"description": "Site ref",
"location": "multipart",
"required": true,
"type": "integer"
},
"token": {
"description": "One use upload token obtained from calling the CreateUploadToken command",
"location": "multipart",
"required": true,
"type": "string"
},
"file": {
"description": "Stream of the file to upload, eg fopen('image.jpg', 'r'); ",
"location": "multipart",
"required": true,
"type": "any"
}
},
"summary": "Upload a file asset",
"uri": "/users/{userRef}/assets"
}
}
}
4 changes: 2 additions & 2 deletions service/widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,12 @@
"location": "json",
"required": false,
"type": "string"
},
},
"values": {
"description": "Optional widget values for setup (JSON Encoded key => value).",
"location": "json",
"required": false,
"type": "string"
"type": "array"
},
"widgetRef": {
"description": "Widget reference to be updated.",
Expand Down
6 changes: 5 additions & 1 deletion src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ private static function createGuzzleClient(array $config, string $authType): Guz
ResponseInterface $response,
RequestInterface $request
): ResultInterface {
$body = (string) $response->getBody();
if (!empty($body)) {
$body = Utils::jsonDecode($body, true);
}
return new Result([
'response' => Utils::jsonDecode((string) $response->getBody(), true)
'response' => $body
]);
}
);
Expand Down

0 comments on commit bcd82c1

Please sign in to comment.