Skip to content

Commit 28f50f2

Browse files
committed
Add haveUnchecked and haveValid keys
1 parent 1ea1de3 commit 28f50f2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Sources/Transmission/Models/Torrent.swift

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Foundation
22

33
/// A Transmission torrent.
44
public struct Torrent: Equatable {
5+
/// The number of bytes of partial pieces.
6+
public var bytesUnchecked: Int64?
7+
/// The number of bytes of checksum verified data.
8+
public var bytesValid: Int64?
59
/// The date the torrent was added to the server.
610
public var dateAdded: Date?
711
/// The file path where the torrent data is being downloaded to.
@@ -37,6 +41,8 @@ public struct Torrent: Equatable {
3741

3842
/// Initializes a torrent.
3943
public init(
44+
bytesUnchecked: Int64? = nil,
45+
bytesValid: Int64? = nil,
4046
dateAdded: Date? = nil,
4147
downloadPath: String? = nil,
4248
downloadRate: Int64? = nil,
@@ -54,6 +60,8 @@ public struct Torrent: Equatable {
5460
uploaded: Int64? = nil,
5561
uploadRate: Int64? = nil
5662
) {
63+
self.bytesUnchecked = bytesUnchecked
64+
self.bytesValid = bytesValid
5765
self.dateAdded = dateAdded
5866
self.downloadPath = downloadPath
5967
self.downloadRate = downloadRate
@@ -98,6 +106,10 @@ public extension Torrent {
98106
public extension Torrent {
99107
/// The keys used to request torrent properties.
100108
enum PropertyKeys: String, CaseIterable {
109+
/// Requests the key `haveUnchecked` from the API.
110+
case bytesUnchecked = "haveUnchecked"
111+
/// Requests the key `haveValid` from the API.
112+
case bytesValid = "haveValid"
101113
/// Requests the key `addedDate` from the API.
102114
case dateAdded = "addedDate"
103115
/// Requests the key `downloadDir` from the API.
@@ -141,6 +153,8 @@ extension Torrent {
141153
dictionary[propertyKey.rawValue] as? Value
142154
}
143155

156+
bytesUnchecked = decode(.bytesUnchecked)
157+
bytesValid = decode(.bytesValid)
144158
dateAdded = decode(.dateAdded).map(Date.init(timeIntervalSince1970:))
145159
downloadPath = decode(.downloadPath)
146160
downloadRate = decode(.downloadRate)

Tests/TransmissionIntegrationTests/TorrentGetRequestsTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ class TorrentGetRequestsTests: IntegrationTestCase {
1919
receiveValue: { torrents in
2020
let torrent = torrents.first { $0.hash == TestConfig.torrent1Hash }
2121
XCTAssertNotNil(torrent?.id)
22+
XCTAssertNotNil(torrent?.bytesUnchecked)
23+
XCTAssertNotNil(torrent?.bytesValid)
2224
XCTAssertNotNil(torrent?.dateAdded)
2325
XCTAssertNotNil(torrent?.downloadPath)
2426
XCTAssertNotNil(torrent?.downloadRate)

0 commit comments

Comments
 (0)