Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Vlad Bukhanets
/
immoscout24-api-php
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Merge Requests
0
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
31d1c521
authored
2019-12-05 15:21:27 +0100
by
fehrlich
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
readded publish/unpublish/delete
1 parent
d0cc95e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
23 deletions
src/ImmoScoutAPI.php
src/exceptions/AuthException.php
src/ImmoScoutAPI.php
View file @
31d1c52
...
...
@@ -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
->
call
User
Method
(
'publishchannel'
);
}
/**
...
...
@@ -560,7 +570,7 @@ abstract class ImmoScoutAPI extends GuzzleClient
*/
public
function
createRealEstate
(
$obj
)
{
$res
=
$this
->
callMethod
(
'realestate/?usenewenergysourceenev2014values=true'
,
'POST'
,
$obj
);
$res
=
$this
->
call
User
Method
(
'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
->
call
Method
(
'realestate/'
.
$id
.
'?usenewenergysourceenev2014values=true'
,
'PUT'
,
$obj
);
$res
=
$this
->
call
UserMethod
(
'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
->
call
Method
(
'realestate/'
.
$reId
.
'/attachment/'
.
$attachmentId
,
'DELETE'
);
$res
=
$this
->
call
UserMethod
(
'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
->
call
Method
(
'realestate/'
.
$objId
.
'/attachment/'
,
'POST'
,
[
$res
=
$this
->
call
UserMethod
(
'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
->
call
Method
(
'realestate/'
.
$objId
.
'/attachment/'
.
$id
,
'PUT'
,
$attachmentData
);
$res
=
$this
->
call
UserMethod
(
'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
->
call
Method
(
'realestate/'
.
$objId
.
'/attachment/attachmentsorder'
,
'PUT'
,
[
$res
=
$this
->
call
UserMethod
(
'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
->
call
User
Method
(
'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
);
}
...
...
src/exceptions/AuthException.php
View file @
31d1c52
...
...
@@ -4,8 +4,6 @@ namespace fehrlich\ImmoScoutAPI\exceptions;
use
Exception
;
use
Exception
;
class
AuthException
extends
Exception
{
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment