diff --git a/app/Http/Controllers/FetchController.php b/app/Http/Controllers/FetchController.php index 90b80c5..003109d 100644 --- a/app/Http/Controllers/FetchController.php +++ b/app/Http/Controllers/FetchController.php @@ -18,18 +18,11 @@ class FetchController extends Controller /** * Set up Guzzle Client for requests * - * @return void + * @param Client $client */ - public function __construct() + public function __construct(Client $client) { - $this->client = new Client( - [ - 'headers' => [ - 'User-Agent' => env('REDDIT_USER_AGENT'), - 'Content-Type' => 'application/x-www-form-urlencoded', - ] - ] - ); + $this->client = $client; $this->access_token = ''; $this->results = []; } @@ -174,7 +167,7 @@ private function notifySlack() 'elements' => [ [ 'type' => 'mrkdwn', - 'text' => '', + 'text' => ' to view all messages', ] ] ]; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index ddec046..cf60d05 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,17 +2,26 @@ namespace App\Providers; +use GuzzleHttp\Client; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { - /** - * Register any application services. - * - * @return void - */ - public function register() - { - // - } + /** + * Register any application services. + * + * @return void + */ + public function register() + { + $this->app->singleton(Client::class, function ($app) { + $client = new Client([ + 'headers' => [ + 'User-Agent' => env('REDDIT_USER_AGENT'), + 'Content-Type' => 'application/x-www-form-urlencoded', + ] + ]); + return $client; + }); + } } diff --git a/bootstrap/app.php b/bootstrap/app.php index ecbeb61..45acad1 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -76,7 +76,7 @@ | */ -// $app->register(App\Providers\AppServiceProvider::class); + $app->register(App\Providers\AppServiceProvider::class); // $app->register(App\Providers\AuthServiceProvider::class); // $app->register(App\Providers\EventServiceProvider::class);