コード例 #1
0
<?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"];
コード例 #2
0
// 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();
// You can then populate this object with the information about the print-job
// and add the base64-encoded content of, or the URI to your PDF. To do this use the properties
// as defined on the object.
//
// In this example, we're going to print a a base64-encoded PDF named invoice.pdf:
$printJob->printer = $printers[1];
$printJob->contentType = 'pdf_base64';
$printJob->content = base64_encode(file_get_contents('a4_portrait.pdf'));
$printJob->source = 'My App/1.0';
$printJob->title = 'Test PrintJob from My App/1.0';
// Hint: The PrintNode PHP API comes complete with PHPDoc comments.
// If you have an editor that supports PHPDoc code completion, you should see hints
// for the properties and method names on each of the objects.
// Once you have populated the object, all that's left to do is submit it:
$response = $request->post($printJob);
// The response returned from the post method is an instance of PrintNode\Response.
// It contains methods for retrieving the response headers, body and HTTP status-code and message.
// Returns the HTTP status code.
$statusCode = $response->getStatusCode();
// Returns the HTTP status message.
$statusMessage = $response->getStatusMessage();
// Returns an array of HTTP headers.
$headers = $response->getHeaders();
// Return the response body.
$content = $response->getContent();
コード例 #3
0
 /**
  * @depends testAccountCreationAndDeletion
  * */
 public function testApiKey()
 {
     $request = new PrintNode\Request($this->credentials);
     $response = $request->post($this->account);
     $request->setChildAccountById($response->GetDecodedContent()["Account"]["id"]);
     $ApiKey = new PrintNode\ApiKey();
     $ApiKey->description = "testing";
     $response = $request->post($ApiKey);
     $this->assertInternalType("string", $response->GetDecodedContent());
     $getKey = $request->getApiKeys("testing");
     $this->assertEquals($response->GetDecodedContent(), $getKey);
     $request->DeleteAccount();
 }
コード例 #4
0
 /**
  * @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());
 }