@@ -9,7 +9,7 @@ import Foundation
99
1010extension PAPI {
1111 class EdgeFunctions : PAPISection {
12- static let pathEntry = " edge-functions "
12+ static let pathEntry = " live-plugins "
1313
1414 func latest( token: String , sourceId: String , completion: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
1515 guard var url = URL ( string: PAPIEndpoint) else { completion ( nil , nil , " Unable to create URL. " ) ; return }
@@ -27,47 +27,11 @@ extension PAPI {
2727 task. resume ( )
2828 }
2929
30- func disable( token: String , sourceId: String , completion: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
31- guard var url = URL ( string: PAPIEndpoint) else { completion ( nil , nil , " Unable to create URL. " ) ; return }
32-
33- url. appendPathComponent ( PAPI . Sources. pathEntry)
34- url. appendPathComponent ( sourceId)
35- url. appendPathComponent ( PAPI . EdgeFunctions. pathEntry)
36- url. appendPathComponent ( " disable " )
37-
38- var request = URLRequest ( url: url, cachePolicy: . reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 30 )
39- request. httpMethod = " PATCH "
40- request. addValue ( " Bearer \( token) " , forHTTPHeaderField: " Authorization " )
41- request. addValue ( " application/json " , forHTTPHeaderField: " Content-Type " )
42- request. httpBody = " { \" sourceId \" : \" \( sourceId) \" } " . data ( using: . utf8)
43-
44- let task = URLSession . shared. dataTask ( with: request, completionHandler: completion)
45- task. resume ( )
46- }
47-
48- func generateUploadURL( token: String , sourceId: String , completion: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
49- guard var url = URL ( string: PAPIEndpoint) else { completion ( nil , nil , " Unable to create URL. " ) ; return }
50-
51- url. appendPathComponent ( PAPI . Sources. pathEntry)
52- url. appendPathComponent ( sourceId)
53- url. appendPathComponent ( PAPI . EdgeFunctions. pathEntry)
54- url. appendPathComponent ( " upload-url " )
55-
56- var request = URLRequest ( url: url, cachePolicy: . reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 30 )
57- request. httpMethod = " POST "
58- request. addValue ( " Bearer \( token) " , forHTTPHeaderField: " Authorization " )
59- request. addValue ( " application/json " , forHTTPHeaderField: " Content-Type " )
60- request. httpBody = " { \" sourceId \" : \" \( sourceId) \" } " . data ( using: . utf8)
61-
62- let task = URLSession . shared. dataTask ( with: request, completionHandler: completion)
63- task. resume ( )
64- }
65-
6630 // http://blah.com/whatever/create?sourceId=1
67-
68- func createNewVersion( token: String , sourceId: String , uploadURL : URL ? , completion: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
31+
32+ func createNewVersion( token: String , sourceId: String , code : String , completion: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
6933 guard var url = URL ( string: PAPIEndpoint) else { completion ( nil , nil , " Unable to create URL. " ) ; return }
70- guard let uploadURL = uploadURL else { completion ( nil , nil , " Upload URL is invalid ." ) ; return }
34+ guard !code . isEmpty else { completion ( nil , nil , " Code cannot be empty ." ) ; return }
7135
7236 url. appendPathComponent ( PAPI . Sources. pathEntry)
7337 url. appendPathComponent ( sourceId)
@@ -77,19 +41,10 @@ extension PAPI {
7741 request. httpMethod = " POST "
7842 request. addValue ( " Bearer \( token) " , forHTTPHeaderField: " Authorization " )
7943 request. addValue ( " application/json " , forHTTPHeaderField: " Content-Type " )
80- request. httpBody = " { \" uploadURL \" : \" \( uploadURL . absoluteString ) \" , \" sourceId \" : \" \( sourceId) \" } " . data ( using: . utf8)
44+ request. httpBody = " { \" code \" : \" \( code ) \" , \" sourceId \" : \" \( sourceId) \" } " . data ( using: . utf8)
8145
8246 let task = URLSession . shared. dataTask ( with: request, completionHandler: completion)
8347 task. resume ( )
8448 }
85-
86- func uploadToGeneratedURL( token: String , url: URL ? , fileURL: URL ? , completion: @escaping ( Data ? , URLResponse ? , Error ? ) -> Void ) {
87- guard let url = url else { completion ( nil , nil , " URL is nil. " ) ; return }
88- guard let fileURL = fileURL else { completion ( nil , nil , " File URL is nil. " ) ; return }
89- var request = URLRequest ( url: url, cachePolicy: . reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 30 )
90- request. httpMethod = " PUT "
91- let task = URLSession . shared. uploadTask ( with: request, fromFile: fileURL, completionHandler: completion)
92- task. resume ( )
93- }
9449 }
9550}
0 commit comments