PHP code example of floorplanner / roomstyler-api-php

1. Go to this page and download the library: Download floorplanner/roomstyler-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

floorplanner / roomstyler-api-php example snippets




  



   read all public data
  $rsapi = new RoomstylerApi();




   read all public data
  # can perform actions on rooms such as placing a comment or toggling a like
  $rsapi = new RoomstylerApi(['user' => ['name' => 'myusername', 'password' => 'mypassword']]);




   read all public data
  # can read all whitelabel data
  $rsapi = new RoomstylerApi(['whitelabel' => ['name' => 'mywhitelabel', 'password' => 'mywhitelabelpassword']]);




   read all public data
  # can read all whitelabel data
  # can perform actions on rooms such as placing a comment or toggling a like
  $rsapi = new RoomstylerApi(['user' => ['name' => 'myusername', 'password' => 'mypassword'],
                              'whitelabel' => ['name' => 'mywhitelabel', 'password' => 'mywhitelabelpassword']]);



  # print the 5 latest rooms
  echo '<pre>';
  print_r($rsapi->rooms->index(['limit' => 5]));
  echo '</pre>';

#call to a new instance of "RoomstylerRoomMethods"
$api->rooms;

#call to a new instance of "RoomstylerComponentMethods"
$api->components;


$api = new RoomstylerApi(['user' => $CONFIG['user_credentials']]);
$user = $api->user->find(972691);

echo '<pre>';
print_r($user);
# =>

RoomstylerUser Object
(
    [_http_status:RoomstylerModelBase:private] => 200
    [_accessible_props:RoomstylerModelBase:private] => ['errors']

    [errors:RoomstylerModelBase:private] => RoomstylerError Object
        (
        )

    [_settings:protected] => Array
        (
            [protocol] => https
            [whitelabel] => Array
                (
                )

            [user] => Array
                (
                    [name] => [email protected]
                    [password] => mysignin_password
                )

            [host] => roomstyler.com
            [prefix] => api
            [token] => 64f97c9ee52df2735fsample-tokene6e252d58837d41b05cd
            [timeout] => 5
            [language] => en
            [connect_timeout] => 30
            [request_headers] => Array
                (
                    [0] => Content-Type: application/json; charset=utf-8
                )

            [debug] =>
            [user_agent] => RoomstylerApi/1.0 Type/normal (https://roomstyler.com)
        )

    [_whitelabeled:protected] =>
    [id] => 972691
    [username] => Sidney Liebrand
    [role] => admin
    [bio] => I'm a 21 year old web developer from the Netherlands, born, raised and still living in the always magnificent Dinteloord.
    [avatar] => https://d2sdvaauesfb7j.cloudfront.net/avatars/972691-1434979777.jpg
    [background] => https://d2sdvaauesfb7j.cloudfront.net/img/empty.jpeg
)

$response = $rsapi->rooms->index(['limit' => 100]);

# full response
# since the API call errored, a single object is returned instead of an array of objects.
print_r($response);

# if this didn't happen, you'd have to call
print_r($response[0]);

# to see the errors (which are always bound to every returned object)

$response->errors
# => RoomstylerError{}

$response = $rsapi->rooms->index(['limit' => 100]);

$response->errors->any();
# => true

$response->errors->get();
# => [0 => 'Some error', 'assoc' => 'too', 'user' => ['nested' => ['errors', 'for a single entity']]]

# => [
  'error' => 'Limit should be between 1 and 50',
  0 => 'Unprocessable entity'
]

