Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit d5ea5d624248d1bd7d013afd3d3e835d693894fa
Author: Alec Ritson <hello@itsalec.co.uk>
Date:   Sun Jul 25 13:55:08 2021 +0100

    Update to latest statamic
  • Loading branch information
alecritson committed Jul 25, 2021
1 parent ae4d718 commit 66ec2ad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -20,6 +20,10 @@
}
},
"extra": {
"statamic": {
"name": "Placid",
"description": "Consume REST API's in your templates."
},
"laravel": {
"providers": [
"Ritson\\Placid\\PlacidServiceProvider"
Expand Down
25 changes: 11 additions & 14 deletions src/PlacidTag.php → src/Placid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions src/PlacidResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
});
}
Expand All @@ -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);
Expand All @@ -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)))
);
}
}
4 changes: 2 additions & 2 deletions src/PlacidServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

0 comments on commit 66ec2ad

Please sign in to comment.