Skip to content

Commit

Permalink
Added ability to use test mode (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanruzak committed Dec 15, 2023
1 parent f18e0bb commit 1f38196
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/Client.php
Expand Up @@ -25,9 +25,7 @@ public function setIsZip($isZip)
$this->isZip = $isZip;
}

const PROD_URL = 'https://www.finn.no/finn/import/fileimport';

protected $url = 'https://import.finn.no/finn/import/fileimport';
protected $liveMode = false;

private $isZip = false;

Expand All @@ -51,15 +49,15 @@ public function getRequestBody()

public function setLiveMode()
{
$this->url = self::PROD_URL;
$this->liveMode = true;
}

/**
* @param string $url
* @return bool
*/
public function setUrl($url)
public function isLiveMode()
{
$this->url = $url;
return $this->liveMode;
}

/**
Expand Down Expand Up @@ -100,11 +98,25 @@ public function transfer($body, $type = 'xml')
'filename' => "file.$type"
]
]);
$this->request = new Request('POST', $this->url, [], $multipart);

$headers = [];
if ($this->isLiveMode()) {
$url = 'https://www.finn.no/finn/import/fileimport';
} else {
// Test mode.
$url = 'https://import.finn.no/finn/import/fileimport';
$headers = [
'Authorization' => 'Basic '. base64_encode('partner:testimport'),
];
}

$this->request = new Request('POST', $url, $headers, $multipart);

if (!$this->isZip) {
$this->requestBody = $body;
}
$res = $this->client->send($this->request);

return $res;
}

Expand Down

0 comments on commit 1f38196

Please sign in to comment.