losant_rest 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,142 @@
1
+ # The MIT License (MIT)
2
+ #
3
+ # Copyright (c) 2017 Losant IoT, Inc.
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ module LosantRest
24
+
25
+ # Class containing all the actions for the Flow Versions Resource
26
+ class FlowVersions
27
+
28
+ def initialize(client)
29
+ @client = client
30
+ end
31
+
32
+ # Returns the flow versions for a flow
33
+ #
34
+ # Authentication:
35
+ # The client must be configured with a valid api
36
+ # access token to call this action. The token
37
+ # must include at least one of the following scopes:
38
+ # all.Application, all.Application.read, all.Organization, all.Organization.read, all.User, all.User.read, flowVersions.*, or flowVersions.get.
39
+ #
40
+ # Parameters:
41
+ # * {string} applicationId - ID associated with the application
42
+ # * {string} flowId - ID associated with the flow
43
+ # * {string} sortField - Field to sort the results by. Accepted values are: version, id, creationDate
44
+ # * {string} sortDirection - Direction to sort the results by. Accepted values are: asc, desc
45
+ # * {string} page - Which page of results to return
46
+ # * {string} perPage - How many items to return per page
47
+ # * {string} filterField - Field to filter the results by. Blank or not provided means no filtering. Accepted values are: version
48
+ # * {string} filter - Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering.
49
+ # * {string} losantdomain - Domain scope of request (rarely needed)
50
+ # * {boolean} _actions - Return resource actions in response
51
+ # * {boolean} _links - Return resource link in response
52
+ # * {boolean} _embedded - Return embedded resources in response
53
+ #
54
+ # Responses:
55
+ # * 200 - Collection of flow versions (https://api.losant.com/#/definitions/flowVersions)
56
+ #
57
+ # Errors:
58
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
59
+ # * 404 - Error if flow was not found (https://api.losant.com/#/definitions/error)
60
+ def get(params = {})
61
+ params = Utils.symbolize_hash_keys(params)
62
+ query_params = { _actions: false, _links: true, _embedded: true }
63
+ headers = {}
64
+ body = nil
65
+
66
+ raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId)
67
+ raise ArgumentError.new("flowId is required") unless params.has_key?(:flowId)
68
+
69
+ query_params[:sortField] = params[:sortField] if params.has_key?(:sortField)
70
+ query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection)
71
+ query_params[:page] = params[:page] if params.has_key?(:page)
72
+ query_params[:perPage] = params[:perPage] if params.has_key?(:perPage)
73
+ query_params[:filterField] = params[:filterField] if params.has_key?(:filterField)
74
+ query_params[:filter] = params[:filter] if params.has_key?(:filter)
75
+ headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain)
76
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
77
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
78
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
79
+
80
+ path = "/applications/#{params[:applicationId]}/flows/#{params[:flowId]}/versions"
81
+
82
+ @client.request(
83
+ method: :get,
84
+ path: path,
85
+ query: query_params,
86
+ headers: headers,
87
+ body: body)
88
+ end
89
+
90
+ # Create or replace a flow version for a flow
91
+ #
92
+ # Authentication:
93
+ # The client must be configured with a valid api
94
+ # access token to call this action. The token
95
+ # must include at least one of the following scopes:
96
+ # all.Application, all.Organization, all.User, flowVersions.*, or flowVersions.post.
97
+ #
98
+ # Parameters:
99
+ # * {string} applicationId - ID associated with the application
100
+ # * {string} flowId - ID associated with the flow
101
+ # * {hash} flowVersion - New flow version information (https://api.losant.com/#/definitions/flowVersionPost)
102
+ # * {undefined} allowReplacement - Allow replacement of an existing flow version with same version name
103
+ # * {string} losantdomain - Domain scope of request (rarely needed)
104
+ # * {boolean} _actions - Return resource actions in response
105
+ # * {boolean} _links - Return resource link in response
106
+ # * {boolean} _embedded - Return embedded resources in response
107
+ #
108
+ # Responses:
109
+ # * 201 - Successfully created flow version (https://api.losant.com/#/definitions/flowVersion)
110
+ #
111
+ # Errors:
112
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
113
+ # * 404 - Error if flow was not found (https://api.losant.com/#/definitions/error)
114
+ def post(params = {})
115
+ params = Utils.symbolize_hash_keys(params)
116
+ query_params = { _actions: false, _links: true, _embedded: true }
117
+ headers = {}
118
+ body = nil
119
+
120
+ raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId)
121
+ raise ArgumentError.new("flowId is required") unless params.has_key?(:flowId)
122
+ raise ArgumentError.new("flowVersion is required") unless params.has_key?(:flowVersion)
123
+
124
+ body = params[:flowVersion] if params.has_key?(:flowVersion)
125
+ query_params[:allowReplacement] = params[:allowReplacement] if params.has_key?(:allowReplacement)
126
+ headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain)
127
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
128
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
129
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
130
+
131
+ path = "/applications/#{params[:applicationId]}/flows/#{params[:flowId]}/versions"
132
+
133
+ @client.request(
134
+ method: :post,
135
+ path: path,
136
+ query: query_params,
137
+ headers: headers,
138
+ body: body)
139
+ end
140
+
141
+ end
142
+ end
@@ -45,7 +45,7 @@ module LosantRest
45
45
  # * {string} perPage - How many items to return per page
46
46
  # * {string} filterField - Field to filter the results by. Blank or not provided means no filtering. Accepted values are: name
47
47
  # * {string} filter - Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering.
48
- # * {hash} triggerFilter - Array of triggers to filter by. (https://api.losant.com/#/definitions/flowTriggerFilter)
48
+ # * {hash} triggerFilter - Array of triggers to filter by - always filters against default flow version. (https://api.losant.com/#/definitions/flowTriggerFilter)
49
49
  # * {string} losantdomain - Domain scope of request (rarely needed)
50
50
  # * {boolean} _actions - Return resource actions in response
51
51
  # * {boolean} _links - Return resource link in response
@@ -21,5 +21,5 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  module LosantRest
24
- VERSION = "1.2.1"
24
+ VERSION = "1.2.2"
25
25
  end
@@ -46,6 +46,8 @@
46
46
  "integrations.*",
47
47
  "flow.*",
48
48
  "flows.*",
49
+ "flowVersion.*",
50
+ "flowVersions.*",
49
51
  "webhook.*",
50
52
  "webhooks.*",
51
53
  "application.delete",
@@ -117,6 +119,12 @@
117
119
  "flow.setStorageEntry",
118
120
  "flows.get",
119
121
  "flows.post",
122
+ "flowVersion.delete",
123
+ "flowVersion.get",
124
+ "flowVersion.log",
125
+ "flowVersion.patch",
126
+ "flowVersions.get",
127
+ "flowVersions.post",
120
128
  "integration.delete",
121
129
  "integration.get",
122
130
  "integration.patch",
@@ -69,16 +69,16 @@
69
69
  "pattern": "^[A-Fa-f\\d]{24}$"
70
70
  },
71
71
  "startX": {
72
- "type": "integer"
72
+ "type": "number"
73
73
  },
74
74
  "startY": {
75
- "type": "integer"
75
+ "type": "number"
76
76
  },
77
77
  "width": {
78
- "type": "integer"
78
+ "type": "number"
79
79
  },
80
80
  "height": {
81
- "type": "integer"
81
+ "type": "number"
82
82
  },
83
83
  "config": {
84
84
  "type": "object"
@@ -27,16 +27,16 @@
27
27
  "pattern": "^[A-Fa-f\\d]{24}$"
28
28
  },
29
29
  "startX": {
30
- "type": "integer"
30
+ "type": "number"
31
31
  },
32
32
  "startY": {
33
- "type": "integer"
33
+ "type": "number"
34
34
  },
35
35
  "width": {
36
- "type": "integer"
36
+ "type": "number"
37
37
  },
38
38
  "height": {
39
- "type": "integer"
39
+ "type": "number"
40
40
  },
41
41
  "config": {
42
42
  "type": "object"
@@ -31,16 +31,16 @@
31
31
  "pattern": "^[A-Fa-f\\d]{24}$"
32
32
  },
33
33
  "startX": {
34
- "type": "integer"
34
+ "type": "number"
35
35
  },
36
36
  "startY": {
37
- "type": "integer"
37
+ "type": "number"
38
38
  },
39
39
  "width": {
40
- "type": "integer"
40
+ "type": "number"
41
41
  },
42
42
  "height": {
43
- "type": "integer"
43
+ "type": "number"
44
44
  },
45
45
  "config": {
46
46
  "type": "object"
@@ -76,16 +76,16 @@
76
76
  "pattern": "^[A-Fa-f\\d]{24}$"
77
77
  },
78
78
  "startX": {
79
- "type": "integer"
79
+ "type": "number"
80
80
  },
81
81
  "startY": {
82
- "type": "integer"
82
+ "type": "number"
83
83
  },
84
84
  "width": {
85
- "type": "integer"
85
+ "type": "number"
86
86
  },
87
87
  "height": {
88
- "type": "integer"
88
+ "type": "number"
89
89
  },
90
90
  "config": {
91
91
  "type": "object"
@@ -44,6 +44,11 @@
44
44
  }
45
45
  },
46
46
  "additionalProperties": false
47
+ },
48
+ "flowVersion": {
49
+ "type": "string",
50
+ "minLength": 1,
51
+ "maxLength": 255
47
52
  }
48
53
  },
49
54
  "required": [
@@ -98,6 +103,11 @@
98
103
  }
99
104
  },
100
105
  "additionalProperties": false
106
+ },
107
+ "flowVersion": {
108
+ "type": "string",
109
+ "minLength": 1,
110
+ "maxLength": 255
101
111
  }
102
112
  },
103
113
  "required": [
@@ -44,6 +44,11 @@
44
44
  }
45
45
  },
46
46
  "additionalProperties": false
47
+ },
48
+ "flowVersion": {
49
+ "type": "string",
50
+ "minLength": 1,
51
+ "maxLength": 255
47
52
  }
48
53
  },
49
54
  "required": [
data/schemas/flow.json CHANGED
@@ -34,6 +34,10 @@
34
34
  "enabled": {
35
35
  "type": "boolean"
36
36
  },
37
+ "defaultVersionId": {
38
+ "type": "string",
39
+ "pattern": "^[A-Fa-f\\d]{24}$"
40
+ },
37
41
  "triggers": {
38
42
  "type": "array",
39
43
  "items": {
@@ -154,6 +158,22 @@
154
158
  },
155
159
  "errorCount": {
156
160
  "type": "number"
161
+ },
162
+ "byVersion": {
163
+ "type": "object",
164
+ "patternProperties": {
165
+ ".*": {
166
+ "type": "object",
167
+ "properties": {
168
+ "runCount": {
169
+ "type": "number"
170
+ },
171
+ "errorCount": {
172
+ "type": "number"
173
+ }
174
+ }
175
+ }
176
+ }
157
177
  }
158
178
  }
159
179
  }
