Skip to content

Commit ccf31c8

Browse files
committed
+ Language API
1 parent 93d4c78 commit ccf31c8

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

Example/Tests/Tests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,4 +663,22 @@ class Tests: XCTestCase {
663663
XCTAssertNil(err, "Something went wrong")
664664
}
665665
}
666+
667+
func testLanguage() {
668+
let asyncExpectation = expectationWithDescription("Fetch Language")
669+
PokemonKit.fetchLanguage("1")
670+
.then{ response -> Void in
671+
XCTAssertNotNil(response);
672+
print(response);
673+
asyncExpectation.fulfill();
674+
}.error{ err in
675+
XCTFail("Should not failed with \(err)")
676+
asyncExpectation.fulfill();
677+
678+
}
679+
680+
self.waitForExpectationsWithTimeout(30) { (err) -> Void in
681+
XCTAssertNil(err, "Something went wrong")
682+
}
683+
}
666684
}

Pod/Classes/PokemonKit.swift

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,37 @@ let baseURL: String = "http://pokeapi.co/api/v2"
1919

2020
// MARK: Classes
2121

22+
/*
23+
id The identifier for this language resource integer
24+
name The name for this language resource string
25+
official Whether or not the games are published in this language boolean
26+
iso639 The two-letter code of the country where this language is spoken. Note that it is not unique. string
27+
iso3166 The two-letter code of the language. Note that it is not unique. string
28+
names The name of this language listed in different languages list Name
29+
*/
30+
public class PKMLanguage: Mappable {
31+
public var id: Int?
32+
public var name: String?
33+
public var official: Bool?
34+
public var iso639: String?
35+
public var iso3166: String?
36+
public var names: [PKMName]?
37+
38+
required public init?(_ map: Map) {
39+
40+
}
41+
42+
public func mapping(map: Map) {
43+
id <- map["id"]
44+
name <- map["name"]
45+
official <- map["official"]
46+
iso639 <- map["iso639"]
47+
iso3166 <- map["iso3166"]
48+
names <- map["names"]
49+
}
50+
}
51+
52+
2253
/*
2354
slot The order the Pokémon's types are listed in integer
2455
pokemon The Pokémon that has the referenced type NamedAPIResource (Pokemon)
@@ -4007,6 +4038,38 @@ public func fetchType(typeId: String) -> Promise<PKMType>{
40074038
reject(response.result.error!)
40084039
}
40094040

4041+
}
4042+
}
4043+
}
4044+
4045+
//Language
4046+
4047+
public func fetchLanguages() -> Promise<PKMPagedObject> {
4048+
return Promise { fulfill, reject in
4049+
let URL = baseURL + "/language"
4050+
4051+
Alamofire.request(.GET, URL).responseObject() { (response: Response<PKMPagedObject, NSError>) in
4052+
if (response.result.isSuccess) {
4053+
fulfill(response.result.value!)
4054+
}else{
4055+
reject(response.result.error!)
4056+
}
4057+
}
4058+
}
4059+
}
4060+
4061+
public func fetchLanguage(languageId: String) -> Promise<PKMLanguage>{
4062+
return Promise { fulfill, reject in
4063+
let URL = baseURL + "/language/" + languageId
4064+
4065+
Alamofire.request(.GET, URL).responseObject() { (response: Response<PKMLanguage, NSError>) in
4066+
4067+
if (response.result.isSuccess) {
4068+
fulfill(response.result.value!)
4069+
}else{
4070+
reject(response.result.error!)
4071+
}
4072+
40104073
}
40114074
}
40124075
}

0 commit comments

Comments
 (0)