Skip to content

Commit

Permalink
Add haveUnchecked and haveValid keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshurst committed Apr 6, 2020
1 parent 1ea1de3 commit 28f50f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/Transmission/Models/Torrent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import Foundation

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

/// Initializes a torrent.
public init(
bytesUnchecked: Int64? = nil,
bytesValid: Int64? = nil,
dateAdded: Date? = nil,
downloadPath: String? = nil,
downloadRate: Int64? = nil,
Expand All @@ -54,6 +60,8 @@ public struct Torrent: Equatable {
uploaded: Int64? = nil,
uploadRate: Int64? = nil
) {
self.bytesUnchecked = bytesUnchecked
self.bytesValid = bytesValid
self.dateAdded = dateAdded
self.downloadPath = downloadPath
self.downloadRate = downloadRate
Expand Down Expand Up @@ -98,6 +106,10 @@ public extension Torrent {
public extension Torrent {
/// The keys used to request torrent properties.
enum PropertyKeys: String, CaseIterable {
/// Requests the key `haveUnchecked` from the API.
case bytesUnchecked = "haveUnchecked"
/// Requests the key `haveValid` from the API.
case bytesValid = "haveValid"
/// Requests the key `addedDate` from the API.
case dateAdded = "addedDate"
/// Requests the key `downloadDir` from the API.
Expand Down Expand Up @@ -141,6 +153,8 @@ extension Torrent {
dictionary[propertyKey.rawValue] as? Value
}

bytesUnchecked = decode(.bytesUnchecked)
bytesValid = decode(.bytesValid)
dateAdded = decode(.dateAdded).map(Date.init(timeIntervalSince1970:))
downloadPath = decode(.downloadPath)
downloadRate = decode(.downloadRate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class TorrentGetRequestsTests: IntegrationTestCase {
receiveValue: { torrents in
let torrent = torrents.first { $0.hash == TestConfig.torrent1Hash }
XCTAssertNotNil(torrent?.id)
XCTAssertNotNil(torrent?.bytesUnchecked)
XCTAssertNotNil(torrent?.bytesValid)
XCTAssertNotNil(torrent?.dateAdded)
XCTAssertNotNil(torrent?.downloadPath)
XCTAssertNotNil(torrent?.downloadRate)
Expand Down

0 comments on commit 28f50f2

Please sign in to comment.