4
4
5
5
use GuzzleHttp \Client ;
6
6
use GuzzleHttp \Exception \GuzzleException ;
7
- use GuzzleHttp \Handler \CurlHandler ;
8
7
use GuzzleHttp \HandlerStack ;
9
8
use GuzzleHttp \Middleware ;
10
9
use GuzzleHttp \Psr7 \Request ;
11
- use GuzzleHttp \Psr7 \Response ;
12
10
use GuzzleHttp \RequestOptions ;
13
11
use Psr \Http \Message \RequestInterface ;
12
+ use Psr \Http \Message \ResponseInterface ;
14
13
15
14
class TextMasterApi
16
15
{
@@ -57,7 +56,7 @@ public function __construct(string $apiKey, string $apiSecret, string $textmaste
57
56
/**
58
57
* @throws GuzzleException
59
58
*/
60
- public function createProject (array $ project ): Response
59
+ public function createProject (array $ project ): ResponseInterface
61
60
{
62
61
$ routeParams = self ::ROUTES ['createProject ' ];
63
62
@@ -67,18 +66,18 @@ public function createProject(array $project): Response
67
66
/**
68
67
* @throws GuzzleException
69
68
*/
70
- public function updateProject (string $ textMasterProjectId , array $ options ): Response
69
+ public function updateProject (string $ textMasterProjectId , array $ options ): ResponseInterface
71
70
{
72
71
$ routeParams = self ::ROUTES ['updateProject ' ];
73
72
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId ]);
74
73
75
- return $ this ->request ($ routeParams [ ' url ' ] , $ routeParams ['method ' ], ['project ' => $ options ]);
74
+ return $ this ->request ($ url , $ routeParams ['method ' ], ['project ' => $ options ]);
76
75
}
77
76
78
77
/**
79
78
* @throws GuzzleException
80
79
*/
81
- public function launchProject (string $ textMasterProjectId ): Response
80
+ public function launchProject (string $ textMasterProjectId ): ResponseInterface
82
81
{
83
82
$ routeParams = self ::ROUTES ['launchProject ' ];
84
83
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId ]);
@@ -89,7 +88,7 @@ public function launchProject(string $textMasterProjectId): Response
89
88
/**
90
89
* @throws GuzzleException
91
90
*/
92
- public function addDocumentsToProject (string $ textMasterProjectId , array $ documents ): Response
91
+ public function addDocumentsToProject (string $ textMasterProjectId , array $ documents ): ResponseInterface
93
92
{
94
93
$ routeParams = self ::ROUTES ['addDocument ' ];
95
94
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId ]);
@@ -100,7 +99,7 @@ public function addDocumentsToProject(string $textMasterProjectId, array $docume
100
99
/**
101
100
* @throws GuzzleException
102
101
*/
103
- public function completeDocument (string $ documentId , string $ textMasterProjectId ): Response
102
+ public function completeDocument (string $ documentId , string $ textMasterProjectId ): ResponseInterface
104
103
{
105
104
$ routeParams = self ::ROUTES ['completeDocument ' ];
106
105
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId , '{documentId} ' => $ documentId ]);
@@ -111,7 +110,7 @@ public function completeDocument(string $documentId, string $textMasterProjectId
111
110
/**
112
111
* @throws GuzzleException
113
112
*/
114
- public function setProjectOptions (string $ textMasterProjectId , array $ options ): Response
113
+ public function setProjectOptions (string $ textMasterProjectId , array $ options ): ResponseInterface
115
114
{
116
115
$ routeParams = self ::ROUTES ['setOptions ' ];
117
116
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId ]);
@@ -122,7 +121,7 @@ public function setProjectOptions(string $textMasterProjectId, array $options):
122
121
/**
123
122
* @throws GuzzleException
124
123
*/
125
- public function getProject (string $ textMasterProjectId ): Response
124
+ public function getProject (string $ textMasterProjectId ): ResponseInterface
126
125
{
127
126
$ routeParams = self ::ROUTES ['getProject ' ];
128
127
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId ]);
@@ -133,7 +132,7 @@ public function getProject(string $textMasterProjectId): Response
133
132
/**
134
133
* @throws GuzzleException
135
134
*/
136
- public function getDocument (string $ textMasterProjectId , string $ textMasterDocumentId ): Response
135
+ public function getDocument (string $ textMasterProjectId , string $ textMasterDocumentId ): ResponseInterface
137
136
{
138
137
$ routeParams = self ::ROUTES ['getDocument ' ];
139
138
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId , '{documentId} ' => $ textMasterDocumentId ]);
@@ -144,7 +143,7 @@ public function getDocument(string $textMasterProjectId, string $textMasterDocum
144
143
/**
145
144
* @throws GuzzleException
146
145
*/
147
- public function getProjectQuotation (array $ project ): Response
146
+ public function getProjectQuotation (array $ project ): ResponseInterface
148
147
{
149
148
$ routeParams = self ::ROUTES ['getProjectQuotation ' ];
150
149
@@ -154,18 +153,17 @@ public function getProjectQuotation(array $project): Response
154
153
/**
155
154
* @throws GuzzleException
156
155
*/
157
- public function getCategories (): Response
156
+ public function getCategories (): ResponseInterface
158
157
{
159
158
$ routeParams = self ::ROUTES ['getCategories ' ];
160
- $ url = $ this ->formatUrl ($ routeParams ['url ' ],[]);
161
159
162
- return $ this ->request ($ url , $ routeParams ['method ' ]);
160
+ return $ this ->request ($ routeParams [ ' url ' ] , $ routeParams ['method ' ]);
163
161
}
164
162
165
163
/**
166
164
* @throws GuzzleException
167
165
*/
168
- public function getAbilities (string $ page ): Response
166
+ public function getAbilities (string $ page ): ResponseInterface
169
167
{
170
168
$ routeParams = self ::ROUTES ['getAbilities ' ];
171
169
$ url = $ this ->formatUrl ($ routeParams ['url ' ],['{page} ' => $ page ]);
@@ -176,15 +174,15 @@ public function getAbilities(string $page): Response
176
174
/**
177
175
* @throws GuzzleException
178
176
*/
179
- public function getAuthorsForProject (string $ textMasterProjectId , string $ status = 'my_textmaster ' ): Response
177
+ public function getAuthorsForProject (string $ textMasterProjectId , string $ status = 'my_textmaster ' ): ResponseInterface
180
178
{
181
179
$ routeParams = self ::ROUTES ['getAuthorsForProject ' ];
182
180
$ url = $ this ->formatUrl ($ routeParams ['url ' ], ['{projectId} ' => $ textMasterProjectId , '{status} ' => $ status ]);
183
181
184
- return $ this ->request ($ routeParams [ ' url ' ] , $ routeParams ['method ' ]);
182
+ return $ this ->request ($ url , $ routeParams ['method ' ]);
185
183
}
186
184
187
- public function extractErrorFromResponse (Response $ response , string $ format = 'html ' ): string
185
+ public function extractErrorFromResponse (ResponseInterface $ response , string $ format = 'html ' ): string
188
186
{
189
187
$ errorMsg = '' ;
190
188
$ lineBreaker = 'html ' === $ format ? '</br> ' : "\n" ;
@@ -205,12 +203,11 @@ public function extractErrorFromResponse(Response $response, string $format = 'h
205
203
/**
206
204
* @throws GuzzleException
207
205
*/
208
- private function request (string $ url , string $ method , array $ payload = []): Response
206
+ private function request (string $ url , string $ method , array $ payload = []): ResponseInterface
209
207
{
210
208
$ request = new Request ($ method , $ url );
211
- $ response = $ this ->client ->send ($ request , [RequestOptions::JSON => $ payload ]);
212
209
213
- return $ response ;
210
+ return $ this -> client -> send ( $ request , [RequestOptions:: JSON => $ payload ]) ;
214
211
}
215
212
216
213
private function createGuzzleClient (array $ options ): Client
0 commit comments