55
66namespace Torchlight ;
77
8- use GuzzleHttp \Promise \Promise ;
98use Illuminate \Http \Client \ConnectionException ;
109use Illuminate \Support \Arr ;
1110use Illuminate \Support \Collection ;
@@ -52,6 +51,7 @@ protected function request(Collection $blocks)
5251 ->withToken ($ this ->getToken ())
5352 ->post ('highlight ' , [
5453 'blocks ' => $ this ->blocksAsRequestParam ($ blocks )->values ()->toArray (),
54+ 'options ' => $ this ->getOptions (),
5555 ]);
5656
5757 if ($ response ->failed ()) {
@@ -87,30 +87,6 @@ protected function request(Collection $blocks)
8787 return $ blocks ;
8888 }
8989
90- protected function requestChunks ($ chunks )
91- {
92- $ host = Torchlight::config ('host ' , 'https://api.torchlight.dev ' );
93- $ timeout = Torchlight::config ('request_timeout ' , 5 );
94-
95- // Can't use Http::pool here because it's not
96- // available in Laravel 7 and early 8.
97- return $ chunks
98- // This first map fires all the requests.
99- ->map (function ($ blocks ) use ($ host , $ timeout ) {
100- return Http::async ()
101- ->baseUrl ($ host )
102- ->timeout ($ timeout )
103- ->withToken ($ this ->getToken ())
104- ->post ('highlight ' , [
105- 'blocks ' => $ this ->blocksAsRequestParam ($ blocks )->values ()->toArray (),
106- ]);
107- })
108- // The second one waits for them all to finish.
109- ->map (function (Promise $ request ) {
110- return $ request ->wait ();
111- });
112- }
113-
11490 protected function collectionOfBlocks ($ blocks )
11591 {
11692 return collect ($ blocks )->each (function ($ block ) {
@@ -133,6 +109,17 @@ protected function getToken()
133109 return $ token ;
134110 }
135111
112+ protected function getOptions ()
113+ {
114+ $ options = Torchlight::config ('options ' , []);
115+
116+ if (!is_array ($ options )) {
117+ $ options = [];
118+ }
119+
120+ return $ options ;
121+ }
122+
136123 protected function potentiallyThrowRequestException ($ exception )
137124 {
138125 if ($ exception ) {
0 commit comments