Skip to content

Commit acb929b

Browse files
agwoosignalagordn52
authored andcommitted
Merged in feature/WFA-8-api-data (pull request #9)
Feature/WFA-8 api data Approved-by: Anthony Gordon <ants52@aol.com>
2 parents e7a68b9 + 2fb770c commit acb929b

File tree

5 files changed

+589
-0
lines changed

5 files changed

+589
-0
lines changed

lib/models/response/api_data.dart

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// To parse this JSON data, do
2+
//
3+
// final apiData = apiDataFromJson(jsonString);
4+
5+
import 'dart:convert';
6+
7+
List<ApiData> apiDataFromJson(String str) =>
8+
List<ApiData>.from(json.decode(str).map((x) => ApiData.fromJson(x)));
9+
10+
String apiDataToJson(List<ApiData> data) =>
11+
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
12+
13+
class ApiData {
14+
ApiData({
15+
this.slug,
16+
this.description,
17+
this.links,
18+
});
19+
20+
String slug;
21+
String description;
22+
Links links;
23+
24+
factory ApiData.fromJson(Map<String, dynamic> json) => ApiData(
25+
slug: json["slug"],
26+
description: json["description"],
27+
links: Links.fromJson(json["_links"]),
28+
);
29+
30+
Map<String, dynamic> toJson() => {
31+
"slug": slug,
32+
"description": description,
33+
"_links": links.toJson(),
34+
};
35+
}
36+
37+
class Links {
38+
Links({
39+
this.self,
40+
this.collection,
41+
});
42+
43+
List<Collection> self;
44+
List<Collection> collection;
45+
46+
factory Links.fromJson(Map<String, dynamic> json) => Links(
47+
self: List<Collection>.from(
48+
json["self"].map((x) => Collection.fromJson(x))),
49+
collection: List<Collection>.from(
50+
json["collection"].map((x) => Collection.fromJson(x))),
51+
);
52+
53+
Map<String, dynamic> toJson() => {
54+
"self": List<dynamic>.from(self.map((x) => x.toJson())),
55+
"collection": List<dynamic>.from(collection.map((x) => x.toJson())),
56+
};
57+
}
58+
59+
class Collection {
60+
Collection({
61+
this.href,
62+
});
63+
64+
String href;
65+
66+
factory Collection.fromJson(Map<String, dynamic> json) => Collection(
67+
href: json["href"],
68+
);
69+
70+
Map<String, dynamic> toJson() => {
71+
"href": href,
72+
};
73+
}

lib/models/response/continent.dart

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// To parse this JSON data, do
2+
//
3+
// final continents = continentsFromJson(jsonString);
4+
5+
import 'dart:convert';
6+
7+
List<Continents> continentsFromJson(String str) =>
8+
List<Continents>.from(json.decode(str).map((x) => Continents.fromJson(x)));
9+
10+
String continentsToJson(List<Continents> data) =>
11+
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
12+
13+
class Continents {
14+
Continents({
15+
this.code,
16+
this.name,
17+
this.countries,
18+
this.links,
19+
});
20+
21+
String code;
22+
String name;
23+
List<Country> countries;
24+
Links links;
25+
26+
factory Continents.fromJson(Map<String, dynamic> json) => Continents(
27+
code: json["code"],
28+
name: json["name"],
29+
countries: List<Country>.from(
30+
json["countries"].map((x) => Country.fromJson(x))),
31+
links: Links.fromJson(json["_links"]),
32+
);
33+
34+
Map<String, dynamic> toJson() => {
35+
"code": code,
36+
"name": name,
37+
"countries": List<dynamic>.from(countries.map((x) => x.toJson())),
38+
"_links": links.toJson(),
39+
};
40+
}
41+
42+
class Country {
43+
Country({
44+
this.code,
45+
this.name,
46+
this.states,
47+
this.currencyCode,
48+
this.currencyPos,
49+
this.decimalSep,
50+
this.dimensionUnit,
51+
this.numDecimals,
52+
this.thousandSep,
53+
this.weightUnit,
54+
});
55+
56+
String code;
57+
String name;
58+
List<State> states;
59+
String currencyCode;
60+
CurrencyPos currencyPos;
61+
Sep decimalSep;
62+
DimensionUnit dimensionUnit;
63+
int numDecimals;
64+
Sep thousandSep;
65+
WeightUnit weightUnit;
66+
67+
factory Country.fromJson(Map<String, dynamic> json) => Country(
68+
code: json["code"],
69+
name: json["name"],
70+
states: List<State>.from(json["states"].map((x) => State.fromJson(x))),
71+
currencyCode:
72+
json["currency_code"] == null ? null : json["currency_code"],
73+
currencyPos: json["currency_pos"] == null
74+
? null
75+
: currencyPosValues.map[json["currency_pos"]],
76+
decimalSep: json["decimal_sep"] == null
77+
? null
78+
: sepValues.map[json["decimal_sep"]],
79+
dimensionUnit: json["dimension_unit"] == null
80+
? null
81+
: dimensionUnitValues.map[json["dimension_unit"]],
82+
numDecimals: json["num_decimals"] == null ? null : json["num_decimals"],
83+
thousandSep: json["thousand_sep"] == null
84+
? null
85+
: sepValues.map[json["thousand_sep"]],
86+
weightUnit: json["weight_unit"] == null
87+
? null
88+
: weightUnitValues.map[json["weight_unit"]],
89+
);
90+
91+
Map<String, dynamic> toJson() => {
92+
"code": code,
93+
"name": name,
94+
"states": List<dynamic>.from(states.map((x) => x.toJson())),
95+
"currency_code": currencyCode == null ? null : currencyCode,
96+
"currency_pos":
97+
currencyPos == null ? null : currencyPosValues.reverse[currencyPos],
98+
"decimal_sep":
99+
decimalSep == null ? null : sepValues.reverse[decimalSep],
100+
"dimension_unit": dimensionUnit == null
101+
? null
102+
: dimensionUnitValues.reverse[dimensionUnit],
103+
"num_decimals": numDecimals == null ? null : numDecimals,
104+
"thousand_sep":
105+
thousandSep == null ? null : sepValues.reverse[thousandSep],
106+
"weight_unit":
107+
weightUnit == null ? null : weightUnitValues.reverse[weightUnit],
108+
};
109+
}
110+
111+
enum CurrencyPos { LEFT, LEFT_SPACE, RIGHT, RIGHT_SPACE }
112+
113+
final currencyPosValues = EnumValues({
114+
"left": CurrencyPos.LEFT,
115+
"left_space": CurrencyPos.LEFT_SPACE,
116+
"right": CurrencyPos.RIGHT,
117+
"right_space": CurrencyPos.RIGHT_SPACE
118+
});
119+
120+
enum Sep { EMPTY, SEP, PURPLE }
121+
122+
final sepValues = EnumValues({".": Sep.EMPTY, " ": Sep.PURPLE, ",": Sep.SEP});
123+
124+
enum DimensionUnit { CM, IN }
125+
126+
final dimensionUnitValues =
127+
EnumValues({"cm": DimensionUnit.CM, "in": DimensionUnit.IN});
128+
129+
class State {
130+
State({
131+
this.code,
132+
this.name,
133+
});
134+
135+
String code;
136+
String name;
137+
138+
factory State.fromJson(Map<String, dynamic> json) => State(
139+
code: json["code"],
140+
name: json["name"],
141+
);
142+
143+
Map<String, dynamic> toJson() => {
144+
"code": code,
145+
"name": name,
146+
};
147+
}
148+
149+
enum WeightUnit { KG, OZ }
150+
151+
final weightUnitValues = EnumValues({"kg": WeightUnit.KG, "oz": WeightUnit.OZ});
152+
153+
class Links {
154+
Links({
155+
this.self,
156+
this.collection,
157+
});
158+
159+
List<Collection> self;
160+
List<Collection> collection;
161+
162+
factory Links.fromJson(Map<String, dynamic> json) => Links(
163+
self: List<Collection>.from(
164+
json["self"].map((x) => Collection.fromJson(x))),
165+
collection: List<Collection>.from(
166+
json["collection"].map((x) => Collection.fromJson(x))),
167+
);
168+
169+
Map<String, dynamic> toJson() => {
170+
"self": List<dynamic>.from(self.map((x) => x.toJson())),
171+
"collection": List<dynamic>.from(collection.map((x) => x.toJson())),
172+
};
173+
}
174+
175+
class Collection {
176+
Collection({
177+
this.href,
178+
});
179+
180+
String href;
181+
182+
factory Collection.fromJson(Map<String, dynamic> json) => Collection(
183+
href: json["href"],
184+
);
185+
186+
Map<String, dynamic> toJson() => {
187+
"href": href,
188+
};
189+
}
190+
191+
class EnumValues<T> {
192+
Map<String, T> map;
193+
Map<T, String> reverseMap;
194+
195+
EnumValues(this.map);
196+
197+
Map<T, String> get reverse {
198+
if (reverseMap == null) {
199+
reverseMap = map.map((k, v) => new MapEntry(v, k));
200+
}
201+
return reverseMap;
202+
}
203+
}

lib/models/response/countries.dart

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// To parse this JSON data, do
2+
//
3+
// final countries = countriesFromJson(jsonString);
4+
5+
import 'dart:convert';
6+
7+
List<Countries> countriesFromJson(String str) =>
8+
List<Countries>.from(json.decode(str).map((x) => Countries.fromJson(x)));
9+
10+
String countriesToJson(List<Countries> data) =>
11+
json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
12+
13+
class Countries {
14+
Countries({
15+
this.code,
16+
this.name,
17+
this.states,
18+
this.links,
19+
});
20+
21+
String code;
22+
String name;
23+
List<State> states;
24+
Links links;
25+
26+
factory Countries.fromJson(Map<String, dynamic> json) => Countries(
27+
code: json["code"],
28+
name: json["name"],
29+
states: List<State>.from(json["states"].map((x) => State.fromJson(x))),
30+
links: Links.fromJson(json["_links"]),
31+
);
32+
33+
Map<String, dynamic> toJson() => {
34+
"code": code,
35+
"name": name,
36+
"states": List<dynamic>.from(states.map((x) => x.toJson())),
37+
"_links": links.toJson(),
38+
};
39+
}
40+
41+
class Links {
42+
Links({
43+
this.self,
44+
this.collection,
45+
});
46+
47+
List<Collection> self;
48+
List<Collection> collection;
49+
50+
factory Links.fromJson(Map<String, dynamic> json) => Links(
51+
self: List<Collection>.from(
52+
json["self"].map((x) => Collection.fromJson(x))),
53+
collection: List<Collection>.from(
54+
json["collection"].map((x) => Collection.fromJson(x))),
55+
);
56+
57+
Map<String, dynamic> toJson() => {
58+
"self": List<dynamic>.from(self.map((x) => x.toJson())),
59+
"collection": List<dynamic>.from(collection.map((x) => x.toJson())),
60+
};
61+
}
62+
63+
class Collection {
64+
Collection({
65+
this.href,
66+
});
67+
68+
String href;
69+
70+
factory Collection.fromJson(Map<String, dynamic> json) => Collection(
71+
href: json["href"],
72+
);
73+
74+
Map<String, dynamic> toJson() => {
75+
"href": href,
76+
};
77+
}
78+
79+
class State {
80+
State({
81+
this.code,
82+
this.name,
83+
});
84+
85+
String code;
86+
String name;
87+
88+
factory State.fromJson(Map<String, dynamic> json) => State(
89+
code: json["code"],
90+
name: json["name"],
91+
);
92+
93+
Map<String, dynamic> toJson() => {
94+
"code": code,
95+
"name": name,
96+
};
97+
}

0 commit comments

Comments
 (0)