-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interface/guest_building_access): standardise guest access
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "json" | ||
|
||
abstract class PlaceOS::Driver | ||
module Interface::GuestBuildingAccess | ||
# use inheritance to provide additional details as required to revoke access | ||
abstract class AccessDetails | ||
include JSON::Serializable | ||
include JSON::Serializable::Unmapped | ||
|
||
property card_hex : String | ||
end | ||
|
||
# a function for granting guests access to a building | ||
# should return a payload that can be encoded into a QR code | ||
# the response is expected to be hexstring | ||
abstract def grant_guest_access(email : String, from : Int64, until : Int64) : AccessDetails | ||
|
||
# revoke access to a building | ||
def revoke_guest_access(access : AccessDetails) : Nil | ||
access_json = access.to_json | ||
details = {{ parse_type("::PlaceOS::Driver::Interface::GuestBuildingAccess::AccessDetails").resolve.subclasses.first }}.from_json(access_json) | ||
revoke_access details | ||
end | ||
|
||
# where details is an instance of your AccessDetails subclass | ||
abstract protected def revoke_access(details) | ||
end | ||
end |