Class: Codelocks::NetCode
- Inherits:
-
Object
- Object
- Codelocks::NetCode
- Defined in:
- lib/codelocks/net_code.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Class Method Summary collapse
-
.generate_netcode(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?.
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
.generate_netcode(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 generate_netcode(opts = {}) netcode = new(opts) if !netcode.identifier raise CodelocksError.new("Either a lock identifier or an access key must be provided") end Request.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 |
# File 'lib/codelocks/net_code.rb', line 90 def duration_id base_duration + urm_offset 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] || Codelocks.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") 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") end end |
#urm? ⇒ Boolean
Are URM codes enabled?
98 99 100 |
# File 'lib/codelocks/net_code.rb', line 98 def urm? !!urm end |