31d1c521 by fehrlich

readded publish/unpublish/delete

1 parent d0cc95e2
......@@ -2,11 +2,11 @@
namespace fehrlich\ImmoScoutAPI;
use function GuzzleHttp\json_decode;
use function GuzzleHttp\json_encode;
use fehrlich\ImmoScoutAPI\exceptions\AuthException;
use fehrlich\ImmoScoutAPI\exceptions\InvalidResponse;
use fehrlich\ImmoScoutAPI\exceptions\InvalidTokenException;
use function GuzzleHttp\json_decode;
use function GuzzleHttp\json_encode;
use GuzzleHttp\Client;
use GuzzleHttp\Command\Guzzle\Description;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
......@@ -266,7 +266,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
throw new InvalidResponse('Could not parse the requested request token');
}
$this->saveRequestToken($body['oauth_token'], $body['oauth_token_secret']);
header('Location: '.$this->getBaseUrl().'security/oauth/confirm_access?oauth_token='.$body['oauth_token']);
header('Location: ' . $this->getBaseUrl() . 'security/oauth/confirm_access?oauth_token=' . $body['oauth_token']);
exit();
}
......@@ -353,10 +353,15 @@ abstract class ImmoScoutAPI extends GuzzleClient
*
* @return string url
*/
private function getUrl($methodUri)
private function getUrl($methodUri, $withUser = true)
{
$url = $this->getBaseUrl();
$path = 'api/offer/v1.0/user/{user}/';
$path = 'api/offer/v1.0/';
if ($withUser) {
$path .= 'user/{user}/';
}
if (substr($methodUri, 0, 1) !== '/') {
$path .= $methodUri;
} else {
......@@ -364,7 +369,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
}
$path = str_replace('{user}', $this->user, $path);
return $url.$path;
return $url . $path;
}
/**
......@@ -465,9 +470,9 @@ abstract class ImmoScoutAPI extends GuzzleClient
*
* @return void
*/
private function call($method, $methodUri, $data = [])
private function call($method, $methodUri, $data = [], $withUser = false)
{
$methodUri = $this->getUrl($methodUri);
$methodUri = $this->getUrl($methodUri, $withUser);
try {
return $this->client->request($method, $methodUri, $data);
} catch (ClientException $ex) {
......@@ -478,7 +483,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
}
}
private function callMethod($methodUri, $method = 'GET', $jsonData = null, $useJson = true)
private function callMethod($methodUri, $method = 'GET', $jsonData = null, $useJson = true, $withUser = false)
{
$data = [];
if ($jsonData && $useJson) {
......@@ -489,7 +494,12 @@ abstract class ImmoScoutAPI extends GuzzleClient
$data = $jsonData;
}
return $this->call($method, $methodUri, $data);
return $this->call($method, $methodUri, $data, $withUser);
}
private function callUserMethod($methodUri, $method = 'GET', $jsonData = null, $useJson = true)
{
return $this->callMethod($methodUri, $method, $jsonData, $useJson, true);
}
/**
......@@ -508,7 +518,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
$msgs = $this->parseMessages($res);
if (!isset($msgs['parsed'][$expectedResponse])) {
$code = isset($msgs['parsed']['ERROR_RESOURCE_NOT_FOUND']) ? 404 : null;
throw new InvalidResponse('Did not get expected response: '.$res->getBody(), $code, null, $res, $msgs);
throw new InvalidResponse('Did not get expected response: ' . $res->getBody(), $code, null, $res, $msgs);
}
if ($expectedResponse == 'MESSAGE_RESOURCE_CREATED') {
return $msgs['parsed'][$expectedResponse][0];
......@@ -548,7 +558,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function getPublishChannels()
{
return $this->callMethod('publishchannel');
return $this->callUserMethod('publishchannel');
}
/**
......@@ -560,7 +570,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function createRealEstate($obj)
{
$res = $this->callMethod('realestate/?usenewenergysourceenev2014values=true', 'POST', $obj);
$res = $this->callUserMethod('realestate/?usenewenergysourceenev2014values=true', 'POST', $obj);
return $this->checkForResponseCreated($res);
}
......@@ -575,7 +585,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function updateRealEstate($id, $obj)
{
$res = $this->callMethod('realestate/'.$id.'?usenewenergysourceenev2014values=true', 'PUT', $obj);
$res = $this->callUserMethod('realestate/' . $id . '?usenewenergysourceenev2014values=true', 'PUT', $obj);
return $this->checkForResponseUpdated($res);
}
......@@ -590,7 +600,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function deleteAttachment($reId, $attachmentId)
{
$res = $this->callMethod('realestate/'.$reId.'/attachment/'.$attachmentId, 'DELETE');
$res = $this->callUserMethod('realestate/' . $reId . '/attachment/' . $attachmentId, 'DELETE');
return $this->checkForResponseDeleted($res);
}
......@@ -615,7 +625,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function createAttachment($objId, $attachmentData, $content, $mimeType = 'image/jpeg', $fileName = 'image.jpg')
{
$res = $this->callMethod('realestate/'.$objId.'/attachment/', 'POST', [
$res = $this->callUserMethod('realestate/' . $objId . '/attachment/', 'POST', [
'multipart' => [
[
'Content-type' => 'application/json',
......@@ -645,7 +655,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function updateAttachment($objId, $id, $attachmentData)
{
$res = $this->callMethod('realestate/'.$objId.'/attachment/'.$id, 'PUT', $attachmentData);
$res = $this->callUserMethod('realestate/' . $objId . '/attachment/' . $id, 'PUT', $attachmentData);
return $this->checkForResponseUpdated($res);
}
......@@ -660,10 +670,10 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function updateAttachmentOrder($objId, $orderArray)
{
$res = $this->callMethod('realestate/'.$objId.'/attachment/attachmentsorder', 'PUT', [
$res = $this->callUserMethod('realestate/' . $objId . '/attachment/attachmentsorder', 'PUT', [
'attachmentsorder.attachmentsorder' => [
'@xmlns' => [
'attachmentsorder' => 'http://rest.immobilienscout24.de/schema/attachmentsorder/1.0',
'attachmentsorder' => 'http://rest.immobilienscout24.de/schema/attachmentsorder/1.0',
],
'attachmentId' => $orderArray,
],
......@@ -679,7 +689,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function getContacts()
{
$res = $this->callMethod('contact');
$res = $this->callUserMethod('contact');
$arr = $this->parseGetResponse($res);
if (!isset($arr['common.realtorContactDetailsList']) || !isset($arr['common.realtorContactDetailsList']['realtorContactDetails'])) {
......@@ -695,7 +705,40 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public function delete($reId)
{
$res = $this->callMethod('realestate/'.$reId, 'DELETE');
$res = $this->callUserMethod('realestate/' . $reId, 'DELETE');
return $this->checkForResponseDeleted($res);
}
/**
* Get an array of all contacts that can be specified for a real estate.
* @param string $reId realestate id used by is24
* @param string $publishchannel publish channel id like 10000
*/
public function publish($reId, $publishchannel = '10000')
{
$res = $this->callMethod('publish/', 'POST', [
'common.publishObject' => [
'realEstate' => [
'@id' => $reId,
],
'publishChannel' => [
'@id' => $publishchannel,
],
],
]);
return $this->checkForResponseCreated($res);
}
/**
* unpublish a real estate
* @param string $reId realestate id used by is24
* @param string $publishchannel publish channel id like 10000
*/
public function unpublish($reId, $publishchannel = '10000')
{
$res = $this->callMethod('publish/' . $reId . '_' . $publishchannel, 'DELETE');
return $this->checkForResponseDeleted($res);
}
......
......@@ -4,8 +4,6 @@ namespace fehrlich\ImmoScoutAPI\exceptions;
use Exception;
use Exception;
class AuthException extends Exception
{
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!