@@ -106,31 +106,17 @@ public function viewWhoAmI()
106
106
107
107
}
108
108
109
- /**
110
- * Makes a credits request to the PrintNode API, returning the credit
111
- * balance for the active account as a string
112
- *
113
- * @return string
114
- */
115
- public function viewCredits ()
116
- {
117
-
118
- $ this ->lastResponse = $ this ->makeRequest ('credits ' , 'GET ' );
119
-
120
- return $ this ->lastResponse ->bodyJson ;
121
-
122
- }
123
-
124
109
/**
125
110
* Makes a computers request to the PrintNode API, returning an array
126
111
* of all the registered computers on the active account.
127
112
*
128
- * @param int $offset (Optional) The start index for the records the API should return
129
113
* @param int $limit (Optional) The number of records the API should return
114
+ * @param int $after (Optional) The computer id after (or before, depending on $dir) which to start returning records
115
+ * @param string $dir (Optional) "asc" for ascending or "desc" for descending, ordered by computer id
130
116
* @param string|array $computerSet (Optional) 'set' string or array of computer ids to which the response should be limited
131
117
* @return \PrintNode\Entity\Computer[]
132
118
*/
133
- public function viewComputers ($ offset = 0 , $ limit = 500 , $ computerSet = null )
119
+ public function viewComputers ($ limit = null , $ after = null , $ dir = null , $ computerSet = null )
134
120
{
135
121
136
122
if (isset ($ computerSet )) {
@@ -139,7 +125,7 @@ public function viewComputers($offset = 0, $limit = 500, $computerSet = null)
139
125
$ url = 'computers ' ;
140
126
}
141
127
142
- $ url = $ this ->applyLimitOffsetToUrl ($ url , $ offset , $ limit );
128
+ $ url = $ this ->applyPaginationToUrl ($ url , $ limit , $ after , $ dir );
143
129
144
130
return $ this ->makeRequestMapped ($ url , 'GET ' , '\PrintNode\Entity\Computer ' );
145
131
@@ -158,13 +144,14 @@ public function viewComputers($offset = 0, $limit = 500, $computerSet = null)
158
144
* Both arguments can be combined to return only certain printers on certain
159
145
* computers
160
146
*
161
- * @param int $offset (Optional) The start index for the records the API should return
162
147
* @param int $limit (Optional) The number of records the API should return
148
+ * @param int $after (Optional) The id after (or before, depending on $dir) which to start returning records
149
+ * @param string $dir (Optional) "asc" for ascending or "desc" for descending, ordered by computer id
163
150
* @param string|array $printerSet (Optional) 'set' string or array of printer ids to which the response should be limited
164
151
* @param string|array $computerSet (Optional) 'set' string or array of computer ids to which the response should be limited
165
152
* @return \PrintNode\Entity\Printer[]
166
153
*/
167
- public function viewPrinters ($ offset = 0 , $ limit = 500 , $ printerSet = null , $ computerSet = null )
154
+ public function viewPrinters ($ limit = null , $ after = null , $ dir = null , $ printerSet = null , $ computerSet = null )
168
155
{
169
156
170
157
if (isset ($ computerSet ) && isset ($ printerSet )){
@@ -177,7 +164,7 @@ public function viewPrinters($offset = 0, $limit = 500, $printerSet = null, $com
177
164
$ url = 'printers ' ;
178
165
}
179
166
180
- $ url = $ this ->applyLimitOffsetToUrl ($ url , $ offset , $ limit );
167
+ $ url = $ this ->applyPaginationToUrl ($ url , $ limit , $ after , $ dir );
181
168
182
169
return $ this ->makeRequestMapped ($ url , 'GET ' , '\PrintNode\Entity\Printer ' );
183
170
@@ -196,13 +183,14 @@ public function viewPrinters($offset = 0, $limit = 500, $printerSet = null, $com
196
183
* Both arguments can be combined to return only certain print jobs on
197
184
* certain printers
198
185
*
199
- * @param int $offset (Optional) The start index for the records the API should return
200
186
* @param int $limit (Optional) The number of records the API should return
187
+ * @param int $after (Optional) The after (or before, depending on $dir) which to start returning records
188
+ * @param string $dir (Optional) "asc" for ascending or "desc" for descending, ordered by computer id
201
189
* @param string|array $printJobSet (Optional) 'set' string or array of print job ids to which the response should be limited
202
190
* @param string|array $printerSet (Optional) 'set' string or array of printer ids to which the response should be limited
203
191
* @return \PrintNode\Entity\PrintJob[]
204
192
*/
205
- public function viewPrintJobs ($ offset = 0 , $ limit = 500 , $ printJobSet = null , $ printerSet = null )
193
+ public function viewPrintJobs ($ limit = null , $ after = null , $ dir = null , $ printJobSet = null , $ printerSet = null )
206
194
{
207
195
208
196
$ url = 'printjobs ' ;
@@ -215,7 +203,7 @@ public function viewPrintJobs($offset = 0, $limit = 500, $printJobSet = null, $p
215
203
$ url = sprintf ('printers/%s/printjobs ' , $ this ->setImplode ($ printerSet ));
216
204
}
217
205
218
- $ url = $ this ->applyLimitOffsetToUrl ($ url , $ offset , $ limit );
206
+ $ url = $ this ->applyPaginationToUrl ($ url , $ limit , $ after , $ dir );
219
207
220
208
return $ this ->makeRequestMapped ($ url , 'GET ' , '\PrintNode\Entity\PrintJob ' );
221
209
@@ -230,12 +218,13 @@ public function viewPrintJobs($offset = 0, $limit = 500, $printJobSet = null, $p
230
218
*
231
219
* Returned is an array of states in an array keyed by the print job id.
232
220
*
233
- * @param int $offset (Optional) The start index for the records the API should return
234
221
* @param int $limit (Optional) The number of records the API should return
222
+ * @param int $after (Optional) The id after (or before, depending on $dir) which to start returning records
223
+ * @param string $dir (Optional) "asc" for ascending or "desc" for descending, ordered by computer id
235
224
* @param string|array $printJobSet (Optional) 'set' string or array of print job ids to which the response should be limited
236
225
* @return array
237
226
*/
238
- public function viewPrintJobState ($ offset = 0 , $ limit = 500 , $ printJobSet = null )
227
+ public function viewPrintJobState ($ limit = null , $ after = null , $ dir = null , $ printJobSet = null )
239
228
{
240
229
241
230
$ url = 'printjobs/states ' ;
@@ -244,7 +233,7 @@ public function viewPrintJobState($offset = 0, $limit = 500, $printJobSet = null
244
233
$ url = sprintf ('printjobs/%s/states ' , $ this ->setImplode ($ printJobSet ));
245
234
}
246
235
247
- $ url = $ this ->applyLimitOffsetToUrl ($ url , $ offset , $ limit );
236
+ $ url = $ this ->applyPaginationToUrl ($ url , $ limit , $ after , $ dir );
248
237
249
238
$ this ->lastResponse = $ this ->makeRequest ($ url , 'GET ' );
250
239
@@ -310,55 +299,64 @@ public function viewScales($computerId, $deviceName = null, $deviceNumber = null
310
299
*
311
300
* Returned is an array of downloads in an array keyed by the download id.
312
301
*
313
- * @param int $offset (Optional) The start index for the records the API should return
314
- * @param int $limit (Optional) The number of records the API should return
315
302
* @param string|array (Optional) $downloadSet 'set' string or array of download ids to which the response should be limited
316
303
* @return array
317
304
*/
318
- public function viewClientDownloads ($ offset = 0 , $ limit = 1 , $ downloadSet = null )
305
+ public function viewClientDownloads ($ downloadSet = null )
319
306
{
320
-
321
307
$ url = 'download/clients ' ;
322
308
323
309
if (isset ($ downloadSet )) {
324
310
$ url = sprintf ('download/clients/%s ' , $ this ->setImplode ($ downloadSet ));
325
311
}
326
312
327
- $ url = $ this ->applyLimitOffsetToUrl ($ url , $ offset , $ limit );
328
-
329
313
return $ this ->makeRequestMapped ($ url , 'GET ' , '\PrintNode\Entity\ClientDownload ' );
330
314
331
315
}
332
316
333
317
/**
334
- * Appends the offset and limit arguments to a given api endpoint url
318
+ * Appends limit argument to a given api endpoint url
335
319
*
336
- * @param string $url (Optional) The url to which any limits or offsets will be applied
337
- * @param int $offset (Optional) The offset to apply to the url
320
+ * @param string $url (Optional) The url to which limit will be applied
338
321
* @param int $limit (Optional) The limit to apply to the url
322
+ * @param int $after (Optional) The id after (or before, depending on $dir) which to start returning records
323
+ * @param string $dir (Optional) "asc" for ascending or "desc" for descending, ordered by computer id
339
324
* @return string
340
325
* @throws \PrintNode\Exception\InvalidArgumentException
341
326
*/
342
- public function applyLimitOffsetToUrl ($ url , $ offset , $ limit )
327
+ public function applyPaginationToUrl ($ url , $ limit , $ after , $ dir )
343
328
{
344
-
345
- if (!\is_numeric ($ offset )) {
346
- throw new \PrintNode \Exception \InvalidArgumentException ('Offset must be a number ' );
347
- }
348
-
349
- if (!\is_numeric ($ limit )) {
350
- throw new \PrintNode \Exception \InvalidArgumentException ('Limit must be a number ' );
351
- }
352
-
353
- if ($ offset < 0 ) {
354
- throw new \PrintNode \Exception \InvalidArgumentException ('Offset cannot be negative ' );
355
- }
356
-
357
- if ($ limit < 1 ) {
358
- throw new \PrintNode \Exception \InvalidArgumentException ('Limit must be greater than zero ' );
359
- }
360
-
361
- return sprintf ('%s?offset=%s&limit=%s ' , $ url , $ offset , $ limit );
329
+ $ vars = Array ();
330
+ if (!is_null ($ limit )) {
331
+ if (!\is_numeric ($ limit )) {
332
+ throw new \PrintNode \Exception \InvalidArgumentException ('Limit must be a number ' );
333
+ }
334
+
335
+ if ($ limit < 1 ) {
336
+ throw new \PrintNode \Exception \InvalidArgumentException ('Limit must be greater than zero ' );
337
+ }
338
+ $ vars [] = sprintf ("limit=%d " , $ limit );
339
+ }
340
+
341
+ if (!is_null ($ after )) {
342
+ if (!\is_numeric ($ after )) {
343
+ throw new \PrintNode \Exception \InvalidArgumentException ('After must be a number ' );
344
+ }
345
+ $ vars [] = sprintf ("after=%d " , $ limit );
346
+ }
347
+
348
+ if (!is_null ($ dir )) {
349
+ if (($ dir !== "asc " ) && ($ dir !== "desc " )) {
350
+ throw new \PrintNode \Exception \InvalidArgumentException ('Dir must be "asc" or "desc" ' );
351
+ }
352
+ $ vars [] = sprintf ("dir=%s " , $ dir );
353
+ }
354
+
355
+ if (count ($ vars ) > 0 ) {
356
+ return $ url . "? " . implode ("& " , $ vars );
357
+ } else {
358
+ return $ url ;
359
+ }
362
360
363
361
}
364
362
0 commit comments