/** * Check-in a new device and add it to the user. * * @param string $device_type * The device type name as in /devices (ex. galaxy-nexus). * * @param string $device_name * A human readable name of the device, so that the user can identify his device. * * @param string $device_local * The value to set local to. * * @throws DeviceManagerException * If inserting a record for the new device fails. */ public function checkinNewDevice($device_type, $device_name, $device_local) { // Check-in new device. $checkin = new Checkin($this->login); $checkin->changeDevice($device_type); $checkin->local = $device_local; $deviceid = $checkin->checkin(); $sql = <<<'EOF' INSERT INTO devices(owner, name, deviceid) VALUES(:uid, :name, :deviceid) EOF; $db = DB::getInstance()->db; $sth = $db->prepare($sql); $sth->bindValue(':uid', $this->user->uid, SQLITE3_INTEGER); $sth->bindValue(':name', $device_name, SQLITE3_TEXT); $sth->bindValue(':deviceid', $deviceid, SQLITE3_TEXT); if ($status = $sth->execute() === FALSE) { throw new DeviceManagerException(_('Could not create a record for the new device in the DB.')); } }
<?php require_once 'DrSlump/Protobuf.php'; \DrSlump\Protobuf::autoload(); require_once __DIR__ . '/../inc/functions.php'; require_once __DIR__ . '/../classes/GoogleAccount.class.php'; require_once __DIR__ . '/../classes/Checkin.class.php'; $google_account = new GoogleAccount('USER_EMAIL', 'USER_PASSWORD'); $checkin = new Checkin($google_account); $checkin->changeDevice('nexus-5'); echo 'AID: ' . $checkin->checkin() . "\n";