lib/losant_rest/devices.rb in losant_rest-1.15.1 vs lib/losant_rest/devices.rb in losant_rest-1.15.2

- old
+ new

@@ -1,8 +1,8 @@ # The MIT License (MIT) # -# Copyright (c) 2021 Losant IoT, Inc. +# Copyright (c) 2022 Losant IoT, Inc. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell @@ -122,9 +122,58 @@ path = "/applications/#{params[:applicationId]}/devices/delete" @client.request( method: :post, + path: path, + query: query_params, + headers: headers, + body: body) + end + + # Gets the device names that match the given query. Maximum 1K returned. + # + # Authentication: + # The client must be configured with a valid api + # access token to call this action. The token + # must include at least one of the following scopes: + # all.Application, all.Application.read, all.Organization, all.Organization.read, all.User, all.User.read, devices.*, or devices.deviceNames. + # + # Parameters: + # * {string} applicationId - ID associated with the application + # * {hash} query - Device filter JSON object (https://api.losant.com/#/definitions/advancedDeviceQuery) + # * {string} startsWith - Filter devices down to those that have names starting with the given string. Case insensitive. + # * {string} losantdomain - Domain scope of request (rarely needed) + # * {boolean} _actions - Return resource actions in response + # * {boolean} _links - Return resource link in response + # * {boolean} _embedded - Return embedded resources in response + # + # Responses: + # * 200 - The matching device names (https://api.losant.com/#/definitions/deviceNamesResponse) + # + # Errors: + # * 400 - Error if malformed request (https://api.losant.com/#/definitions/error) + # * 404 - Error if application was not found (https://api.losant.com/#/definitions/error) + def device_names(params = {}) + params = Utils.symbolize_hash_keys(params) + query_params = { _actions: false, _links: true, _embedded: true } + headers = {} + body = nil + + raise ArgumentError.new("applicationId is required") unless params.has_key?(:applicationId) + + query_params[:query] = params[:query] if params.has_key?(:query) + query_params[:query] = JSON.dump(query_params[:query]) if query_params.has_key?(:query) + query_params[:startsWith] = params[:startsWith] if params.has_key?(:startsWith) + headers[:losantdomain] = params[:losantdomain] if params.has_key?(:losantdomain) + query_params[:_actions] = params[:_actions] if params.has_key?(:_actions) + query_params[:_links] = params[:_links] if params.has_key?(:_links) + query_params[:_embedded] = params[:_embedded] if params.has_key?(:_embedded) + + path = "/applications/#{params[:applicationId]}/devices/deviceNames" + + @client.request( + method: :get, path: path, query: query_params, headers: headers, body: body) end