main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$curl = curl_init();

$jsonObj = json_encode(array(
  "name" => "The White Housadse",
  "room_type" => "Private room",
  "property_type" => "Townhouse",
  "price" => 124,
  "has_availability" => true,
  "accommodates" => 2,
  "bedrooms" => 1,
  "bathrooms" => 1.5,
  "beds" => 1,
  "bed_type" => "Real Bed",
  "host_image" => "https://a2.muscache.com/ac/pictures/7c28a155-3eb8-438d-8f51-426b191ab795.jpg?interpolation=lanczos-none&crop=w:w;*,*&crop=h:h;*,*&resize=50:*&output-format=jpg&output-quality=70",
  "host_name" => "Alyson",
  "image" => "https://a0.muscache.com/im/pictures/68837752/96cae4d1_original.jpg?aki_policy=medium",
  "listing_url" => "https://www.airbnb.com/rooms/5364119",
  "location" => array(
    "lat" => 47.53540733743967,
    "lon" => -122.27983057017123
  ),
  "date_from" => 20170426,
  "date_to" => 20170421
));

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://scalr.api.appbase.io/housing-demo/listing/H1",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS => $jsonObj,
  CURLOPT_HTTPHEADER => array(
    "Authorization: Basic WW5DZ1Z3b3pWOmU5ZWM1Y2IwLTU4ZDgtNGJiMC1iYWRjLWFjYWY3MjY2NjFmMQ==",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  $json = json_decode($response, true);
  print_r("@index success: ");
  print_r($json);
}
PHP 7.0.8 (cli) (built: Jun 23 2016 23:39:14) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies