losant_rest 1.5.1 → 1.5.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) 2018 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 Files Resource
26
+ class Files
27
+
28
+ def initialize(client)
29
+ @client = client
30
+ end
31
+
32
+ # Returns the files for an application
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, files.*, or files.get.
39
+ #
40
+ # Parameters:
41
+ # * {string} applicationId - ID associated with the application
42
+ # * {string} sortField - Field to sort the results by. Accepted values are: lastUpdated, type, name, creationDate
43
+ # * {string} sortDirection - Direction to sort the results by. Accepted values are: asc, desc
44
+ # * {string} page - Which page of results to return
45
+ # * {string} perPage - How many items to return per page
46
+ # * {string} filterField - Field to filter the results by. Blank or not provided means no filtering. Accepted values are: name
47
+ # * {string} filter - Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering.
48
+ # * {string} type - Limit by the type (file or directory) of the file
49
+ # * {string} status - Limit the result to only files of this status. Accepted values are: completed, pending
50
+ # * {string} directory - Get files that are inside of this directory
51
+ # * {string} losantdomain - Domain scope of request (rarely needed)
52
+ # * {boolean} _actions - Return resource actions in response
53
+ # * {boolean} _links - Return resource link in response
54
+ # * {boolean} _embedded - Return embedded resources in response
55
+ #
56
+ # Responses:
57
+ # * 200 - Collection of files (https://api.losant.com/#/definitions/files)
58
+ #
59
+ # Errors:
60
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
61
+ # * 404 - Error if application was not found (https://api.losant.com/#/definitions/error)
62
+ def get(params = {})
63
+ params = Utils.symbolize_hash_keys(params)
64
+ query_params = { _actions: false, _links: true, _embedded: true }
65
+ headers = {}
66
+ body = nil
67
+
68
+ raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId)
69
+
70
+ query_params[:sortField] = params[:sortField] if params.has_key?(:sortField)
71
+ query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection)
72
+ query_params[:page] = params[:page] if params.has_key?(:page)
73
+ query_params[:perPage] = params[:perPage] if params.has_key?(:perPage)
74
+ query_params[:filterField] = params[:filterField] if params.has_key?(:filterField)
75
+ query_params[:filter] = params[:filter] if params.has_key?(:filter)
76
+ query_params[:type] = params[:type] if params.has_key?(:type)
77
+ query_params[:status] = params[:status] if params.has_key?(:status)
78
+ query_params[:directory] = params[:directory] if params.has_key?(:directory)
79
+ headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain)
80
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
81
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
82
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
83
+
84
+ path = "/applications/#{params[:applicationId]}/files"
85
+
86
+ @client.request(
87
+ method: :get,
88
+ path: path,
89
+ query: query_params,
90
+ headers: headers,
91
+ body: body)
92
+ end
93
+
94
+ # Create a new file for an application
95
+ #
96
+ # Authentication:
97
+ # The client must be configured with a valid api
98
+ # access token to call this action. The token
99
+ # must include at least one of the following scopes:
100
+ # all.Application, all.Organization, all.User, files.*, or files.post.
101
+ #
102
+ # Parameters:
103
+ # * {string} applicationId - ID associated with the application
104
+ # * {hash} file - New file information (https://api.losant.com/#/definitions/filePost)
105
+ # * {string} losantdomain - Domain scope of request (rarely needed)
106
+ # * {boolean} _actions - Return resource actions in response
107
+ # * {boolean} _links - Return resource link in response
108
+ # * {boolean} _embedded - Return embedded resources in response
109
+ #
110
+ # Responses:
111
+ # * 201 - Successfully created file and returned a post url to respond with (https://api.losant.com/#/definitions/fileUploadPostResp)
112
+ #
113
+ # Errors:
114
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
115
+ # * 404 - Error if application was not found (https://api.losant.com/#/definitions/error)
116
+ def post(params = {})
117
+ params = Utils.symbolize_hash_keys(params)
118
+ query_params = { _actions: false, _links: true, _embedded: true }
119
+ headers = {}
120
+ body = nil
121
+
122
+ raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId)
123
+ raise ArgumentError.new("file is required") unless params.has_key?(:file)
124
+
125
+ body = params[:file] if params.has_key?(:file)
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]}/files"
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
@@ -21,5 +21,5 @@
21
21
  # SOFTWARE.
22
22
 
23
23
  module LosantRest
