diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..114b4b3 --- /dev/null +++ b/composer.json @@ -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" +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..8b72da7 --- /dev/null +++ b/composer.lock @@ -0,0 +1,218 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "074f6b855183335b50d0cb23d75f5d28", + "packages": [ + { + "name": "guzzlehttp/guzzle", + "version": "5.3.3", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "93bbdb30d59be6cd9839495306c65f2907370eb9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/93bbdb30d59be6cd9839495306c65f2907370eb9", + "reference": "93bbdb30d59be6cd9839495306c65f2907370eb9", + "shasum": "" + }, + "require": { + "guzzlehttp/ringphp": "^1.1", + "php": ">=5.4.0", + "react/promise": "^2.2" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2018-07-31T13:33:10+00:00" + }, + { + "name": "guzzlehttp/ringphp", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/RingPHP.git", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/5e2a174052995663dd68e6b5ad838afd47dd615b", + "reference": "5e2a174052995663dd68e6b5ad838afd47dd615b", + "shasum": "" + }, + "require": { + "guzzlehttp/streams": "~3.0", + "php": ">=5.4.0", + "react/promise": "~2.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "~4.0" + }, + "suggest": { + "ext-curl": "Guzzle will use specific adapters if cURL is present" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Ring\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", + "time": "2018-07-31T13:22:33+00:00" + }, + { + "name": "guzzlehttp/streams", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/streams.git", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Stream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Provides a simple abstraction over streams of data", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "Guzzle", + "stream" + ], + "time": "2014-10-12T19:18:40+00:00" + }, + { + "name": "react/promise", + "version": "v2.7.0", + "source": { + "type": "git", + "url": "https://github.com/reactphp/promise.git", + "reference": "f4edc2581617431aea50430749db55cc3fc031b3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/reactphp/promise/zipball/f4edc2581617431aea50430749db55cc3fc031b3", + "reference": "f4edc2581617431aea50430749db55cc3fc031b3", + "shasum": "" + }, + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "React\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Sorgalla", + "email": "jsorgalla@gmail.com" + } + ], + "description": "A lightweight implementation of CommonJS Promises/A for PHP", + "keywords": [ + "promise", + "promises" + ], + "time": "2018-06-13T15:59:06+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/Webflow/Api.php b/src/Webflow/Api.php new file mode 100644 index 0000000..0586bbb --- /dev/null +++ b/src/Webflow/Api.php @@ -0,0 +1,93 @@ +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(); + } + +} diff --git a/src/Webflow/WebflowException.php b/src/Webflow/WebflowException.php new file mode 100644 index 0000000..547f790 --- /dev/null +++ b/src/Webflow/WebflowException.php @@ -0,0 +1,8 @@ +message = "Argument '{$argument}' is required but was not present"; + return $this; + } +}