@@ -35,8 +35,8 @@ struct PagerDutyAPI {
3535 struct Oncall : Codable { }
3636 }
3737
38- func isOnCall( ) async throws -> Bool {
39- let data = try await get ( " /oncalls " , [ " user_ids[] " : userID] )
38+ func isOnCall( _ apiKey : String ) async throws -> Bool {
39+ let data = try await get ( apiKey , " /oncalls " , [ " user_ids[] " : userID] )
4040 let decoder = JSONDecoder ( )
4141 decoder. keyDecodingStrategy = . convertFromSnakeCase
4242 let resp = try decoder. decode ( OncallsResp . self, from: data)
@@ -48,8 +48,8 @@ struct PagerDutyAPI {
4848 let incidents : Incidents
4949 }
5050
51- func getIncidents( ) async throws -> Incidents {
52- let data = try await get ( " /incidents " , [ " user_ids[] " : userID] )
51+ func getIncidents( _ apiKey : String ) async throws -> Incidents {
52+ let data = try await get ( apiKey , " /incidents " , [ " user_ids[] " : userID] )
5353 let decoder = JSONDecoder ( )
5454 decoder. keyDecodingStrategy = . convertFromSnakeCase
5555 decoder. dateDecodingStrategy = . iso8601
@@ -58,14 +58,14 @@ struct PagerDutyAPI {
5858 return resp. incidents
5959 }
6060
61- private func get( _ path: String , _ query: [ String : String ] = [ : ] ) async throws -> Data {
61+ private func get( _ apiKey : String , _ path: String , _ query: [ String : String ] = [ : ] ) async throws -> Data {
6262 var url = endpoint. appendingPathComponent ( path)
6363 url. append ( queryItems: query. map { key, val in URLQueryItem ( name: key, value: val) } )
6464
6565 var req = URLRequest ( url: url)
6666 req. setValue ( " application/json " , forHTTPHeaderField: " Accept " )
6767 req. setValue ( " application/json " , forHTTPHeaderField: " Content-Type " )
68- req. setValue ( " Token token= \( Vault . apiKey) " , forHTTPHeaderField: " Authorization " )
68+ req. setValue ( " Token token= \( apiKey) " , forHTTPHeaderField: " Authorization " )
6969
7070 let ( data, rawResp) = try await URLSession . shared. data ( for: req)
7171
0 commit comments