$response->errors->each(function($error, $labels) {
  if ($labels) $label = join('.', $labels);
  else $label = 'default_label';

  print_r($label": $error");
});


  print_r($rsapi->rooms->search_meta());
  # => RoomstylerSearchMeta{}


  print_r($rsapi->rooms->index());
  # => [RoomstylerRoom{}, RoomstylerRoom{}, ...]


  # ($rsapi->wl->rooms->index());
  # => [RoomstylerRoom{}, RoomstylerRoom{}, ...]


  print_r($rsapi->rooms->find(123456));
  # => RoomstylerRoom{}


  print_r($rsapi->rooms->search(['q' => 'test']));
  # => [RoomstylerRoom{}, RoomstylerRoom{}, ...]


  print_r($rsapi->rooms->panoramas());
  # => [RoomstylerRoom{}, RoomstylerRoom{}, ...]

 $room = $rsapi->rooms->find(123456); 


  print_r($room->panorama());
  # => RoomstylerRoomPanorama{}


  # ($room->comment('My awesome comment!'));
  # => RoomstylerComment{}


  # ($room->toggle_love());
  # => RoomstylerRoom{}


  # ($room->chown(972691));
  # => RoomstylerComment{}



  # $room->delete());
  # => RoomstylerRoom{}



  print_r($room->products());
  # => [RoomstylerProduct{}, RoomstylerProduct{}, ...]


  print_r($room->loved_by());
  # => [RoomstylerUser{}, RoomstylerUser{}, ...]


  print_r($room->related_rooms());
  # => [RoomstylerRoom{}, RoomstylerRoom{}, ...]


  print_r($room->comments());
  # => [RoomstylerComment{}, RoomstylerComment{}, ...]


  print_r($room->add_tags(['first-tag', 'second-tag']));
  # => RoomstylerRoom{}


  print_r($room->add_tags('first-tag,second-tag'));
  # => RoomstylerRoom{}


  print_r($room->remove_tags(['first-tag', 'second-tag']));
  # => RoomstylerRoom{}


  print_r($room->remove_tags('first-tag,second-tag'));
  # => RoomstylerRoom{}


  print_r($room->render());
  # => RoomstylerRoom{}


  print_r($api->users->find(972691));
  # => RoomstylerUser{}


  print_r($api->users->find([972691, 972691]));
  # => [RoomstylerUser{}, RoomstylerUser{}, ...]


  print_r($api->users->find('972691, 972691'));
  # => [RoomstylerUser{}, RoomstylerUser{}, ...]


  print_r($api->users->create(['email' => '[email protected]', 'username' => 'myusername', 'password' => 'mypassword']));
  # => RoomstylerUser{}


  print_r($api->users->login('[email protected]', 'mypassword'));
  # => RoomstylerUser{}

 $user = $rsapi->users->find(972691); 


  print_r($user->delete());
  # => RoomstylerUser{}


  print_r($user->loved_rooms());
  # => [RoomstylerRoom{}, RoomstylerRoom{}, ...]


  print_r($user->collections());
  # => [RoomstylerCollection{}, RoomstylerCollection{}, ...]


print_r($user->collection(44));
# => RoomstylerCollection{}


print_r($api->contests->index());
# => [RoomstylerContest{}, RoomstylerContest{}, ...]


print_r($api->contests->find(1317));
# => RoomstylerContest{}

 $contest = $rsapi->contests->find(1317); 


print_r($contest->entries());
# => [RoomstylerContestEntry{}, RoomstylerContestEntry{}, ...]

 $contest_entry = $rsapi->contests->find(1317)->entries()[0]; 


# ($contest_entry->vote());
# => RoomstylerVote{}


print_r($api->materials->find(3360));
# => RoomstylerMaterial{}


print_r($api->components->find('7b7e830978663ca44cafe62f095ee5f05af7670b'));
# => RoomstylerComponent{}


print_r($api->categories->index());
# => [RoomstylerCategory{}, RoomstylerCategory{}, ...]


print_r($api->editor->embed());
# => <iframe...>

RoomstylerRoomMethods->find($id);

RoomstylerRoomMethods->panoramas($params = ['limit' => 50, 'page' => 1]);

RoomstylerRoom->comment($content);

RoomstylerUser->collection($id)

RoomstylerContestMethods->find($id)

RoomstylerMaterialMethods->find($id)

RoomstylerComponentMethods->find($id)