24
- VERSION = "1.5.1"
24
+ VERSION = "1.5.2"
25
25
  end
@@ -51,6 +51,8 @@
51
51
  "experienceViews.*",
52
52
  "integration.*",
53
53
  "integrations.*",
54
+ "file.*",
55
+ "files.*",
54
56
  "flow.*",
55
57
  "flows.*",
56
58
  "flowVersion.*",
@@ -149,6 +151,12 @@
149
151
  "experienceView.patch",
150
152
  "experienceViews.get",
151
153
  "experienceViews.post",
154
+ "file.get",
155
+ "file.patch",
156
+ "file.move",
157
+ "file.delete",
158
+ "files.get",
159
+ "files.post",
152
160
  "flow.delete",
153
161
  "flow.clearStorageEntries",
154
162
  "flow.get",
@@ -14,7 +14,8 @@
14
14
  "newPassword": {
15
15
  "type": "string",
16
16
  "minLength": 8,
17
- "maxLength": 2048
17
+ "maxLength": 2048,
18
+ "pattern": "^(?=.*[A-Z])(?=.*[^A-z0-9])(?=.*[0-9])(?=.*[a-z]).{8,}$"
18
19
  },
19
20
  "invalidateExistingTokens": {
20
21
  "type": "boolean"
@@ -8,7 +8,91 @@
8
8
  "maxLength": 1024
9
9
  },
10
10
  "query": {
11
- "$ref": "#/definitions/dataTableQuery"
11
+ "title": "Data Table Query",
12
+ "description": "Schema for a data table query",
13
+ "type": "object",
14
+ "properties": {
15
+ "$and": {
16
+ "type": "array",
17
+ "items": {
18
+ "$ref": "#/definitions/dataTableQuery"
19
+ }
20
+ },
21
+ "$or": {
22
+ "type": "array",
23
+ "items": {
24
+ "$ref": "#/definitions/dataTableQuery"
25
+ }
26
+ }
27
+ },
28
+ "patternProperties": {
29
+ "^[0-9a-zA-Z_-]{1,255}$": {
30
+ "oneOf": [
31
+ {
32
+ "type": [
33
+ "string",
34
+ "number",
35
+ "boolean",
36
+ "null"
37
+ ]
38
+ },
39
+ {
40
+ "type": "object",
41
+ "properties": {
42
+ "$eq": {
43
+ "type": [
44
+ "string",
45
+ "number",
46
+ "boolean",
47
+ "null"
48
+ ]
49
+ },
50
+ "$ne": {
51
+ "type": [
52
+ "string",
53
+ "number",
54
+ "boolean",
55
+ "null"
56
+ ]
57
+ },
58
+ "$gt": {
59
+ "type": [
60
+ "string",
61
+ "number",
62
+ "boolean",
63
+ "null"
64
+ ]
65
+ },
66
+ "$lt": {
67
+ "type": [
68
+ "string",
69
+ "number",
70
+ "boolean",
71
+ "null"
72
+ ]
73
+ },
74
+ "$gte": {
75
+ "type": [
76
+ "string",
77
+ "number",
78
+ "boolean",
79
+ "null"
80
+ ]
81
+ },
82
+ "$lte": {
83
+ "type": [
84
+ "string",
85
+ "number",
86
+ "boolean",
87
+ "null"
88
+ ]
89
+ }
90
+ }
91
+ }
92
+ ]
93
+ }
94
+ },
95
+ "additionalProperties": false
12
96
  },
