readded publish/unpublish/delete
Showing
2 changed files
with
64 additions
and
23 deletions
| ... | @@ -2,11 +2,11 @@ | ... | @@ -2,11 +2,11 @@ |
| 2 | 2 | ||
| 3 | namespace fehrlich\ImmoScoutAPI; | 3 | namespace fehrlich\ImmoScoutAPI; |
| 4 | 4 | ||
| 5 | use function GuzzleHttp\json_decode; | ||
| 6 | use function GuzzleHttp\json_encode; | ||
| 7 | use fehrlich\ImmoScoutAPI\exceptions\AuthException; | 5 | use fehrlich\ImmoScoutAPI\exceptions\AuthException; |
| 8 | use fehrlich\ImmoScoutAPI\exceptions\InvalidResponse; | 6 | use fehrlich\ImmoScoutAPI\exceptions\InvalidResponse; |
| 9 | use fehrlich\ImmoScoutAPI\exceptions\InvalidTokenException; | 7 | use fehrlich\ImmoScoutAPI\exceptions\InvalidTokenException; |
| 8 | use function GuzzleHttp\json_decode; | ||
| 9 | use function GuzzleHttp\json_encode; | ||
| 10 | use GuzzleHttp\Client; | 10 | use GuzzleHttp\Client; |
| 11 | use GuzzleHttp\Command\Guzzle\Description; | 11 | use GuzzleHttp\Command\Guzzle\Description; |
| 12 | use GuzzleHttp\Command\Guzzle\GuzzleClient; | 12 | use GuzzleHttp\Command\Guzzle\GuzzleClient; |
| ... | @@ -266,7 +266,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -266,7 +266,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 266 | throw new InvalidResponse('Could not parse the requested request token'); | 266 | throw new InvalidResponse('Could not parse the requested request token'); |
| 267 | } | 267 | } |
| 268 | $this->saveRequestToken($body['oauth_token'], $body['oauth_token_secret']); | 268 | $this->saveRequestToken($body['oauth_token'], $body['oauth_token_secret']); |
| 269 | header('Location: '.$this->getBaseUrl().'security/oauth/confirm_access?oauth_token='.$body['oauth_token']); | 269 | header('Location: ' . $this->getBaseUrl() . 'security/oauth/confirm_access?oauth_token=' . $body['oauth_token']); |
| 270 | exit(); | 270 | exit(); |
| 271 | } | 271 | } |
| 272 | 272 | ||
| ... | @@ -353,10 +353,15 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -353,10 +353,15 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 353 | * | 353 | * |
| 354 | * @return string url | 354 | * @return string url |
| 355 | */ | 355 | */ |
| 356 | private function getUrl($methodUri) | 356 | private function getUrl($methodUri, $withUser = true) |
| 357 | { | 357 | { |
| 358 | $url = $this->getBaseUrl(); | 358 | $url = $this->getBaseUrl(); |
| 359 | $path = 'api/offer/v1.0/user/{user}/'; | 359 | $path = 'api/offer/v1.0/'; |
| 360 | |||
| 361 | if ($withUser) { | ||
| 362 | $path .= 'user/{user}/'; | ||
| 363 | } | ||
| 364 | |||
| 360 | if (substr($methodUri, 0, 1) !== '/') { | 365 | if (substr($methodUri, 0, 1) !== '/') { |
| 361 | $path .= $methodUri; | 366 | $path .= $methodUri; |
| 362 | } else { | 367 | } else { |
| ... | @@ -364,7 +369,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -364,7 +369,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 364 | } | 369 | } |
| 365 | $path = str_replace('{user}', $this->user, $path); | 370 | $path = str_replace('{user}', $this->user, $path); |
| 366 | 371 | ||
| 367 | return $url.$path; | 372 | return $url . $path; |
| 368 | } | 373 | } |
| 369 | 374 | ||
| 370 | /** | 375 | /** |
| ... | @@ -465,9 +470,9 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -465,9 +470,9 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 465 | * | 470 | * |
| 466 | * @return void | 471 | * @return void |
| 467 | */ | 472 | */ |
| 468 | private function call($method, $methodUri, $data = []) | 473 | private function call($method, $methodUri, $data = [], $withUser = false) |
| 469 | { | 474 | { |
| 470 | $methodUri = $this->getUrl($methodUri); | 475 | $methodUri = $this->getUrl($methodUri, $withUser); |
| 471 | try { | 476 | try { |
| 472 | return $this->client->request($method, $methodUri, $data); | 477 | return $this->client->request($method, $methodUri, $data); |
| 473 | } catch (ClientException $ex) { | 478 | } catch (ClientException $ex) { |
| ... | @@ -478,7 +483,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -478,7 +483,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 478 | } | 483 | } |
| 479 | } | 484 | } |
| 480 | 485 | ||
| 481 | private function callMethod($methodUri, $method = 'GET', $jsonData = null, $useJson = true) | 486 | private function callMethod($methodUri, $method = 'GET', $jsonData = null, $useJson = true, $withUser = false) |
| 482 | { | 487 | { |
| 483 | $data = []; | 488 | $data = []; |
| 484 | if ($jsonData && $useJson) { | 489 | if ($jsonData && $useJson) { |
| ... | @@ -489,7 +494,12 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -489,7 +494,12 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 489 | $data = $jsonData; | 494 | $data = $jsonData; |
| 490 | } | 495 | } |
| 491 | 496 | ||
| 492 | return $this->call($method, $methodUri, $data); | 497 | return $this->call($method, $methodUri, $data, $withUser); |
| 498 | } | ||
| 499 | |||
| 500 | private function callUserMethod($methodUri, $method = 'GET', $jsonData = null, $useJson = true) | ||
| 501 | { | ||
| 502 | return $this->callMethod($methodUri, $method, $jsonData, $useJson, true); | ||
| 493 | } | 503 | } |
| 494 | 504 | ||
| 495 | /** | 505 | /** |
| ... | @@ -508,7 +518,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -508,7 +518,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 508 | $msgs = $this->parseMessages($res); | 518 | $msgs = $this->parseMessages($res); |
| 509 | if (!isset($msgs['parsed'][$expectedResponse])) { | 519 | if (!isset($msgs['parsed'][$expectedResponse])) { |
| 510 | $code = isset($msgs['parsed']['ERROR_RESOURCE_NOT_FOUND']) ? 404 : null; | 520 | $code = isset($msgs['parsed']['ERROR_RESOURCE_NOT_FOUND']) ? 404 : null; |
| 511 | throw new InvalidResponse('Did not get expected response: '.$res->getBody(), $code, null, $res, $msgs); | 521 | throw new InvalidResponse('Did not get expected response: ' . $res->getBody(), $code, null, $res, $msgs); |
| 512 | } | 522 | } |
| 513 | if ($expectedResponse == 'MESSAGE_RESOURCE_CREATED') { | 523 | if ($expectedResponse == 'MESSAGE_RESOURCE_CREATED') { |
| 514 | return $msgs['parsed'][$expectedResponse][0]; | 524 | return $msgs['parsed'][$expectedResponse][0]; |
| ... | @@ -548,7 +558,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -548,7 +558,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 548 | */ | 558 | */ |
| 549 | public function getPublishChannels() | 559 | public function getPublishChannels() |
| 550 | { | 560 | { |
| 551 | return $this->callMethod('publishchannel'); | 561 | return $this->callUserMethod('publishchannel'); |
| 552 | } | 562 | } |
| 553 | 563 | ||
| 554 | /** | 564 | /** |
| ... | @@ -560,7 +570,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -560,7 +570,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 560 | */ | 570 | */ |
| 561 | public function createRealEstate($obj) | 571 | public function createRealEstate($obj) |
| 562 | { | 572 | { |
| 563 | $res = $this->callMethod('realestate/?usenewenergysourceenev2014values=true', 'POST', $obj); | 573 | $res = $this->callUserMethod('realestate/?usenewenergysourceenev2014values=true', 'POST', $obj); |
| 564 | 574 | ||
| 565 | return $this->checkForResponseCreated($res); | 575 | return $this->checkForResponseCreated($res); |
| 566 | } | 576 | } |
| ... | @@ -575,7 +585,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -575,7 +585,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 575 | */ | 585 | */ |
| 576 | public function updateRealEstate($id, $obj) | 586 | public function updateRealEstate($id, $obj) |
| 577 | { | 587 | { |
| 578 | $res = $this->callMethod('realestate/'.$id.'?usenewenergysourceenev2014values=true', 'PUT', $obj); | 588 | $res = $this->callUserMethod('realestate/' . $id . '?usenewenergysourceenev2014values=true', 'PUT', $obj); |
| 579 | 589 | ||
| 580 | return $this->checkForResponseUpdated($res); | 590 | return $this->checkForResponseUpdated($res); |
| 581 | } | 591 | } |
| ... | @@ -590,7 +600,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -590,7 +600,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 590 | */ | 600 | */ |
| 591 | public function deleteAttachment($reId, $attachmentId) | 601 | public function deleteAttachment($reId, $attachmentId) |
| 592 | { | 602 | { |
| 593 | $res = $this->callMethod('realestate/'.$reId.'/attachment/'.$attachmentId, 'DELETE'); | 603 | $res = $this->callUserMethod('realestate/' . $reId . '/attachment/' . $attachmentId, 'DELETE'); |
| 594 | 604 | ||
| 595 | return $this->checkForResponseDeleted($res); | 605 | return $this->checkForResponseDeleted($res); |
| 596 | } | 606 | } |
| ... | @@ -615,7 +625,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -615,7 +625,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 615 | */ | 625 | */ |
| 616 | public function createAttachment($objId, $attachmentData, $content, $mimeType = 'image/jpeg', $fileName = 'image.jpg') | 626 | public function createAttachment($objId, $attachmentData, $content, $mimeType = 'image/jpeg', $fileName = 'image.jpg') |
| 617 | { | 627 | { |
| 618 | $res = $this->callMethod('realestate/'.$objId.'/attachment/', 'POST', [ | 628 | $res = $this->callUserMethod('realestate/' . $objId . '/attachment/', 'POST', [ |
| 619 | 'multipart' => [ | 629 | 'multipart' => [ |
| 620 | [ | 630 | [ |
| 621 | 'Content-type' => 'application/json', | 631 | 'Content-type' => 'application/json', |
| ... | @@ -645,7 +655,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -645,7 +655,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 645 | */ | 655 | */ |
| 646 | public function updateAttachment($objId, $id, $attachmentData) | 656 | public function updateAttachment($objId, $id, $attachmentData) |
| 647 | { | 657 | { |
| 648 | $res = $this->callMethod('realestate/'.$objId.'/attachment/'.$id, 'PUT', $attachmentData); | 658 | $res = $this->callUserMethod('realestate/' . $objId . '/attachment/' . $id, 'PUT', $attachmentData); |
| 649 | 659 | ||
| 650 | return $this->checkForResponseUpdated($res); | 660 | return $this->checkForResponseUpdated($res); |
| 651 | } | 661 | } |
| ... | @@ -660,10 +670,10 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -660,10 +670,10 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 660 | */ | 670 | */ |
| 661 | public function updateAttachmentOrder($objId, $orderArray) | 671 | public function updateAttachmentOrder($objId, $orderArray) |
| 662 | { | 672 | { |
| 663 | $res = $this->callMethod('realestate/'.$objId.'/attachment/attachmentsorder', 'PUT', [ | 673 | $res = $this->callUserMethod('realestate/' . $objId . '/attachment/attachmentsorder', 'PUT', [ |
| 664 | 'attachmentsorder.attachmentsorder' => [ | 674 | 'attachmentsorder.attachmentsorder' => [ |
| 665 | '@xmlns' => [ | 675 | '@xmlns' => [ |
| 666 | 'attachmentsorder' => 'http://rest.immobilienscout24.de/schema/attachmentsorder/1.0', | 676 | 'attachmentsorder' => 'http://rest.immobilienscout24.de/schema/attachmentsorder/1.0', |
| 667 | ], | 677 | ], |
| 668 | 'attachmentId' => $orderArray, | 678 | 'attachmentId' => $orderArray, |
| 669 | ], | 679 | ], |
| ... | @@ -679,7 +689,7 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -679,7 +689,7 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 679 | */ | 689 | */ |
| 680 | public function getContacts() | 690 | public function getContacts() |
| 681 | { | 691 | { |
| 682 | $res = $this->callMethod('contact'); | 692 | $res = $this->callUserMethod('contact'); |
| 683 | $arr = $this->parseGetResponse($res); | 693 | $arr = $this->parseGetResponse($res); |
| 684 | 694 | ||
| 685 | if (!isset($arr['common.realtorContactDetailsList']) || !isset($arr['common.realtorContactDetailsList']['realtorContactDetails'])) { | 695 | if (!isset($arr['common.realtorContactDetailsList']) || !isset($arr['common.realtorContactDetailsList']['realtorContactDetails'])) { |
| ... | @@ -695,7 +705,40 @@ abstract class ImmoScoutAPI extends GuzzleClient | ... | @@ -695,7 +705,40 @@ abstract class ImmoScoutAPI extends GuzzleClient |
| 695 | */ | 705 | */ |
| 696 | public function delete($reId) | 706 | public function delete($reId) |
| 697 | { | 707 | { |
| 698 | $res = $this->callMethod('realestate/'.$reId, 'DELETE'); | 708 | $res = $this->callUserMethod('realestate/' . $reId, 'DELETE'); |
| 709 | |||
| 710 | return $this->checkForResponseDeleted($res); | ||
| 711 | } | ||
| 712 | |||
| 713 | /** | ||
| 714 | * Get an array of all contacts that can be specified for a real estate. | ||
| 715 | * @param string $reId realestate id used by is24 | ||
| 716 | * @param string $publishchannel publish channel id like 10000 | ||
| 717 | */ | ||
| 718 | public function publish($reId, $publishchannel = '10000') | ||
| 719 | { | ||
| 720 | $res = $this->callMethod('publish/', 'POST', [ | ||
| 721 | 'common.publishObject' => [ | ||
| 722 | 'realEstate' => [ | ||
| 723 | '@id' => $reId, | ||
| 724 | ], | ||
| 725 | 'publishChannel' => [ | ||
| 726 | '@id' => $publishchannel, | ||
| 727 | ], | ||
| 728 | ], | ||
| 729 | ]); | ||
| 730 | |||
| 731 | return $this->checkForResponseCreated($res); | ||
| 732 | } | ||
| 733 | |||
| 734 | /** | ||
| 735 | * unpublish a real estate | ||
| 736 | * @param string $reId realestate id used by is24 | ||
| 737 | * @param string $publishchannel publish channel id like 10000 | ||
| 738 | */ | ||
| 739 | public function unpublish($reId, $publishchannel = '10000') | ||
| 740 | { | ||
| 741 | $res = $this->callMethod('publish/' . $reId . '_' . $publishchannel, 'DELETE'); | ||
| 699 | 742 | ||
| 700 | return $this->checkForResponseDeleted($res); | 743 | return $this->checkForResponseDeleted($res); |
| 701 | } | 744 | } | ... | ... |
-
Please register or sign in to post a comment