Skip to content

Commit

Permalink
Port from official js sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
wivern-co-uk committed Aug 2, 2018
1 parent ece7c41 commit 1ac1a14
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 0 deletions.
16 changes: 16 additions & 0 deletions composer.json
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"
}
218 changes: 218 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions src/Webflow/Api.php
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();
}

}
8 changes: 8 additions & 0 deletions src/Webflow/WebflowException.php
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;
}
}

0 comments on commit 1ac1a14

Please sign in to comment.