Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
feat: ask question api (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
omartinma authored Nov 22, 2023
1 parent d43a5ba commit 36e3582
Show file tree
Hide file tree
Showing 22 changed files with 457 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/main_development.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() {
bootstrap(
() {
final apiClient = ApiClient(
baseUrl: 'http://localhost:8080',
baseUrl: 'http://development',
idTokenStream: const Stream.empty(),
refreshIdToken: () async => Future.value(),
);
Expand Down
13 changes: 13 additions & 0 deletions packages/api_client/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:api_client/api_client.dart';

Future<void> main() async {
final apiClient = ApiClient(
baseUrl: 'http://development',
idTokenStream: const Stream.empty(),
refreshIdToken: () async => Future.value(),
);
final questionsResource = apiClient.questionsResource;
final answer = await questionsResource.getVertexResponse('random');
// ignore: avoid_print
print(answer);
}
2 changes: 2 additions & 0 deletions packages/api_client/lib/api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
library api_client;

export 'src/api_client.dart';
export 'src/models/models.dart';
export 'src/resources/resources.dart';
4 changes: 4 additions & 0 deletions packages/api_client/lib/src/api_client.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';
import 'dart:io';

import 'package:api_client/api_client.dart';
import 'package:http/http.dart' as http;

/// {@template api_client_error}
Expand Down Expand Up @@ -89,6 +90,9 @@ class ApiClient {
if (_idToken != null) 'Authorization': 'Bearer $_idToken',
};

/// Questions resource.
late final QuestionsResource questionsResource = const QuestionsResource();

Future<http.Response> _handleUnauthorized(
Future<http.Response> Function() sendRequest,
) async {
Expand Down
3 changes: 3 additions & 0 deletions packages/api_client/lib/src/models/models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export 'vertex_document.dart';
export 'vertex_metadata.dart';
export 'vertex_response.dart';
26 changes: 26 additions & 0 deletions packages/api_client/lib/src/models/vertex_document.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:api_client/api_client.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';

part 'vertex_document.g.dart';

/// {@template vertex_document}
/// Vertex document
/// {@endtemplate}
@JsonSerializable(createToJson: false)
class VertexDocument extends Equatable {
/// {@macro vertex_document}
const VertexDocument({
required this.metadata,
});

/// Convert from Map<String, dynamic> to [VertexDocument]
factory VertexDocument.fromJson(Map<String, dynamic> json) =>
_$VertexDocumentFromJson(json);

/// Metadata.
final VertexMetadata metadata;

@override
List<Object?> get props => [metadata];
}
13 changes: 13 additions & 0 deletions packages/api_client/lib/src/models/vertex_document.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions packages/api_client/lib/src/models/vertex_metadata.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:api_client/api_client.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';

part 'vertex_metadata.g.dart';

/// {@template vertex_metadata}
/// Vertex metadata inside a [VertexDocument]
/// {@endtemplate}
@JsonSerializable(createToJson: false)
class VertexMetadata extends Equatable {
/// {@macro vertex_metadata}
const VertexMetadata({
required this.url,
required this.title,
required this.description,
});

/// Convert from Map<String, dynamic> to [VertexMetadata]
factory VertexMetadata.fromJson(Map<String, dynamic> json) =>
_$VertexMetadataFromJson(json);

/// Url
final String url;

/// Title
final String title;

/// Description
final String description;

@override
List<Object?> get props => [url, title, description];
}
14 changes: 14 additions & 0 deletions packages/api_client/lib/src/models/vertex_metadata.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions packages/api_client/lib/src/models/vertex_response.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:api_client/api_client.dart';
import 'package:equatable/equatable.dart';
import 'package:json_annotation/json_annotation.dart';

part 'vertex_response.g.dart';

/// {@template vertex_response}
/// Vertex response
/// {@endtemplate}
@JsonSerializable(createToJson: false)
class VertexResponse extends Equatable {
/// {@macro vertex_response}
const VertexResponse({
required this.summary,
required this.documents,
});

/// Convert from Map<String, dynamic> to [VertexResponse]
factory VertexResponse.fromJson(Map<String, dynamic> json) =>
_$VertexResponseFromJson(json);

/// Summary.
final String summary;

/// Documents.
final List<VertexDocument> documents;

@override
List<Object?> get props => [
summary,
documents,
];
}
15 changes: 15 additions & 0 deletions packages/api_client/lib/src/models/vertex_response.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

168 changes: 168 additions & 0 deletions packages/api_client/lib/src/resources/fake_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"summary": "Hot reload loads code changes into the VM and re-builds the widget tree, preserving the app state [1]. Hot restart loads code changes into the VM, and restarts the Flutter app, losing the app state [1].",
"total_size": 701,
"attribution_token": "W_BaCgwIiN6vqgYQ5O6q0AMSJDY1NDNiODJhLTAwMDAtMjA3NS05YmQyLTE0YzE0ZWY0ZWVmMCIHR0VORVJJQyocpovvF8XL8xecho4iooaOIsLwnhXUsp0Vjr6dFQ",
"next_page_token": "AjZlVGNmVGNxMGNx0iMkJWOtUzNwITLwADMw0SOygjYzQTN2QiGCEM9JyMEGo6vHrICMIBMxIgC",
"documents": [
{
"id": "fee364b1-5b75-4042-9669-2bd123364094",
"metadata": {
"url": "https://docs.flutter.dev/tools/hot-reload",
"title": "Hot reload | Flutter",
"tags": "missing",
"keywords": "",
"description": "Speed up development using Flutter's hot reload feature.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/tools/hot-reload",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-tools-hot-reload.html",
"snippets": [
"... <b>What is the difference between hot reload</b>, <b>hot restart</b>, and full restart? Hot reload loads code changes into the VM and re-builds the widget tree&nbsp;..."
]
},
{
"id": "8fec71e3-4dbb-4948-b3ca-ec13af65691e",
"metadata": {
"url": "https://docs.flutter.dev/tools/vs-code",
"title": "Visual Studio Code | Flutter",
"tags": "fake",
"keywords": "",
"description": "How to develop Flutter apps in Visual Studio Code.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/tools/vs-code",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-tools-vs-code.html",
"snippets": [
"... <b>with a</b> placeholder Play ... command from the Command Palette. <b>Hot reload</b> vs. <b>hot restart Hot reload</b> works by injecting updated source code files into the running&nbsp;..."
]
},
{
"id": "e5e6bfd4-6da8-44a9-8ced-5a9493960087",
"metadata": {
"url": "https://docs.flutter.dev/tools/android-studio",
"title": "Android Studio and IntelliJ | Flutter",
"tags": "missing",
"keywords": "",
"description": "How to develop Flutter apps in Android Studio or other IntelliJ products.\n",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/tools/android-studio",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-tools-android-studio.html",
"snippets": [
"... <b>between</b> Android Studio and IntelliJ. In Android Studio: <b>In the</b> IDE, click ... <b>Hot reload</b> vs. <b>hot restart Hot reload</b> works by injecting updated source code files&nbsp;..."
]
},
{
"id": "b5103539-2e8f-4450-952b-b21428972bb5",
"metadata": {
"url": "https://docs.flutter.dev/platform-integration/web/faq",
"title": "Web FAQ | Flutter",
"tags": "unknown",
"keywords": "",
"description": "Some gotchas and differences when writing or running web apps in Flutter.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/platform-integration/web/faq",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-platform-integration-web-faq.html",
"snippets": [
"See building a web app with Flutter. Does <b>hot reload</b> work <b>with a</b> web app? No ... feature for Flutter mobile development. The only <b>difference</b> is that <b>hot reload</b>&nbsp;..."
]
},
{
"id": "aa9bb7db-a635-4a85-b7ca-239a9386b53f",
"metadata": {
"url": "https://docs.flutter.dev/add-to-app/debugging",
"title": "Debug your add-to-app module | Flutter",
"tags": "fake",
"keywords": "",
"description": "How to run, debug, and hot reload your add-to-app Flutter module.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/add-to-app/debugging",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-add-to-app-debugging.html",
"snippets": [
"... <b>with a</b> placeholder Play and pause a video Navigation &amp; routing Overview Add ... <b>Hot reload</b> Profiling Install Flutter DevTools Cookbook Codelabs Get started&nbsp;..."
]
},
{
"id": "b3559279-c9a9-4349-9fa6-5afbb30b572e",
"metadata": {
"url": "https://docs.flutter.dev/testing/build-modes",
"title": "Flutter's build modes | Flutter",
"tags": "missing",
"keywords": "",
"description": "Describes Flutter's build modes and when you should use debug, release, or profile mode.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/testing/build-modes",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-testing-build-modes.html",
"snippets": [
"... <b>with a</b> placeholder Play and pause a video Navigation &amp; routing ... <b>Hot reload</b> Profiling Install Flutter DevTools Cookbook Codelabs Get started Flutter 3.13&nbsp;..."
]
},
{
"id": "c0c9df6a-7f18-439b-b55a-269230829dc7",
"metadata": {
"url": "https://docs.flutter.dev/packages-and-plugins/using-packages",
"title": "Using packages | Flutter",
"tags": "unknown",
"keywords": "",
"description": "How to use packages in your Flutter app.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/packages-and-plugins/using-packages",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-packages-and-plugins-using-packages.html",
"snippets": [
"scratch. <b>What is the difference between</b> a package and a plugin? A plugin is a ... <b>Hot reload and hot restart</b> only update the Dart code, so a full <b>restart</b> of&nbsp;..."
]
},
{
"id": "f1652580-ef94-4620-9b9f-e012cef86977",
"metadata": {
"url": "https://docs.flutter.dev/resources/faq",
"title": "FAQ | Flutter",
"tags": "missing",
"keywords": "",
"description": "Frequently asked questions and answers about Flutter.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/resources/faq",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-resources-faq.html",
"snippets": [
"<b>between</b> edit and refresh? How is <b>hot reload</b> different from <b>hot restart</b>? Where can I deploy my Flutter app? What devices and OS versions does Flutter run on&nbsp;..."
]
},
{
"id": "9b8c10b0-0d70-4cc8-ba5c-f85237350ab2",
"metadata": {
"url": "https://docs.flutter.dev/get-started/test-drive",
"title": "Test drive | Flutter",
"tags": "missing",
"keywords": "",
"description": "How to create a templated Flutter app and use hot reload.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/get-started/test-drive",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-get-started-test-drive.html",
"snippets": [
"... <b>How to</b> use \u201c<b>hot reload</b>\u201d after you make changes to the app. Details for these ... <b>restart</b> it for VS Code&#39;s Flutter plugin to detect the Flutter SDK&nbsp;..."
]
},
{
"id": "407b18f1-c655-438c-a033-2d42df430def",
"metadata": {
"url": "https://docs.flutter.dev/ui/interactivity",
"title": "Add interactivity to your Flutter app | Flutter",
"tags": "missing",
"keywords": "",
"description": "How to implement a stateful widget that responds to taps.",
"image_uri": "/assets/images/shared/brand/flutter/logo+text/horizontal/default.svg"
},
"link": "https://docs.flutter.dev/ui/interactivity",
"doc_link": "gs://alanblount-sandbox-flutter-docs/docs-flutter-dev-ui-interactivity.html",
"snippets": [
"Flutter Understanding constraints Flutter&#39;s build modes <b>Hot reload</b> ... <b>How to</b> create a custom widget. The <b>difference between</b> stateless and stateful widgets."
]
}
]
}
23 changes: 23 additions & 0 deletions packages/api_client/lib/src/resources/questions_resource.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:convert';
import 'dart:io';

import 'package:api_client/api_client.dart';

/// {@template questions_resource}
/// An api resource to get response to question from the VERTEX api
/// {@endtemplate}
class QuestionsResource {
/// {@macro questions_resource}
const QuestionsResource();

/// Get /game/prompt/terms
///
/// Returns a [List<String>].
Future<VertexResponse> getVertexResponse(String query) async {
const path = 'lib/src/resources/fake_response.json';
final fakeResponse = await File(path).readAsString();

final json = jsonDecode(fakeResponse) as Map<String, dynamic>;
return VertexResponse.fromJson(json);
}
}
1 change: 1 addition & 0 deletions packages/api_client/lib/src/resources/resources.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'questions_resource.dart';
Loading

0 comments on commit 36e3582

Please sign in to comment.