HttpServiceProvider::registerGuzzle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Magister\Services\Http;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;
7
use Magister\Services\Support\ServiceProvider;
8
9
/**
10
 * Class HttpServiceProvider.
11
 */
12
class HttpServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Register bindings in the container.
16
     *
17
     * @return void
18
     */
19
    public function register()
20
    {
21
        $this->registerGuzzle();
22
    }
23
24
    /**
25
     * Register the Guzzle driver.
26
     *
27
     * @return void
28
     */
29
    protected function registerGuzzle()
30
    {
31
        $this->app->singleton('http', function ($app) {
32
            $client = new Client([
33
                'base_url' => "https://{$app['school']}.magister.net/api/",
34
            ]);
35
36
            $client->setDefaultOption('exceptions', false);
37
38
            $client->setDefaultOption('cookies', new SessionCookieJar($app['cookie']));
39
40
            $client->setDefaultOption('headers', [
41
                'X-API-Client-ID' => env('MAGISTER_API_KEY', '12D8'),
42
            ]);
43
44
            CacheSubscriber::attach($client);
45
46
            return $client;
47
        });
48
    }
49
}
50