-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ece7c41
commit 1ac1a14
Showing
4 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "expertlead/webflow-php-sdk", | ||
"description": "PHP SDK for the Webflow CMS API", | ||
"type": "library", | ||
"require": { | ||
"guzzlehttp/guzzle": "^5" | ||
}, | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Oleksii Antypov", | ||
"email": "echo@wivern.co.uk" | ||
} | ||
], | ||
"minimum-stability": "stable" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Webflow; | ||
|
||
use Webflow\WebflowException; | ||
use GuzzleHttp\Client; | ||
|
||
class Api { | ||
|
||
const WEBFLOW_API_ENDPOINT = 'https://api.webflow.com'; | ||
|
||
private $client; | ||
|
||
function __construct( | ||
$token, | ||
$version = '1.0.0' | ||
) { | ||
if (empty($token)) { | ||
throw new WebflowException('token'); | ||
} | ||
|
||
$this->client = new Client([ | ||
'base_uri' => self::WEBFLOW_API_ENDPOINT, | ||
'headers' => [ | ||
'Authorization' => "Bearer {$token}", | ||
'accept-version' => $version, | ||
'Accept' => 'application/json', | ||
'Content-Type' => 'application/json', | ||
] | ||
]); | ||
|
||
return $this; | ||
} | ||
|
||
// Meta | ||
|
||
public function info() { | ||
return $this->client->get('/info')->getBody(); | ||
} | ||
|
||
public function sites() { | ||
return $this->client->get('/sites')->getBody(); | ||
} | ||
|
||
public function site(string $siteId) { | ||
return $this->client->get("/sites/{$siteId}")->getBody(); | ||
} | ||
|
||
public function domains(string $siteId) { | ||
return $this->client->get("/sites/{$siteId}/domains")->getBody(); | ||
} | ||
|
||
public function publishSite(string $siteId, array $domains) { | ||
return $this->client->post(`/sites/${siteId}/publish`, $domains); | ||
} | ||
|
||
// Collections | ||
|
||
public function collections(string $siteId) { | ||
return $this->client->get("/sites/{$siteId}/collections")->getBody(); | ||
} | ||
|
||
public function collection(string $collectionId) { | ||
return $this->client->get("/collections/{$collectionId}")->getBody(); | ||
} | ||
|
||
// Items | ||
|
||
public function items(string $collectionId) { | ||
return $this->client->get("/collections/{$collectionId}/items")->getBody(); | ||
} | ||
|
||
public function item(string $collectionId, string $itemId) { | ||
return $this->client->get("/collections/{$collectionId}/items/{$itemId}")->getBody(); | ||
} | ||
|
||
public function createItem(string $collectionId, array $data) { | ||
return $this->client->post("/collections/{$collectionId}/items", [ | ||
'json' => [ | ||
'fields' => $data, | ||
], | ||
])->getBody(); | ||
} | ||
|
||
public function updateItem(string $collectionId, string $itemId, array $data) { | ||
return $this->client->put("/collections/{$collectionId}/items/{$itemId}", $data); | ||
} | ||
|
||
public function removeItem(string $collectionId, $itemId) { | ||
return $this->client->delete("/collections/{$collectionId}/items/{$itemId}")->getBody(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
class WebflowException extends Exception { | ||
public function __construct(string $argument){ | ||
$this->message = "Argument '{$argument}' is required but was not present"; | ||
return $this; | ||
} | ||
} |