Skip to content

Commit 5cc160d

Browse files
authored
Merge pull request #5 from SimplyPrint/dev
Merge dev
2 parents ceb2fe4 + 596173d commit 5cc160d

File tree

11 files changed

+780
-31
lines changed

11 files changed

+780
-31
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ charset = utf-8
1616

1717
[*.md]
1818
trim_trailing_whitespace = false
19+
20+
[*.py]
21+
indent_size = 4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@ doc/
2525

2626
# Vagrant artifacts
2727
ubuntu-*-console.log
28+
29+
# Python
30+
__pycache__/
31+
/scripts/settings.py

scripts/check_outdated.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
import re
3+
4+
from settings import ENDPOINTS_DIR
5+
6+
DOCUMENTATION_DIR = os.path.join(os.path.dirname(__file__), "../source/includes")
7+
8+
def get_all_endpoints():
9+
endpoints = []
10+
for root, dirs, files in os.walk(ENDPOINTS_DIR):
11+
for file in files:
12+
with open(os.path.join(root, file), 'r') as f:
13+
if re.search(r"public bool \$api_disabled = true;", f.read()):
14+
continue
15+
16+
endpoints.append(root.split(ENDPOINTS_DIR)[1] + "/" + file[:-4])
17+
18+
endpoints.sort()
19+
return endpoints
20+
21+
def get_all_documented_endpoints():
22+
endpoints = []
23+
24+
for file in os.listdir(DOCUMENTATION_DIR):
25+
file_cat = file[1:-3]
26+
with open(os.path.join(DOCUMENTATION_DIR, file), 'r') as f:
27+
for line in f.readlines():
28+
match = re.match(r"curl https:\/\/api\.simplyprint\.io\/\{id\}(.*?)(\?| \\).*$", line)
29+
30+
if not match:
31+
continue
32+
33+
endpoints.append(match.group(1))
34+
35+
endpoints.sort()
36+
return endpoints
37+
38+
if __name__ == "__main__":
39+
endpoints = get_all_endpoints()
40+
documented_endpoints = get_all_documented_endpoints()
41+
42+
# Show endpoints that are not documented and endpoints that have been removed
43+
print("Undocumented endpoints:")
44+
for endpoint in endpoints:
45+
if endpoint not in documented_endpoints and not endpoint.startswith("/status/"):
46+
print(f" - {endpoint}")
47+
48+
print("Removed endpoints:")
49+
for endpoint in documented_endpoints:
50+
if endpoint not in endpoints:
51+
print(f" - {endpoint}")

scripts/generate_markdown.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import os
44
import re
5-
import json
5+
from settings import ENDPOINTS_DIR
66

7-
ENDPOINTS_DIR = "/home/dnorhoj/Documents/Work/Code/local-site-dev/api/Endpoints"
8-
#OUTPUT_DIR = "./_generated/"
9-
OUTPUT_DIR = "../source/includes/"
7+
OUTPUT_DIR = "./output"
108

119
# Template
1210
TEMPLATE = """

source/includes/_account.md

Lines changed: 126 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Create company groups
44

55
```shell
6-
curl https://api.simplyprint.io/{id}/account/settings/rank/Create \
6+
curl https://api.simplyprint.io/{id}/account/settings/groups/Create \
77
-X POST \
88
-H 'accept: application/json' \
99
-H 'X-API-KEY: {API_KEY}'
@@ -56,7 +56,7 @@ This endpoint creates a new group in the company.
5656

5757
### Request
5858

59-
`POST /{id}/account/settings/rank/Create`
59+
`POST /{id}/account/settings/groups/Create`
6060

6161
| Parameter | Type | Required | Description |
6262
| --------- | ---- | -------- | ----------- |
@@ -77,7 +77,7 @@ This endpoint creates a new group in the company.
7777
## Update company groups
7878

7979
```shell
80-
curl https://api.simplyprint.io/{id}/account/settings/rank/Update \
80+
curl https://api.simplyprint.io/{id}/account/settings/groups/Update \
8181
-X POST \
8282
-H 'accept: application/json' \
8383
-H 'X-API-KEY: {API_KEY}'
@@ -132,7 +132,7 @@ This endpoint updates the groups in the company.
132132

133133
### Request
134134

135-
`POST /{id}/account/settings/rank/Update`
135+
`POST /{id}/account/settings/groups/Update`
136136

137137
| Parameter | Type | Required | Description |
138138
| --------- | ---- | -------- | ----------- |
@@ -218,7 +218,7 @@ This endpoint returns a list of groups that exist in the company.
218218
## Delete company group
219219

220220
```shell
221-
curl https://api.simplyprint.io/{id}/account/settings/rank/Delete \
221+
curl https://api.simplyprint.io/{id}/account/settings/groups/Delete \
222222
-X POST \
223223
-H 'accept: application/json' \
224224
-H 'X-API-KEY: {API_KEY}'
@@ -252,7 +252,7 @@ curl https://api.simplyprint.io/{id}/account/settings/rank/Delete \
252252

253253
### Request
254254

255-
`POST /{id}/account/settings/rank/Delete`
255+
`POST /{id}/account/settings/groups/Delete`
256256

257257
| Parameter | Type | Required | Description |
258258
| --------- | ---- | -------- | ----------- |
@@ -265,3 +265,123 @@ curl https://api.simplyprint.io/{id}/account/settings/rank/Delete \
265265
| --------- | ---- | ----------- |
266266
| `status` | boolean | True if the request was successful. |
267267
| `message` | string | Error message if `status` is false. |
268+
269+
## Get statistics
270+
271+
```shell
272+
curl https://api.simplyprint.io/{id}/account/GetStatistics \
273+
-X POST \
274+
-H 'accept: application/json' \
275+
-H 'X-API-KEY: {API_KEY}'
276+
```
277+
278+
> Request body
279+
280+
```json
281+
{
282+
"users": [1234, 1235, 1945],
283+
"printers": [1234, 1235, 1945],
284+
"start_date": "1677629786",
285+
"end_date": "1677629786"
286+
}
287+
```
288+
289+
> Success response
290+
291+
```json
292+
{
293+
"status": true,
294+
"message": null,
295+
"data": {
296+
"total_print_seconds": 1234,
297+
"total_filament_usage_gram": 1241.1231231,
298+
"print_job_count": 123,
299+
"regretted_print_jobs": 123,
300+
"failed_print_jobs": 123,
301+
"printer_error_print_jobs": 123,
302+
"done_print_jobs": 123,
303+
"date_range": {
304+
"from": "2023-02-22",
305+
"to": "2023-03-02",
306+
"general": false
307+
},
308+
"printers": {
309+
"3104": {
310+
"name": "Printer 1",
311+
"done": 0,
312+
"failed": 0,
313+
"printer_error": 0,
314+
"regretted": 0,
315+
"filament_usage_gram": 0
316+
},
317+
...
318+
},
319+
"print_jobs": [
320+
{
321+
"date": "2023-02-27",
322+
"started": "2023-02-27 11:39:34",
323+
"ended": "2023-02-27 11:56:18",
324+
"cancelled": 1,
325+
"failed": 0,
326+
"cancel_reason_type": 5,
327+
"print_seconds": 1004,
328+
"filament_usage_gram": 0.03758012402132279
329+
},
330+
...
331+
]
332+
}
333+
}
334+
```
335+
336+
<aside class="notice">
337+
This endpoint requires the <b>Pro</b> plan.
338+
</aside>
339+
340+
This endpoint returns statistics for the user / company.
341+
342+
### Request
343+
344+
`POST /{id}/account/GetStatistics`
345+
346+
| Parameter | Type | Required | Description |
347+
| --------- | ---- | -------- | ----------- |
348+
| `users` | array | no | Array of user ids to get statistics for. Don't include this parameter to get statistics for all users. |
349+
| `printers` | array | no | Array of printer ids to get statistics for. Don't include this parameter to get statistics for all printers. |
350+
| `start_date` | string | no | The start date of the statistics. Provide a unix timestamp in seconds. |
351+
| `end_date` | string | no | The end date of the statistics. Provide a unix timestamp in seconds. |
352+
353+
### Response
354+
355+
| Parameter | Type | Description |
356+
| --------- | ---- | ----------- |
357+
| `status` | boolean | True if the request was successful. |
358+
| `message` | string | Error message if `status` is false. |
359+
| `data` | object | Statistics object. |
360+
| `data.total_print_seconds` | integer | Total print seconds. |
361+
| `data.total_filament_usage_gram` | float | Total filament usage in grams. |
362+
| `data.print_job_count` | integer | Total print job count. |
363+
| `data.regretted_print_jobs` | integer | Total regretted print job count. |
364+
| `data.failed_print_jobs` | integer | Total failed print job count. |
365+
| `data.printer_error_print_jobs` | integer | Total printer error print job count. |
366+
| `data.done_print_jobs` | integer | Total successful print job count. |
367+
| `data.date_range` | object | Date range object. |
368+
| `data.date_range.from` | string | Start date of the statistics. |
369+
| `data.date_range.to` | string | End date of the statistics. |
370+
| `data.date_range.general` | boolean | True if the date range is general. |
371+
| `data.printers` | object | Object of printer statistics. |
372+
| `data.printers.{id}` | object | Printer statistics object. |
373+
| `data.printers.{id}.name` | string | Printer name. |
374+
| `data.printers.{id}.done` | integer | Successful print job count. |
375+
| `data.printers.{id}.failed` | integer | Failed print job count. |
376+
| `data.printers.{id}.printer_error` | integer | Printer error print job count. |
377+
| `data.printers.{id}.regretted` | integer | Regretted print job count. |
378+
| `data.printers.{id}.filament_usage_gram` | float | Filament usage in grams. |
379+
| `data.print_jobs` | array | Array of print job statistics. |
380+
| `data.print_jobs[].date` | string | Date of the print job. |
381+
| `data.print_jobs[].started` | string | Start time of the print job. |
382+
| `data.print_jobs[].ended` | string | End time of the print job. |
383+
| `data.print_jobs[].cancelled` | integer | True if the print job was cancelled. |
384+
| `data.print_jobs[].failed` | integer | True if the print job failed. |
385+
| `data.print_jobs[].cancel_reason_type` | integer | The reason for cancelling the print job. |
386+
| `data.print_jobs[].print_seconds` | integer | Print seconds. |
387+
| `data.print_jobs[].filament_usage_gram` | float | Filament usage in grams. |

source/includes/_files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Files
22

3-
## Get Files
3+
## List Files and Folders
44

55
```shell
66
curl https://api.simplyprint.io/{id}/files/GetFiles?f=123&search=benchy \

source/includes/_jobs.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Print Jobs
2+
3+
## Get Print Jobs
4+
5+
```shell
6+
curl https://api.simplyprint.io/{id}/jobs/GetPaginatedPrintJobs \
7+
-X POST \
8+
-H 'accept: application/json' \
9+
-H 'X-API-KEY: {API_KEY}'
10+
```
11+
12+
> Request body
13+
14+
```json
15+
{
16+
"page": 1,
17+
"page_size": 10,
18+
"printer_ids": [385],
19+
"status": ["cancelled", "finished"],
20+
"start_date": "2023-02-28"
21+
}
22+
```
23+
24+
> Success response
25+
26+
```json
27+
{
28+
"status": true,
29+
"message": null,
30+
"data": [
31+
{
32+
"id": 549145,
33+
"uid": "7df103aa-b12c-4b33-8305-b55f91c11a4d",
34+
"status": "cancelled",
35+
"cancelReasonType": "5",
36+
"rating": -2,
37+
"filename": "Benchy.gcode",
38+
"startDate": "2023-02-28T21:05:50+00:00",
39+
"endDate": "2023-02-28T21:06:07+00:00",
40+
"user": 5933,
41+
"printer": 385,
42+
"filament": "{\"e0\": {\"usage\": 60}}",
43+
"filUsage": 60,
44+
"filUsageGram": 0,
45+
"currentPercentage": 48,
46+
"printTime": 17
47+
},
48+
...
49+
],
50+
"page_amount": 1
51+
}
52+
```
53+
54+
Get paginated data about ongoing or finished print jobs.
55+
56+
### Request
57+
58+
`POST /{id}/jobs/GetPaginatedPrintJobs`
59+
60+
| Parameter | Type | Required | Description |
61+
|-----------|------|----------|-------------|
62+
| `page` | integer | yes | The page number to get. |
63+
| `page_size` | integer | yes | The number of items per page. (Between 1 and 100) |
64+
| `printer_types[]` | integer[] | no | Array of printer type ids to filter on. |
65+
| `printer_ids[]` | integer[] | no | Array of printer ids to filter on. |
66+
| `user_ids[]` | integer[] | no | Array of user ids to filter on. |
67+
| `accepted_statuses[]` | string[] | no | Array of job statuses to filter on. One of `ongoing`, `cancelled`, `failed`, `done`. |
68+
| `start_date` | string | no | The start date to filter on. In unix timestamp format. Can be set without `end_date`. |
69+
| `end_date` | string | no | The end date to filter on. In unix timestamp format. Can be set without `start_date`. |
70+
71+
### Response
72+
73+
| Parameter | Type | Description |
74+
| --------- | ---- | ----------- |
75+
| `status` | boolean | True if the request was successful. |
76+
| `message` | string | Error message if `status` is false. |
77+
| `data` | array | The jobs. |
78+
| `data[].id` | integer | The job id. |
79+
| `data[].uid` | string | The job uid. |
80+
| `data[].status` | string | The job status. One of `ongoing`, `cancelled`, `failed`, `done`. |
81+
| `data[].cancelReasonType` | string | The job cancel reason type. |
82+
| `data[].rating` | integer | The job rating. |
83+
| `data[].filename` | string | The job filename. |
84+
| `data[].startDate` | string | The job start date. |
85+
| `data[].endDate` | string/null | The job end date. Is null if the job is ongoing. |
86+
| `data[].user` | integer | The user id of the user who started the job. |
87+
| `data[].printer` | integer | The printer id that was used to print the job. |
88+
| `data[].filament` | string | The filament usage. JSON encoded string with usage per extruder. |
89+
| `data[].filUsage` | integer | The filament usage in mm. |
90+
| `data[].filUsageGram` | integer | The filament usage in grams. |
91+
| `data[].currentPercentage` | integer | The current percentage of the job. |
92+
| `page_amount` | integer | The total number of pages for the given parameters. |

source/includes/_printers.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Get printer info
44

55
```shell
6-
curl https://api.simplyprint.io/{id}/printers/actions/Get \
6+
curl https://api.simplyprint.io/{id}/printers/Get \
77
-X ? \
88
-H 'accept: application/json' \
99
-H 'X-API-KEY: {API_KEY}'
@@ -13,26 +13,11 @@ curl https://api.simplyprint.io/{id}/printers/actions/Get \
1313
This endpoint has not been implemented yet, and is just a placeholder for now.
1414
</aside>
1515

16-
### Request
17-
18-
`? /{id}/printers/actions/Get`
19-
20-
## List printers
21-
22-
```shell
23-
curl https://api.simplyprint.io/{id}/printers/actions/List \
24-
-X ? \
25-
-H 'accept: application/json' \
26-
-H 'X-API-KEY: {API_KEY}'
27-
```
28-
29-
<aside class="warning">
30-
This endpoint has not been implemented yet, and is just a placeholder for now.
31-
</aside>
16+
TODO: Document this endpoint.
3217

3318
### Request
3419

35-
`? /{id}/printers/actions/List`
20+
`? /{id}/printers/Get`
3621

3722
## Start print / create job
3823

0 commit comments

Comments
 (0)