data/schemas/flowLog.json CHANGED
@@ -4,6 +4,9 @@
4
4
  "items": {
5
5
  "type": "object",
6
6
  "properties": {
7
+ "flowVersionId": {
8
+ "type": "string"
9
+ },
7
10
  "time": {
8
11
  "type": "string",
9
12
  "format": "date-time"
@@ -14,6 +14,17 @@
14
14
  "enabled": {
15
15
  "type": "boolean"
16
16
  },
17
+ "defaultVersionId": {
18
+ "oneOf": [
19
+ {
20
+ "type": "string",
21
+ "pattern": "^[A-Fa-f\\d]{24}$"
22
+ },
23
+ {
24
+ "type": "null"
25
+ }
26
+ ]
27
+ },
17
28
  "triggers": {
18
29
  "type": "array",
19
30
  "items": {
@@ -0,0 +1,154 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "id": {
6
+ "type": "string",
7
+ "pattern": "^[A-Fa-f\\d]{24}$"
8
+ },
9
+ "flowVersionId": {
10
+ "type": "string",
11
+ "pattern": "^[A-Fa-f\\d]{24}$"
12
+ },
13
+ "flowId": {
14
+ "type": "string",
15
+ "pattern": "^[A-Fa-f\\d]{24}$"
16
+ },
17
+ "applicationId": {
18
+ "type": "string",
19
+ "pattern": "^[A-Fa-f\\d]{24}$"
20
+ },
21
+ "creationDate": {
22
+ "type": "string",
23
+ "format": "date-time"
24
+ },
25
+ "lastUpdated": {
26
+ "type": "string",
27
+ "format": "date-time"
28
+ },
29
+ "version": {
30
+ "type": "string",
31
+ "minLength": 1,
32
+ "maxLength": 255
33
+ },
34
+ "notes": {
35
+ "type": "string",
36
+ "maxLength": 32767
37
+ },
38
+ "enabled": {
39
+ "type": "boolean"
40
+ },
41
+ "triggers": {
42
+ "type": "array",
43
+ "items": {
44
+ "type": "object",
45
+ "properties": {
46
+ "key": {
47
+ "type": "string",
48
+ "maxLength": 1024
49
+ },
50
+ "type": {
51
+ "type": "string",
52
+ "enum": [
53
+ "deviceId",
54
+ "deviceIdConnect",
55
+ "deviceIdDisconnect",
56
+ "deviceTag",
57
+ "deviceTagConnect",
58
+ "deviceTagDisconnect",
59
+ "endpoint",
60
+ "event",
61
+ "mqttTopic",
62
+ "integration",
63
+ "timer",
64
+ "virtualButton",
65
+ "webhook"
66
+ ]
67
+ },
68
+ "config": {
69
+ "type": "object"
70
+ },
71
+ "meta": {
72
+ "type": "object"
73
+ },
74
+ "outputIds": {
75
+ "type": "array",
76
+ "items": {
77
+ "type": "array",
78
+ "items": {
79
+ "type": "string",
80
+ "maxLength": 255
81
+ },
82
+ "maxItems": 100
83
+ },
84
+ "maxItems": 100
85
+ }
86
+ },
87
+ "additionalProperties": false,
88
+ "required": [
89
+ "type"
90
+ ]
91
+ }
92
+ },
93
+ "nodes": {
94
+ "type": "array",
95
+ "items": {
96
+ "type": "object",
97
+ "properties": {
98
+ "id": {
99
+ "type": "string",
100
+ "maxLength": 1024
101
+ },
102
+ "type": {
103
+ "type": "string",
104
+ "minLength": 1,
105
+ "maxLength": 1024
106
+ },
107
+ "config": {
108
+ "type": "object"
109
+ },
110
+ "meta": {
111
+ "type": "object"
112
+ },
113
+ "outputIds": {
114
+ "type": "array",
115
+ "items": {
116
+ "type": "array",
117
+ "items": {
118
+ "type": "string",
119
+ "maxLength": 255
120
+ },
121
+ "maxItems": 100
122
+ },
123
+ "maxItems": 100
124
+ }
125
+ },
126
+ "additionalProperties": false,
127
+ "required": [
128
+ "type"
129
+ ]
130
+ }
131
+ },
132
+ "globals": {
133
+ "type": "array",
134
+ "items": {
135
+ "type": "object",
136
+ "properties": {
137
+ "key": {
138
+ "type": "string",
139
+ "pattern": "^[0-9a-zA-Z_-]{1,255}$"
140
+ },
141
+ "json": {
142
+ "type": "string",
143
+ "minLength": 1
144
+ }
145
+ },
146
+ "additionalProperties": false,
147
+ "required": [
148
+ "key",
149
+ "json"
150
+ ]
151
+ }
152
+ }
153
+ }
154
+ }