Skip to content

Commit 7881295

Browse files
Merge pull request #6 from weglot/fix/urls
Fix/Url placeholder replacement
2 parents d3d45b6 + 779e3bc commit 7881295

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

Service/TextMasterApi.php

+19-22
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44

55
use GuzzleHttp\Client;
66
use GuzzleHttp\Exception\GuzzleException;
7-
use GuzzleHttp\Handler\CurlHandler;
87
use GuzzleHttp\HandlerStack;
98
use GuzzleHttp\Middleware;
109
use GuzzleHttp\Psr7\Request;
11-
use GuzzleHttp\Psr7\Response;
1210
use GuzzleHttp\RequestOptions;
1311
use Psr\Http\Message\RequestInterface;
12+
use Psr\Http\Message\ResponseInterface;
1413

1514
class TextMasterApi
1615
{
@@ -57,7 +56,7 @@ public function __construct(string $apiKey, string $apiSecret, string $textmaste
5756
/**
5857
* @throws GuzzleException
5958
*/
60-
public function createProject(array $project): Response
59+
public function createProject(array $project): ResponseInterface
6160
{
6261
$routeParams = self::ROUTES['createProject'];
6362

@@ -67,18 +66,18 @@ public function createProject(array $project): Response
6766
/**
6867
* @throws GuzzleException
6968
*/
70-
public function updateProject(string $textMasterProjectId, array $options): Response
69+
public function updateProject(string $textMasterProjectId, array $options): ResponseInterface
7170
{
7271
$routeParams = self::ROUTES['updateProject'];
7372
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId]);
7473

75-
return $this->request($routeParams['url'], $routeParams['method'], ['project' => $options]);
74+
return $this->request($url, $routeParams['method'], ['project' => $options]);
7675
}
7776

7877
/**
7978
* @throws GuzzleException
8079
*/
81-
public function launchProject(string $textMasterProjectId): Response
80+
public function launchProject(string $textMasterProjectId): ResponseInterface
8281
{
8382
$routeParams = self::ROUTES['launchProject'];
8483
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId]);
@@ -89,7 +88,7 @@ public function launchProject(string $textMasterProjectId): Response
8988
/**
9089
* @throws GuzzleException
9190
*/
92-
public function addDocumentsToProject(string $textMasterProjectId, array $documents): Response
91+
public function addDocumentsToProject(string $textMasterProjectId, array $documents): ResponseInterface
9392
{
9493
$routeParams = self::ROUTES['addDocument'];
9594
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId]);
@@ -100,7 +99,7 @@ public function addDocumentsToProject(string $textMasterProjectId, array $docume
10099
/**
101100
* @throws GuzzleException
102101
*/
103-
public function completeDocument(string $documentId, string $textMasterProjectId): Response
102+
public function completeDocument(string $documentId, string $textMasterProjectId): ResponseInterface
104103
{
105104
$routeParams = self::ROUTES['completeDocument'];
106105
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId, '{documentId}' => $documentId]);
@@ -111,7 +110,7 @@ public function completeDocument(string $documentId, string $textMasterProjectId
111110
/**
112111
* @throws GuzzleException
113112
*/
114-
public function setProjectOptions(string $textMasterProjectId, array $options): Response
113+
public function setProjectOptions(string $textMasterProjectId, array $options): ResponseInterface
115114
{
116115
$routeParams = self::ROUTES['setOptions'];
117116
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId]);
@@ -122,7 +121,7 @@ public function setProjectOptions(string $textMasterProjectId, array $options):
122121
/**
123122
* @throws GuzzleException
124123
*/
125-
public function getProject(string $textMasterProjectId): Response
124+
public function getProject(string $textMasterProjectId): ResponseInterface
126125
{
127126
$routeParams = self::ROUTES['getProject'];
128127
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId]);
@@ -133,7 +132,7 @@ public function getProject(string $textMasterProjectId): Response
133132
/**
134133
* @throws GuzzleException
135134
*/
136-
public function getDocument(string $textMasterProjectId, string $textMasterDocumentId): Response
135+
public function getDocument(string $textMasterProjectId, string $textMasterDocumentId): ResponseInterface
137136
{
138137
$routeParams = self::ROUTES['getDocument'];
139138
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId, '{documentId}' => $textMasterDocumentId]);
@@ -144,7 +143,7 @@ public function getDocument(string $textMasterProjectId, string $textMasterDocum
144143
/**
145144
* @throws GuzzleException
146145
*/
147-
public function getProjectQuotation(array $project): Response
146+
public function getProjectQuotation(array $project): ResponseInterface
148147
{
149148
$routeParams = self::ROUTES['getProjectQuotation'];
150149

@@ -154,18 +153,17 @@ public function getProjectQuotation(array $project): Response
154153
/**
155154
* @throws GuzzleException
156155
*/
157-
public function getCategories(): Response
156+
public function getCategories(): ResponseInterface
158157
{
159158
$routeParams = self::ROUTES['getCategories'];
160-
$url = $this->formatUrl($routeParams['url'],[]);
161159

162-
return $this->request($url, $routeParams['method']);
160+
return $this->request($routeParams['url'], $routeParams['method']);
163161
}
164162

165163
/**
166164
* @throws GuzzleException
167165
*/
168-
public function getAbilities(string $page): Response
166+
public function getAbilities(string $page): ResponseInterface
169167
{
170168
$routeParams = self::ROUTES['getAbilities'];
171169
$url = $this->formatUrl($routeParams['url'],['{page}' => $page]);
@@ -176,15 +174,15 @@ public function getAbilities(string $page): Response
176174
/**
177175
* @throws GuzzleException
178176
*/
179-
public function getAuthorsForProject(string $textMasterProjectId, string $status = 'my_textmaster'): Response
177+
public function getAuthorsForProject(string $textMasterProjectId, string $status = 'my_textmaster'): ResponseInterface
180178
{
181179
$routeParams = self::ROUTES['getAuthorsForProject'];
182180
$url = $this->formatUrl($routeParams['url'], ['{projectId}' => $textMasterProjectId, '{status}' => $status]);
183181

184-
return $this->request($routeParams['url'], $routeParams['method']);
182+
return $this->request($url, $routeParams['method']);
185183
}
186184

187-
public function extractErrorFromResponse(Response $response, string $format = 'html'): string
185+
public function extractErrorFromResponse(ResponseInterface $response, string $format = 'html'): string
188186
{
189187
$errorMsg = '';
190188
$lineBreaker = 'html' === $format ? '</br>' : "\n";
@@ -205,12 +203,11 @@ public function extractErrorFromResponse(Response $response, string $format = 'h
205203
/**
206204
* @throws GuzzleException
207205
*/
208-
private function request(string $url, string $method, array $payload = []): Response
206+
private function request(string $url, string $method, array $payload = []): ResponseInterface
209207
{
210208
$request = new Request($method, $url);
211-
$response = $this->client->send($request, [RequestOptions::JSON => $payload]);
212209

213-
return $response;
210+
return $this->client->send($request, [RequestOptions::JSON => $payload]);
214211
}
215212

216213
private function createGuzzleClient(array $options): Client

0 commit comments

Comments
 (0)