Skip to content

Commit 7a435ce

Browse files
committed
Added final versions of Entities, Credentials and Exceptions
1 parent 829a12f commit 7a435ce

20 files changed

+537
-131
lines changed

README.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
PrintNode-PHP
22
=============
33

4-
PrintNode is a cloud printing services which allows you to connect any printer to your application using our PrintNode Client and easy to use JSON API.
4+
PrintNode is a cloud printing services which allows you to connect any printer
5+
to your application using our PrintNode Client and easy to use JSON API.
56

67
See www.printnode.com for more information.
78

8-
This quick start guide covers using the PHP API library. It shows how to find which Computers and Printers you have available for printing and how you can submit PrintJobs using the provided PHP API libraries.
9+
This quick start guide covers using the PHP API library. It shows how to find
10+
which Computers and Printers you have available for printing and how you can
11+
submit PrintJobs using the provided PHP API libraries.
912

1013
## Step 1: Sign Up
11-
Before you can use the API, you will need to sign up to PrintNode account, and make a new API key. You can sign up here https://app.printnode.com/account/register
14+
Before you can use the API, you will need to sign up to PrintNode account, and
15+
make a new API key. You can sign up here https://app.printnode.com/account/register
1216

1317
## Step 2: Add a computer and printer
14-
To have somewhere to print to you need to download and install the PrintNode desktop client on a computer with some printers. You can download the PrintNode Client installer here - www.printnode.com/download . It should be intuitive to setup but for more detailed instructions please see here: https://www.printnode.com/docs/installation/windows/ .
18+
To have somewhere to print to you need to download and install the PrintNode
19+
desktop client on a computer with some printers. You can download the PrintNode
20+
Client installer here - www.printnode.com/download . It should be intuitive
21+
to setup but for more detailed instructions please see
22+
here: https://www.printnode.com/docs/installation/windows/ .
1523

1624
## Step 3: Install library
1725

1826
### Download the PHP Library
19-
You can download the client from our Github account. If you have a git client installed locally, you can clone our repository
27+
You can download the client from our Github account. If you have a git client
28+
installed locally, you can clone our repository
2029

2130
https://github.com/PrintNode/PrintNode-PHP/archive/master.zip
2231

@@ -28,4 +37,4 @@ composer require PrintNode/printnode-php:dev-master
2837

2938
## Step 4: See examples how to use this library
3039

31-
See `examples` directory to learn how to use this library.
40+
See `examples` directory to learn how to use this library.

src/PrintNode/Bootstrap.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
*
66
* Include this file in your script to add the PrintNode Autoloader.
77
*
8-
* The bootstrap file assumes that all the PrintNode files are located in a
9-
* subdirectory called 'PrintNode'.
10-
*
118
*/
129

13-
require_once('PrintNode/Autoloader.php');
10+
require_once('Autoloader.php');
1411

1512
\spl_autoload_register('\PrintNode\Autoloader::autoload');

src/PrintNode/Client.php

-12
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ class Client
4444
*/
4545
public $apiHost;
4646

47-
/**
48-
* Request logging callback
49-
* @var function
50-
*/
51-
public $requestLogMethod;
52-
53-
/**
54-
* Response logging callback
55-
* @var function
56-
*/
57-
public $responseLogMethod;
58-
5947
/**
6048
* Stores the last request object processed
6149
* @var \PrintNode\Response

src/PrintNode/Credentials/ApiKey.php

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ class ApiKey extends \PrintNode\Credentials
1212
public function __construct ($apiKey)
1313
{
1414

15+
if (!\is_string($apiKey)
16+
|| (mb_strlen(trim($apiKey)) == 0)) {
17+
18+
$emsg = 'Argument 1 passed to PrintNode\Credentials\ApiKey::__construct() must be a valid ApiKey string';
19+
20+
throw new \PrintNode\Exception\InvalidArgumentException($emsg);
21+
22+
}
23+
1524
$this->apiKey = $apiKey;
1625

1726
}

src/PrintNode/Credentials/Username.php

+18
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,24 @@ class Username extends \PrintNode\Credentials
1313
public function __construct ($username, $password)
1414
{
1515

16+
if (!\is_string($username)
17+
|| (mb_strlen(trim($username)) == 0)) {
18+
19+
$emsg = 'Argument 1 passed to PrintNode\Credentials\ApiKey::__construct() must be a valid username string';
20+
21+
throw new \PrintNode\Exception\InvalidArgumentException($emsg);
22+
23+
}
24+
25+
if (!\is_string($password)
26+
|| (mb_strlen(trim($password)) == 0)) {
27+
28+
$emsg = 'Argument 2 passed to PrintNode\Credentials\ApiKey::__construct() must be a valid password string';
29+
30+
throw new \PrintNode\Exception\InvalidArgumentException($emsg);
31+
32+
}
33+
1634
$this->username = $username;
1735
$this->password = $password;
1836

src/PrintNode/Entity.php

+11
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,15 @@ public function jsonSerialize()
121121

122122
}
123123

124+
/**
125+
* Implements the toString magic method.
126+
*
127+
* @return string
128+
*/
129+
public function __toString() {
130+
131+
return print_r(\json_decode(\json_encode($this->jsonSerialize()), true), true);
132+
133+
}
134+
124135
}

