diff --git a/Sources/DragonService/DragonService.swift b/Sources/DragonService/DragonService.swift index 33ba5eb..7d10ee9 100644 --- a/Sources/DragonService/DragonService.swift +++ b/Sources/DragonService/DragonService.swift @@ -196,6 +196,29 @@ public class DragonService { } } + public class Perk: DragonService { + public override init() { + super.init() + } + + public func list(version: String, locale: String, completionHandler: @escaping (Perks) -> Void, errorHandler: @escaping(Error) -> Void) { + guard let response = fetchCdn(version: version, locale: locale, endpoint: DragonService.EndpointConstants.Perks.rawValue) else { + return + } + + response.responsePerks { response in + switch response.result { + case .success: + if let perks = response.result.value { + completionHandler(perks) + } + case .failure(let error): + errorHandler(error) + } + } + } + } + public class ProfileIcon: DragonService { public override init() { super.init() @@ -342,5 +365,6 @@ extension DragonService { case Masteries = "mastery.json" case Runes = "rune.json" case SummonerSpells = "summoner.json" + case Perks = "runesReforged.json" } } diff --git a/Sources/DragonService/Extensions/DataRequestExtensions.swift b/Sources/DragonService/Extensions/DataRequestExtensions.swift index 010fcfe..f90b11b 100644 --- a/Sources/DragonService/Extensions/DataRequestExtensions.swift +++ b/Sources/DragonService/Extensions/DataRequestExtensions.swift @@ -65,4 +65,9 @@ extension DataRequest { func responseChampions(queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse) -> Void) -> Self { return responseDecodable(queue: queue, completionHandler: completionHandler) } + + @discardableResult + func responsePerks(queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse) -> Void) -> Self { + return responseDecodable(queue: queue, completionHandler: completionHandler) + } } diff --git a/Sources/DragonService/Models/Perks.swift b/Sources/DragonService/Models/Perks.swift new file mode 100644 index 0000000..9bd1a1d --- /dev/null +++ b/Sources/DragonService/Models/Perks.swift @@ -0,0 +1,27 @@ +// +// Perks.swift +// dragon-service +// +// Created by James Glenn on 10/4/18. +// Copyright © 2018 James Glenn. All rights reserved. +// + +import Foundation + +public typealias Perks = [Perk] + +public struct Perk: Codable { + public let id: Int + public let key, icon, name: String + public let slots: [Slot] +} + +public struct Slot: Codable { + public let runes: [PerkRune] +} + +public struct PerkRune: Codable { + public let id: Int + public let key, icon, name, shortDesc: String + public let longDesc: String +} diff --git a/Tests/DragonService-Tests/DragonService-Tests.swift b/Tests/DragonService-Tests/DragonService-Tests.swift index 791268d..18de08f 100644 --- a/Tests/DragonService-Tests/DragonService-Tests.swift +++ b/Tests/DragonService-Tests/DragonService-Tests.swift @@ -329,6 +329,28 @@ final class dragon_serviceTests: XCTestCase { wait(for: expectations, timeout: 600) } + func testPerks() { + var expectations: [XCTestExpectation] = [] + for version in versions { + let expectation = XCTestExpectation(description: "Perks \(version)") + DragonService.Perk().list(version: version, locale: locale, completionHandler: { (perks) in + XCTAssertNotNil(perks) + expectation.fulfill() + }, errorHandler: { (error) in + if version.isVersion(lessThan: "7.22.1") { + XCTAssertNotNil(error) + } else { + print(version) + XCTAssertNil(error) + } + expectation.fulfill() + }) + expectations.append(expectation) + } + + wait(for: expectations, timeout: 600) + } + func testProfileIcons() { var expectations: [XCTestExpectation] = [] for version in versions { @@ -423,6 +445,7 @@ final class dragon_serviceTests: XCTestCase { ("testLanguages", testLanguages), ("testLanguages2", testLanguages2), ("testMasteries", testMasteries), + ("testPerks", testPerks), ("testProfileIcons", testProfileIcons), ("testRealms", testRealms), ("testRunes", testRunes),