Skip to content

Commit

Permalink
Merge pull request #45 from ash-jc-allen/feature/oauth-flag
Browse files Browse the repository at this point in the history
Added `--oauth` option to the `saloon:connector` command
  • Loading branch information
Sammyjo20 authored Sep 17, 2023
2 parents dfe07d2 + 3a784d8 commit 1eab980
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 49 deletions.
9 changes: 8 additions & 1 deletion src/Console/Commands/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ abstract class MakeCommand extends GeneratorCommand
*/
protected function getStub()
{
return $this->resolveStubPath('/stubs/' . $this->stub);
return $this->resolveStubPath('/stubs/' . $this->resolveStubName());
}

protected function resolveStubName(): string
{
return method_exists($this, 'stub')
? $this->stub()
: $this->stub;
}

/**
Expand Down
39 changes: 36 additions & 3 deletions src/Console/Commands/MakeConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

namespace Saloon\Laravel\Console\Commands;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function Laravel\Prompts\select;

class MakeConnector extends MakeCommand
{
/**
Expand Down Expand Up @@ -34,10 +39,38 @@ class MakeConnector extends MakeCommand
*/
protected $namespace = '\Http\Integrations\{integration}';

protected function resolveStubName(): string
{
return $this->option('oauth')
? 'saloon.oauth-connector.stub'
: 'saloon.connector.stub';
}

protected function getOptions()
{
return [
['oauth', null, InputOption::VALUE_NONE, 'Whether the connector should include the OAuth boilerplate'],
];
}

/**
* The default stub
* Interact further with the user if they were prompted for missing arguments.
*
* @var string
* @param \Symfony\Component\Console\Input\InputInterface $input
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return void
*/
protected $stub = 'saloon.connector.stub';
protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)
{
if ($this->didReceiveOptions($input)) {
return;
}

$type = $this->choice('Should the connector support OAuth?', [
true => 'Yes',
false => 'No',
]);

$input->setOption('oauth', $type);
}
}
43 changes: 0 additions & 43 deletions src/Console/Commands/MakeOAuthConnector.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/SaloonServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Saloon\Laravel\Http\Middleware\SendRequestEvent;
use Saloon\Laravel\Http\Middleware\SendResponseEvent;
use Saloon\Laravel\Console\Commands\MakeAuthenticator;
use Saloon\Laravel\Console\Commands\MakeOAuthConnector;

class SaloonServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -80,7 +79,6 @@ protected function registerCommands(): self
{
$this->commands([
MakeConnector::class,
MakeOAuthConnector::class,
MakeRequest::class,
MakeResponse::class,
MakePlugin::class,
Expand Down

0 comments on commit 1eab980

Please sign in to comment.