Skip to content

Commit 20ec68f

Browse files
committed
-- spacing
1 parent a8fe030 commit 20ec68f

29 files changed

+1997
-1996
lines changed

.DS_Store

0 Bytes
Binary file not shown.

Sources/ipinfoKit/API/API.swift

+46-46
Original file line numberDiff line numberDiff line change
@@ -11,58 +11,58 @@ import Foundation
1111
// MARK: - Service.Router
1212

1313
extension Service {
14-
enum Router {
15-
case geoLocation(ipAddress: String)
16-
case ASN(asn: String)
17-
case batch(withFilter: Bool)
18-
}
14+
enum Router {
15+
case geoLocation(ipAddress: String)
16+
case ASN(asn: String)
17+
case batch(withFilter: Bool)
18+
}
1919
}
2020

2121
extension Service.Router {
22-
var endPoint: String {
23-
switch self {
24-
case .geoLocation(let ipAddress):
25-
"\(Service.shared.ipInfoURL)/\(ipAddress)/json"
26-
case .ASN(let asn):
27-
"\(Service.shared.ipInfoURL)/\(asn)/json"
28-
case .batch(let withFilter):
29-
"\(Service.shared.ipInfoURL)/batch" + (withFilter ? "&filter=1" : "")
30-
}
31-
}
22+
var endPoint: String {
23+
switch self {
24+
case .geoLocation(let ipAddress):
25+
"\(Service.shared.ipInfoURL)/\(ipAddress)/json"
26+
case .ASN(let asn):
27+
"\(Service.shared.ipInfoURL)/\(asn)/json"
28+
case .batch(let withFilter):
29+
"\(Service.shared.ipInfoURL)/batch" + (withFilter ? "&filter=1" : "")
30+
}
31+
}
3232
}
3333

3434
// MARK: - Service
3535

3636
class Service {
37-
38-
// MARK: Lifecycle
39-
40-
private init() { }
41-
42-
// MARK: Internal
43-
44-
static let shared = Service()
45-
46-
var ipInfoURL = "https://ipinfo.io"
47-
let headers: HTTPHeaders = [
48-
"Authorization": "Bearer \(Constants.ACCESS_TOKEN)",
49-
]
50-
51-
func requestAPI(
52-
URL: Service.Router,
53-
method: HTTPMethod,
54-
params: Parameters? = nil,
55-
completion: @escaping (_ status: Response,_ data: Data,_ msg: String) -> Void) {
56-
57-
AF.request(URL.endPoint , method: method, parameters: params , encoding: JSONEncoding.default, headers: headers)
58-
.response { response in
59-
switch response.result {
60-
case .success(let value):
61-
completion(.success, value ?? Data(), "Success")
62-
case .failure(let err):
63-
completion(.failure, Data(), err.localizedDescription)
64-
break
65-
}
66-
}
67-
}
37+
38+
// MARK: Lifecycle
39+
40+
private init() { }
41+
42+
// MARK: Internal
43+
44+
static let shared = Service()
45+
46+
var ipInfoURL = "https://ipinfo.io"
47+
let headers: HTTPHeaders = [
48+
"Authorization": "Bearer \(Constants.ACCESS_TOKEN)",
49+
]
50+
51+
func requestAPI(
52+
URL: Service.Router,
53+
method: HTTPMethod,
54+
params: Parameters? = nil,
55+
completion: @escaping (_ status: Response,_ data: Data,_ msg: String) -> Void) {
56+
57+
AF.request(URL.endPoint , method: method, parameters: params , encoding: JSONEncoding.default, headers: headers)
58+
.response { response in
59+
switch response.result {
60+
case .success(let value):
61+
completion(.success, value ?? Data(), "Success")
62+
case .failure(let err):
63+
completion(.failure, Data(), err.localizedDescription)
64+
break
65+
}
66+
}
67+
}
6868
}

Sources/ipinfoKit/ASN/ASN.swift

+29-29
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,33 @@ import Foundation
99

1010
// Extension for IPINFO class
1111
extension IPINFO {
12-
13-
// Function to get ASN details
14-
public func getASNDetails(asn: String, completion: @escaping (_ status: Response,_ data: ASNResponse?,_ msg: String?) -> Void) {
15-
16-
// Check if ASN details are cached
17-
if CachingManager.shared.getASNDataFromCache()[asn] == nil {
18-
19-
// If not cached, make API request to fetch ASN details
20-
Service.shared.requestAPI(URL: .ASN(asn: asn), method: .get) { status, data, msg in
21-
switch status {
22-
case .success:
23-
// If API request is successful, cache the response and save to local storage
24-
do {
25-
let response = try JSONDecoder().decode(ASNResponse.self, from: data)
26-
CachingManager.shared.saveASNResult([asn:response])
27-
completion(.success, response, nil)
28-
} catch {
29-
completion(.failure, nil, error.localizedDescription)
30-
}
31-
case .failure:
32-
// If API request fails, return failure status and empty data
33-
completion(.failure, nil, msg)
34-
}
35-
}
36-
} else {
37-
// If ASN details are already cached, return cached data
38-
completion(.success, CachingManager.shared.getASNDataFromCache()[asn], "Success")
39-
}
40-
}
12+
13+
// Function to get ASN details
14+
public func getASNDetails(asn: String, completion: @escaping (_ status: Response,_ data: ASNResponse?,_ msg: String?) -> Void) {
15+
16+
// Check if ASN details are cached
17+
if CachingManager.shared.getASNDataFromCache()[asn] == nil {
18+
19+
// If not cached, make API request to fetch ASN details
20+
Service.shared.requestAPI(URL: .ASN(asn: asn), method: .get) { status, data, msg in
21+
switch status {
22+
case .success:
23+
// If API request is successful, cache the response and save to local storage
24+
do {
25+
let response = try JSONDecoder().decode(ASNResponse.self, from: data)
26+
CachingManager.shared.saveASNResult([asn:response])
27+
completion(.success, response, nil)
28+
} catch {
29+
completion(.failure, nil, error.localizedDescription)
30+
}
31+
case .failure:
32+
// If API request fails, return failure status and empty data
33+
completion(.failure, nil, msg)
34+
}
35+
}
36+
} else {
37+
// If ASN details are already cached, return cached data
38+
completion(.success, CachingManager.shared.getASNDataFromCache()[asn], "Success")
39+
}
40+
}
4141
}

0 commit comments

Comments
 (0)