Skip to content

Commit

Permalink
Merge pull request #2 from WxWatch/feature/runes-reforged
Browse files Browse the repository at this point in the history
Add Runes Reforged data
  • Loading branch information
WxWatch authored Oct 4, 2018
2 parents fbe56b1 + 7157158 commit cf613c6
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Sources/DragonService/DragonService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -342,5 +365,6 @@ extension DragonService {
case Masteries = "mastery.json"
case Runes = "rune.json"
case SummonerSpells = "summoner.json"
case Perks = "runesReforged.json"
}
}
5 changes: 5 additions & 0 deletions Sources/DragonService/Extensions/DataRequestExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ extension DataRequest {
func responseChampions(queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse<Champions>) -> Void) -> Self {
return responseDecodable(queue: queue, completionHandler: completionHandler)
}

@discardableResult
func responsePerks(queue: DispatchQueue? = nil, completionHandler: @escaping (DataResponse<Perks>) -> Void) -> Self {
return responseDecodable(queue: queue, completionHandler: completionHandler)
}
}
27 changes: 27 additions & 0 deletions Sources/DragonService/Models/Perks.swift
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions Tests/DragonService-Tests/DragonService-Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -423,6 +445,7 @@ final class dragon_serviceTests: XCTestCase {
("testLanguages", testLanguages),
("testLanguages2", testLanguages2),
("testMasteries", testMasteries),
("testPerks", testPerks),
("testProfileIcons", testProfileIcons),
("testRealms", testRealms),
("testRunes", testRunes),
Expand Down

0 comments on commit cf613c6

Please sign in to comment.