Lockitron Community

Ruby on Rails gem


I have created a virtual lock and am trying to integrate it into a Ruby on Rails application. Using the lockitron-ruby gem (which I understand is outdated). I’m having trouble locking and unlocking the lock from the application. While in rails console I can change the status but the (local) server must be restarted before the change is recognized.

When viewing the lock - I can select a button to lock (or unlock: not copied in here) which runs the lock_the_lock from that particular Lock instance. Sorry if the following is confusing. Basically, I want to be able to change the lock status from within an application. Thanks!

class RoomLock < ActiveRecord::Base

require 'Lockitron’
attr_accessible :lid, :name, :status, :token

 def setup_lock
   client_id = "sample_83283hkjnd_numbers"
   client_secret = "4168a863620e116nope_sample_data5c20d13a8ab9e9356"
   redirect_uri = "https://lockitron.com"
   access_token = "e92ebb8_sample_cb7564c61bdbc807_data_eee"

   client = OAuth2::Client.new(client_id, client_secret, :site => "https://api.lockitron.com/v1")

   # Due to a bug in OAuth2, you'll need to run the next line as well:
   client.options[:token_url] = "/v1/oauth/token"

   # Here it actually gets the token.
   self.token = client.auth_code.get_token(code, :redirect_uri => redirect_uri)   
 def lock_the_lock   
   Lockitron::Locks.access_token = "e92ebb869_my_access_token_bdbc807abee9e2789ee"

I can update the lock status which can be viewed via the url link that returns the status. However, I cannot retrieve the updated lock/lock status from within the application without restarting the server



We’ll take a look at this. The V2 API is nearly ready but we still need to bring up documentation. The OAuth flow should be a bit simpler.



Are you still having this issue?