src/PrintNode/Entity/Account.php

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
class Account extends Entity
1717
{
18+
1819
/**
1920
* Account Id
2021
* @var int

src/PrintNode/Entity/AccountDetail.php

-34
This file was deleted.

src/PrintNode/Entity/ChildAccount.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@
1414
class ChildAccount extends Entity
1515
{
1616

17-
protected $Account;
17+
/**
18+
* A printnode Account object
19+
* @var \PrintNode\Entity\Account
20+
*/
21+
public $Account;
1822

23+
/**
24+
* An array of API keys
25+
* @var array
26+
*/
1927
public $ApiKeys;
2028

29+
/**
30+
* An array of tags
31+
* @var array
32+
*/
2133
public $Tags;
2234

2335
/**
@@ -30,11 +42,4 @@ class ChildAccount extends Entity
3042
'Tags' => null,
3143
);
3244

33-
public function addAccount(\PrintNode\Entity\Account $Account)
34-
{
35-
36-
$this->Account = $Account;
37-
38-
}
39-
4045
}

src/PrintNode/Entity/ClientDownload.php

+49
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,64 @@
2323
class ClientDownload extends Entity
2424
{
2525

26+
/**
27+
* The client download id
28+
* @var int
29+
*/
2630
protected $id;
31+
32+
/**
33+
* The flag that indicates if this download is currently available
34+
* @var bool
35+
*/
2736
protected $enabled;
37+
38+
/**
39+
* The edition of the client download
40+
* @var string
41+
*/
2842
protected $edition;
43+
44+
/**
45+
* The client version
46+
* @var string
47+
*/
2948
protected $version;
49+
50+
/**
51+
* The operating system for which this client download is intended
52+
* @var string
53+
*/
3054
protected $os;
55+
56+
/**
57+
* The filename for this client installer
58+
* @var string
59+
*/
3160
protected $filename;
61+
62+
/**
63+
* The file size of the client installer
64+
* @var string
65+
*/
3266
protected $filesize;
67+
68+
/**
69+
* SHA1 fingerprint for the client installer
70+
* @var string
71+
*/
3372
protected $sha1;
73+
74+
/**
75+
* The timestamp for the client installer release
76+
* @var int
77+
*/
3478
protected $releaseTimestamp;
79+
80+
/**
81+
* The URL at which the client installer can be downloaded
82+
* @var int
83+
*/
3584
protected $url;
3685

3786
/**

src/PrintNode/Entity/Computer.php

+71-11
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,70 @@
2323
class Computer extends Entity
2424
{
2525

26+
/**
27+
* Computer Id
28+
* @var int
29+
*/
2630
protected $id;
31+
32+
/**
33+
* Computer Name
34+
* @var string
35+
*/
2736
protected $name;
37+
38+
/**
39+
* Reserved
40+
* @var mixed
41+
*/
2842
protected $inet;
43+
44+
/**
45+
* Reserved
46+
* @var mixed
47+
*/
2948
protected $inet6;
49+
50+
/**
51+
* Reserved
52+
* @var mixed
53+
*/
3054
protected $hostname;
55+
56+
/**
57+
* Reserved
58+
* @var mixed
59+
*/
3160
protected $version;
61+
62+
/**
63+
* Reserved
64+
* @var mixed
65+
*/
3266
protected $jre;
67+
68+
/**
69+
* Reserved
70+
* @var mixed
71+
*/
3372
protected $systemInfo;
73+
74+
/**
75+
* Reserved
76+
* @var mixed
77+
*/
3478
protected $acceptOfflinePrintJobs;
79+
80+
/**
81+
* The time and date the computer was first registered with PrintNode
82+
* @var mixed
83+
*/
3584
protected $createTimestamp;
85+
86+
/**
87+
* Current state of the computer
88+
* @var mixed
89+
*/
3690
protected $state;
3791

3892
/**
@@ -53,24 +107,30 @@ class Computer extends Entity
53107
'state' => null,
54108
);
55109

56-
public function viewPrinters($printerSet = null)
57-
{
58-
59-
60-
61-
}
62-
63-
public function viewPrintJobs()
110+
/**
111+
* Returns an array of the printers present on this computer
112+
*
113+
* @param int $offset
114+
* @param int $limit
115+
* @param mixed $printerSet
116+
* @return array
117+
*/
118+
public function viewPrinters($offset = 0, $limit = 500, $printerSet = null)
64119
{
65120

66-
121+
return $this->client->viewPrinters($offset, $limit, $printerSet, $this->id);
67122

68123
}
69124

70-
public function viewScales()
125+
/**
126+
*
127+
* @param type $deviceName
128+
* @param type $deviceNumber
129+
*/
130+
public function viewScales($deviceName = null, $deviceNumber = null)
71131
{
72132

73-
133+
return $this->client->viewScales($this->id, $deviceName, $deviceNumber);
74134

75135
}
76136

0 commit comments

Comments
 (0)