class LosantRest::Device

Class containing all the actions for the Device Resource

Public Class Methods

new(client) click to toggle source
# File lib/losant_rest/device.rb, line 30
def initialize(client)
  @client = client
end

Public Instance Methods

delete(params = {}) click to toggle source

Deletes a device

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.Organization, all.User, device.*, or device.delete.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 56
def delete(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  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/#{params[:deviceId]}"

  @client.request(
    method: :delete,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
export(params = {}) click to toggle source

Creates a device data export. Defaults to all data.

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, device.*, or device.export.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} start - Start time of export (ms since epoch - 0 means now, negative is relative to now)

  • {string} end - End time of export (ms since epoch - 0 means now, negative is relative to now)

  • {string} email - Email address to send export to. Defaults to current user's email.

  • {string} callbackUrl - Callback URL to call with export result

  • {string} includeBlobData - If set will export any blob attributes in base64 form, otherwise they will be downloadable links which will expire.

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 107
def export(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:start] = params[:start] if params.has_key?(:start)
  query_params[:end] = params[:end] if params.has_key?(:end)
  query_params[:email] = params[:email] if params.has_key?(:email)
  query_params[:callbackUrl] = params[:callbackUrl] if params.has_key?(:callbackUrl)
  query_params[:includeBlobData] = params[:includeBlobData] if params.has_key?(:includeBlobData)
  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/#{params[:deviceId]}/export"

  @client.request(
    method: :post,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
get(params = {}) click to toggle source

Retrieves information on a device

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.Device, all.Device.read, all.Organization, all.Organization.read, all.User, all.User.read, device.*, or device.get.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} excludeConnectionInfo - If set, do not return connection info

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 159
def get(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:excludeConnectionInfo] = params[:excludeConnectionInfo] if params.has_key?(:excludeConnectionInfo)
  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/#{params[:deviceId]}"

  @client.request(
    method: :get,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
get_command(params = {}) click to toggle source

Retrieve the last known commands(s) sent to the device

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.Device, all.Device.read, all.Organization, all.Organization.read, all.User, all.User.read, device.*, or device.getCommand.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} limit - Maximum number of command entries to return

  • {string} since - Look for command entries since this time (ms since epoch)

  • {string} sortDirection - Direction to sort the command entries (by time). Accepted values are: asc, desc

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 209
def get_command(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:limit] = params[:limit] if params.has_key?(:limit)
  query_params[:since] = params[:since] if params.has_key?(:since)
  query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection)
  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/#{params[:deviceId]}/command"

  @client.request(
    method: :get,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
get_composite_state(params = {}) click to toggle source

Retrieve the composite last complete state of the device

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.Device, all.Device.read, all.Organization, all.Organization.read, all.User, all.User.read, device.*, or device.getCompositeState.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} start - Start of time range to look at to build composite state

  • {string} end - End of time range to look at to build composite state

  • {string} attributes - Comma-separated list of attributes to include. When not provided, returns all attributes.

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 261
def get_composite_state(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:start] = params[:start] if params.has_key?(:start)
  query_params[:end] = params[:end] if params.has_key?(:end)
  query_params[:attributes] = params[:attributes] if params.has_key?(:attributes)
  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/#{params[:deviceId]}/compositeState"

  @client.request(
    method: :get,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
get_log_entries(params = {}) click to toggle source

Retrieve the recent log entries about the device

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.Device, all.Device.read, all.Organization, all.Organization.read, all.User, all.User.read, device.*, or device.getLogEntries.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} limit - Maximum number of log entries to return

  • {string} since - Look for log entries since this time (ms since epoch)

  • {string} sortDirection - Direction to sort the log entries (by time). Accepted values are: asc, desc

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 313
def get_log_entries(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:limit] = params[:limit] if params.has_key?(:limit)
  query_params[:since] = params[:since] if params.has_key?(:since)
  query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection)
  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/#{params[:deviceId]}/logs"

  @client.request(
    method: :get,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
get_state(params = {}) click to toggle source

Retrieve the last known state(s) of the device

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.Device, all.Device.read, all.Organization, all.Organization.read, all.User, all.User.read, device.*, or device.getState.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} limit - Maximum number of state entries to return

  • {string} since - Look for state entries since this time (ms since epoch)

  • {string} sortDirection - Direction to sort the state entries (by time). Accepted values are: asc, desc

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 365
def get_state(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:limit] = params[:limit] if params.has_key?(:limit)
  query_params[:since] = params[:since] if params.has_key?(:since)
  query_params[:sortDirection] = params[:sortDirection] if params.has_key?(:sortDirection)
  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/#{params[:deviceId]}/state"

  @client.request(
    method: :get,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
patch(params = {}) click to toggle source

Updates information about a device

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.Organization, all.User, device.*, or device.patch.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {hash} device - Object containing new properties of the device (api.losant.com/#/definitions/devicePatch)

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 415
def patch(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)
  raise ArgumentError.new("device is required") unless params.has_key?(:device)

  body = params[:device] if params.has_key?(:device)
  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/#{params[:deviceId]}"

  @client.request(
    method: :patch,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
payload_counts(params = {}) click to toggle source

Returns payload counts for the time range specified for this device

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, device.*, or device.payloadCounts.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} start - Start of range for payload count query (ms since epoch)

  • {string} end - End of range for payload count query (ms since epoch)

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 465
def payload_counts(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:start] = params[:start] if params.has_key?(:start)
  query_params[:end] = params[:end] if params.has_key?(:end)
  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/#{params[:deviceId]}/payloadCounts"

  @client.request(
    method: :get,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
remove_data(params = {}) click to toggle source

Removes all device data for the specified time range. Defaults to all data.

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.Organization, all.User, device.*, or device.removeData.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {string} start - Start time of export (ms since epoch - 0 means now, negative is relative to now)

  • {string} end - End time of export (ms since epoch - 0 means now, negative is relative to now)

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 515
def remove_data(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)

  query_params[:start] = params[:start] if params.has_key?(:start)
  query_params[:end] = params[:end] if params.has_key?(:end)
  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/#{params[:deviceId]}/data"

  @client.request(
    method: :delete,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
send_command(params = {}) click to toggle source

Send a command to a device

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.Device, all.Organization, all.User, device.*, or device.sendCommand.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {hash} deviceCommand - Command to send to the device (api.losant.com/#/definitions/deviceCommand)

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 564
def send_command(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)
  raise ArgumentError.new("deviceCommand is required") unless params.has_key?(:deviceCommand)

  body = params[:deviceCommand] if params.has_key?(:deviceCommand)
  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/#{params[:deviceId]}/command"

  @client.request(
    method: :post,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
send_state(params = {}) click to toggle source

Send the current state of the device

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.Device, all.Organization, all.User, device.*, or device.sendState.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {hash} deviceState - A single device state object, or an array of device state objects (api.losant.com/#/definitions/deviceStateOrStates)

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 613
def send_state(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)
  raise ArgumentError.new("deviceState is required") unless params.has_key?(:deviceState)

  body = params[:deviceState] if params.has_key?(:deviceState)
  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/#{params[:deviceId]}/state"

  @client.request(
    method: :post,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end
set_connection_status(params = {}) click to toggle source

Set the current connection status of the device

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.Device, all.Organization, all.User, device.*, or device.setConnectionStatus.

Parameters:

  • {string} applicationId - ID associated with the application

  • {string} deviceId - ID associated with the device

  • {hash} connectionStatus - The current connection status of the device (api.losant.com/#/definitions/deviceConnectionStatus)

  • {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:

Errors:

# File lib/losant_rest/device.rb, line 662
def set_connection_status(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)
  raise ArgumentError.new("deviceId is required") unless params.has_key?(:deviceId)
  raise ArgumentError.new("connectionStatus is required") unless params.has_key?(:connectionStatus)

  body = params[:connectionStatus] if params.has_key?(:connectionStatus)
  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/#{params[:deviceId]}/setConnectionStatus"

  @client.request(
    method: :post,
    path: path,
    query: query_params,
    headers: headers,
    body: body)
end