diff --git a/filcnaplo/lib/api/client.dart b/filcnaplo/lib/api/client.dart index b4b19d0..42638e9 100644 --- a/filcnaplo/lib/api/client.dart +++ b/filcnaplo/lib/api/client.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:filcnaplo/models/config.dart'; import 'package:filcnaplo/models/news.dart'; import 'package:filcnaplo/models/release.dart'; +import 'package:filcnaplo/models/supporter.dart'; import 'package:filcnaplo_kreta_api/models/school.dart'; import 'package:http/http.dart' as http; @@ -10,6 +11,7 @@ class FilcAPI { static const SCHOOL_LIST = "https://filcnaplo.hu/v2/school_list.json"; static const CONFIG = "https://filcnaplo.hu/v2/config.json"; static const NEWS = "https://filcnaplo.hu/v2/news.json"; + static const SUPPORTERS = "https://filcnaplo.hu/v2/supporters.json"; static const REPO = "filc/naplo"; static const RELEASES = "https://api.github.com/repos/$REPO/releases"; @@ -55,6 +57,20 @@ class FilcAPI { } } + static Future getSupporters() async { + try { + http.Response res = await http.get(Uri.parse(SUPPORTERS)); + + if (res.statusCode == 200) { + return Supporters.fromJson(jsonDecode(res.body)); + } else { + throw "HTTP ${res.statusCode}: ${res.body}"; + } + } catch (error) { + print("ERROR: FilcAPI.getSupporters: $error"); + } + } + static Future?> getReleases() async { try { http.Response res = await http.get(Uri.parse(RELEASES)); diff --git a/filcnaplo/lib/models/supporter.dart b/filcnaplo/lib/models/supporter.dart new file mode 100644 index 0000000..20e1cdc --- /dev/null +++ b/filcnaplo/lib/models/supporter.dart @@ -0,0 +1,38 @@ +class Supporter { + String name; + String amount; + String platform; + + Supporter(this.name, this.amount, this.platform); + + factory Supporter.fromJson(Map json) { + return Supporter( + json["name"] ?? "", + json["amount"] ?? "", + json["platform"] ?? "", + ); + } +} + +class Supporters { + List top; + List all; + int progress; + int max; + + Supporters({ + required this.top, + required this.all, + required this.progress, + required this.max, + }); + + factory Supporters.fromJson(Map json) { + return Supporters( + max: (json["progress"] ?? {})["max"] ?? 1, + progress: (json["progress"] ?? {})["value"] ?? 0, + all: ((json["all"] ?? []) as List).cast().map((e) => Supporter.fromJson(e)).toList(), + top: ((json["top"] ?? []) as List).cast().map((e) => Supporter.fromJson(e)).toList(), + ); + } +}