module Devise::Models::Latcheable
Public Instance Methods
latch_enable()
click to toggle source
# File lib/devise_latcheable/model.rb, line 78 def latch_enable ::DeviseLatcheable.initialize if ::DeviseLatcheable.config.nil? if ::DeviseLatcheable.config['always_enabled'] == true self.latch_enabled = true end end
latch_enabled?()
click to toggle source
# File lib/devise_latcheable/model.rb, line 18 def latch_enabled? latch_enabled end
latch_pair!()
click to toggle source
> Pairs an user with the server.¶ ↑
If an error occurs, it copies the error at errors base so you can access it with model_instance.errors On success, it sets latch_account_id to the value that latch server sent on its response @returns true on success, false otherwise
# File lib/devise_latcheable/model.rb, line 64 def latch_pair! return true unless latch_enabled? ::DeviseLatcheable.initialize if ::DeviseLatcheable.api.nil? api_response = ::DeviseLatcheable.api.pair latch_pair_code if api_response.error.nil? self.latch_account_id = api_response.data['accountId'] return true else errors.add(:base, "Latch error: #{api_response.error.message}") return false end end
latch_unlocked?()
click to toggle source
> Checks if the app lock is open¶ ↑
@returns true if the latch is unlocked @returns false if the latch is locked or if there was an error
# File lib/devise_latcheable/model.rb, line 25 def latch_unlocked? return true unless latch_enabled? return false if latch_account_id.nil? ::DeviseLatcheable.initialize if ::DeviseLatcheable.api.nil? api_response = ::DeviseLatcheable.api.status latch_account_id if api_response.error.nil? key = api_response.data['operations'].keys.first status = api_response.data['operations'][key]['status'] return (status == 'on') else return false end end
latch_unpair!()
click to toggle source
> Removes the pairing from latch¶ ↑
If an error occurs, it copies the error at errors base so you can access it with model_instance.errors @returns true on success, false otherwise
# File lib/devise_latcheable/model.rb, line 44 def latch_unpair! return true unless latch_enabled? return true if latch_account_id.nil? ::DeviseLatcheable.initialize if ::DeviseLatcheable.api.nil? api_response = ::DeviseLatcheable.api.unpair latch_account_id if api_response.error.nil? return true else errors.add(:base, "Latch error: #{api_response.error.message}") return false end end