Route::match(['get'], 'webflow/auth', function () {
$id = request()->get('state');
$wf = ToolWebflow::withoutGlobalScopes()->find($id);
- $wf->webflow_api_token = Webflow::getToken(request()->get('code'));
+ $wf->webflow_api_token = Webflow::getTokenFromCode(request()->get('code'));
$wf->save();
return redirect(backpack_url('tool-webflow/' . $id . '/edit'));
});
use App\Http\Controllers\Admin\Operations\Tools\WebflowOperation;
use App\Jobs\WebflowPublish;
use App\Models\Base\ToolboxModel;
+use App\Services\Webflow;
use Cubist\Backpack\Magic\Fields\Code;
use Cubist\Backpack\Magic\Fields\SelectFromArray;
use Cubist\Backpack\Magic\Fields\Table;
protected function _parsePages()
{
-
+ Webflow::setToken($this->webflow_api_token);
+ dd(Webflow::listPages($this->webflow));
}
public function getLocales()
namespace App\Services;
+
+use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
class Webflow
{
- public static function getToken($code, $data = [])
+
+ const BASE_URL = 'https://api.webflow.com/beta/';
+
+ protected static $_token = null;
+
+ public static function setToken($token)
+ {
+ self::$_token = $token;
+ }
+
+ public static function getToken()
+ {
+ return self::$_token;
+ }
+
+ public static function getTokenFromCode($code, $data = [])
{
$response = Http::post('https://api.webflow.com/oauth/access_token',
array_merge(
return $response->json()['access_token'];
}
+
+ public static function request($url, $data = [], $method = 'get', $ttl = 7200)
+ {
+ return Cache::remember('webflow_' . static::getToken() . '_' . $method . '_' . $url . '_' . sha1(print_r($data, true)), $ttl, function () use ($url, $method, $data) {
+ $response = Http::withToken(self::getToken())->$method(self::BASE_URL . $url, $data);
+ return $response->json();
+ });
+ }
+
+ public static function listSites()
+ {
+ return self::request('sites')['sites'];
+ }
+
+ public static function getSiteId($shortname)
+ {
+ foreach (self::listSites() as $s) {
+ if ($s['shortName'] === $shortname) {
+ return $s['id'];
+ }
+ }
+ }
+
+ public static function getPageMeta($shortname, $pageID)
+ {
+ foreach (self::listPages($shortname) as $page) {
+ if($page['id']==$pageID){
+ return $page;
+ }
+ }
+ }
+
+ public static function listPages($shortname)
+ {
+ return self::request('sites/' . self::getSiteId($shortname) . '/pages')['pages'];
+ }
}