-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This endpoint is not officially documented and was reverse-engineered from the raider.io website.
- Loading branch information
Showing
13 changed files
with
307 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
### Added | ||
|
||
* Added search endpoint. | ||
* Make slug types equatable with their rawValue. | ||
|
||
### Fixed | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Class.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
public struct Class { | ||
|
||
public let id: Int | ||
public let name: String | ||
public let slug: String | ||
|
||
} | ||
|
||
// MARK: - Decodable | ||
|
||
extension Class: Decodable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Race.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
public struct Race { | ||
|
||
public let id: Int | ||
public let name: String | ||
public let slug: String | ||
public let faction: Faction | ||
|
||
} | ||
|
||
// MARK: - Decodable | ||
|
||
extension Race: Decodable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// CharacterSearchResult.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
public struct CharacterSearchResult { | ||
|
||
public let id: Int | ||
public let name: String | ||
public let faction: Faction | ||
public let region: Region | ||
public let realm: Realm | ||
public let `class`: Class | ||
|
||
} | ||
|
||
// MARK: - Decodable | ||
|
||
extension CharacterSearchResult: Decodable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// GuildSearchResult.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
public struct GuildSearchResult { | ||
|
||
public let id: Int | ||
public let name: String | ||
public let faction: Faction | ||
public let realm: Realm | ||
public let region: Region | ||
public let path: String | ||
|
||
} | ||
|
||
// MARK: - Decodable | ||
|
||
extension GuildSearchResult: Decodable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// RaideRIO+Search.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
extension RaiderIO { | ||
|
||
private struct SearchResponse: Decodable { | ||
|
||
public let matches: [SearchResult] | ||
|
||
} | ||
|
||
private static let searchUrl = URL(string: "https://raider.io/api/search")! | ||
|
||
public func search(for term: String) async throws -> [SearchResult] { | ||
guard var urlComponents = URLComponents(url: RaiderIO.searchUrl, resolvingAgainstBaseURL: true) else { | ||
throw Errors.invalidUrlParameters | ||
} | ||
urlComponents.queryItems = [ | ||
URLQueryItem(name: "term", value: term) | ||
] | ||
|
||
guard let url = urlComponents.url else { | ||
throw Errors.invalidUrlParameters | ||
} | ||
|
||
let response: SearchResponse = try await request(url: url) | ||
return response.matches | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// SearchResult.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
public struct SearchResult { | ||
|
||
public enum ResultType: String { | ||
|
||
case character | ||
case guild | ||
case team | ||
|
||
} | ||
|
||
public enum ResultData { | ||
|
||
case character(CharacterSearchResult) | ||
case guild(GuildSearchResult) | ||
case team(TeamSearchResult) | ||
|
||
} | ||
|
||
public let type: ResultType | ||
public let name: String | ||
public let data: ResultData | ||
|
||
} | ||
|
||
// MARK: - Decodable | ||
|
||
extension SearchResult: Decodable { | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
|
||
case type | ||
case name | ||
case data | ||
|
||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
|
||
type = try container.decode(ResultType.self, forKey: .type) | ||
name = try container.decode(String.self, forKey: .name) | ||
|
||
switch type { | ||
case .character: | ||
let result = try container.decode(CharacterSearchResult.self, forKey: .data) | ||
data = .character(result) | ||
case .guild: | ||
let result = try container.decode(GuildSearchResult.self, forKey: .data) | ||
data = .guild(result) | ||
case .team: | ||
let result = try container.decode(TeamSearchResult.self, forKey: .data) | ||
data = .team(result) | ||
} | ||
} | ||
|
||
} | ||
extension SearchResult.ResultType: Decodable {} | ||
extension SearchResult.ResultData: Decodable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// TeamSearchResult.swift | ||
// RaiderIO | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
|
||
|
||
public struct TeamSearchResult { | ||
|
||
public let keystonePlatoonId: Int? | ||
public let charterId: Int | ||
public let platoonId: Int? | ||
public let name: String | ||
public let slug: String | ||
public let faction: Faction | ||
public let region: Region | ||
public let subRegion: Region? | ||
public let path: String | ||
|
||
} | ||
|
||
// MARK: - Decodable | ||
|
||
extension TeamSearchResult: Decodable { | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
|
||
case keystonePlatoonId = "keystone_platoon_id" | ||
case charterId = "charter_id" | ||
case platoonId = "platoon_id" | ||
case name | ||
case slug | ||
case faction | ||
case region | ||
case subRegion | ||
case path | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// SearchTests.swift | ||
// RaiderIOTests | ||
// | ||
// Created by Sören Gade on 10.03.22. | ||
// | ||
|
||
|
||
import Foundation | ||
import XCTest | ||
@testable import RaiderIO | ||
|
||
|
||
final class SearchTests: XCTestCase { | ||
|
||
var client: RaiderIO! | ||
|
||
override func setUp() { | ||
client = RaiderIO(urlSession: .shared) | ||
} | ||
|
||
func testSearchForCharacter() async throws { | ||
do { | ||
let results = try await client.search(for: "Kiaro") | ||
|
||
let expectedResult = results.first(where: { | ||
if case .character(let character) = $0.data { | ||
return character.region.slug == .eu && character.realm.name == "Frostwolf" && character.name == "Kiaro" | ||
} | ||
return false | ||
}) | ||
|
||
XCTAssertNotNil(expectedResult) | ||
} catch { | ||
print(error) | ||
throw error | ||
} | ||
} | ||
|
||
} |