Rename CollectorRequest->Collector and add extras to target
This commit is contained in:
parent
467d1c6edf
commit
f41fabab3f
@ -16,7 +16,7 @@ void main() async {
|
|||||||
|
|
||||||
final sdk = VLogs.create(APP_ID, API_KEY);
|
final sdk = VLogs.create(APP_ID, API_KEY);
|
||||||
|
|
||||||
var request = CollectorRequest.builder()
|
var request = Collector.builder()
|
||||||
.message("Hello World")
|
.message("Hello World")
|
||||||
.source(CollectorSource.mobile.name)
|
.source(CollectorSource.mobile.name)
|
||||||
.type(CollectorType.log.name)
|
.type(CollectorType.log.name)
|
||||||
|
@ -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
|
include: package:lints/recommended.yaml
|
||||||
|
|
||||||
# Uncomment the following section to specify additional rules.
|
# Uncomment the following section to specify additional rules.
|
||||||
|
@ -8,12 +8,18 @@ void main() async {
|
|||||||
|
|
||||||
final sdk = VLogs.create(APP_ID, API_KEY);
|
final sdk = VLogs.create(APP_ID, API_KEY);
|
||||||
|
|
||||||
var request = CollectorRequest.builder()
|
var request = Collector.builder()
|
||||||
.message("Hello World")
|
.message("Hello World")
|
||||||
.source(CollectorSource.mobile.name)
|
.source(CollectorSource.mobile.name)
|
||||||
.type(CollectorType.log.name)
|
.type(CollectorType.log.name)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
// Run this to test non-blocking collect
|
||||||
|
sdk.collectAsync(request);
|
||||||
|
|
||||||
|
// Run this to test blocking collect
|
||||||
var response = await sdk.collect(request);
|
var response = await sdk.collect(request);
|
||||||
|
|
||||||
|
// Output the response
|
||||||
print("Response: ${response.toJson()}");
|
print("Response: ${response.toJson()}");
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,13 @@ class VLogs {
|
|||||||
|
|
||||||
_service = VLogsService(_baseUrl);
|
_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 = {
|
var headers = {
|
||||||
APP_ID_HEADER_PREFIX: _appId,
|
APP_ID_HEADER_PREFIX: _appId,
|
||||||
API_KEY_HEADER_PREFIX: _apiKey,
|
API_KEY_HEADER_PREFIX: _apiKey,
|
||||||
@ -66,13 +69,12 @@ class VLogs {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void collectAsync(CollectorRequest request) async {
|
void collectAsync(Collector request) {
|
||||||
try {
|
collect(request)
|
||||||
var response = await collect(request);
|
.then((value) => {_logger.d("VLogs: Collected logs response: $value")})
|
||||||
_logger.i("VLogs: ${response.message}");
|
.catchError((error) {
|
||||||
} catch (e) {
|
_logger.e("VLogs: Error while collecting logs: $error");
|
||||||
_logger.e("VLogs: ${e.toString()}");
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static VLogs createWithOptions(VLogsOptions options) {
|
static VLogs createWithOptions(VLogsOptions options) {
|
||||||
|
@ -13,12 +13,14 @@ class Telegram {
|
|||||||
String? chatId;
|
String? chatId;
|
||||||
TelegramParseMode? parseMode;
|
TelegramParseMode? parseMode;
|
||||||
bool? disabled;
|
bool? disabled;
|
||||||
|
dynamic extras;
|
||||||
|
|
||||||
Telegram({
|
Telegram({
|
||||||
this.token,
|
this.token,
|
||||||
this.chatId,
|
this.chatId,
|
||||||
this.parseMode,
|
this.parseMode,
|
||||||
this.disabled,
|
this.disabled,
|
||||||
|
this.extras,
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
@ -27,6 +29,7 @@ class Telegram {
|
|||||||
'chat_id': chatId,
|
'chat_id': chatId,
|
||||||
'parse_mode': parseMode,
|
'parse_mode': parseMode,
|
||||||
'disabled': disabled,
|
'disabled': disabled,
|
||||||
|
'extras': extras,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +43,7 @@ class TelegramBuilder {
|
|||||||
String? _chatId;
|
String? _chatId;
|
||||||
TelegramParseMode? _parseMode;
|
TelegramParseMode? _parseMode;
|
||||||
bool? _disabled;
|
bool? _disabled;
|
||||||
|
dynamic _extras;
|
||||||
|
|
||||||
TelegramBuilder();
|
TelegramBuilder();
|
||||||
|
|
||||||
@ -63,12 +67,18 @@ class TelegramBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TelegramBuilder extras(dynamic extras) {
|
||||||
|
_extras = extras;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
Telegram build() {
|
Telegram build() {
|
||||||
return Telegram(
|
return Telegram(
|
||||||
token: _token,
|
token: _token,
|
||||||
chatId: _chatId,
|
chatId: _chatId,
|
||||||
parseMode: _parseMode,
|
parseMode: _parseMode,
|
||||||
disabled: _disabled,
|
disabled: _disabled,
|
||||||
|
extras: _extras,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,19 +88,22 @@ class Discord {
|
|||||||
String? webhookToken;
|
String? webhookToken;
|
||||||
String? webhookUrl;
|
String? webhookUrl;
|
||||||
bool? disabled;
|
bool? disabled;
|
||||||
|
dynamic extras;
|
||||||
|
|
||||||
Discord({
|
Discord({
|
||||||
this.webhookId,
|
this.webhookId,
|
||||||
this.webhookToken,
|
this.webhookToken,
|
||||||
this.webhookUrl,
|
this.webhookUrl,
|
||||||
this.disabled,
|
this.disabled,
|
||||||
|
this.extras,
|
||||||
});
|
});
|
||||||
|
|
||||||
Discord._builder(DiscordBuilder builder)
|
Discord._builder(DiscordBuilder builder)
|
||||||
: webhookId = builder._webhookId,
|
: webhookId = builder._webhookId,
|
||||||
webhookToken = builder._webhookToken,
|
webhookToken = builder._webhookToken,
|
||||||
webhookUrl = builder._webhookUrl,
|
webhookUrl = builder._webhookUrl,
|
||||||
disabled = builder._disabled;
|
disabled = builder._disabled,
|
||||||
|
extras = builder._extras;
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
@ -98,6 +111,7 @@ class Discord {
|
|||||||
'webhook_token': webhookToken,
|
'webhook_token': webhookToken,
|
||||||
'webhook_url': webhookUrl,
|
'webhook_url': webhookUrl,
|
||||||
'disabled': disabled,
|
'disabled': disabled,
|
||||||
|
'extras': extras,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +125,7 @@ class DiscordBuilder {
|
|||||||
String? _webhookToken;
|
String? _webhookToken;
|
||||||
String? _webhookUrl;
|
String? _webhookUrl;
|
||||||
bool? _disabled;
|
bool? _disabled;
|
||||||
|
dynamic _extras;
|
||||||
|
|
||||||
DiscordBuilder();
|
DiscordBuilder();
|
||||||
|
|
||||||
@ -134,6 +149,11 @@ class DiscordBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiscordBuilder extras(dynamic extras) {
|
||||||
|
_extras = extras;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
Discord build() {
|
Discord build() {
|
||||||
return Discord._builder(this);
|
return Discord._builder(this);
|
||||||
}
|
}
|
||||||
@ -270,7 +290,7 @@ class TargetBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CollectorRequest {
|
class Collector {
|
||||||
String? id;
|
String? id;
|
||||||
String? type;
|
String? type;
|
||||||
String? source;
|
String? source;
|
||||||
@ -281,7 +301,7 @@ class CollectorRequest {
|
|||||||
Target? target;
|
Target? target;
|
||||||
List<String>? tags;
|
List<String>? tags;
|
||||||
|
|
||||||
CollectorRequest(
|
Collector(
|
||||||
{this.id,
|
{this.id,
|
||||||
this.type,
|
this.type,
|
||||||
this.source,
|
this.source,
|
||||||
@ -318,12 +338,12 @@ class CollectorRequest {
|
|||||||
|
|
||||||
String toJson() => json.encode(toMap());
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
static CollectorRequestBuilder builder() {
|
static CollectorBuilder builder() {
|
||||||
return CollectorRequestBuilder();
|
return CollectorBuilder();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CollectorRequestBuilder {
|
class CollectorBuilder {
|
||||||
String? _id;
|
String? _id;
|
||||||
String? _type;
|
String? _type;
|
||||||
String? _source;
|
String? _source;
|
||||||
@ -334,55 +354,55 @@ class CollectorRequestBuilder {
|
|||||||
Target? _target;
|
Target? _target;
|
||||||
List<String>? _tags;
|
List<String>? _tags;
|
||||||
|
|
||||||
CollectorRequestBuilder();
|
CollectorBuilder();
|
||||||
|
|
||||||
CollectorRequestBuilder id(String? id) {
|
CollectorBuilder id(String? id) {
|
||||||
_id = id;
|
_id = id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder type(String? type) {
|
CollectorBuilder type(String? type) {
|
||||||
_type = type;
|
_type = type;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder source(String? source) {
|
CollectorBuilder source(String? source) {
|
||||||
_source = source;
|
_source = source;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder message(String? message) {
|
CollectorBuilder message(String? message) {
|
||||||
_message = message;
|
_message = message;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder data(dynamic data) {
|
CollectorBuilder data(dynamic data) {
|
||||||
_data = data;
|
_data = data;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder userAgent(String? userAgent) {
|
CollectorBuilder userAgent(String? userAgent) {
|
||||||
_userAgent = userAgent;
|
_userAgent = userAgent;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder timestamp(int? timestamp) {
|
CollectorBuilder timestamp(int? timestamp) {
|
||||||
_timestamp = timestamp;
|
_timestamp = timestamp;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder target(Target? target) {
|
CollectorBuilder target(Target? target) {
|
||||||
_target = target;
|
_target = target;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequestBuilder tags(List<String>? tags) {
|
CollectorBuilder tags(List<String>? tags) {
|
||||||
_tags = tags;
|
_tags = tags;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectorRequest build() {
|
Collector build() {
|
||||||
return CollectorRequest(
|
return Collector(
|
||||||
id: _id,
|
id: _id,
|
||||||
type: _type,
|
type: _type,
|
||||||
source: _source,
|
source: _source,
|
||||||
@ -413,6 +433,9 @@ class CollectorResponse {
|
|||||||
|
|
||||||
String toJson() => json.encode(toMap());
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => toJson();
|
||||||
|
|
||||||
factory CollectorResponse.fromMap(Map<String, dynamic> map) {
|
factory CollectorResponse.fromMap(Map<String, dynamic> map) {
|
||||||
return CollectorResponse(
|
return CollectorResponse(
|
||||||
message: map['message'],
|
message: map['message'],
|
||||||
|
@ -4,7 +4,7 @@ version: 1.0.0
|
|||||||
repository: https://github.com/CUBETIQ/vlogs_sdk_dart.git
|
repository: https://github.com/CUBETIQ/vlogs_sdk_dart.git
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.0.2
|
sdk: ">=2.19.0 <3.0.0"
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
http:
|
http:
|
||||||
|
@ -1,22 +1,21 @@
|
|||||||
// ignore_for_file: non_constant_identifier_names
|
// ignore_for_file: non_constant_identifier_names
|
||||||
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:vlogs/src/model.dart';
|
|
||||||
import 'package:vlogs/vlogs.dart';
|
import 'package:vlogs/vlogs.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
final APP_ID = "72bd14c306a91fa8a590330e3898ddcc";
|
final APP_ID = "72bd14c306a91fa8a590330e3898ddcc";
|
||||||
final API_KEY = "vlogs_gX9WwSdKatMNdpUClLU0IfCx575tvdoeQ";
|
final API_KEY = "vlogs_gX9WwSdKatMNdpUClLU0IfCx575tvdoeQ";
|
||||||
|
|
||||||
group('A group of tests', () {
|
group('Run collecting the logs', () {
|
||||||
final sdk = VLogs.create(APP_ID, API_KEY);
|
final sdk = VLogs.create(APP_ID, API_KEY);
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
// Additional setup goes here.
|
expect(sdk, isNotNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Emit the logs to collector', () async {
|
test('Emit the logs to collector', () async {
|
||||||
var request = CollectorRequest.builder()
|
var request = Collector.builder()
|
||||||
.message("Hello World")
|
.message("Hello World")
|
||||||
.source(CollectorSource.mobile.name)
|
.source(CollectorSource.mobile.name)
|
||||||
.type(CollectorType.log.name)
|
.type(CollectorType.log.name)
|
||||||
|
Loading…
Reference in New Issue
Block a user