-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathGraphSchema.swift
43 lines (35 loc) · 1.04 KB
/
GraphSchema.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Foundation
import Prelude
// MARK: - Base Query Types
extension Never: CustomStringConvertible {
public var description: String {
fatalError()
}
}
public func decodeBase64(_ input: String) -> String? {
return Data(base64Encoded: input)
.flatMap { String(data: $0, encoding: .utf8) }
}
public func decompose(id: String) -> Int? {
return decodeBase64(id)
.flatMap { id -> Int? in
let pair = id.split(separator: "-", maxSplits: 1)
return pair.last.flatMap { Int($0) }
}
}
public func encodeToBase64(_ input: String) -> String {
return Data(input.utf8).base64EncodedString()
}
public struct GraphResponseError: Decodable {
public let message: String
}
public enum GraphError: Error {
case invalidInput
case invalidJson(responseString: String?)
case requestError(Error, URLResponse?)
case emptyResponse(URLResponse?)
case decodeError(GraphResponseError)
case jsonDecodingError(responseString: String?, error: Error?)
}
public typealias ServerFeature = GraphAPI.Feature
extension ServerFeature: Decodable {}