13
97
  "queryOptions": {
14
98
  "type": "object",
@@ -0,0 +1,78 @@
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
+ "applicationId": {
10
+ "type": "string",
11
+ "pattern": "^[A-Fa-f\\d]{24}$"
12
+ },
13
+ "creationDate": {
14
+ "type": "string",
15
+ "format": "date-time"
16
+ },
17
+ "lastUpdated": {
18
+ "type": "string",
19
+ "format": "date-time"
20
+ },
21
+ "authorId": {
22
+ "type": "string",
23
+ "pattern": "^[A-Fa-f\\d]{24}$"
24
+ },
25
+ "authorType": {
26
+ "type": "string",
27
+ "enum": [
28
+ "flow",
29
+ "user",
30
+ "device",
31
+ "apiToken"
32
+ ]
33
+ },
34
+ "status": {
35
+ "type": "string",
36
+ "enum": [
37
+ "pending",
38
+ "moving",
39
+ "deleting",
40
+ "completed"
41
+ ]
42
+ },
43
+ "name": {
44
+ "type": "string",
45
+ "minLength": 1,
46
+ "maxLength": 2048
47
+ },
48
+ "parentDirectory": {
49
+ "type": "string",
50
+ "maxLength": 2048
51
+ },
52
+ "type": {
53
+ "type": "string",
54
+ "enum": [
55
+ "file",
56
+ "directory"
57
+ ]
58
+ },
59
+ "fileSize": {
60
+ "type": "number"
61
+ },
62
+ "contentType": {
63
+ "type": "string",
64
+ "maxLength": 1024
65
+ },
66
+ "fileDimensions": {
67
+ "type": "object",
68
+ "properties": {
69
+ "width": {
70
+ "type": "number"
71
+ },
72
+ "height": {
73
+ "type": "number"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "fileSize": {
6
+ "type": "number"
7
+ },
8
+ "contentType": {
9
+ "type": "string",
10
+ "maxLength": 1024
11
+ },
12
+ "fileDimensions": {
13
+ "type": "object",
14
+ "properties": {
15
+ "width": {
16
+ "type": "number"
17
+ },
18
+ "height": {
19
+ "type": "number"
20
+ }
21
+ }
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-04/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "name": {
6
+ "type": "string",
7
+ "minLength": 1,
8
+ "maxLength": 2048
9
+ },
10
+ "parentDirectory": {
11
+ "type": "string",
12
+ "maxLength": 2048
13
+ },
14
+ "type": {
15
+ "type": "string",
16
+ "enum": [
17
+ "file",
18
+ "directory"
19
+ ]
20
+ },
21
+ "fileSize": {
22
+ "type": "number"
23
+ },
24
+ "contentType": {
25
+ "type": "string",
26
+ "maxLength": 1024
27
+ },
28
+ "fileDimensions": {
29
+ "type": "object",
30
+ "properties": {
31
+ "width": {
32
+ "type": "number"
33
+ },
34
+ "height": {
35
+ "type": "number"
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,109 @@
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
+ "applicationId": {
10
+ "type": "string",
11
+ "pattern": "^[A-Fa-f\\d]{24}$"
12
+ },
13
+ "creationDate": {
14
+ "type": "string",
15
+ "format": "date-time"
16
+ },
17
+ "lastUpdated": {
18
+ "type": "string",
19
+ "format": "date-time"
20
+ },
21
+ "authorId": {
22
+ "type": "string",
23
+ "pattern": "^[A-Fa-f\\d]{24}$"
24
+ },
25
+ "authorType": {
26
+ "type": "string",
27
+ "enum": [
28
+ "flow",
29
+ "user",
30
+ "device",
31
+ "apiToken"
32
+ ]
33
+ },
34
+ "status": {
35
+ "type": "string",
36
+ "enum": [
37
+ "pending",
38
+ "moving",
39
+ "deleting",
40
+ "completed"
41
+ ]
42
+ },
43
+ "name": {
44
+ "type": "string",
45
+ "minLength": 1,
46
+ "maxLength": 2048
47
+ },
48
+ "parentDirectory": {
49
+ "type": "string",
50
+ "maxLength": 2048
51
+ },
52
+ "type": {
53
+ "type": "string",
54
+ "enum": [
55
+ "file",
56
+ "directory"
57
+ ]
58
+ },
59
+ "fileSize": {
60
+ "type": "number"
61
+ },
62
+ "contentType": {
63
+ "type": "string",
64
+ "maxLength": 1024
65
+ },
66
+ "fileDimensions": {
67
+ "type": "object",
68
+ "properties": {
69
+ "width": {
70
+ "type": "number"
71
+ },
72
+ "height": {
73
+ "type": "number"
74
+ }
75
+ }
76
+ },
77
+ "upload": {
78
+ "url": {
79
+ "type": "string"
80
+ },
81
+ "fields": {
82
+ "type": "object",
83
+ "properties": {
84
+ "key": {
85
+ "type": "string"
86
+ },
87
+ "bucket": {
88
+ "type": "string"
89
+ },
90
+ "X-Amz-Algorithm": {
91
+ "type": "string"
92
+ },
93
+ "X-Amz-Credential": {
94
+ "type": "string"
95
+ },
96
+ "X-Amz-Date": {
97
+ "type": "string"
98
+ },
99
+ "Policy": {
100
+ "type": "string"
101
+ },
102
+ "X-Amz-Signature": {
103
+ "type": "string"
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }