Rename CollectorRequest->Collector and add extras to target

This commit is contained in:
Sambo Chea 2023-05-27 09:04:53 +07:00
parent 467d1c6edf
commit f41fabab3f
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
7 changed files with 64 additions and 47 deletions

View File

@ -16,7 +16,7 @@ void main() async {
final sdk = VLogs.create(APP_ID, API_KEY);
var request = CollectorRequest.builder()
var request = Collector.builder()
.message("Hello World")
.source(CollectorSource.mobile.name)
.type(CollectorType.log.name)

View File

@ -1,16 +1,3 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.

View File

@ -8,12 +8,18 @@ void main() async {
final sdk = VLogs.create(APP_ID, API_KEY);
var request = CollectorRequest.builder()
var request = Collector.builder()
.message("Hello World")
.source(CollectorSource.mobile.name)
.type(CollectorType.log.name)
.build();
// Run this to test non-blocking collect
sdk.collectAsync(request);
// Run this to test blocking collect
var response = await sdk.collect(request);
// Output the response
print("Response: ${response.toJson()}");
}

View File

@ -35,10 +35,13 @@ class VLogs {
_service = VLogsService(_baseUrl);
_logger.i("VLogs: Initialized AppID: $_appId | SDK Version: $VERSION-$VERSION_CODE");
_logger.i(
"VLogs: Initialized AppID: $_appId | SDK Version: $VERSION-$VERSION_CODE");
}
Future<CollectorResponse> collect(CollectorRequest request) async {
Future<CollectorResponse> collect(Collector request) async {
_logger.d("VLogs: Collecting logs for ${request.getId()}");
var headers = {
APP_ID_HEADER_PREFIX: _appId,
API_KEY_HEADER_PREFIX: _apiKey,
@ -66,13 +69,12 @@ class VLogs {
return response;
}
void collectAsync(CollectorRequest request) async {
try {
var response = await collect(request);
_logger.i("VLogs: ${response.message}");
} catch (e) {
_logger.e("VLogs: ${e.toString()}");
}
void collectAsync(Collector request) {
collect(request)
.then((value) => {_logger.d("VLogs: Collected logs response: $value")})
.catchError((error) {
_logger.e("VLogs: Error while collecting logs: $error");
});
}
static VLogs createWithOptions(VLogsOptions options) {

View File

@ -13,12 +13,14 @@ class Telegram {
String? chatId;
TelegramParseMode? parseMode;
bool? disabled;
dynamic extras;
Telegram({
this.token,
this.chatId,
this.parseMode,
this.disabled,
this.extras,
});
Map<String, dynamic> toMap() {
@ -27,6 +29,7 @@ class Telegram {
'chat_id': chatId,
'parse_mode': parseMode,
'disabled': disabled,
'extras': extras,
};
}
@ -40,6 +43,7 @@ class TelegramBuilder {
String? _chatId;
TelegramParseMode? _parseMode;
bool? _disabled;
dynamic _extras;
TelegramBuilder();
@ -63,12 +67,18 @@ class TelegramBuilder {
return this;
}
TelegramBuilder extras(dynamic extras) {
_extras = extras;
return this;
}
Telegram build() {
return Telegram(
token: _token,
chatId: _chatId,
parseMode: _parseMode,
disabled: _disabled,
extras: _extras,
);
}
}
@ -78,19 +88,22 @@ class Discord {
String? webhookToken;
String? webhookUrl;
bool? disabled;
dynamic extras;
Discord({
this.webhookId,
this.webhookToken,
this.webhookUrl,
this.disabled,
this.extras,
});
Discord._builder(DiscordBuilder builder)
: webhookId = builder._webhookId,
webhookToken = builder._webhookToken,
webhookUrl = builder._webhookUrl,
disabled = builder._disabled;
disabled = builder._disabled,
extras = builder._extras;
Map<String, dynamic> toMap() {
return {
@ -98,6 +111,7 @@ class Discord {
'webhook_token': webhookToken,
'webhook_url': webhookUrl,
'disabled': disabled,
'extras': extras,
};
}
@ -111,6 +125,7 @@ class DiscordBuilder {
String? _webhookToken;
String? _webhookUrl;
bool? _disabled;
dynamic _extras;
DiscordBuilder();
@ -134,6 +149,11 @@ class DiscordBuilder {
return this;
}
DiscordBuilder extras(dynamic extras) {
_extras = extras;
return this;
}
Discord build() {
return Discord._builder(this);
}
@ -270,7 +290,7 @@ class TargetBuilder {
}
}
class CollectorRequest {
class Collector {
String? id;
String? type;
String? source;
@ -281,7 +301,7 @@ class CollectorRequest {
Target? target;
List<String>? tags;
CollectorRequest(
Collector(
{this.id,
this.type,
this.source,
@ -318,12 +338,12 @@ class CollectorRequest {
String toJson() => json.encode(toMap());
static CollectorRequestBuilder builder() {
return CollectorRequestBuilder();
static CollectorBuilder builder() {
return CollectorBuilder();
}
}
class CollectorRequestBuilder {
class CollectorBuilder {
String? _id;
String? _type;
String? _source;
@ -334,55 +354,55 @@ class CollectorRequestBuilder {
Target? _target;
List<String>? _tags;
CollectorRequestBuilder();
CollectorBuilder();
CollectorRequestBuilder id(String? id) {
CollectorBuilder id(String? id) {
_id = id;
return this;
}
CollectorRequestBuilder type(String? type) {
CollectorBuilder type(String? type) {
_type = type;
return this;
}
CollectorRequestBuilder source(String? source) {
CollectorBuilder source(String? source) {
_source = source;
return this;
}
CollectorRequestBuilder message(String? message) {
CollectorBuilder message(String? message) {
_message = message;
return this;
}
CollectorRequestBuilder data(dynamic data) {
CollectorBuilder data(dynamic data) {
_data = data;
return this;
}
CollectorRequestBuilder userAgent(String? userAgent) {
CollectorBuilder userAgent(String? userAgent) {
_userAgent = userAgent;
return this;
}
CollectorRequestBuilder timestamp(int? timestamp) {
CollectorBuilder timestamp(int? timestamp) {
_timestamp = timestamp;
return this;
}
CollectorRequestBuilder target(Target? target) {
CollectorBuilder target(Target? target) {
_target = target;
return this;
}
CollectorRequestBuilder tags(List<String>? tags) {
CollectorBuilder tags(List<String>? tags) {
_tags = tags;
return this;
}
CollectorRequest build() {
return CollectorRequest(
Collector build() {
return Collector(
id: _id,
type: _type,
source: _source,
@ -413,6 +433,9 @@ class CollectorResponse {
String toJson() => json.encode(toMap());
@override
String toString() => toJson();
factory CollectorResponse.fromMap(Map<String, dynamic> map) {
return CollectorResponse(
message: map['message'],

View File

@ -4,7 +4,7 @@ version: 1.0.0
repository: https://github.com/CUBETIQ/vlogs_sdk_dart.git
environment:
sdk: ^3.0.2
sdk: ">=2.19.0 <3.0.0"
dependencies:
http:

View File

@ -1,22 +1,21 @@
// ignore_for_file: non_constant_identifier_names
import 'package:test/test.dart';
import 'package:vlogs/src/model.dart';
import 'package:vlogs/vlogs.dart';
void main() {
final APP_ID = "72bd14c306a91fa8a590330e3898ddcc";
final API_KEY = "vlogs_gX9WwSdKatMNdpUClLU0IfCx575tvdoeQ";
group('A group of tests', () {
group('Run collecting the logs', () {
final sdk = VLogs.create(APP_ID, API_KEY);
setUp(() {
// Additional setup goes here.
expect(sdk, isNotNull);
});
test('Emit the logs to collector', () async {
var request = CollectorRequest.builder()
var request = Collector.builder()
.message("Hello World")
.source(CollectorSource.mobile.name)
.type(CollectorType.log.name)