2022-08-29 20:38:28 -06:00
|
|
|
import 'package:wonders/logic/common/http_client.dart';
|
|
|
|
import 'package:wonders/logic/data/artifact_data.dart';
|
|
|
|
|
2023-10-03 14:15:36 -06:00
|
|
|
class ArtifactAPIService {
|
2022-08-29 20:38:28 -06:00
|
|
|
final String _baseMETUrl = 'https://collectionapi.metmuseum.org/public/collection/v1';
|
2023-10-03 14:15:36 -06:00
|
|
|
final String _baseSelfHostedUrl = 'https://www.wonderous.info/met';
|
2022-08-29 20:38:28 -06:00
|
|
|
|
2023-10-03 14:15:36 -06:00
|
|
|
Future<ServiceResult<ArtifactData?>> getMetObjectByID(String id) async {
|
2022-08-29 20:38:28 -06:00
|
|
|
HttpResponse? response = await HttpClient.send('$_baseMETUrl/objects/$id');
|
|
|
|
return ServiceResult<ArtifactData?>(response, _parseArtifactData);
|
|
|
|
}
|
|
|
|
|
2023-10-03 14:15:36 -06:00
|
|
|
Future<ServiceResult<ArtifactData?>> getSelfHostedObjectByID(String id) async {
|
|
|
|
HttpResponse? response = await HttpClient.send('$_baseSelfHostedUrl/$id.json');
|
|
|
|
return ServiceResult<ArtifactData?>(response, _parseArtifactData);
|
|
|
|
}
|
|
|
|
|
2022-08-29 20:38:28 -06:00
|
|
|
ArtifactData? _parseArtifactData(Map<String, dynamic> content) {
|
|
|
|
// Source: https://metmuseum.github.io/
|
|
|
|
return ArtifactData(
|
|
|
|
objectId: content['objectID'].toString(),
|
|
|
|
title: content['title'] ?? '',
|
|
|
|
image: content['primaryImage'] ?? '',
|
|
|
|
date: content['objectDate'] ?? '',
|
|
|
|
objectType: content['objectName'] ?? '',
|
|
|
|
period: content['period'] ?? '',
|
|
|
|
country: content['country'] ?? '',
|
|
|
|
medium: content['medium'] ?? '',
|
|
|
|
dimension: content['dimension'] ?? '',
|
|
|
|
classification: content['classification'] ?? '',
|
|
|
|
culture: content['culture'] ?? '',
|
|
|
|
objectBeginYear: content['objectBeginDate'],
|
|
|
|
objectEndYear: content['objectEndDate'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|