-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathComponentsEndpoint.swift
More file actions
60 lines (48 loc) · 1.41 KB
/
ComponentsEndpoint.swift
File metadata and controls
60 lines (48 loc) · 1.41 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Foundation
#if os(Linux)
import FoundationNetworking
#endif
public struct ComponentsEndpoint: BaseEndpoint {
public typealias Content = [Component]
private let fileId: String
public init(fileId: String) {
self.fileId = fileId
}
func content(from root: ComponentsResponse) -> [Component] {
return root.meta.components
}
public func makeRequest(baseURL: URL) -> URLRequest {
let url = baseURL
.appendingPathComponent("files")
.appendingPathComponent(fileId)
.appendingPathComponent("components")
return URLRequest(url: url)
}
}
// MARK: - Response
struct ComponentsResponse: Codable {
let meta: Meta
}
struct Meta: Codable {
let components: [Component]
}
public struct Component: Codable {
public let key: String
public let nodeId: String
public let name: String
public let description: String?
public let containingFrame: ContainingFrame
public init(key: String, nodeId: String, name: String, description: String?, containingFrame: ContainingFrame) {
self.key = key
self.nodeId = nodeId
self.name = name
self.description = description
self.containingFrame = containingFrame
}
}
// MARK: - ContainingFrame
public struct ContainingFrame: Codable {
public let nodeID: String?
public let name: String?
public let pageName: String
}