<?php

/**
* Example showing how to manually subscribe to Netatmo Welcome Webhooks notifications.
* For further information regarding the webhook system, see https://dev.netatmo.com/doc/webhooks
*/
define('__ROOT__', dirname(dirname(__FILE__)));
require_once __ROOT__ . '/src/Netatmo/autoload.php';
require_once 'Config.php';
require_once 'Utils.php';
//API client configuration
$config = array("client_id" => $client_id, "client_secret" => $client_secret, "username" => $test_username, "password" => $test_password, "scope" => Netatmo\Common\NAScopes::SCOPE_READ_CAMERA);
$client = new Netatmo\Clients\NAWelcomeApiClient($config);
//Retrieve access token
try {
    $tokens = $client->getAccessToken();
} catch (Netatmo\Exceptions\NAClientException $ex) {
    $error_msg = "An error happened  while trying to retrieve your tokens \n" . $ex->getMessage() . "\n";
    handleError($error_msg, TRUE);
}
// Adding/droping Webhooks for the current user
try {
    //Adding a Webhook for your app for the current user
    $client->subscribeToWebhook("");
    //insert the URL of your webhook endpoint here
    //Droping your webhook notification for the current user
    $client->dropWebhook();
} catch (Netatmo\Exceptions\NAClientException $ex) {
    echo "An error occured while trying to subscribe to a webhook";
    die;
}
#!/usr/bin/php
<?php 
/**
* Example of Netatmo Welcome API
* For further information, please take a look at https://dev.netatmo.com/doc
*/
define('__ROOT__', dirname(dirname(__FILE__)));
require_once __ROOT__ . '/src/Netatmo/autoload.php';
require_once 'Config.php';
require_once 'Utils.php';
$scope = Netatmo\Common\NAScopes::SCOPE_READ_CAMERA;
//Client configuration from Config.php
$conf = array("client_id" => $client_id, "client_secret" => $client_secret, "username" => $test_username, "password" => $test_password, "scope" => $scope);
$client = new Netatmo\Clients\NAWelcomeApiClient($conf);
//Retrieve access token
try {
    $tokens = $client->getAccessToken();
} catch (Netatmo\Exceptions\NAClientException $ex) {
    $error_msg = "An error happened  while trying to retrieve your tokens \n" . $ex->getMessage() . "\n";
    handleError($error_msg, TRUE);
}
//Try to retrieve user's Welcome information
try {
    //retrieve every user's homes and their last 10 events
    $response = $client->getData(NULL, 10);
    $homes = $response->getData();
} catch (Netatmo\Exceptions\NASDKException $ex) {
    handleError("An error happened while trying to retrieve home information: " . $ex->getMessage() . "\n", TRUE);
}
if (is_null($homes) || empty($homes)) {
    handleError("No home found for this user...", TRUE);