@@ -116,7 +116,7 @@ protected static function data($data)
116116 * @param string $resource
117117 *
118118 * @return string
119- * @throws \ Exception
119+ * @throws Exception
120120 */
121121 protected function createSignature ($ resource )
122122 {
@@ -175,7 +175,7 @@ protected function getRequestHeaders($resource)
175175 * @param array $headers
176176 *
177177 * @return \stdClass
178- * @throws \PDFGeneratorAPI\Exception
178+ * @throws \ActualReports\ PDFGeneratorAPI\Exception
179179 */
180180 public function request ($ method = self ::REQUEST_POST , $ resource , array $ params = [], array $ headers = [])
181181 {
@@ -211,24 +211,28 @@ public function request($method = self::REQUEST_POST, $resource, array $params =
211211 * @param $resource
212212 * @param $options
213213 *
214- * @return \stdClass
214+ * @return \stdClass|null
215+ * @throws \ActualReports\PDFGeneratorAPI\Exception
215216 */
216217 protected function handleRequest ($ method , $ resource , $ options )
217218 {
219+ $ response = null ;
218220 try
219221 {
220- return $ this ->handleResponse ($ this ->getHttpClient ()->request ($ method , $ resource , $ options ));
222+ $ response = $ this ->handleResponse ($ this ->getHttpClient ()->request ($ method , $ resource , $ options ));
221223 }
222224 catch (RequestException $ e )
223225 {
224226 $ this ->handleException ($ e );
225227 }
228+
229+ return $ response ;
226230 }
227231
228232 /**
229233 * @param \GuzzleHttp\Exception\RequestException $e
230234 *
231- * @throws \PDFGeneratorAPI\Exception
235+ * @throws \ActualReports\ PDFGeneratorAPI\Exception
232236 */
233237 protected function handleException (RequestException $ e )
234238 {
@@ -261,7 +265,7 @@ protected function handleException(RequestException $e)
261265 * @param \Psr\Http\Message\ResponseInterface $response
262266 *
263267 * @return \stdClass
264- * @throws \PDFGeneratorAPI\Exception
268+ * @throws \ActualReports\ PDFGeneratorAPI\Exception
265269 */
266270 protected function handleResponse (ResponseInterface $ response )
267271 {
@@ -277,19 +281,34 @@ protected function handleResponse(ResponseInterface $response)
277281 }
278282
279283 /**
280- * Returns list templates available in active workspace and returns template info
284+ * Returns list of templates available in active workspace
281285 *
282286 * @param array $access
283287 * @param array $tags
284288 *
285- * @return \stdClass
289+ * @return array
286290 */
287- public function get (array $ access = [], array $ tags = [])
291+ public function getAll (array $ access = [], array $ tags = [])
288292 {
289- return $ this ->request (self ::REQUEST_GET , 'templates ' , [
293+ $ response = $ this ->request (self ::REQUEST_GET , 'templates ' , [
290294 'access ' => implode (', ' , $ access ),
291295 'tags ' => implode (', ' , $ tags )
292296 ]);
297+
298+ return $ response ->response ;
299+ }
300+
301+ /**
302+ * Returns template configuration
303+ *
304+ * @param integer $template
305+ *
306+ * @return \stdClass
307+ */
308+ public function get ($ template )
309+ {
310+ $ response = $ this ->request (self ::REQUEST_GET , 'templates/ ' .$ template );
311+ return $ response ->response ;
293312 }
294313
295314 /**
@@ -300,7 +319,7 @@ public function get(array $access = [], array $tags = [])
300319 */
301320 public function create ($ name )
302321 {
303- return $ this ->request (self ::REQUEST_POST , 'templates ' , [
322+ $ response = $ this ->request (self ::REQUEST_POST , 'templates ' , [
304323 'data ' =>[
305324 'name ' => $ name ,
306325 'layout ' => [
@@ -322,6 +341,8 @@ public function create($name)
322341 ]]
323342 ]
324343 ]);
344+
345+ return $ response ->response ;
325346 }
326347
327348 /**
@@ -333,9 +354,11 @@ public function create($name)
333354 */
334355 public function copy ($ template , $ newName = null )
335356 {
336- return $ this ->request (self ::REQUEST_POST , 'templates/ ' .$ template .'/copy ' , [
357+ $ response = $ this ->request (self ::REQUEST_POST , 'templates/ ' .$ template .'/copy ' , [
337358 'name ' => $ newName
338359 ]);
360+
361+ return $ response ->response ;
339362 }
340363
341364 /**
@@ -344,31 +367,35 @@ public function copy($template, $newName = null)
344367 * @param integer $template
345368 * @param string|array|\stdClass $data
346369 * @param string $format
370+ * @param string $name
371+ * @param array $params
347372 *
348373 * @return \stdClass
349374 */
350- public function output ($ template , $ data , $ format = self ::FORMAT_PDF )
375+ public function output ($ template , $ data , $ format = self ::FORMAT_PDF , $ name = null , array $ params = [] )
351376 {
352- return $ this ->request (self ::REQUEST_POST , 'templates/ ' .$ template .'/output ' , [
377+ return $ this ->request (self ::REQUEST_POST , 'templates/ ' .$ template .'/output ' , array_merge ( [
353378 'data ' => $ data ,
354379 'format ' => $ format ,
355- ]);
380+ 'name ' => $ name
381+ ], $ params ));
356382 }
357383
358384 /**
359385 * Creates editor url
360386 * @param integer $template
361387 * @param array|\stdClass|string $data
388+ * @param array $params
362389 * @return string
363390 */
364- public function editor ($ template , $ data = null )
391+ public function editor ($ template , $ data = null , array $ params = [] )
365392 {
366393 $ resource = 'templates/ ' .$ template .'/editor ' ;
367- $ params = [
394+ $ params = array_merge ( [
368395 'token ' => $ this ->token ,
369396 'workspace ' => $ this ->workspace ,
370397 'signature ' => $ this ->createSignature ($ resource )
371- ];
398+ ], $ params ) ;
372399
373400 if ($ data )
374401 {
0 commit comments