Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Global app service provider for Guzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
eriley committed Jul 16, 2019
1 parent 8d70367 commit d64f1f4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
15 changes: 4 additions & 11 deletions app/Http/Controllers/FetchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
Expand Down Expand Up @@ -174,7 +167,7 @@ private function notifySlack()
'elements' => [
[
'type' => 'mrkdwn',
'text' => '<https://mod.reddit.com/mail/|View Modmail>',
'text' => '<https://mod.reddit.com/mail/all|Open Modmail> to view all messages',
]
]
];
Expand Down
27 changes: 18 additions & 9 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}
2 changes: 1 addition & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit d64f1f4

Please sign in to comment.