Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeffutter/particle-elixir
An Elixir Client for the Particle Cloud API
https://github.com/jeffutter/particle-elixir
Last synced: 3 months ago
JSON representation
An Elixir Client for the Particle Cloud API
- Host: GitHub
- URL: https://github.com/jeffutter/particle-elixir
- Owner: jeffutter
- License: mit
- Created: 2016-08-09T20:59:15.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-05-29T15:55:35.000Z (over 5 years ago)
- Last Synced: 2024-11-01T09:34:54.341Z (3 months ago)
- Language: Elixir
- Size: 48.8 KB
- Stars: 6
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - An Elixir client for the Particle IoT platform's HTTP API. (Third Party APIs)
- fucking-awesome-elixir - particle - An Elixir client for the Particle IoT platform's HTTP API. (Third Party APIs)
- awesome-elixir - particle - An Elixir client for the Particle IoT platform's HTTP API. (Third Party APIs)
README
# Particle
[![Build Status](https://travis-ci.org/jeffutter/particle-elixir.svg?branch=master)](https://travis-ci.org/jeffutter/particle-elixir)
[![Hex.pm](https://img.shields.io/hexpm/v/particle.svg?maxAge=2592000)](https://hex.pm/packages/particle)
[![Inline docs](http://inch-ci.org/github/jeffutter/particle-elixir.svg)](http://inch-ci.org/github/jeffutter/particle-elixir)
[![Deps Status](https://beta.hexfaktor.org/badge/all/github/jeffutter/particle-elixir.svg)](https://beta.hexfaktor.org/github/jeffutter/particle-elixir)
[![License](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)Particle Cloud API Client for Elixir:
This is an unofficial client for the [Particle IoT platform's HTTP API](https://docs.particle.io/reference/api/).
## Usage
Installation
```elixir
def deps do
[{:particle, "~> 0.1.0"}]
end
```and run `mix deps.get`. Now, list the :particle application as your application dependency:
```elixir
def application do
[applications: [:particle]]
end
```## Configuration
You will need to set the following configuration variables in your `config/config.exs` file:
```elixir
use Mix.Configconfig :particle,
particle_key: System.get_env("PARTICLE_KEY")
```## Stream Usage
Create a module responsible for the handling of the events. Customize `handle_events` for your application.
```elixir
defmodule MyApp.ParticleEventHandler do
alias Experimental.GenStage
alias Particle.Streamuse GenStage
def start_link() do
GenStage.start_link(__MODULE__, :ok, name: __MODULE__)
enddef init(:ok) do
# Starts a permanent subscription to the broadcaster
# which will automatically start requesting items.
{:consumer, :ok, subscribe_to: [Stream]}
enddef handle_events(events, _from, state) do
IO.inspect events
{:noreply, [], state}
end
end
```Start the workers in the `Application`.
```elixir
defmodule MyApp do
use Application
alias Particle.Streamdef start(_type, _args) do
import Supervisor.Specchildren = [
worker(Particle.Stream, ["https://api.particle.io/v1/devices/events/status", Particle.Http, [name: Stream]]), # define url here
worker(MyApp.ParticleEventHandler, [])
]
opts = [strategy: :one_for_one, name: MyApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
```