-
Notifications
You must be signed in to change notification settings - Fork 1
/
WPWordEnvelope.swift
64 lines (54 loc) 路 1.62 KB
/
WPWordEnvelope.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// WordEnvelope.swift
// Boilerplate
//
// Created by JohnP on 4/7/17.
// Copyright 漏 2017 JohnP. All rights reserved.
//
import Foundation
import Argo
import Curry
import Runes
public struct WordEnvelope {
public let words: [Word]
public let urls: UrlsEnvelope
public let stats: StatsEnvelope
public struct UrlsEnvelope {
public let api: ApiEnvelope
public struct ApiEnvelope {
public let moreWords: String
public init(more_words: String) {
moreWords = more_words
}
}
}
public struct StatsEnvelope {
public let count: Int
}
}
extension WordEnvelope: Decodable {
public static func decode(_ json: JSON) -> Decoded<WordEnvelope> {
return curry(WordEnvelope.init)
<^> json <|| "words"
<*> json <| "urls"
<*> json <| "stats"
}
}
extension WordEnvelope.UrlsEnvelope: Decodable {
public static func decode(_ json: JSON) -> Decoded<WordEnvelope.UrlsEnvelope> {
return curry(WordEnvelope.UrlsEnvelope.init)
<^> json <| "api"
}
}
extension WordEnvelope.UrlsEnvelope.ApiEnvelope: Decodable {
public static func decode(_ json: JSON) -> Decoded<WordEnvelope.UrlsEnvelope.ApiEnvelope> {
return curry(WordEnvelope.UrlsEnvelope.ApiEnvelope.init)
<^> json <| "more_words"
}
}
extension WordEnvelope.StatsEnvelope: Decodable {
public static func decode(_ json: JSON) -> Decoded<WordEnvelope.StatsEnvelope> {
return curry(WordEnvelope.StatsEnvelope.init)
<^> json <| "count"
}
}