-
Notifications
You must be signed in to change notification settings - Fork 31
/
HubSpotServiceProvider.php
81 lines (68 loc) · 1.71 KB
/
HubSpotServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Rossjcooper\LaravelHubSpot;
use GuzzleHttp\Client;
use HubSpot\Discovery\Discovery;
use HubSpot\Factory;
use Illuminate\Support\ServiceProvider;
class HubSpotServiceProvider extends ServiceProvider
{
public function register()
{
$this->includeConfig();
$this->app->bind(Discovery::class, function ($app) {
$this->includeConfig();
$this->mergeConfigFrom(
__DIR__.'/config/hubspot.php',
'hubspot'
);
$handlerStack = \GuzzleHttp\HandlerStack::create();
if (config('hubspot.enable_constant_delay')) {
$handlerStack->push(
\HubSpot\RetryMiddlewareFactory::createRateLimitMiddleware(
\HubSpot\Delay::getConstantDelayFunction()
)
);
}
if ($exponentialDelay = config('hubspot.exponential_delay')) {
$handlerStack->push(
\HubSpot\RetryMiddlewareFactory::createRateLimitMiddleware(
\HubSpot\Delay::getExponentialDelayFunction($exponentialDelay)
)
);
}
$client = new Client(array_merge(
config('hubspot.client_options'),
[
'handler' => $handlerStack,
]
));
if ($accessToken = config('hubspot.access_token')) {
return Factory::createWithAccessToken(
$accessToken,
$client,
);
}
return Factory::createWithDeveloperApiKey(
config('hubspot.developer_key'),
$client,
);
});
}
/**
* Perform post-registration booting of services.
*/
public function boot()
{
// config
$this->publishes([
__DIR__.'/config/hubspot.php' => config_path('hubspot.php'),
], 'config');
}
protected function includeConfig(): void
{
$this->mergeConfigFrom(
__DIR__.'/config/hubspot.php',
'hubspot'
);
}
}