Class: Codelocks::NetCode
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Class Method Summary collapse
-
.create(opts = {}) ⇒ Codelocks::NetCode::Response
Predefined method for generating a new NetCode.
Instance Method Summary collapse
-
#duration_id ⇒ Integer
NetCode duration ID.
-
#identifier ⇒ String
Return either a supplied identifier or the predefined access key.
-
#initialize(opts = {}) ⇒ NetCode
constructor
A new instance of NetCode.
- #method_missing(method, *args, &block) ⇒ Object
-
#start_date ⇒ String
String representing the start date in YYYY-MM-DD format.
-
#start_datetime ⇒ String
Full date time formatted for API use.
-
#start_time ⇒ String
String representing the start time.
-
#urm? ⇒ Boolean
Are URM codes enabled?.
Methods inherited from Model
Constructor Details
#initialize(opts = {}) ⇒ NetCode
Returns a new instance of NetCode.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/codelocks/net_code.rb', line 34 def initialize(opts = {}) self.opts = { lock_model: nil || "K3CONNECT", lock_id: nil, start: nil, duration: 0, urm: false, identifier: nil }.merge!(opts) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
45 46 47 48 |
# File 'lib/codelocks/net_code.rb', line 45 def method_missing(method, *args, &block) return opts[method] if opts.include?(method) super end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
32 33 34 |
# File 'lib/codelocks/net_code.rb', line 32 def opts @opts end |
Class Method Details
.create(opts = {}) ⇒ Codelocks::NetCode::Response
Predefined method for generating a new NetCode
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/codelocks/net_code.rb', line 15 def create(opts = {}) netcode = new(opts) if !netcode.identifier raise CodelocksError.new("Either a lock identifier or an access key must be provided") end client.requests.create("netcode/#{netcode.lock_id}", "id": netcode.lock_id, "start": netcode.start_datetime, "duration": netcode.duration_id, "lockmodel": netcode.lock_model, "identifier": netcode.identifier ) end |
Instance Method Details
#duration_id ⇒ Integer
NetCode duration ID
90 91 92 93 94 95 96 |
# File 'lib/codelocks/net_code.rb', line 90 def duration_id if urm? urm_duration else base_duration end end |
#identifier ⇒ String
Return either a supplied identifier or the predefined access key
54 55 56 |
# File 'lib/codelocks/net_code.rb', line 54 def identifier opts[:identifier] || client.access_key end |
#start_date ⇒ String
String representing the start date in YYYY-MM-DD format
62 63 64 |
# File 'lib/codelocks/net_code.rb', line 62 def start_date start.strftime("%Y-%m-%d") unless start.nil? end |
#start_datetime ⇒ String
Full date time formatted for API use
82 83 84 |
# File 'lib/codelocks/net_code.rb', line 82 def start_datetime [start_date, start_time].join(" ") end |
#start_time ⇒ String
String representing the start time. Hour has a leading zero
70 71 72 73 74 75 76 |
# File 'lib/codelocks/net_code.rb', line 70 def start_time if urm? && duration_id >= 31 # URM enabled and >= 24 hours duration "00:00" else start.strftime("%H:%M") unless start.nil? end end |
#urm? ⇒ Boolean
Are URM codes enabled?
102 103 104 |
# File 'lib/codelocks/net_code.rb', line 102 def urm? !!urm end |