Skip to content

Commit

Permalink
Service
Browse files Browse the repository at this point in the history
  • Loading branch information
aquilax committed May 29, 2015
1 parent 8a02491 commit be59025
Show file tree
Hide file tree
Showing 10 changed files with 479 additions and 172 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php" colors="true">
<phpunit bootstrap="tests/bootstrap.php" colors="true" beStrictAboutOutputDuringTests="true">
<testsuites>
<testsuite name="Fyndiq Prestashop Module">
<directory>tests/src/</directory>
Expand Down
Expand Up @@ -3,10 +3,16 @@
class FmOrderFetch extends FyndiqPaginatedFetch
{

function __construct($fmConfig, $fmOrder, $fmApiModel){
$this->fmConfig = $fmConfig;
$this->fmOrder = $fmOrder;
$this->fmApiModel = $fmApiModel;
}

function getInitialPath()
{
$url = 'orders/';
$date = FmConfig::get('import_date');
$date = $this->fmConfig->get('import_date');
if (!empty($date)) {
$url .= '?min_date=' . urlencode($date);
}
Expand All @@ -15,15 +21,15 @@ function getInitialPath()

function getPageData($path)
{
$ret = FmHelpers::callApi('GET', $path);
$ret = $this->fmApiModel->callApi('GET', $path);
return $ret['data'];
}

function processData($data)
{
foreach ($data as $order) {
if (!FmOrder::orderExists($order->id)) {
FmOrder::create($order);
if (!$this->fmOrder->orderExists($order->id)) {
$this->fmOrder->create($order);
}
}
return true;
Expand Down
30 changes: 30 additions & 0 deletions src/backoffice/FmOutput.php
Expand Up @@ -59,6 +59,24 @@ public function renderJSON($data)
return true;
}

/**
* create a error to be send back to client.
*
* @param $title
* @param $message
*/
public function responseError($title, $message)
{
$response = array(
'fm-service-status' => 'error',
'title' => $title,
'message' => $message,
);
$json = json_encode($response);
$this->output($json);
return null;
}

public function header($content)
{
return header($content);
Expand All @@ -69,4 +87,16 @@ public function output($output)
echo $output;
return true;
}

public function streamFile($file, $fileName, $contentType)
{
$this->header('Content-Type: ' . $contentType);
$this->header('Content-Disposition: attachment; filename="' . $fileName . '"');
$this->header('Content-Transfer-Encoding: binary');
$this->header('Content-Length: ' . filesize($file));
$this->header('Expires: 0');
rewind($file);
return fpassthru($file);
}

}

0 comments on commit be59025

Please sign in to comment.