init
Showing
8 changed files
with
132 additions
and
1 deletions
.gitignore
0 → 100644
| 1 | vendor | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | # immoscout24-api-php | 1 | # immoscout24-api-php |
| 2 | 2 | ||
| 3 | An example implementation for the immoscout24 rest api in php. | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 3 | An example implementation for the immoscout24 rest api in php. This Client is not complete and only implements some methods for the export/import api, but it should be quite easy to extend. | ||
| 4 | |||
| 5 | ## install | ||
| 6 | |||
| 7 | `composer install fehrlich/immoscout24-api-php` | ||
| 8 | |||
| 9 | |||
| 10 | ## usage | ||
| 11 | |||
| 12 | The libary contains an abstract class that needs to be extended by an user defined class and implement 4 methods, that are needed to restore and save tokens. | ||
| 13 | |||
| 14 | ### example implementation | ||
| 15 | |||
| 16 | ``` | ||
| 17 | class MyAPI extends \fehrlich\ScoutAPI\ImmoScoutAPI | ||
| 18 | { | ||
| 19 | /** | ||
| 20 | * should save the request token with tokenname + secret, the token can be temporarily saved within a session | ||
| 21 | * this token is only needed during the "request an access token" phase. | ||
| 22 | * | ||
| 23 | * @param string $token | ||
| 24 | * @param string $secret | ||
| 25 | * | ||
| 26 | * @return void | ||
| 27 | */ | ||
| 28 | public function saveRequestToken($token, $secret){ | ||
| 29 | $_SESSION['is24reqtoken'] = $token; | ||
| 30 | $_SESSION['is24reqsecret'] = $secret; | ||
| 31 | } | ||
| 32 | |||
| 33 | /** | ||
| 34 | * restores the temporarily saved request token. | ||
| 35 | * | ||
| 36 | * @return array with 2 elements: first element is the token name, second element is the secret | ||
| 37 | */ | ||
| 38 | public function restoreRequestToken(){ | ||
| 39 | if(isset($_SESSION['is24reqtoken']) && isset($_SESSION['is24reqsecret'])){ | ||
| 40 | return [ | ||
| 41 | $_SESSION['is24reqtoken'], | ||
| 42 | $_SESSION['is24reqsecret'] | ||
| 43 | ]; | ||
| 44 | } | ||
| 45 | return null; | ||
| 46 | } | ||
| 47 | |||
| 48 | /** | ||
| 49 | * saves the access token, the information should be stored persistently, for example in a database or file. | ||
| 50 | * the progress of getting an access token only needs to be done once per user. | ||
| 51 | * | ||
| 52 | * @param string $token | ||
| 53 | * @param string $secret | ||
| 54 | * | ||
| 55 | * @return void | ||
| 56 | */ | ||
| 57 | public function saveAccessToken($token, $secret){ | ||
| 58 | file_put_contents('accessToken', serialize([$token, $secret])); | ||
| 59 | } | ||
| 60 | |||
| 61 | /** | ||
| 62 | * restores the saved access token. | ||
| 63 | * | ||
| 64 | * @return array with 2 elements: first element is the token name, second element is the secret | ||
| 65 | */ | ||
| 66 | public static function restoreAccessToken(){ | ||
| 67 | if(file_exists('accessToken')) { | ||
| 68 | return unserialize(file_get_contents('accessToken')); | ||
| 69 | } | ||
| 70 | return null; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | ``` | ||
| 74 | |||
| 75 | If you want to support multiple user, you can use `$this->getUser()` within the class. | ||
| 76 | |||
| 77 | ### example usage | ||
| 78 | |||
| 79 | |||
| 80 | ``` | ||
| 81 | $key = 'my consumer key'; | ||
| 82 | $secret = 'my consumer secret'; | ||
| 83 | |||
| 84 | // $api->dontUseSandbox(); | ||
| 85 | |||
| 86 | $api = MyAPI::createClient($key, $secret); | ||
| 87 | if ($api->isVerified()) { | ||
| 88 | // get a list of possible contacts used in a real estate | ||
| 89 | $contactArray = $api->getContacts(); | ||
| 90 | var_dump($contactArray); | ||
| 91 | } else { | ||
| 92 | // this will trigger the verifiaction with immoscout24, and will try to reconnect | ||
| 93 | // to the current url else you can also use a paramater to specify the callback url | ||
| 94 | $api->verifyApplication(); | ||
| 95 | } | ||
| 96 | ``` | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
composer.json
0 → 100644
| 1 | { | ||
| 2 | "name": "fehrlich/immoscout24-api-php", | ||
| 3 | "description": "PHP Client for interacting with the Immoscout24 REST API", | ||
| 4 | "type": "library", | ||
| 5 | "authors": [ | ||
| 6 | { | ||
| 7 | "name": "fehrlich", | ||
| 8 | "email": "franz.ehrlich@googlemail.com" | ||
| 9 | } | ||
| 10 | ], | ||
| 11 | "require": { | ||
| 12 | "guzzlehttp/guzzle-services": "^1.1", | ||
| 13 | "guzzlehttp/oauth-subscriber": "^0.3.0", | ||
| 14 | "guzzlehttp/guzzle": "^6.3" | ||
| 15 | } | ||
| 16 | } |
composer.lock
0 → 100644
This diff is collapsed.
Click to expand it.
src/ImmoScoutAPI.php
0 → 100644
This diff is collapsed.
Click to expand it.
src/exceptions/AuthException.php
0 → 100644
src/exceptions/InvalidResponse.php
0 → 100644
-
Please register or sign in to post a comment