losant_rest 1.0.0

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.
Files changed (139) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rbenv-version +1 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +2 -0
  6. data/LICENSE +21 -0
  7. data/README.md +237 -0
  8. data/Rakefile +12 -0
  9. data/docs/_schemas.md +6348 -0
  10. data/docs/accessToken.md +107 -0
  11. data/docs/accessTokens.md +68 -0
  12. data/docs/application.md +107 -0
  13. data/docs/applicationKey.md +115 -0
  14. data/docs/applicationKeys.md +81 -0
  15. data/docs/applications.md +76 -0
  16. data/docs/auth.md +104 -0
  17. data/docs/dashboard.md +107 -0
  18. data/docs/dashboards.md +76 -0
  19. data/docs/data.md +78 -0
  20. data/docs/device.md +300 -0
  21. data/docs/deviceRecipe.md +152 -0
  22. data/docs/deviceRecipes.md +81 -0
  23. data/docs/devices.md +117 -0
  24. data/docs/event.md +115 -0
  25. data/docs/events.md +153 -0
  26. data/docs/flow.md +261 -0
  27. data/docs/flows.md +81 -0
  28. data/docs/me.md +312 -0
  29. data/docs/org.md +279 -0
  30. data/docs/orgs.md +75 -0
  31. data/docs/webhook.md +115 -0
  32. data/docs/webhooks.md +81 -0
  33. data/examples/auth.rb +32 -0
  34. data/examples/list_devices.rb +45 -0
  35. data/lib/losant_rest/access_token.rb +122 -0
  36. data/lib/losant_rest/access_tokens.rb +80 -0
  37. data/lib/losant_rest/application.rb +122 -0
  38. data/lib/losant_rest/application_key.rb +128 -0
  39. data/lib/losant_rest/application_keys.rb +98 -0
  40. data/lib/losant_rest/applications.rb +94 -0
  41. data/lib/losant_rest/auth.rb +122 -0
  42. data/lib/losant_rest/client.rb +132 -0
  43. data/lib/losant_rest/dashboard.rb +122 -0
  44. data/lib/losant_rest/dashboards.rb +94 -0
  45. data/lib/losant_rest/data.rb +89 -0
  46. data/lib/losant_rest/device.rb +336 -0
  47. data/lib/losant_rest/device_recipe.rb +169 -0
  48. data/lib/losant_rest/device_recipes.rb +98 -0
  49. data/lib/losant_rest/devices.rb +139 -0
  50. data/lib/losant_rest/error.rb +12 -0
  51. data/lib/losant_rest/event.rb +128 -0
  52. data/lib/losant_rest/events.rb +183 -0
  53. data/lib/losant_rest/flow.rb +290 -0
  54. data/lib/losant_rest/flows.rb +98 -0
  55. data/lib/losant_rest/me.rb +362 -0
  56. data/lib/losant_rest/org.rb +314 -0
  57. data/lib/losant_rest/orgs.rb +92 -0
  58. data/lib/losant_rest/utils.rb +22 -0
  59. data/lib/losant_rest/version.rb +3 -0
  60. data/lib/losant_rest/webhook.rb +128 -0
  61. data/lib/losant_rest/webhooks.rb +98 -0
  62. data/lib/losant_rest.rb +43 -0
  63. data/losant_rest.gemspec +25 -0
  64. data/schemas/accessToken.json +52 -0
  65. data/schemas/accessTokenPatch.json +19 -0
  66. data/schemas/accessTokenPost.json +32 -0
  67. data/schemas/accessTokens.json +65 -0
  68. data/schemas/application.json +65 -0
  69. data/schemas/applicationKey.json +68 -0
  70. data/schemas/applicationKeyPatch.json +18 -0
  71. data/schemas/applicationKeyPost.json +36 -0
  72. data/schemas/applicationKeys.json +110 -0
  73. data/schemas/applicationPatch.json +16 -0
  74. data/schemas/applicationPost.json +23 -0
  75. data/schemas/applications.json +103 -0
  76. data/schemas/authedDevice.json +34 -0
  77. data/schemas/authedUser.json +18 -0
  78. data/schemas/dashboard.json +95 -0
  79. data/schemas/dashboardPatch.json +69 -0
  80. data/schemas/dashboardPost.json +76 -0
  81. data/schemas/dashboards.json +133 -0
  82. data/schemas/device.json +113 -0
  83. data/schemas/deviceCommand.json +20 -0
  84. data/schemas/deviceCommands.json +25 -0
  85. data/schemas/deviceCredentials.json +22 -0
  86. data/schemas/deviceLog.json +28 -0
  87. data/schemas/devicePatch.json +78 -0
  88. data/schemas/devicePost.json +81 -0
  89. data/schemas/deviceRecipe.json +106 -0
  90. data/schemas/deviceRecipeBulkCreate.json +15 -0
  91. data/schemas/deviceRecipeBulkCreatePost.json +19 -0
  92. data/schemas/deviceRecipePatch.json +87 -0
  93. data/schemas/deviceRecipePost.json +90 -0
  94. data/schemas/deviceRecipes.json +148 -0
  95. data/schemas/deviceState.json +30 -0
  96. data/schemas/deviceStates.json +35 -0
  97. data/schemas/deviceTagFilter.json +19 -0
  98. data/schemas/devices.json +155 -0
  99. data/schemas/disableTwoFactorAuth.json +20 -0
  100. data/schemas/enableTwoFactorAuth.json +21 -0
  101. data/schemas/error.json +12 -0
  102. data/schemas/event.json +115 -0
  103. data/schemas/eventPatch.json +20 -0
  104. data/schemas/eventPost.json +39 -0
  105. data/schemas/events.json +165 -0
  106. data/schemas/flow.json +137 -0
  107. data/schemas/flowLog.json +46 -0
  108. data/schemas/flowPatch.json +107 -0
  109. data/schemas/flowPost.json +110 -0
  110. data/schemas/flowStorageEntries.json +7 -0
  111. data/schemas/flowStorageEntry.json +16 -0
  112. data/schemas/flows.json +179 -0
  113. data/schemas/githubLogin.json +14 -0
  114. data/schemas/lastValueData.json +34 -0
  115. data/schemas/lastValueQuery.json +36 -0
  116. data/schemas/me.json +173 -0
  117. data/schemas/mePatch.json +43 -0
  118. data/schemas/multiDeviceCommand.json +45 -0
  119. data/schemas/org.json +81 -0
  120. data/schemas/orgInvitePost.json +24 -0
  121. data/schemas/orgInvites.json +36 -0
  122. data/schemas/orgMemberPatch.json +23 -0
  123. data/schemas/orgPatch.json +16 -0
  124. data/schemas/orgPost.json +19 -0
  125. data/schemas/orgs.json +119 -0
  126. data/schemas/recentItem.json +27 -0
  127. data/schemas/recentItemList.json +36 -0
  128. data/schemas/success.json +12 -0
  129. data/schemas/timeSeriesData.json +89 -0
  130. data/schemas/timeSeriesQuery.json +64 -0
  131. data/schemas/userCredentials.json +25 -0
  132. data/schemas/virtualButtonPress.json +14 -0
  133. data/schemas/webhook.json +52 -0
  134. data/schemas/webhookPatch.json +29 -0
  135. data/schemas/webhookPost.json +32 -0
  136. data/schemas/webhooks.json +94 -0
  137. data/test/basic_test.rb +67 -0
  138. data/test/test_helper.rb +14 -0
  139. metadata +239 -0
