@@ -19,6 +19,211 @@ let baseURL: String = "http://pokeapi.co/api/v2"
1919
2020// MARK: Classes
2121
22+ /*
23+ slot The order the Pokémon's types are listed in integer
24+ pokemon The Pokémon that has the referenced type NamedAPIResource (Pokemon)
25+ */
26+ public class PKMTypePokemon : Mappable {
27+ public var slot : Int ?
28+ public var pokemon : PKMNamedAPIResource ?
29+
30+ required public init ? ( _ map: Map ) {
31+
32+ }
33+
34+ public func mapping( map: Map ) {
35+ slot <- map [ " slot " ]
36+ pokemon <- map [ " pokemon " ]
37+ }
38+ }
39+
40+
41+ /*
42+ no_damage_to A list of types this type has no effect on list NamedAPIResource (Type)
43+ half_damage_to A list of types this type is not very effect against list NamedAPIResource (Type)
44+ double_damage_to A list of types this type is very effect against list NamedAPIResource (Type)
45+ no_damage_from A list of types that have no effect on this type list NamedAPIResource (Type)
46+ half_damage_from A list of types that are not very effective against this type list NamedAPIResource (Type)
47+ double_damage_from A list of types that are very effective against this type list NamedAPIResource (Type)
48+ */
49+ public class PKMTypeRelations : Mappable {
50+ public var noDamageTo : [ PKMNamedAPIResource ] ?
51+ public var halfDamageTo : [ PKMNamedAPIResource ] ?
52+ public var doubleDamageTo : [ PKMNamedAPIResource ] ?
53+ public var noDamageFrom : [ PKMNamedAPIResource ] ?
54+ public var halfDamageFrom : [ PKMNamedAPIResource ] ?
55+ public var doubleDamageFrom : [ PKMNamedAPIResource ] ?
56+
57+ required public init ? ( _ map: Map ) {
58+
59+ }
60+
61+ public func mapping( map: Map ) {
62+ noDamageTo <- map [ " no_damage_to " ]
63+ halfDamageTo <- map [ " half_damage_to " ]
64+ doubleDamageTo <- map [ " double_damage_to " ]
65+ noDamageFrom <- map [ " no_damage_from " ]
66+ halfDamageFrom <- map [ " half_damage_from " ]
67+ doubleDamageFrom <- map [ " double_damage_from " ]
68+ }
69+ }
70+
71+
72+ /*
73+ id The identifier for this type resource integer
74+ name The name for this type resource string
75+ damage_relations A detail of how effective this type is toward others and vice versa TypeRelations
76+ game_indices A list of game indices relevent to this item by generation list GenerationGameIndex
77+ generation The generation this type was introduced in NamedAPIResource (Generation)
78+ move_damage_class The class of damage inflicted by this type NamedAPIResource (MoveDamageClass)
79+ names The name of this type listed in different languages list Name
80+ pokemon A list of details of Pokémon that have this type TypePokemon
81+ moves A list of moves that have this type list NamedAPIResource (Move)
82+ */
83+ public class PKMType : Mappable {
84+ public var id : Int ?
85+ public var name : String ?
86+ public var damageRelations : PKMTypeRelations ?
87+ public var gameIndices : [ PKMGenerationGameIndex ] ?
88+ public var generation : PKMNamedAPIResource ?
89+ public var moveDamageClass : PKMNamedAPIResource ?
90+ public var names : [ PKMName ] ?
91+ public var pokemon : [ PKMTypePokemon ] ?
92+ public var moves : [ PKMNamedAPIResource ] ?
93+
94+ required public init ? ( _ map: Map ) {
95+
96+ }
97+
98+ public func mapping( map: Map ) {
99+ id <- map [ " id " ]
100+ name <- map [ " name " ]
101+ damageRelations <- map [ " damage_relations " ]
102+ gameIndices <- map [ " game_indices " ]
103+ generation <- map [ " generation " ]
104+ moveDamageClass <- map [ " move_damage_class " ]
105+ names <- map [ " names " ]
106+ pokemon <- map [ " pokemon " ]
107+ moves <- map [ " moves " ]
108+ }
109+ }
110+
111+
112+ /*
113+ increase A list of natures and how they change the referenced stat list NatureStatAffect
114+ decrease A list of nature sand how they change the referenced stat list NatureStatAffect
115+ */
116+ public class PKMNatureStatAffectSets : Mappable {
117+ public var increase : [ PKMNatureStatAffect ] ?
118+ public var decrease : [ PKMNatureStatAffect ] ?
119+
120+ required public init ? ( _ map: Map ) {
121+
122+ }
123+
124+ public func mapping( map: Map ) {
125+ increase <- map [ " increase " ]
126+ decrease <- map [ " decrease " ]
127+ }
128+ }
129+
130+
131+ /*
132+ max_change The maximum amount of change to the referenced stat integer
133+ nature The nature causing the change NamedAPIResource (Nature)
134+ */
135+ public class PKMNatureStatAffect : Mappable {
136+ public var maxChange : Int ?
137+ public var nature : PKMNamedAPIResource ?
138+
139+ required public init ? ( _ map: Map ) {
140+
141+ }
142+
143+ public func mapping( map: Map ) {
144+ maxChange <- map [ " max_change " ]
145+ nature <- map [ " nature " ]
146+ }
147+ }
148+
149+ /*
150+ max_change The maximum amount of change to the referenced stat integer
151+ move The move causing the change NamedAPIResource (Move)
152+ */
153+ public class PKMMoveStatAffect : Mappable {
154+ public var maxChange : Int ?
155+ public var move : PKMNamedAPIResource ?
156+
157+ required public init ? ( _ map: Map ) {
158+
159+ }
160+
161+ public func mapping( map: Map ) {
162+ maxChange <- map [ " max_change " ]
163+ move <- map [ " move " ]
164+ }
165+ }
166+
167+
168+ /*
169+ increase A list of natures and how they change the referenced stat list NatureStatAffect
170+ decrease A list of nature sand how they change the referenced stat list NatureStatAffect
171+ */
172+ public class PKMMoveStatAffectSets : Mappable {
173+ public var increase : [ PKMMoveStatAffect ] ?
174+ public var decrease : [ PKMMoveStatAffect ] ?
175+
176+ required public init ? ( _ map: Map ) {
177+
178+ }
179+
180+ public func mapping( map: Map ) {
181+ increase <- map [ " increase " ]
182+ decrease <- map [ " decrease " ]
183+ }
184+ }
185+
186+
187+ /*
188+ id The identifier for this stat resource integer
189+ name The name for this stat resource string
190+ game_index ID the games use for this stat integer
191+ is_battle_only Whether this stat only exists within a battle boolean
192+ affecting_moves A detail of moves which affect this stat positively or negatively MoveStatAffectSets
193+ affecting_natures A detail of natures which affect this stat positively or negatively NatureStatAffectSets
194+ characteristics A list of characteristics that are set on a Pokémon when its highest base stat is this stat list APIResource (Characteristic)
195+ move_damage_class The class of damage this stat is directly related to NamedAPIResource (MoveDamageClass)
196+ names The name of this region listed in different languages list Name
197+ */
198+ public class PKMStat : Mappable {
199+ public var id : Int ?
200+ public var name : String ?
201+ public var gameIndex : Int ?
202+ public var isBattleOnly : Bool ?
203+ public var affectingMoves : PKMMoveStatAffectSets ?
204+ public var affectingNatures : PKMNatureStatAffectSets ?
205+ public var characteristics : [ PKMAPIResource ] ?
206+ public var moveDamageClass : PKMNamedAPIResource ?
207+ public var names : [ PKMName ] ?
208+
209+ required public init ? ( _ map: Map ) {
210+
211+ }
212+
213+ public func mapping( map: Map ) {
214+ id <- map [ " id " ]
215+ name <- map [ " name " ]
216+ gameIndex <- map [ " game_index " ]
217+ isBattleOnly <- map [ " is_battle_only " ]
218+ affectingMoves <- map [ " affecting_moves " ]
219+ affectingNatures <- map [ " affecting_natures " ]
220+ characteristics <- map [ " characteristics " ]
221+ moveDamageClass <- map [ " move_damage_class " ]
222+ names <- map [ " names " ]
223+ }
224+ }
225+
226+
22227/*
23228entry_number The index number within the Pokédex integer
24229name The Pokédex the referenced Pokémon species can be found in NamedAPIResource (Pokedex)
@@ -3738,6 +3943,70 @@ public func fetchPokemonSpecies(pokemonSpeciesId: String) -> Promise<PKMPokemonS
37383943 reject ( response. result. error!)
37393944 }
37403945
3946+ }
3947+ }
3948+ }
3949+
3950+ //Stat
3951+
3952+ public func fetchStats( ) -> Promise < PKMPagedObject > {
3953+ return Promise { fulfill, reject in
3954+ let URL = baseURL + " /stat "
3955+
3956+ Alamofire . request ( . GET, URL) . responseObject ( ) { ( response: Response < PKMPagedObject , NSError > ) in
3957+ if ( response. result. isSuccess) {
3958+ fulfill ( response. result. value!)
3959+ } else {
3960+ reject ( response. result. error!)
3961+ }
3962+ }
3963+ }
3964+ }
3965+
3966+ public func fetchStat( statId: String ) -> Promise < PKMStat > {
3967+ return Promise { fulfill, reject in
3968+ let URL = baseURL + " /stat/ " + statId
3969+
3970+ Alamofire . request ( . GET, URL) . responseObject ( ) { ( response: Response < PKMStat , NSError > ) in
3971+
3972+ if ( response. result. isSuccess) {
3973+ fulfill ( response. result. value!)
3974+ } else {
3975+ reject ( response. result. error!)
3976+ }
3977+
3978+ }
3979+ }
3980+ }
3981+
3982+ //Type
3983+
3984+ public func fetchType( ) -> Promise < PKMPagedObject > {
3985+ return Promise { fulfill, reject in
3986+ let URL = baseURL + " /type "
3987+
3988+ Alamofire . request ( . GET, URL) . responseObject ( ) { ( response: Response < PKMPagedObject , NSError > ) in
3989+ if ( response. result. isSuccess) {
3990+ fulfill ( response. result. value!)
3991+ } else {
3992+ reject ( response. result. error!)
3993+ }
3994+ }
3995+ }
3996+ }
3997+
3998+ public func fetchType( typeId: String ) -> Promise < PKMType > {
3999+ return Promise { fulfill, reject in
4000+ let URL = baseURL + " /type/ " + typeId
4001+
4002+ Alamofire . request ( . GET, URL) . responseObject ( ) { ( response: Response < PKMType , NSError > ) in
4003+
4004+ if ( response. result. isSuccess) {
4005+ fulfill ( response. result. value!)
4006+ } else {
4007+ reject ( response. result. error!)
4008+ }
4009+
37414010 }
37424011 }
37434012}
0 commit comments