Skip to content

Commit

Permalink
Queue: method request return ResponseInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Oct 3, 2018
1 parent fc07f94 commit c011fc0
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/Request/Queue.php
Expand Up @@ -66,9 +66,11 @@ public function setSleep($sleep)
*/
public function download($token, $url)
{
return $this->request($token, function (GuzzleHttp\Client $client) use ($url) {
$response = $this->request($token, function (GuzzleHttp\Client $client) use ($url) {
return $client->request('GET', $url, $this->downloadOptions);
}, 'download');
});
self::detectDownloadResponse($response);
return $response->getBody();
}

/**
Expand All @@ -85,19 +87,19 @@ public function upload($url, $token, array $post, $filename)

$response = $this->request($token, function (GuzzleHttp\Client $client) use ($url, $newPost) {
return $client->request('POST', $url, [GuzzleHttp\RequestOptions::MULTIPART => $newPost]);
}, 'upload');
return self::createXmlResponse($response);
});
return self::createXmlResponse($response->getBody());
}

/**
* @param $token
* @param $fallback
* @param string $action
* @return GuzzleHttp\Psr7\Stream
* @return ResponseInterface
* @throws Fio\QueueLimitException
* @throws Fio\ServiceUnavailableException
*/
private function request($token, $fallback, $action)
private function request($token, $fallback)
{
$request = new GuzzleHttp\Client(['headers' => ['X-Powered-By' => 'h4kuna/fio']]);
$tempFile = $this->loadFileName($token);
Expand Down Expand Up @@ -130,11 +132,7 @@ private function request($token, $fallback, $action)
fclose($file);
touch($tempFile);

if ($action === 'download') {
self::detectDownloadResponse($response);
}

return $response->getBody();
return $response;
}

/**
Expand Down

0 comments on commit c011fc0

Please sign in to comment.