25
25
//
26
26
27
27
import Foundation
28
- import Freddy
29
28
30
- struct Video : Codable , JSONDecodable , JSONEncodable {
29
+ struct Video : Codable {
31
30
32
31
let id : String
33
32
let title : String
@@ -49,50 +48,6 @@ struct Video: Codable, JSONDecodable, JSONEncodable {
49
48
return ( hours > 0 ? " \( hours) : " : " " ) + String( format: " %d:%02d " , minutes, seconds)
50
49
}
51
50
52
- // MARK: - JSONDecodable
53
-
54
- init ( json value: JSON ) throws {
55
- let nullable : JSON . SubscriptingOptions = [ . NullBecomesNil, . MissingKeyBecomesNil]
56
- id = try value. getString ( at: " id " )
57
- title = try value. getString ( at: " attributes " , " title " )
58
- subtitle = try value. getString ( at: " attributes " , " subtitle " , alongPath: nullable)
59
- description = try value. getString ( at: " attributes " , " description " , alongPath: nullable)
60
- length = try value. getInt ( at: " attributes " , " length " , or: 0 )
61
- youtube = try value. getString ( at: " attributes " , " embed-url " )
62
- source = try value. getString ( at: " attributes " , " video-url " , alongPath: nullable)
63
- cover = try value. getString ( at: " attributes " , " cover-url " )
64
- }
65
-
66
- // MARK: - JSONEncodable
67
-
68
- func toJSON( ) -> JSON {
69
- var attributes : [ String : JSON ] = [
70
- " title " : . string( title) ,
71
- " embed-url " : . string( youtube) ,
72
- " cover-url " : . string( cover) ,
73
- " length " : . int( length)
74
- ]
75
-
76
- if let source = source {
77
- attributes [ " video-url " ] = . string( source)
78
- }
79
-
80
- if let subtitle = subtitle {
81
- attributes [ " subtitle " ] = . string( subtitle)
82
- }
83
-
84
- if let description = description {
85
- attributes [ " description " ] = . string( description)
86
- }
87
-
88
- let json : [ String : JSON ] = [
89
- " id " : . string( id) ,
90
- " attributes " : . dictionary( attributes)
91
- ]
92
-
93
- return . dictionary( json)
94
- }
95
-
96
51
// MARK: - Codable
97
52
98
53
private enum CodingKeys : String , CodingKey {
0 commit comments