summaryrefslogtreecommitdiff
path: root/DomainDig/IPGeolocationService.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-03-18 11:59:38 -0500
committerChristian Cleberg <[email protected]>2026-03-18 11:59:38 -0500
commit376e7b55b4a0c4f54faa0c2828dea4fd17dff288 (patch)
tree540d11ad423f14975553f2490617e05aea61ae2c /DomainDig/IPGeolocationService.swift
parente11b7d29a6aa9e52f63fcb35ee7ed9127850fffe (diff)
downloaddomain-dig-376e7b55b4a0c4f54faa0c2828dea4fd17dff288.tar.gz
domain-dig-376e7b55b4a0c4f54faa0c2828dea4fd17dff288.tar.bz2
domain-dig-376e7b55b4a0c4f54faa0c2828dea4fd17dff288.zip
realigning commits
Diffstat (limited to 'DomainDig/IPGeolocationService.swift')
-rw-r--r--DomainDig/IPGeolocationService.swift17
1 files changed, 17 insertions, 0 deletions
diff --git a/DomainDig/IPGeolocationService.swift b/DomainDig/IPGeolocationService.swift
new file mode 100644
index 0000000..6c60295
--- /dev/null
+++ b/DomainDig/IPGeolocationService.swift
@@ -0,0 +1,17 @@
+import Foundation
+
+struct IPGeolocationService {
+ static func lookup(ip: String) async throws -> IPGeolocation {
+ let url = URL(string: "https://ipapi.co/\(ip)/json/")!
+ let request = URLRequest(url: url, timeoutInterval: 10)
+
+ let (data, response) = try await URLSession.shared.data(for: request)
+
+ guard let httpResponse = response as? HTTPURLResponse,
+ httpResponse.statusCode == 200 else {
+ throw URLError(.badServerResponse)
+ }
+
+ return try JSONDecoder().decode(IPGeolocation.self, from: data)
+ }
+}