If you haven't read Getting Started, we'd suggest reading that first.

Want to control your Lono with Ruby (or from your Rails app)? The easiest way is probably with our Lono gem!

Our Gem

Our gem is at rubygems.org/gems/lono-api. You can install it with gem install lono-api.

Single User Application Example

require 'lono-api'

# configure lono
Lono.configure do |lono|
  lono.client_id = 'client id'
  lono.client_secret = 'client secret'
  lono.auth_token = 'auth token'
  lono.scope = ['write'] # or any other scopes
end

# apply for an access token and get access to the device
token = Lono::SessionToken.fetch
device = Lono::Device.new 'device id', token

# turn on a zone
# turn on the first zone
device.set_zone(0, true)

Multi User Application Example

require 'lono-api'

# configure lono
Lono.configure do |lono|
  lono.client_id = 'client id'
  lono.client_secret = 'client secret'
  lono.scope = ['write'] # or any other scopes
end

# step one: redirect users here to sign in and give your app permission
auth_url = Lono::AuthUrl.fetch "http://on_success_redirect_here.com"

# step two: once the OAuth2 callback is received, specify the token
Lono.configure do |lono|
  lono.auth_token = 'auth token'
end

# apply for an access token and get access to the device
token = Lono::SessionToken.fetch
device = Lono::Device.new 'device id', token

# turn on a zone
# turn on the first zone
device.set_zone(0, true)