@@ -0,0 +1,122 @@
1
+ module LosantRest
2
+
3
+ # Class containing all the actions for the Auth Resource
4
+ class Auth
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Authenticates a device using the provided credentials
11
+ #
12
+ # Parameters:
13
+ # * {hash} credentials - Device authentication credentials (https://api.losant.com/#/definitions/deviceCredentials)
14
+ # * {boolean} _actions - Return resource actions in response
15
+ # * {boolean} _links - Return resource link in response
16
+ # * {boolean} _embedded - Return embedded resources in response
17
+ #
18
+ # Responses:
19
+ # * 200 - Successful authentication (https://api.losant.com/#/definitions/authedDevice)
20
+ #
21
+ # Errors:
22
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
23
+ # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error)
24
+ def authenticate_device(params = {})
25
+ params = Utils.symbolize_hash_keys(params)
26
+ query_params = { _actions: false, _links: true, _embedded: true }
27
+ headers = {}
28
+ body = nil
29
+
30
+ raise ArgumentError.new("credentials is required") unless params.has_key?(:credentials)
31
+
32
+ body = params[:credentials] if params.has_key?(:credentials)
33
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
34
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
35
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
36
+
37
+ path = "/auth/device"
38
+
39
+ @client.request(
40
+ method: :post,
41
+ path: path,
42
+ query: query_params,
43
+ headers: headers,
44
+ body: body)
45
+ end
46
+
47
+ # Authenticates a user using the provided credentials
48
+ #
49
+ # Parameters:
50
+ # * {hash} credentials - User authentication credentials (https://api.losant.com/#/definitions/userCredentials)
51
+ # * {boolean} _actions - Return resource actions in response
52
+ # * {boolean} _links - Return resource link in response
53
+ # * {boolean} _embedded - Return embedded resources in response
54
+ #
55
+ # Responses:
56
+ # * 200 - Successful authentication (https://api.losant.com/#/definitions/authedUser)
57
+ #
58
+ # Errors:
59
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
60
+ # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error)
61
+ def authenticate_user(params = {})
62
+ params = Utils.symbolize_hash_keys(params)
63
+ query_params = { _actions: false, _links: true, _embedded: true }
64
+ headers = {}
65
+ body = nil
66
+
67
+ raise ArgumentError.new("credentials is required") unless params.has_key?(:credentials)
68
+
69
+ body = params[:credentials] if params.has_key?(:credentials)
70
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
71
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
72
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
73
+
74
+ path = "/auth/user"
75
+
76
+ @client.request(
77
+ method: :post,
78
+ path: path,
79
+ query: query_params,
80
+ headers: headers,
81
+ body: body)
82
+ end
83
+
84
+ # Authenticates a user via GitHub OAuth
85
+ #
86
+ # Parameters:
87
+ # * {hash} oauth - User authentication credentials (access token) (https://api.losant.com/#/definitions/githubLogin)
88
+ # * {boolean} _actions - Return resource actions in response
89
+ # * {boolean} _links - Return resource link in response
90
+ # * {boolean} _embedded - Return embedded resources in response
91
+ #
92
+ # Responses:
93
+ # * 200 - Successful authentication (https://api.losant.com/#/definitions/authedUser)
94
+ #
95
+ # Errors:
96
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
97
+ # * 401 - Unauthorized error if authentication fails (https://api.losant.com/#/definitions/error)
98
+ def authenticate_user_github(params = {})
99
+ params = Utils.symbolize_hash_keys(params)
100
+ query_params = { _actions: false, _links: true, _embedded: true }
101
+ headers = {}
102
+ body = nil
103
+
104
+ raise ArgumentError.new("oauth is required") unless params.has_key?(:oauth)
105
+
106
+ body = params[:oauth] if params.has_key?(:oauth)
107
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
108
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
109
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
110
+
111
+ path = "/auth/user/github"
112
+
113
+ @client.request(
114
+ method: :post,
115
+ path: path,
116
+ query: query_params,
117
+ headers: headers,
118
+ body: body)
119
+ end
120
+
121
+ end
122
+ end
@@ -0,0 +1,132 @@
1
+ require "httparty"
2
+
3
+ module LosantRest
4
+ # Losant API
5
+ #
6
+ # User API for accessing Losant data
7
+ #
8
+ # Built For Version 1.3.9
9
+ class Client
10
+ attr_accessor :auth_token, :url
11
+
12
+ def initialize(options = {})
13
+ self.auth_token = options.fetch(:auth_token, nil)
14
+ self.url = options.fetch(:url, "https://api.losant.com")
15
+ end
16
+
17
+ def access_token
18
+ @access_token ||= AccessToken.new(self)
19
+ end
20
+
21
+ def access_tokens
22
+ @access_tokens ||= AccessTokens.new(self)
23
+ end
24
+
25
+ def application
26
+ @application ||= Application.new(self)
27
+ end
28
+
29
+ def application_key
30
+ @application_key ||= ApplicationKey.new(self)
31
+ end
32
+
33
+ def application_keys
34
+ @application_keys ||= ApplicationKeys.new(self)
35
+ end
36
+
37
+ def applications
38
+ @applications ||= Applications.new(self)
39
+ end
40
+
41
+ def auth
42
+ @auth ||= Auth.new(self)
43
+ end
44
+
45
+ def dashboard
46
+ @dashboard ||= Dashboard.new(self)
47
+ end
48
+
49
+ def dashboards
50
+ @dashboards ||= Dashboards.new(self)
51
+ end
52
+
53
+ def data
54
+ @data ||= Data.new(self)
55
+ end
56
+
57
+ def device
58
+ @device ||= Device.new(self)
59
+ end
60
+
61
+ def device_recipe
62
+ @device_recipe ||= DeviceRecipe.new(self)
63
+ end
64
+
65
+ def device_recipes
66
+ @device_recipes ||= DeviceRecipes.new(self)
67
+ end
68
+
69
+ def devices
70
+ @devices ||= Devices.new(self)
71
+ end
72
+
73
+ def event
74
+ @event ||= Event.new(self)
75
+ end
76
+
77
+ def events
78
+ @events ||= Events.new(self)
79
+ end
80
+
81
+ def flow
82
+ @flow ||= Flow.new(self)
83
+ end
84
+
85
+ def flows
86
+ @flows ||= Flows.new(self)
87
+ end
88
+
89
+ def me
90
+ @me ||= Me.new(self)
91
+ end
92
+
93
+ def org
94
+ @org ||= Org.new(self)
95
+ end
96
+
97
+ def orgs
98
+ @orgs ||= Orgs.new(self)
99
+ end
100
+
101
+ def webhook
102
+ @webhook ||= Webhook.new(self)
103
+ end
104
+
105
+ def webhooks
106
+ @webhooks ||= Webhooks.new(self)
107
+ end
108
+
109
+ def request(options = {})
110
+ headers = options.fetch(:headers, {})
111
+ method = options.fetch(:method, :get)
112
+
113
+ headers["Accept"] = "application/json"
114
+ headers["Content-Type"] = "application/json"
115
+ headers["Accept-Version"] = "^1.3.9"
116
+ headers["Authorization"] = "Bearer #{self.auth_token}" if self.auth_token
117
+ path = self.url + options.fetch(:path, "")
118
+
119
+ response = HTTParty.send(method, path,
120
+ query: Utils.fix_query_arrays(options[:query]),
121
+ body: options[:body] && options[:body].to_json(),
122
+ headers: headers)
123
+
124
+ result = response.parsed_response
125
+ if response.code >= 400
126
+ raise ResponseError.new(response.code, result)
127
+ end
128
+
129
+ result
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,122 @@
1
+ module LosantRest
2
+
3
+ # Class containing all the actions for the Dashboard Resource
4
+ class Dashboard
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Deletes a dashboard
11
+ #
12
+ # Parameters:
13
+ # * {string} dashboardId - ID of the associated dashboard
14
+ # * {boolean} _actions - Return resource actions in response
15
+ # * {boolean} _links - Return resource link in response
16
+ # * {boolean} _embedded - Return embedded resources in response
17
+ #
18
+ # Responses:
19
+ # * 200 - If dashboard was successfully deleted (https://api.losant.com/#/definitions/success)
20
+ #
21
+ # Errors:
22
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
23
+ # * 404 - Error if dashboard was not found (https://api.losant.com/#/definitions/error)
24
+ def delete(params = {})
25
+ params = Utils.symbolize_hash_keys(params)
26
+ query_params = { _actions: false, _links: true, _embedded: true }
27
+ headers = {}
28
+ body = nil
29
+
30
+ raise ArgumentError.new("dashboardId is required") unless params.has_key?(:dashboardId)
31
+
32
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
33
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
34
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
35
+
36
+ path = "/dashboards/#{params[:dashboardId]}"
37
+
38
+ @client.request(
39
+ method: :delete,
40
+ path: path,
41
+ query: query_params,
42
+ headers: headers,
43
+ body: body)
44
+ end
45
+
46
+ # Retrieves information on a dashboard
47
+ #
48
+ # Parameters:
49
+ # * {string} dashboardId - ID of the associated dashboard
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 - Dashboard information (https://api.losant.com/#/definitions/dashboard)
56
+ #
57
+ # Errors:
58
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
59
+ # * 404 - Error if dashboard 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("dashboardId is required") unless params.has_key?(:dashboardId)
67
+
68
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
69
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
70
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
71
+
72
+ path = "/dashboards/#{params[:dashboardId]}"
73
+
74
+ @client.request(
75
+ method: :get,
76
+ path: path,
77
+ query: query_params,
78
+ headers: headers,
79
+ body: body)
80
+ end
81
+
82
+ # Updates information about a dashboard
83
+ #
84
+ # Parameters:
85
+ # * {string} dashboardId - ID of the associated dashboard
86
+ # * {hash} dashboard - Object containing new dashboard properties (https://api.losant.com/#/definitions/dashboardPatch)
87
+ # * {boolean} _actions - Return resource actions in response
88
+ # * {boolean} _links - Return resource link in response
89
+ # * {boolean} _embedded - Return embedded resources in response
90
+ #
91
+ # Responses:
92
+ # * 200 - Update dashboard information (https://api.losant.com/#/definitions/dashboard)
93
+ #
94
+ # Errors:
95
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
96
+ # * 404 - Error if dashboard was not found (https://api.losant.com/#/definitions/error)
97
+ def patch(params = {})
98
+ params = Utils.symbolize_hash_keys(params)
99
+ query_params = { _actions: false, _links: true, _embedded: true }
100
+ headers = {}
101
+ body = nil
102
+
103
+ raise ArgumentError.new("dashboardId is required") unless params.has_key?(:dashboardId)
104
+ raise ArgumentError.new("dashboard is required") unless params.has_key?(:dashboard)
105
+
106
+ body = params[:dashboard] if params.has_key?(:dashboard)
107
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
108
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
109
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
110
+
111
+ path = "/dashboards/#{params[:dashboardId]}"
112
+
113
+ @client.request(
114
+ method: :patch,
115
+ path: path,
116
+ query: query_params,
117
+ headers: headers,
118
+ body: body)
119
+ end
120
+
121
+ end
122
+ end
@@ -0,0 +1,94 @@
1
+ module LosantRest
2
+
3
+ # Class containing all the actions for the Dashboards Resource
4
+ class Dashboards
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Returns the dashboards the current user has permission to see
11
+ #
12
+ # Parameters:
13
+ # * {string} sortField - Field to sort the results by. Accepted values are: name, id, creationDate, ownerId
14
+ # * {string} sortDirection - Direction to sort the results by. Accepted values are: asc, desc
15
+ # * {string} page - Which page of results to return
16
+ # * {string} perPage - How many items to return per page
17
+ # * {string} filterField - Field to filter the results by. Blank or not provided means no filtering. Accepted values are: name
18
+ # * {string} filter - Filter to apply against the filtered field. Supports globbing. Blank or not provided means no filtering.
19
+ # * {string} orgId - If not provided, return all dashboards. If provided but blank, only return dashboards belonging to the current user. If provided and an id, only return dashboards belonging to the given organization id.
20
+ # * {boolean} _actions - Return resource actions in response
21
+ # * {boolean} _links - Return resource link in response
22
+ # * {boolean} _embedded - Return embedded resources in response
23
+ #
24
+ # Responses:
25
+ # * 200 - Collection of dashboards (https://api.losant.com/#/definitions/dashboards)
26
+ #
27
+ # Errors:
28
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
29
+ def get(params = {})
30
+ params = Utils.symbolize_hash_keys(params)
31
+ query_params = { _actions: false, _links: true, _embedded: true }
32
+ headers = {}
33
+ body = nil
34
+
35
+
36
+ query_params[:sortField] = params[:sortField] if params.has_key?(:sortField)
37
+ query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection)
38
+ query_params[:page] = params[:page] if params.has_key?(:page)
39
+ query_params[:perPage] = params[:perPage] if params.has_key?(:perPage)
40
+ query_params[:filterField] = params[:filterField] if params.has_key?(:filterField)
41
+ query_params[:filter] = params[:filter] if params.has_key?(:filter)
42
+ query_params[:orgId] = params[:orgId] if params.has_key?(:orgId)
43
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
44
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
45
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
46
+
47
+ path = "/dashboards"
48
+
49
+ @client.request(
50
+ method: :get,
51
+ path: path,
52
+ query: query_params,
53
+ headers: headers,
54
+ body: body)
55
+ end
56
+
57
+ # Create a new dasboard
58
+ #
59
+ # Parameters:
60
+ # * {hash} dashboard - New dashboard information (https://api.losant.com/#/definitions/dashboardPost)
61
+ # * {boolean} _actions - Return resource actions in response
62
+ # * {boolean} _links - Return resource link in response
63
+ # * {boolean} _embedded - Return embedded resources in response
64
+ #
65
+ # Responses:
66
+ # * 201 - Successfully created dashboard (https://api.losant.com/#/definitions/dashboard)
67
+ #
68
+ # Errors:
69
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
70
+ def post(params = {})
71
+ params = Utils.symbolize_hash_keys(params)
72
+ query_params = { _actions: false, _links: true, _embedded: true }
73
+ headers = {}
74
+ body = nil
75
+
76
+ raise ArgumentError.new("dashboard is required") unless params.has_key?(:dashboard)
77
+
78
+ body = params[:dashboard] if params.has_key?(:dashboard)
79
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
80
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
81
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
82
+
83
+ path = "/dashboards"
84
+
85
+ @client.request(
86
+ method: :post,
87
+ path: path,
88
+ query: query_params,
89
+ headers: headers,
90
+ body: body)
91
+ end
92
+
93
+ end
94
+ end
@@ -0,0 +1,89 @@
1
+ module LosantRest
2
+
3
+ # Class containing all the actions for the Data Resource
4
+ class Data
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ # Returns the last known data for the given attribute
11
+ #
12
+ # Parameters:
13
+ # * {string} applicationId - ID associated with the application
14
+ # * {hash} query - The query parameters (https://api.losant.com/#/definitions/lastValueQuery)
15
+ # * {boolean} _actions - Return resource actions in response
16
+ # * {boolean} _links - Return resource link in response
17
+ # * {boolean} _embedded - Return embedded resources in response
18
+ #
19
+ # Responses:
20
+ # * 200 - Last known data for the requested attribute (https://api.losant.com/#/definitions/lastValueData)
21
+ #
22
+ # Errors:
23
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
24
+ # * 404 - Error if application was not found (https://api.losant.com/#/definitions/error)
25
+ def last_value_query(params = {})
26
+ params = Utils.symbolize_hash_keys(params)
27
+ query_params = { _actions: false, _links: true, _embedded: true }
28
+ headers = {}
29
+ body = nil
30
+
31
+ raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId)
32
+ raise ArgumentError.new("query is required") unless params.has_key?(:query)
33
+
34
+ body = params[:query] if params.has_key?(:query)
35
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
36
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
37
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
38
+
39
+ path = "/applications/#{params[:applicationId]}/data/last-value-query"
40
+
41
+ @client.request(
42
+ method: :post,
43
+ path: path,
44
+ query: query_params,
45
+ headers: headers,
46
+ body: body)
47
+ end
48
+
49
+ # Returns the data for the given query
50
+ #
51
+ # Parameters:
52
+ # * {string} applicationId - ID associated with the application
53
+ # * {hash} query - The query parameters (https://api.losant.com/#/definitions/timeSeriesQuery)
54
+ # * {boolean} _actions - Return resource actions in response
55
+ # * {boolean} _links - Return resource link in response
56
+ # * {boolean} _embedded - Return embedded resources in response
57
+ #
58
+ # Responses:
59
+ # * 200 - Data for requested time range (https://api.losant.com/#/definitions/timeSeriesData)
60
+ #
61
+ # Errors:
62
+ # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error)
63
+ # * 404 - Error if application was not found (https://api.losant.com/#/definitions/error)
64
+ def time_series_query(params = {})
65
+ params = Utils.symbolize_hash_keys(params)
66
+ query_params = { _actions: false, _links: true, _embedded: true }
67
+ headers = {}
68
+ body = nil
69
+
70
+ raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId)
71
+ raise ArgumentError.new("query is required") unless params.has_key?(:query)
72
+
73
+ body = params[:query] if params.has_key?(:query)
74
+ query_params[:_actions] = params[:_actions] if params.has_key?(:_actions)
75
+ query_params[:_links] = params[:_links] if params.has_key?(:_links)
76
+ query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded)
77
+
78
+ path = "/applications/#{params[:applicationId]}/data/time-series-query"
79
+
80
+ @client.request(
81
+ method: :post,
82
+ path: path,
83
+ query: query_params,
84
+ headers: headers,
85
+ body: body)
86
+ end
87
+
88
+ end
89
+ end