iobroker.rest-api 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,9 @@ This adapter can run as web-extension. In this case the path is available under
51
51
  -->
52
52
 
53
53
  ## Changelog
54
+ ### 0.3.6 (2022-04-22)
55
+ * (bluefox) Added object creation and enumerations reading
56
+
54
57
  ### 0.3.5 (2022-04-22)
55
58
  * (bluefox) Allowed the reading of current subscriptions
56
59
 
package/io-package.json CHANGED
@@ -1,8 +1,20 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "rest-api",
4
- "version": "0.3.5",
4
+ "version": "0.3.6",
5
5
  "news": {
6
+ "0.3.6": {
7
+ "en": "Added object creation and enumerations reading",
8
+ "de": "Objekterstellung und Lesen von Aufzählungen hinzugefügt",
9
+ "ru": "Добавлено создание объектов и чтение перечислений",
10
+ "pt": "Adicionado criação de objetos e leitura de enumerações",
11
+ "nl": "Toegevoegd objectcreatie en opsommingen lezen",
12
+ "fr": "Ajout de la création d'objets et de la lecture des énumérations",
13
+ "it": "Aggiunta creazione di oggetti e lettura di enumerazioni",
14
+ "es": "Añadida creación de objetos y lectura de enumeraciones.",
15
+ "pl": "Dodano tworzenie obiektów i odczytywanie wyliczeń",
16
+ "zh-cn": "添加了对象创建和枚举读取"
17
+ },
6
18
  "0.3.5": {
7
19
  "en": "Allowed the reading of current subscriptions",
8
20
  "de": "Erlaubt das Lesen aktueller Abonnements",
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+ const commonLib = require('./common.js');
3
+
4
+ module.exports = {
5
+ readMainEnums: function (req, res) {
6
+ commonLib.checkPermissions(req._adapter, req._user, [{type: 'object', operation: 'read'}], async err => {
7
+ if (err) {
8
+ res.status(403).json({error: err});
9
+ } else {
10
+ // check if instance is alive
11
+ try {
12
+ const enums = await req._adapter.getEnumsAsync('', {user: req._user});
13
+ res.json(enums);
14
+ } catch (error) {
15
+ res.status(500).json({error});
16
+ }
17
+ }
18
+ });
19
+ },
20
+ readEnums: function (req, res) {
21
+ commonLib.checkPermissions(req._adapter, req._user, [{type: 'object', operation: 'read'}], async err => {
22
+ if (err) {
23
+ res.status(403).json({error: err});
24
+ } else {
25
+ const params = commonLib.parseUrl(req.url, req.swagger);
26
+ // check if instance is alive
27
+ try {
28
+ const enums = await req._adapter.getEnumAsync(params.enumId, {user: req._user});
29
+ if (enums && enums.result) {
30
+ res.json(Object.keys(enums.result).filter(id => id.split('.').length > 2).map(id => ({
31
+ _id: id,
32
+ common: enums.result[id].common
33
+ })));
34
+ } else {
35
+ res.json([]);
36
+ }
37
+ } catch (error) {
38
+ res.status(500).json({error});
39
+ }
40
+
41
+ }
42
+ });
43
+ },
44
+ };
@@ -64,6 +64,28 @@ module.exports = {
64
64
  });
65
65
  },
66
66
 
67
+ createObject: function (req, res) {
68
+ commonLib.checkPermissions(req._adapter, req._user, [{type: 'object', operation: 'write'}], async err => {
69
+ if (err) {
70
+ res.status(403).json({error: err});
71
+ } else {
72
+ const params = commonLib.parseUrl(req.url, req.swagger);
73
+ const body = req.body;
74
+ try {
75
+ const obj = await req._adapter.getForeignObjectAsync(params.objectId, {user: req._user});
76
+ if (!obj) {
77
+ await req._adapter.setForeignObjectAsync(params.objectId, body, {user: req._user});
78
+ res.status(200).json(body);
79
+ } else {
80
+ res.status(409).json({error: 'Object already exists', id: params.objectId});
81
+ }
82
+ } catch (error) {
83
+ res.status(500).json({error, objectId: params.objectId});
84
+ }
85
+ }
86
+ });
87
+ },
88
+
67
89
  deleteObject: function (req, res) {
68
90
  commonLib.checkPermissions(req._adapter, req._user, [{type: 'object', operation: 'write'}], async err => {
69
91
  if (err) {
@@ -20,6 +20,8 @@ tags:
20
20
  description: "Read the objects"
21
21
  - name: "history"
22
22
  description: "Read the history"
23
+ - name: "enum"
24
+ description: "Read the categories"
23
25
  securityDefinitions:
24
26
  basicAuth:
25
27
  type: basic
@@ -379,11 +381,44 @@ paths:
379
381
  description: "Object not found"
380
382
  400:
381
383
  description: "Invalid object ID supplied"
384
+ post:
385
+ tags:
386
+ - "object"
387
+ summary: "Create the object"
388
+ description: "Create new object. If object already exists, the error will be returned"
389
+ operationId: "createObject"
390
+ consumes:
391
+ - "application/json"
392
+ produces:
393
+ - "application/json"
394
+ parameters:
395
+ - in: "path"
396
+ name: "objectId"
397
+ description: "ID of the object to write"
398
+ required: true
399
+ type: "string"
400
+ - in: "body"
401
+ name: "value"
402
+ description: "Object"
403
+ required: true
404
+ schema:
405
+ $ref: "#/definitions/Object"
406
+ responses:
407
+ 200:
408
+ description: "successful operation"
409
+ schema:
410
+ $ref: "#/definitions/Object"
411
+ 400:
412
+ description: "Invalid object ID supplied"
413
+ 409:
414
+ description: "Object already exists"
415
+ 405:
416
+ description: "Invalid object structure"
382
417
  put:
383
418
  tags:
384
419
  - "object"
385
420
  summary: "Update the object"
386
- description: "To delete the parts of the object, set the value to 'null', like {\"common\": {\"desc\": null} to delete the \"common.desc\""
421
+ description: "To delete the parts of the object, set the value to 'null', like {\"common\": {\"desc\": null} to delete the \"common.desc\". If object does not exist it will be created"
387
422
  operationId: "updateObject"
388
423
  consumes:
389
424
  - "application/json"
@@ -782,6 +817,40 @@ paths:
782
817
  $ref: "#/definitions/HistoryAddResponse"
783
818
  422:
784
819
  description: "Invalid options supplied"
820
+ /enum:
821
+ x-swagger-router-controller: enum
822
+ get:
823
+ tags:
824
+ - "enum"
825
+ summary: "Reads categories of enums"
826
+ operationId: "readMainEnums"
827
+ produces:
828
+ - "application/json"
829
+ responses:
830
+ 200:
831
+ description: "successful operation"
832
+ /enum/{enumId}:
833
+ x-swagger-router-controller: enum
834
+ get:
835
+ tags:
836
+ - "enum"
837
+ summary: "Reads enums of specific type"
838
+ operationId: "readEnums"
839
+ produces:
840
+ - "application/json"
841
+ parameters:
842
+ - name: "enumId"
843
+ in: "path"
844
+ description: "Enum ID in form \"functions\" or \"room\" without \"enum.\""
845
+ type: "string"
846
+ required: true
847
+ responses:
848
+ 200:
849
+ description: "successful operation"
850
+ schema:
851
+ $ref: "#/definitions/EnumResponse"
852
+ 404:
853
+ description: "Category not found"
785
854
  definitions:
786
855
  State:
787
856
  type: "object"
@@ -989,6 +1058,37 @@ definitions:
989
1058
  error:
990
1059
  type: "string"
991
1060
  description: "Error description"
1061
+ EnumCommon:
1062
+ type: "object"
1063
+ properties:
1064
+ name:
1065
+ type: "string"
1066
+ description: "Name can be string or object"
1067
+ icon:
1068
+ type: "string"
1069
+ description: "Icon for category (optional)"
1070
+ desc:
1071
+ type: "string"
1072
+ description: "Description can be string or object"
1073
+ members:
1074
+ type: "array"
1075
+ items:
1076
+ type: "string"
1077
+ EnumEntry:
1078
+ type: "object"
1079
+ properties:
1080
+ _id:
1081
+ type: "string"
1082
+ description: "Enum ID"
1083
+ common:
1084
+ $ref: "#/definitions/EnumCommon"
1085
+ type:
1086
+ type: "string"
1087
+ description: "Always enum"
1088
+ EnumResponse:
1089
+ type: "array"
1090
+ items:
1091
+ $ref: "#/definitions/EnumEntry"
992
1092
  externalDocs:
993
1093
  description: "Find out more about ioBroker"
994
1094
  url: "https://www.iobroker.net"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iobroker.rest-api",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "RESTful interface for ioBroker with GUI.",
5
5
  "author": {
6
6
  "name": "bluefox",