defmodule ExParticle do use Application def start do import Supervisor.Spec, warn: false children = [ worker(ExParticle.Events.Listener, []), worker(ExParticle.Events.Handler, []) ] # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: ExParticle.Supervisor] Supervisor.start_link(children, opts) end @moduledoc """ Provides access to the Particle Cloud API. """ @doc """ List devices the currently authenticated user has access to. ## Example iex> ExParticle.devices [%ExParticle.Model.Device{connected: true, id: "device_id", last_app: nil, last_heard: "2015-12-28T22:58:35.066Z", last_ip_address: "192.168.11.10", name: "my_iot", product_id: 6, status: "normal"}] """ defdelegate devices, to: ExParticle.API.Devices, as: :devices @doc """ Get basic information about the given device, including the custom variables and functions it has exposed. Params: * device_id ## Example iex> ExParticle.device_info("decice_id") %ExParticle.Model.DeviceInfo{ cc3000_patch_version: "wl0: Nov 7 2014 16:03:45 version 5.90.230.12 FWID 01-212234f8", connected: false, functions: nil, id: "decice_id", last_heard: nil, name: "my_iot", product_id: 6, status: "normal", variables: nil} """ defdelegate device_info(device_id), to: ExParticle.API.Devices, as: :device_info @doc """ Generate a device claim code that allows the device to be successfully claimed to a user's account during the SoftAP setup process. ## Example iex> ExParticle.create_claims %{claim_code: "i31YZ5bRq9Z9xxX+YgGO6rY+DDJn6CzFpNA02wiBF9SvIgYbW3QtIhgnYVAt0Ow", device_ids: ["device_id"]} """ defdelegate create_claims, to: ExParticle.API.Devices, as: :create_claims @doc """ Request the current value of a variable exposed by the device. Params: * device_id * var_name ## Example: iex> ExParticle.device_vars("device_id", "analogvalue") %{cmd: "VarReturn", coreInfo: %{connected: true, deviceID: "device_id", last_app: "", last_handshake_at: "2015-12-29T20:16:03.762Z", last_heard: "2015-12-29T20:16:33.010Z", product_id: 6}, name: "analogvalue", result: 0} """ defdelegate device_vars(device_id, var_name), to: ExParticle.API.Devices, as: :device_vars @doc """ Claim a new or unclaimed device to your account. Params: * device_id Example: iex(1)> ExParticle.claim_device("423o54o56664356243455t6") %{connected: true, id: "423o54o56664356243455t6", ok: true, user_id: "56630100e5a6cbe63b0000c6"} """ defdelegate claim_device(device_id), to: ExParticle.API.Devices, as: :claim_device @doc """ Request device transfer from another user. Params: * device_id ## Example: iex(1)> ExParticle.request_transfer("device_id") %{connected: true, id: "device_id", ok: true, user_id: "56630100e5a6cbe63b0000c6"} """ defdelegate request_transfer(device_id), to: ExParticle.API.Devices, as: :request_transfer @doc """ Call a function exposed by the device, with arguments passed in the request body. Params: * device_id * function_name * args * format ## Example: iex> ExParticle.call_function("device_id", "function_name", "args") %{connected: true, id: "device_id", last_app: "", return_value: 1} """ defdelegate call_function(device_id, function, args), to: ExParticle.API.Devices, as: :call_function @doc """ Events will start listening on all the events generated by the device Params * function ## Example iex> ExParticle.events( fn(event) -> IO.inspect(event) end ) :ok %ExParticle.Model.SseEvent{coreid: "423o54o56664356243455t6", data: "19.600000", name: "temperature", published_at: "2016-03-14T10:40:38.065Z", ttl: "60"} %ExParticle.Model.SseEvent{coreid: "423o54o56664356243455t6", data: "48.900000", name: "humidity", published_at: "2016-03-14T10:40:40.065Z", ttl: "60"} """ defdelegate events(function), to: ExParticle.Events.Handler, as: :events end