-
Notifications
You must be signed in to change notification settings - Fork 0
/
Live.swift
103 lines (94 loc) · 3.8 KB
/
Live.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import Foundation
import BibleCore
import ComposableArchitecture
fileprivate let decoder = JSONDecoder()
extension BibleClient: DependencyKey {
public static let liveValue: BibleClient = Self(
translations: {
let (data, _) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/translations"
)!
)
return try decoder.decode([Translation].self, from: data)
},
translation: { id in
let (data, _) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/translations/\(id)"
)!
)
return try decoder.decode(Translation.self, from: data)
},
genres: {
let (data, error) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/genres"
)!
)
return try decoder.decode([Genre].self, from: data)
},
genre: { genre in
let (data, error) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/genres/\(genre)"
)!
)
return try decoder.decode(Genre.self, from: data)
},
books: {
let (data, error) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/books"
)!
)
return try decoder.decode([Book].self, from: data)
},
book: { id in
let (data, error) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/books/\(id)"
)!
)
return try decoder.decode(Book.self, from: data)
},
chapters: { book in
let (data, error) = try await URLSession.shared.data(
from: URL(
//https://bible-go-api.rkeplin.com/v1/books/1/chapters
string: "https://bible-go-api.rkeplin.com/v1/books/\(book)/chapters"
)!
)
return try decoder.decode([Chapter].self, from: data)
},
verses: { book, chapter in
let (data, error) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/books/\(book)/chapters/\(chapter)"
)!
)
return try decoder.decode([Verse].self, from: data)
},
verse: { book, chapter, verse in
let (data, error) = try await URLSession.shared.data(
from: URL(
string: "https://bible-go-api.rkeplin.com/v1/books/\(book)/chapters/\(chapter)/\(verse)"
)!
)
return try decoder.decode(Verse.self, from: data)
}
)
}
//extension BibleClient {
// public static var previewValue: BibleClient = Self(
// translations: <#@Sendable () async throws -> [Translation]#>,
// translation: <#@Sendable (TranslationID) async throws -> Translation#>,
// genres: <#@Sendable () async throws -> [Genre]#>,
// genre: <#@Sendable (GenreID) async throws -> Genre#>,
// books: <#@Sendable () async throws -> [Book]#>,
// book: <#@Sendable (BookID) async throws -> Book#>,
// chapters: <#@Sendable (BookID) async throws -> [Chapter]#>,
// verses: <#@Sendable (BookID, ChapterID) async throws -> [Verse]#>,
// verse: <#@Sendable (BookID, ChapterID, VerseID) async throws -> Verse#>
// )
//}