<?php

include 'vendor/autoload.php';
/**
 * To create Child Accounts you need a PrintNode Integrator Account. 
 * You then need to authenticate with your API Key.
 **/
$credentials = new PrintNode\Credentials();
$credentials->setApiKey(PRINTNODE_APIKEY);
$request = new PrintNode\Request($credentials);
// Initialise a Child Account
$account = new PrintNode\Account();
// Set properties on the Child Account
$account->Account = array("firstname" => "A", "lastname" => "ALastName", "password" => "superStrongPassword", "email" => "*****@*****.**");
// Post the Child Account to the API
$aNewAccount = $request->post($account);
// You can get the Child Account ID from the response object
$id = $aNewAccount->GetDecodedContent()["Account"]["id"];
 public function testClientKey()
 {
     $request = new PrintNode\Request($this->credentials);
     $response = $request->getClientKey('0a756864-602e-428f-a90b-842dee47f57e', '4.7.1', 'printnode');
     $this->assertInternaltype("string", $response->GetDecodedContent());
 }
include 'vendor/autoload.php';
$credentials = new PrintNode\Credentials();
/**
 * There are two ways of authenticating when manipulating a Child Account
 * 
 * - Using the Parent Account API Key
 * - Using the Child Account API Key
 * 
 * You can only manipulate a Child Account details when using the Parent Account API Key. 
 * For example: to change a Child Accounts name, email address, password or delete a Child Account 
 * you must be use the Parent Account API Key.
 * 
 * For this example, you must be authenticated as the Parent Account.
 **/
$credentials->setApiKey(PRINTNODE_APIKEY);
$request = new PrintNode\Request($credentials);
/**
 * You can specify the Child Account to manipulate using any of these methods:
 *  
 * - PrintNode\Request->setChildAccountById($id)
 * - PrintNode\Request->setChildAccountByEmail($email)
 * - PrintNode\Request->setChildAccountByCreatorRef($creatorRef)
 *
 * We will set the Child Account by ID
 **/
$request->setChildAccountById($id);
// All requests from this request object will now operate on this Child Account.
$whoami = $request->getWhoami();
$computers = $request->getComputers();
$printers = $request->getPrinters();
/**
// Include the autoloader
// To include all the PrintNode PHP API classes in your own code, all you need to do is
// include/require the autoload.php in your code:
include 'vendor/autoload.php';
include 'credentials.php';
// Open a connection to PrintNode
// You first need to establish a connection to PrintNode.
// This can be done by using a PrintNode\ApiKey instance using your api-key.
$credentials = new PrintNode\ApiKey(PRINTNODE_APIKEY);
// Hint: Your API username is in the format description.integer, where description
// is the name given to the API key when you created it, followed by a dot (.) and an integer.
// All this information is provided for you when you create your API Key.
// Step 3: Get a list of computers, printers or printjobs which are available.
// To get a list of computers, printers or printjobs, create a new PrintNode\Request
// object, passing it your credentials as the argument to it's constructor.
$request = new PrintNode\Request($credentials);
// Hint: Before you can get a list of computers or printers, you must have successfully
// connected using the PrintNode Client software. If you have not yet connected with
// the client software you will not receive any results from the API.
// Call the getComputers, getPrinters() or getPrintJobs() method on the object:
$computers = $request->getComputers();
$printers = $request->getPrinters();
$printJobs = $request->getPrintJobs();
// Hint: The return value from these methods is always an array containing 0 or more
// instances of PrintNode\Computer, PrintNode\Printer or PrintNode\PrintJob depending
// on the method called. You can iterate over this array however you please, for example
// you might use a while or foreach loop.
// Step 4: Send a PrintJob to Printnode.
// PrintNode currently only accepts PDF documents.
// To print something, you need to create a new instance of PrintNode\PrintJob:
$printJob = new PrintNode\PrintJob();
 /**
  * @depends testPrintJobs
  *
  * */
 public function testPrintJobsPost()
 {
     $request = new PrintNode\Request($this->credentials);
     $printers = $request->getPrinters();
     $printJob = new PrintNode\PrintJob();
     $printJob->printer = $printers[0];
     $printJob->contentType = 'pdf_base64';
     $printJob->content = base64_encode(file_get_contents('a4_portrait.pdf'));
     $printJob->source = 'testing print';
     $printJob->title = 'Test Printjob for PHP API Tests';
     $response = $request->post($printJob);
     $this->assertInternalType('int', $response->GetDecodedContent());
 }