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

Commit d64f1f4

Browse files
author
eriley
committed
Global app service provider for Guzzle
1 parent 8d70367 commit d64f1f4

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

app/Http/Controllers/FetchController.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@ class FetchController extends Controller
1818
/**
1919
* Set up Guzzle Client for requests
2020
*
21-
* @return void
21+
* @param Client $client
2222
*/
23-
public function __construct()
23+
public function __construct(Client $client)
2424
{
25-
$this->client = new Client(
26-
[
27-
'headers' => [
28-
'User-Agent' => env('REDDIT_USER_AGENT'),
29-
'Content-Type' => 'application/x-www-form-urlencoded',
30-
]
31-
]
32-
);
25+
$this->client = $client;
3326
$this->access_token = '';
3427
$this->results = [];
3528
}
@@ -174,7 +167,7 @@ private function notifySlack()
174167
'elements' => [
175168
[
176169
'type' => 'mrkdwn',
177-
'text' => '<https://mod.reddit.com/mail/|View Modmail>',
170+
'text' => '<https://mod.reddit.com/mail/all|Open Modmail> to view all messages',
178171
]
179172
]
180173
];

app/Providers/AppServiceProvider.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22

33
namespace App\Providers;
44

5+
use GuzzleHttp\Client;
56
use Illuminate\Support\ServiceProvider;
67

78
class AppServiceProvider extends ServiceProvider
89
{
9-
/**
10-
* Register any application services.
11-
*
12-
* @return void
13-
*/
14-
public function register()
15-
{
16-
//
17-
}
10+
/**
11+
* Register any application services.
12+
*
13+
* @return void
14+
*/
15+
public function register()
16+
{
17+
$this->app->singleton(Client::class, function ($app) {
18+
$client = new Client([
19+
'headers' => [
20+
'User-Agent' => env('REDDIT_USER_AGENT'),
21+
'Content-Type' => 'application/x-www-form-urlencoded',
22+
]
23+
]);
24+
return $client;
25+
});
26+
}
1827
}

bootstrap/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
|
7777
*/
7878

79-
// $app->register(App\Providers\AppServiceProvider::class);
79+
$app->register(App\Providers\AppServiceProvider::class);
8080
// $app->register(App\Providers\AuthServiceProvider::class);
8181
// $app->register(App\Providers\EventServiceProvider::class);
8282

0 commit comments

Comments
 (0)