Skip to content

Commit d47de1a

Browse files
committed
feat(gallagher/rest_api): update interface
1 parent 54cb043 commit d47de1a

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

drivers/gallagher/rest_api.cr

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ class Gallagher::RestAPI < PlaceOS::Driver
563563
doors.map { |d| Door.new(d.id, d.name) }
564564
end
565565

566+
@[Security(Level::Support)]
566567
def unlock(door_id : String) : Bool?
567568
response = post("#{@doors_endpoint}/#{door_id}/open", headers: @headers)
568569
response.success?
@@ -628,28 +629,67 @@ class Gallagher::RestAPI < PlaceOS::Driver
628629
# ==============================
629630
# Zone Access Security Interface
630631
# ==============================
631-
632+
633+
alias CardHolderDetails = PlaceOS::Driver::Interface::ZoneAccessSecurity::CardHolderDetails
634+
alias ZoneDetails = PlaceOS::Driver::Interface::ZoneAccessSecurity::ZoneDetails
635+
636+
struct CardHolder < CardHolderDetails
637+
def initialize(@id, @name, @email)
638+
end
639+
end
640+
641+
struct ZoneInfo < ZoneDetails
642+
def initialize(@id, @name, @description)
643+
end
644+
end
645+
632646
# using an email address, lookup the security system id for a user
647+
@[Security(Level::Support)]
633648
def card_holder_id_lookup(email : String) : String | Int64 | Nil
634649
query_cardholders(email, @unique_pdf_name).first?.try(&.id)
635650
end
636651

652+
# given a card holder id, lookup the details of the card holder
653+
def card_holder_lookup(id : String | Int64) : CardHolderDetails
654+
details = get_cardholder(id.to_s)
655+
first_name = details.first_name
656+
last_name = details.last_name
657+
short_name = details.short_name
658+
name = if first_name.presence && last_name.presence
659+
"#{first_name} #{last_name}"
660+
else
661+
short_name || ""
662+
end
663+
email_key = "@#{@unique_pdf_name}"
664+
CardHolder.new(id, name, details.json_unmapped[email_key]?.try(&.as_s))
665+
end
666+
637667
# using a name, lookup the access zone id
668+
@[Security(Level::Support)]
638669
def zone_access_id_lookup(name : String, exact_match : Bool = true) : String | Int64 | Nil
639670
get_access_groups(name, exact_match).first?.try(&.id)
640671
end
641672

673+
# given an access zone id, lookup the details of the zone
674+
def zone_access_lookup(id : String | Int64) : ZoneDetails
675+
details = get_access_group(id.to_s)
676+
ZoneInfo.new(id, details.name, details.description)
677+
end
678+
642679
# return the id that represents the access permission (truthy indicates access)
680+
@[Security(Level::Support)]
643681
def zone_access_member?(zone_id : String | Int64, card_holder_id : String | Int64) : String | Int64 | Nil
644682
access_group_member?(zone_id.to_s, card_holder_id.to_s)
645683
end
646684

647685
# add a member to the zone
686+
@[Security(Level::Support)]
648687
def zone_access_add_member(zone_id : String | Int64, card_holder_id : String | Int64, from_unix : Int64? = nil, until_unix : Int64? = nil)
649688
add_access_group_member(zone_id.to_s, card_holder_id.to_s, from_unix, until_unix)
650689
end
651690

652691
# remove a member from the zone
692+
@[Security(Level::Support)]
653693
def zone_access_remove_member(zone_id : String | Int64, card_holder_id : String | Int64)
654694
remove_access_group_member zone_id.to_s, card_holder_id.to_s
655695
end

shard.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ shards:
227227

228228
placeos-driver:
229229
git: https://github.com/placeos/driver.git
230-
version: 7.3.2
230+
version: 7.3.3
231231

232232
placeos-log-backend:
233233
git: https://github.com/place-labs/log-backend.git

0 commit comments

Comments
 (0)