Get PDF function

parent 1c5ee0a3
......@@ -130,5 +130,18 @@ if ($show) {
}
}
/**
* Λειτουργία λήψης αρχείου με δεδομένο hash id $options['save'] ή $options['get']
*/
if ($get) {
if ($save) {
$doc_details = $app->savePdf($options['save'], $apikey);
echo "Λεπτομέρειες αποθήκευσης εγγράφου: ", PHP_EOL, print_r($doc_details, true), PHP_EOL;
} else {
$doc_details = $app->getPdf($options['get'], $apikey);
echo "Λεπτομέρειες εγγράφου: ", PHP_EOL, print_r($doc_details, true), PHP_EOL;
}
}
echo "Done.", PHP_EOL;
exit(0);
......@@ -114,12 +114,27 @@ class App
public function getPdf($hashid, $apikey = null)
{
if ($this->_debug) {
echo "getPdf:: hash id: {$hashid}", PHP_EOL;
}
$response = json_decode($this->client->getPdf($hashid, $apikey === null ? $this->getApiKey() : $apikey), true);
return $response;
}
public function savePdf($hashid, $apikey = null)
{
if ($this->_debug) {
echo "savePdf:: hash id: {$hashid}", PHP_EOL;
}
$result = $this->getPdf($hashid, $apikey = null);
$save = file_put_contents($result["fileName"], base64_decode($result["document"]["base64"]));
return [
'file_name' => $result["fileName"],
'description' => $result["description"],
'save' => ($save ? 'Αποθηκεύτηκε' : 'ΔΕΝ αποθηκεύθηκε')
];
}
/**
......
......@@ -56,6 +56,17 @@ class Client
return $result;
}
public function getPdf($hashid, $apikey)
{
$result = $this->get("{$this->_settings['base_uri']}/document/pdf/{$hashid}", [], [
"api_key: {$apikey}",
"Content-Type: text/plain",
"Accept: application/json",
]
);
return $result;
}
protected function setCommonCurlOptions($ch, $uri, $headers)
{
curl_setopt($ch, CURLOPT_URL, $uri);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment