Start developping the catalog
This commit is contained in:
		
							
								
								
									
										33
									
								
								lib/api/third_party/chartmuseum.dart
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								lib/api/third_party/chartmuseum.dart
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
import 'dart:async';
 | 
			
		||||
import 'dart:convert';
 | 
			
		||||
 | 
			
		||||
import 'package:dio/dio.dart';
 | 
			
		||||
 | 
			
		||||
class HelmChart {
 | 
			
		||||
  final String name;
 | 
			
		||||
  final String version;
 | 
			
		||||
 | 
			
		||||
  const HelmChart({
 | 
			
		||||
    required this.name,
 | 
			
		||||
    required this.version,
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Future<List<HelmChart>> fetchCharts() async {
 | 
			
		||||
  final dio = Dio();
 | 
			
		||||
  final response = await dio.get('https://helm.badhouseplants.net/api/charts',
 | 
			
		||||
      options: Options(headers: {
 | 
			
		||||
        "Accept": "application/json",
 | 
			
		||||
      }));
 | 
			
		||||
  if (response.statusCode == 200) {
 | 
			
		||||
    final Map<dynamic, dynamic> charsRaw = json.decode(response.data);
 | 
			
		||||
 | 
			
		||||
    List<HelmChart> charts = [];
 | 
			
		||||
    charsRaw.forEach((key, value) {
 | 
			
		||||
      charts.add(HelmChart(name: key, version: value.first["version"]));
 | 
			
		||||
    });
 | 
			
		||||
    return charts;
 | 
			
		||||
  } else {
 | 
			
		||||
    throw Exception('Failed to load album');
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user