lib/folio_client/inventory.rb in folio_client-0.3.1 vs lib/folio_client/inventory.rb in folio_client-0.4.0

- old
+ new

@@ -21,7 +21,24 @@ # next lookup the instance given the instance_uuid so we can fetch the hrid result = client.get("/inventory/instances/#{instance_uuid}") result.dig("hrid") end + + # @param hrid [String] folio instance HRID + # @param status_id [String] uuid for an instance status code + # @raise [FolioClient::UnexpectedResponse::ResourceNotFound] if search by hrid returns 0 results + def has_instance_status?(hrid:, status_id:) + # get the instance record and its statusId + instance = client.get("/inventory/instances", {query: "hrid==#{hrid}"}) + raise FolioClient::UnexpectedResponse::ResourceNotFound, "No matching instance found for #{hrid}" if instance["totalRecords"] == 0 + + instance_status_id = instance.dig("instances", 0, "statusId") + + return false unless instance_status_id + + return true if instance_status_id == status_id + + false + end end end