Last active
December 26, 2015 04:29
-
-
Save technovangelist/7093302 to your computer and use it in GitHub Desktop.
How to import a listing to Placester
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function geturls($url) { | |
$apikey=PL_Options::get('placester_api_key'); | |
$urls = array( | |
image => 'https://api.placester.com/v2/listings/media/temp/image?api_key=' . $apikey, | |
listing => 'https://api.placester.com/v2/listings?api_key=' . $apikey, | |
); | |
return $urls[$url]; | |
} | |
function curlpost($data, $url) { | |
$curlimp = curl_init(); | |
curl_setopt($curlimp, CURLOPT_URL,geturls($url)); | |
curl_setopt($curlimp, CURLOPT_POST, 1); | |
curl_setopt($curlimp, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($curlimp, CURLOPT_POSTFIELDS, $data); | |
$curlout = curl_exec($curlimp); | |
curl_close($curlimp); | |
return json_decode($curlout,true); | |
} | |
function uploadimage($filename) { | |
// $curlimp = curl_init(); | |
$data = array('file' =>"@".$filename); | |
return curlpost($data, 'image'); | |
} | |
function newlisting($address, $city, $region, $postal, $image) { | |
$data = "compound_type=res_sale&location[address]=$address&location[locality]=$city&location[region]=$region&location[postal]=$postal&images[1][filename]=$image"; | |
return curlpost($data, 'listing'); | |
} | |
$filename=TEMPLATEPATH.'/screenshot.jpg'; | |
$image=uploadimage($filename); | |
newlisting('485 Ridgewood Road', 'Key Biscayne', 'Florida', '33149', $image[filename]); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment