Skip to content

Commit 1391eb5

Browse files
committed
Port from official js sdk
1 parent ece7c41 commit 1391eb5

File tree

4 files changed

+366
-0
lines changed

4 files changed

+366
-0
lines changed

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "expertlead/webflow-php-sdk",
3+
"description": "PHP SDK for the Webflow CMS API",
4+
"type": "library",
5+
"require": {
6+
"guzzlehttp/guzzle": "^6"
7+
},
8+
"license": "MIT",
9+
"authors": [
10+
{
11+
"name": "Oleksii Antypov",
12+
"email": "echo@wivern.co.uk"
13+
}
14+
],
15+
"minimum-stability": "stable"
16+
}

composer.lock

Lines changed: 249 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Webflow/Api.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
namespace Webflow;
4+
5+
use Webflow\WebflowException;
6+
use GuzzleHttp\Client;
7+
8+
class Api {
9+
10+
const WEBFLOW_API_ENDPOINT = 'https://api.webflow.com';
11+
12+
private $client;
13+
14+
function __construct(
15+
$token,
16+
$version = '1.0.0'
17+
) {
18+
if (empty($token)) {
19+
throw new WebflowException('token');
20+
}
21+
22+
$this->client = new Client([
23+
'base_uri' => self::WEBFLOW_API_ENDPOINT,
24+
'headers' => [
25+
'Authorization' => "Bearer {$token}",
26+
'accept-version' => $version,
27+
'Accept' => 'application/json',
28+
'Content-Type' => 'application/json',
29+
]
30+
]);
31+
32+
return $this;
33+
}
34+
35+
// Meta
36+
37+
public function info() {
38+
return $this->client->get('/info')->getBody();
39+
}
40+
41+
public function sites() {
42+
return $this->client->get('/sites')->getBody();
43+
}
44+
45+
public function site(string $siteId) {
46+
return $this->client->get("/sites/{$siteId}")->getBody();
47+
}
48+
49+
public function domains(string $siteId) {
50+
return $this->client->get("/sites/{$siteId}/domains")->getBody();
51+
}
52+
53+
public function publishSite(string $siteId, array $domains) {
54+
return $this->client->post(`/sites/${siteId}/publish`, $domains);
55+
}
56+
57+
// Collections
58+
59+
public function collections(string $siteId) {
60+
return $this->client->get("/sites/{$siteId}/collections")->getBody();
61+
}
62+
63+
public function collection(string $collectionId) {
64+
return $this->client->get("/collections/{$collectionId}")->getBody();
65+
}
66+
67+
// Items
68+
69+
public function items(string $collectionId) {
70+
return $this->client->get("/collections/{$collectionId}/items")->getBody();
71+
}
72+
73+
public function item(string $collectionId, string $itemId) {
74+
return $this->client->get("/collections/{$collectionId}/items/{$itemId}")->getBody();
75+
}
76+
77+
public function createItem(string $collectionId, array $data) {
78+
return $this->client->post("/collections/{$collectionId}/items", [
79+
'json' => [
80+
'fields' => $data,
81+
],
82+
])->getBody();
83+
}
84+
85+
public function updateItem(string $collectionId, string $itemId, array $data) {
86+
return $this->client->put("/collections/{$collectionId}/items/{$itemId}", $data);
87+
}
88+
89+
public function removeItem(string $collectionId, $itemId) {
90+
return $this->client->delete("/collections/{$collectionId}/items/{$itemId}")->getBody();
91+
}
92+
93+
}

src/Webflow/WebflowException.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
class WebflowException extends Exception {
4+
public function __construct(string $argument){
5+
$this->message = "Argument '{$argument}' is required but was not present";
6+
return $this;
7+
}
8+
}

0 commit comments

Comments
 (0)