diff --git a/composer.json b/composer.json index f8460d0..59b8380 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "description": "Consume RESTful APIs in your Statamic templates", "type": "statamic-addon", "require": { - "guzzlehttp/guzzle": "~6.0", - "statamic/cms": "3.0.*@beta" + "guzzlehttp/guzzle": "^6.3 || ^7.0", + "statamic/cms": "^3.1" }, "license": "MIT", "authors": [ @@ -20,6 +20,10 @@ } }, "extra": { + "statamic": { + "name": "Placid", + "description": "Consume REST API's in your templates." + }, "laravel": { "providers": [ "Ritson\\Placid\\PlacidServiceProvider" diff --git a/src/PlacidTag.php b/src/Placid.php similarity index 58% rename from src/PlacidTag.php rename to src/Placid.php index bad4058..3f8ab05 100644 --- a/src/PlacidTag.php +++ b/src/Placid.php @@ -2,15 +2,12 @@ namespace Ritson\Placid; -use Exception; use Ritson\Placid\PlacidRepository; use Ritson\Placid\PlacidResource; use Statamic\Tags\Tags; -class PlacidTag extends Tags +class Placid extends Tags { - protected static $handle = 'placid'; - public function __construct(PlacidRepository $repo) { $this->repo = $repo; @@ -30,18 +27,18 @@ public function index() */ public function request() { - $handle = $this->getParam('handle', null); + $handle = $this->params->get('handle', null); $options = [ - 'host' => $this->getParam('host', null), - 'headers' => $this->getParam('headers', null), - 'path' => $this->getParam('path', null), - 'cache' => $this->getParam('cache', null), - 'method' => $this->getParam('method', null), - 'segments' => $this->getParam('segments', null), - 'url' => $this->getParam('url', null), - 'query' => $this->getParam('query', null), - 'auth' => $this->getParam('auth', null) + 'host' => $this->params->get('host', null), + 'headers' => $this->params->get('headers', null), + 'path' => $this->params->get('path', null), + 'cache' => $this->params->get('cache', null), + 'method' => $this->params->get('method', null), + 'segments' => $this->params->get('segments', null), + 'url' => $this->params->get('url', null), + 'query' => $this->params->get('query', null), + 'auth' => $this->params->get('auth', null) ]; if ($handle) { diff --git a/src/PlacidResource.php b/src/PlacidResource.php index 3d59d23..e3e60f2 100644 --- a/src/PlacidResource.php +++ b/src/PlacidResource.php @@ -53,6 +53,11 @@ class PlacidResource extends AbstractResource */ protected $auth = null; + /** + * The full URL to use for the request + */ + protected $url = null; + /** * Set the value for access token * @param String $value @@ -147,7 +152,7 @@ public function execute() if ($this->cache && !$this->auth) { return Cache::remember($this->getCacheKey(), $this->cache, function () { - $response = $this->client()->request($this->method, $this->path); + $response = $this->client()->request($this->method, $this->url ?? $this->path); return (new PlacidResponse)->resolve($response); }); } @@ -156,7 +161,7 @@ public function execute() $this->prepareAuth(); try { - $response = $this->client()->request($this->method, $this->path); + $response = $this->client()->request($this->method, $this->url ?? $this->path); return (new PlacidResponse)->resolve($response); } catch (RequestException $e) { return (new PlacidResponse)->resolve($e->getResponse() ?? $e); @@ -166,7 +171,7 @@ public function execute() protected function getCacheKey() { return base64_encode( - urlencode($this->host . $this->path . implode('&', $this->query)) + urlencode($this->url ?? ($this->host . $this->path . implode('&', $this->query))) ); } } diff --git a/src/PlacidServiceProvider.php b/src/PlacidServiceProvider.php index a6f8a53..5389f09 100644 --- a/src/PlacidServiceProvider.php +++ b/src/PlacidServiceProvider.php @@ -3,11 +3,11 @@ namespace Ritson\Placid; use Statamic\Providers\AddonServiceProvider; -use Ritson\Placid\PlacidTag; +use Ritson\Placid\Placid; class PlacidServiceProvider extends AddonServiceProvider { protected $tags = [ - PlacidTag::class, + Placid::class, ]; }