mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 20:54:51 +00:00
fixed giphy api call
This commit is contained in:
1 file changed
+11
-6
@@ -13,6 +13,7 @@ import Combine
|
|||||||
class GifHoarder: Hoarder, ObservableObject {
|
class GifHoarder: Hoarder, ObservableObject {
|
||||||
static let container: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
|
static let container: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.neon443.StickerSlack")!.appendingPathComponent("Library", conformingTo: .directory)
|
||||||
|
|
||||||
|
static var apiKey: String = ""
|
||||||
var endpoint: URL = URL(string: "https://api.giphy.com/v1/gifs/trending")!
|
var endpoint: URL = URL(string: "https://api.giphy.com/v1/gifs/trending")!
|
||||||
var endpointSearch: URL = URL(string: "https://api.giphy.com/v1/gifs/search")!
|
var endpointSearch: URL = URL(string: "https://api.giphy.com/v1/gifs/search")!
|
||||||
|
|
||||||
@@ -29,14 +30,18 @@ class GifHoarder: Hoarder, ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
var request = URLRequest(url: endpoint)
|
var components = URLComponents(url: endpoint, resolvingAgainstBaseURL: false)
|
||||||
request.setValue("", forHTTPHeaderField: "api_key")
|
components?.queryItems = [
|
||||||
request.setValue("100", forHTTPHeaderField: "limit")
|
URLQueryItem(name: "api_key", value: GifHoarder.apiKey),
|
||||||
|
URLQueryItem(name: "limit", value: "100")
|
||||||
|
]
|
||||||
Task {
|
Task {
|
||||||
do {
|
do {
|
||||||
async let (data, _) = try URLSession.shared.data(from: endpoint)
|
async let (data, _) = try URLSession.shared.data(from: components!.url!)
|
||||||
dump(await data)
|
dump(try await data)
|
||||||
print(await data.base64EncodedString())
|
print(try await data.base64EncodedString())
|
||||||
|
} catch {
|
||||||
|
print(error.localizedDescription)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||