diff --git a/.gitignore b/.gitignore index 9190715..bd8e325 100644 --- a/.gitignore +++ b/.gitignore @@ -105,7 +105,6 @@ app.*.map.json !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages !/dev/ci/**/Gemfile.lock !.vscode/extensions.json -!.vscode/launch.json !.idea/codeStyles/ !.idea/dictionaries/ !.idea/runConfigurations/ diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index f0752cd..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Launch development", - "request": "launch", - "type": "dart", - "program": "lib/main_development.dart", - "args": [ - "--flavor", - "development", - "--target", - "lib/main_development.dart" - ] - }, - { - "name": "Launch production", - "request": "launch", - "type": "dart", - "program": "lib/main_production.dart", - "args": [ - "--flavor", - "production", - "--target", - "lib/main_production.dart" - ] - } - ] -} \ No newline at end of file diff --git a/lib/main_production.dart b/lib/main_production.dart index 7016e31..ca78926 100644 --- a/lib/main_production.dart +++ b/lib/main_production.dart @@ -8,7 +8,8 @@ void main() async { await bootstrap( () async { final apiClient = ApiClient( - baseUrl: 'http://production', + realApiEnabled: true, + baseUrl: const String.fromEnvironment('AI_API_URL'), ); final questionsRepository = diff --git a/packages/api_client/lib/src/api_client.dart b/packages/api_client/lib/src/api_client.dart index d21f3e8..8de72dd 100644 --- a/packages/api_client/lib/src/api_client.dart +++ b/packages/api_client/lib/src/api_client.dart @@ -57,17 +57,12 @@ class ApiClient { realApiEnabled: _realApiEnabled, ); - /// Sends a POST request to the specified [path] with the given [body]. - Future post( - String path, { + /// Sends a POST request with the given [body]. + Future post({ Object? body, - Map? queryParameters, }) async { final response = await _post( - _base.replace( - path: path, - queryParameters: queryParameters, - ), + _base, body: body, headers: _headers..addContentTypeJson(), ); diff --git a/packages/api_client/lib/src/resources/questions_resource.dart b/packages/api_client/lib/src/resources/questions_resource.dart index e16448a..1a571e3 100644 --- a/packages/api_client/lib/src/resources/questions_resource.dart +++ b/packages/api_client/lib/src/resources/questions_resource.dart @@ -23,21 +23,12 @@ class QuestionsResource { String body; if (_realApiEnabled) { final response = await _apiClient.post( - // TODO(oscar): update with real API once is enabled - // and add possible failures. - 'google.es', - queryParameters: { - 'query': query, - }, + body: jsonEncode( + { + 'search_term': query, + }, + ), ); - if (response.statusCode != 200) { - throw ApiClientError( - 'GET getVertexResponse with query=$query ' - 'returned status ${response.statusCode} ' - 'with the following response: "${response.body}"', - StackTrace.current, - ); - } body = response.body; } else { await Future.delayed(const Duration(seconds: 2)); diff --git a/packages/api_client/test/src/api_client_test.dart b/packages/api_client/test/src/api_client_test.dart index a797232..ed38337 100644 --- a/packages/api_client/test/src/api_client_test.dart +++ b/packages/api_client/test/src/api_client_test.dart @@ -92,7 +92,7 @@ void main() { group('post', () { test('returns the response', () async { - final response = await apiClient.post('/'); + final response = await apiClient.post(); expect(response.statusCode, equals(expectedResponse.statusCode)); expect(response.body, equals(expectedResponse.body)); @@ -100,14 +100,12 @@ void main() { test('sends the request correctly', () async { await apiClient.post( - '/path/to/endpoint', - queryParameters: {'param1': 'value1', 'param2': 'value2'}, body: 'BODY_CONTENT', ); verify( () => httpClient.post( - Uri.parse('$baseUrl/path/to/endpoint?param1=value1¶m2=value2'), + Uri.parse(baseUrl), body: 'BODY_CONTENT', headers: {HttpHeaders.contentTypeHeader: ContentType.json.value}, ), diff --git a/packages/api_client/test/src/resources/questions_resource_test.dart b/packages/api_client/test/src/resources/questions_resource_test.dart index c9a8d93..1c3fa96 100644 --- a/packages/api_client/test/src/resources/questions_resource_test.dart +++ b/packages/api_client/test/src/resources/questions_resource_test.dart @@ -24,8 +24,7 @@ void main() { questionsResourceApiNotEnabled = QuestionsResource(apiClient: apiClient); when( () => apiClient.post( - any(), - queryParameters: any(named: 'queryParameters'), + body: any(named: 'body'), ), ).thenAnswer((_) async => response); });