Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/client_deta_api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
## 0.0.2

* docs: update **README.md**

## 0.0.3-dev.1

* feat: add `onSendProgress` and `onReceiveProgress` callback.
* fix: rename `Response` to `DetaResponse` in `toString` method.
21 changes: 21 additions & 0 deletions packages/client_deta_api/lib/src/client_deta_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ abstract class ClientDetaApi {
Future<DetaResponse<T>> get<T>(
Uri url, {
Map<String, String> headers = const {},
ProgressRequestCallback? onReceiveProgress,
});

/// Make http `POST` request.
Future<DetaResponse<T>> post<T>(
Uri url, {
Map<String, String> headers = const {},
Object? data,
ProgressRequestCallback? onSendProgress,
ProgressRequestCallback? onReceiveProgress,
});

/// Make http `PUT` request.
Future<DetaResponse<T>> put<T>(
Uri url, {
Map<String, String> headers = const {},
Object? data,
ProgressRequestCallback? onSendProgress,
ProgressRequestCallback? onReceiveProgress,
});

/// Make http `DELETE` request.
Expand All @@ -40,5 +45,21 @@ abstract class ClientDetaApi {
Uri url, {
Map<String, String> headers = const {},
Object? data,
ProgressRequestCallback? onSendProgress,
ProgressRequestCallback? onReceiveProgress,
});
}

/// Callback to listen the progress for sending/receiving data.
///
/// [progress] is the length of the bytes have been sent/received.
///
/// [total] is the content length of the response/request body.
/// 1.When receiving data:
/// [total] is the request body length.
/// 2.When receiving data:
/// [total] will be -1 if the size of the response body is not known in
/// advance, for example: response data is compressed with gzip or no
/// content-length header.
/// [Dio](https://pub.dev/packages/dio) package.
typedef ProgressRequestCallback = void Function(int progress, int total);
2 changes: 1 addition & 1 deletion packages/client_deta_api/lib/src/deta_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DetaError implements Exception {

@override
String toString() {
return 'DetaError(response: Response(body: ${response?.body}, '
return 'DetaError(response: DetaResponse(body: ${response?.body}, '
'statusCode: ${response?.statusCode}))';
}
}
2 changes: 1 addition & 1 deletion packages/client_deta_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: client_deta_api
description: Basic interface of requests from a client to interact with the Deta API.
version: 0.0.2
version: 0.0.3-dev.1
repository: https://github.com/yeikel16/deta-dart
homepage: https://github.com/yeikel16/deta-dart

Expand Down
6 changes: 6 additions & 0 deletions packages/deta/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
3 changes: 3 additions & 0 deletions packages/deta/example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
1 change: 1 addition & 0 deletions packages/deta/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A simple command-line application.
1 change: 1 addition & 0 deletions packages/deta/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:very_good_analysis/analysis_options.2.4.0.yaml
Binary file added packages/deta/example/assets/dart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 46 additions & 0 deletions packages/deta/example/bin/deta_dio_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ignore_for_file: avoid_print

import 'dart:io';

import 'package:deta/deta.dart';
import 'package:dio/dio.dart';
import 'package:dio_client_deta_api/dio_client_deta_api.dart';
import 'package:path/path.dart' as path;

const projectKey = 'put-your-proyect-key-here';

Future<void> main(List<String> args) async {
// We declare class Deta, which receives our private credentials
// as a parameter.
// You can chouse a client that you want to use,
// DioClietnDetaApi or HttpClientDetaApi, remember add to depencencies
// the client.
final deta = Deta(
projectKey: projectKey,
client: DioClientDetaApi(dio: Dio()),
);

// We define our `DetaDrive`, with witch we are going to work from the name.
// In case `DetaDrive` not exist it will be created instantly on first use,
// you can create as many `DetaDrive` as you need.
final detaDrive = deta.drive('lenguages');

final filePath = path.join(Directory.current.path, 'assets', 'dart.png');
final fileName = path.basename(filePath);

final file = File(filePath);
print(filePath);

// We upload a file to the `DetaDrive`
final driveResponse = await detaDrive.uploadFile(
file,
fileName,
onSendProgress: (progress, total) {
if (total != -1) {
final pos = progress / total * 1024;
print('progress: ${pos.toStringAsFixed(2)} KB');
}
},
);
print(driveResponse);
}
46 changes: 46 additions & 0 deletions packages/deta/example/bin/deta_http_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ignore_for_file: avoid_print

import 'dart:io';

import 'package:deta/deta.dart';
import 'package:http/http.dart' as http;
import 'package:http_client_deta_api/http_client_deta_api.dart';
import 'package:path/path.dart' as path;

const projectKey = 'put-your-proyect-key-here';

Future<void> main(List<String> args) async {
// We declare class Deta, which receives our private credentials
// as a parameter.
// You can chouse a client that you want to use,
// DioClietnDetaApi or HttpClientDetaApi, remember add to depencencies
// the client.
final deta = Deta(
projectKey: projectKey,
client: HttpClientDetaApi(http: http.Client()),
);

// We define our `DetaDrive`, with witch we are going to work from the name.
// In case `DetaDrive` not exist it will be created instantly on first use,
// you can create as many `DetaDrive` as you need.
final detaDrive = deta.drive('lenguages');

final filePath = path.join(Directory.current.path, 'example.md');
final fileName = path.basename(filePath);

final file = File(filePath);
print(filePath);

// We upload a file to the `DetaDrive`
final driveResponse = await detaDrive.uploadFile(
file,
fileName,
onSendProgress: (progress, total) {
if (total != -1) {
final pos = progress / total * 1024;
print('progress: ${pos.toStringAsFixed(2)} KB');
}
},
);
print(driveResponse);
}
22 changes: 22 additions & 0 deletions packages/deta/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: deta_example
description: A simple example for using Deta.
version: 1.0.0
# homepage: https://www.example.com
publish_to: none

environment:
sdk: ">=2.16.1 <3.0.0"

dependencies:
deta:
path: ../../deta
dio: ^4.0.4
dio_client_deta_api:
path: ../../dio_client_deta_api
http: ^0.13.4
http_client_deta_api:
path: ../../http_client_deta_api
path: ^1.8.0

dev_dependencies:
very_good_analysis: ^2.4.0
23 changes: 23 additions & 0 deletions packages/deta/lib/src/deta.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import 'dart:io';

import 'package:client_deta_api/client_deta_api.dart';
import 'package:deta/src/exceptions.dart';

part 'deta_drive.dart';
part 'deta_base.dart';
part 'deta_query.dart';

Expand Down Expand Up @@ -32,4 +35,24 @@ class Deta {
deta: this,
baseName: baseName,
);

/// Connect to a `DetaDrive` from `driveName`.
///
/// In case not exist it will be created instantly on first use.
/// Your data is encrypted and stored safely at rest. You have 10GB per
/// Deta account. There is no limit on how many "Drives" you can create.
DetaDrive drive(String driveName) => _DetaDrive(
client: client,
deta: this,
driveName: driveName,
);
}

/// Base URL for [DetaBase] API.
const baseUrl = 'https://database.deta.sh';

/// Base URL for [DetaDrive] API.
const driveBaseUrl = 'https://drive.deta.sh';

/// API version.
const apiVersion = 'v1';
8 changes: 0 additions & 8 deletions packages/deta/lib/src/deta_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ abstract class DetaBase {
Future<Map> update({required String key, required Map item});
}

/// Base URL for Deta API.
const baseUrl = 'https://database.deta.sh';

/// API version.
const apiVersion = 'v1';

/// {@template deta_base}
/// Implemtation of the [DetaBase] interface.
/// {@endtemplate}
Expand All @@ -134,8 +128,6 @@ class _DetaBase extends DetaBase {
/// The `baseName` is the name given to your database
final String baseName;

// https://database.deta.sh/v1/{project_id}/{base_name}

// Deta instance.
final Deta deta;

Expand Down
Loading