{"_id":"55a6eabfcdb2971900df6d3a","__v":9,"category":{"_id":"55a6ea5516d20b1900ed8f53","pages":["55a6eabfcdb2971900df6d3a","55b23dda329f363900fbc937","55b23f277f5e073900ea81e0","55b23ff17f5e073900ea81e5","55b240a10e11590d008f7945"],"version":"55a47338e75ca60d00a39332","__v":5,"project":"55a47338e75ca60d00a3932f","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-15T23:18:45.872Z","from_sync":false,"order":3,"slug":"ruby-api","title":"Ruby API"},"user":"55a4f13d02b09d1900d00a9f","version":{"_id":"55a47338e75ca60d00a39332","project":"55a47338e75ca60d00a3932f","__v":8,"createdAt":"2015-07-14T02:26:00.724Z","releaseDate":"2015-07-14T02:26:00.724Z","categories":["55a47339e75ca60d00a39333","55a4fb7e1a5f991700a940f0","55a6702b80c8a30d00b32684","55a6703b80c8a30d00b32685","55a6ea5516d20b1900ed8f53","55b23ad2329f363900fbc92f","55b23b0a329f363900fbc932","55b2426a0e11590d008f7950"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"55a47338e75ca60d00a3932f","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-15T23:20:31.669Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"If you haven't read [Getting Started](/docs/getting-started), we'd suggest reading that first.\n\nWant to control your Lono with Ruby (or from your Rails app)? The easiest way is probably with our Lono gem!\n\nOur Gem\n---\nOur gem is at [rubygems.org/gems/lono-api](//rubygems.org/gems/lono-api). You can install it with `gem install lono-api`.\n\n\nSingle User Application Example\n---\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"require 'lono-api'\\n\\n# configure lono\\nLono.configure do |lono|\\n  lono.client_id = 'client id'\\n  lono.client_secret = 'client secret'\\n  lono.auth_token = 'auth token'\\n  lono.scope = ['write'] # or any other scopes\\nend\\n\\n# apply for an access token and get access to the device\\ntoken = Lono::SessionToken.fetch\\ndevice = Lono::Device.new 'device id', token\\n\\n# turn on a zone\\n# turn on the first zone\\ndevice.set_zone(0, true)\\n\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]\nMulti User Application Example\n---\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"require 'lono-api'\\n\\n# configure lono\\nLono.configure do |lono|\\n  lono.client_id = 'client id'\\n  lono.client_secret = 'client secret'\\n  lono.scope = ['write'] # or any other scopes\\nend\\n\\n# step one: redirect users here to sign in and give your app permission\\nauth_url = Lono::AuthUrl.fetch \\\"http://on_success_redirect_here.com\\\"\\n\\n# step two: once the OAuth2 callback is received, specify the token\\nLono.configure do |lono|\\n  lono.auth_token = 'auth token'\\nend\\n\\n# apply for an access token and get access to the device\\ntoken = Lono::SessionToken.fetch\\ndevice = Lono::Device.new 'device id', token\\n\\n# turn on a zone\\n# turn on the first zone\\ndevice.set_zone(0, true)\\n\",\n      \"language\": \"ruby\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"getting-started-ruby","type":"basic","title":"Getting Started in Ruby"}

Getting Started in Ruby


If you haven't read [Getting Started](/docs/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](//rubygems.org/gems/lono-api). You can install it with `gem install lono-api`. Single User Application Example --- [block:code] { "codes": [ { "code": "require 'lono-api'\n\n# configure lono\nLono.configure do |lono|\n lono.client_id = 'client id'\n lono.client_secret = 'client secret'\n lono.auth_token = 'auth token'\n lono.scope = ['write'] # or any other scopes\nend\n\n# apply for an access token and get access to the device\ntoken = Lono::SessionToken.fetch\ndevice = Lono::Device.new 'device id', token\n\n# turn on a zone\n# turn on the first zone\ndevice.set_zone(0, true)\n", "language": "ruby" } ] } [/block] Multi User Application Example --- [block:code] { "codes": [ { "code": "require 'lono-api'\n\n# configure lono\nLono.configure do |lono|\n lono.client_id = 'client id'\n lono.client_secret = 'client secret'\n lono.scope = ['write'] # or any other scopes\nend\n\n# step one: redirect users here to sign in and give your app permission\nauth_url = Lono::AuthUrl.fetch \"http://on_success_redirect_here.com\"\n\n# step two: once the OAuth2 callback is received, specify the token\nLono.configure do |lono|\n lono.auth_token = 'auth token'\nend\n\n# apply for an access token and get access to the device\ntoken = Lono::SessionToken.fetch\ndevice = Lono::Device.new 'device id', token\n\n# turn on a zone\n# turn on the first zone\ndevice.set_zone(0, true)\n", "language": "ruby" } ] } [/block]