Implement BenchmarkService with generateReport and pollUpdates methods

This commit introduces the `BenchmarkService` class, which encapsulates API calls related to benchmarking operations. The class includes two methods:

1. `generateReport`: Takes a `ReportRequestBody` object as input and performs a POST request to the `/reports` URL, serializing the object to JSON format.
2. `pollUpdates`: Accepts a UNIX UTC timestamp as an argument and performs a GET request to the `/updates?last_update_time=<timestamp>` URL.

Both methods use the `RestApiUtility` for making HTTP requests and are designed to work with different base URLs, controlled by the `ApiType` enum.
pull/5220/head
hunteraraujo 2023-09-14 20:04:44 -07:00
parent 595a892f71
commit 16efb96409
1 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import 'dart:async';
import 'package:auto_gpt_flutter_client/models/benchmark_service/report_request_body.dart';
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
import 'package:auto_gpt_flutter_client/models/benchmark_service/api_type.dart';
class BenchmarkService {
final RestApiUtility api;
BenchmarkService(this.api);
/// Generates a report using POST REST API at the /reports URL.
///
/// [reportRequestBody] is a Map representing the request body for generating a report.
Future<Map<String, dynamic>> generateReport(
ReportRequestBody reportRequestBody) async {
try {
return await api.post('reports', reportRequestBody.toJson(),
apiType: ApiType.benchmark);
} catch (e) {
throw Exception('Failed to generate report: $e');
}
}
/// Polls for updates using the GET REST API at the /updates?last_update_time=TIMESTAMP URL.
///
/// [lastUpdateTime] is the UNIX UTC timestamp for last update time.
Future<Map<String, dynamic>> pollUpdates(int lastUpdateTime) async {
try {
return await api.get('updates?last_update_time=$lastUpdateTime',
apiType: ApiType.benchmark);
} catch (e) {
throw Exception('Failed to poll updates: $e');
}
}
}