Skip to content

Commit

Permalink
Merge pull request #8 from fluttercuba/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
leynier authored Sep 4, 2021
2 parents fd17feb + 24da861 commit c1914e6
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 26 deletions.
10 changes: 10 additions & 0 deletions packages/apklis_dio_web_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.1.0+1

- Update a dependency to the latest release.

## 0.1.0

> Note: This release has breaking changes.
- **BREAKING** **FEAT**: improve error system.

## 0.0.1+5

- **DOCS**: update readmes.
Expand Down
11 changes: 9 additions & 2 deletions packages/apklis_dio_web_api/lib/apklis_dio_web_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library apklis_dio_web_api;

import 'package:apklis_web_api/apklis_api_result.dart';
import 'package:apklis_web_api/apklis_web_api.dart';
import 'package:apklis_web_api/models/apklis_error_model.dart';
import 'package:apklis_web_api/models/models.dart';
import 'package:dio/dio.dart';

Expand All @@ -20,10 +21,16 @@ class ApklisDioWebApi extends ApklisWebApi {
final model = ApklisModel.fromJson(json);
return ApklisApiResult.success(model);
} else {
return ApklisApiResult.failure(response.statusMessage!);
return ApklisApiResult.failure(ApklisErrorModel(
statusCode: response.statusCode!,
statusMessage: response.statusMessage!,
));
}
} catch (e) {
return ApklisApiResult.failure(e.toString());
return ApklisApiResult.failure(ApklisErrorModel(
statusCode: -1,
statusMessage: e.toString(),
));
}
}
}
4 changes: 2 additions & 2 deletions packages/apklis_dio_web_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: apklis_dio_web_api
description: Implementación concreta del paquete apklis_web_api para interactuar
con la API de Apklis utilizando el paquete dio.
version: 0.0.1+5
version: 0.1.0+1
homepage: https://github.com/fluttercuba/apklis-dart-flutter

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
apklis_web_api: ^0.1.0+1
apklis_web_api: ^0.2.0+1
dio: ^4.0.0

dev_dependencies:
Expand Down
6 changes: 4 additions & 2 deletions packages/apklis_dio_web_api/test/apklis_dio_web_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ void main() {
throw Exception('Result should be failure.');
},
failure: (error) {
expect(error.isNotEmpty, true);
expect(error.statusCode, isNot(200));
expect(error.statusMessage.isNotEmpty, true);
},
);
});
Expand Down Expand Up @@ -97,7 +98,8 @@ void main() {
throw Exception('Result should be failure.');
},
failure: (error) {
expect(error.isNotEmpty, true);
expect(error.statusCode, isNot(200));
expect(error.statusMessage.isNotEmpty, true);
},
);
});
Expand Down
5 changes: 5 additions & 0 deletions packages/apklis_direct_payment_checker/example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.0.1

- **FEAT**: implement apklis_direct_payment_checker.
- **CI**: fix some scripts of melos.yaml.

10 changes: 10 additions & 0 deletions packages/apklis_http_web_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.1.0+1

- Update a dependency to the latest release.

## 0.1.0

> Note: This release has breaking changes.
- **BREAKING** **FEAT**: improve error system.

## 0.0.1+4

- **DOCS**: update readmes.
Expand Down
11 changes: 9 additions & 2 deletions packages/apklis_http_web_api/lib/apklis_http_web_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';

import 'package:apklis_web_api/apklis_api_result.dart';
import 'package:apklis_web_api/apklis_web_api.dart';
import 'package:apklis_web_api/models/apklis_error_model.dart';
import 'package:apklis_web_api/models/models.dart';
import 'package:http/http.dart';

Expand All @@ -28,10 +29,16 @@ class ApklisHttpWebApi extends ApklisWebApi {
final model = ApklisModel.fromJson(json);
return ApklisApiResult.success(model);
} else {
return ApklisApiResult.failure(response.reasonPhrase!);
return ApklisApiResult.failure(ApklisErrorModel(
statusCode: response.statusCode,
statusMessage: response.reasonPhrase!,
));
}
} catch (e) {
return ApklisApiResult.failure(e.toString());
return ApklisApiResult.failure(ApklisErrorModel(
statusCode: -1,
statusMessage: e.toString(),
));
}
}
}
4 changes: 2 additions & 2 deletions packages/apklis_http_web_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: apklis_http_web_api
description: Implementación concreta del paquete apklis_web_api para interactuar
con la API de Apklis utilizando el paquete http.
version: 0.0.1+4
version: 0.1.0+1
homepage: https://github.com/fluttercuba/apklis-dart-flutter

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
apklis_web_api: ^0.1.0+1
apklis_web_api: ^0.2.0+1
http: ^0.13.3

dev_dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void main() {
throw Exception('Result should be failure.');
},
failure: (error) {
expect(error.isNotEmpty, true);
expect(error.statusCode, isNot(200));
expect(error.statusMessage.isNotEmpty, true);
},
);
});
Expand All @@ -64,7 +65,8 @@ void main() {
throw Exception('Result should be failure.');
},
failure: (error) {
expect(error.isNotEmpty, true);
expect(error.statusCode, isNot(200));
expect(error.statusMessage.isNotEmpty, true);
},
);
});
Expand Down
10 changes: 10 additions & 0 deletions packages/apklis_web_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.2.0+1

- **FIX**: remove parser methods to ApklisErrorModel.

## 0.2.0

> Note: This release has breaking changes.
- **BREAKING** **FEAT**: improve error system.

## 0.1.0+1

- **DOCS**: update readmes.
Expand Down
4 changes: 3 additions & 1 deletion packages/apklis_web_api/lib/apklis_api_result.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:apklis_web_api/models/apklis_error_model.dart';
import 'package:apklis_web_api/models/models.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

Expand All @@ -7,5 +8,6 @@ part 'apklis_api_result.freezed.dart';
class ApklisApiResult with _$ApklisApiResult {
const factory ApklisApiResult.success(ApklisModel result) =
_SuccessApklisApiResult;
const factory ApklisApiResult.failure(String error) = _FailureApklisApiResult;
const factory ApklisApiResult.failure(ApklisErrorModel error) =
_FailureApklisApiResult;
}
24 changes: 12 additions & 12 deletions packages/apklis_web_api/lib/apklis_api_result.freezed.dart

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

9 changes: 9 additions & 0 deletions packages/apklis_web_api/lib/models/apklis_error_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ApklisErrorModel {
const ApklisErrorModel({
required this.statusCode,
required this.statusMessage,
});

final int statusCode;
final String statusMessage;
}
2 changes: 1 addition & 1 deletion packages/apklis_web_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: apklis_web_api
description: Interfaz para la posterior implementación de un paquete en Dart
para interactuar con la API de Apklis.
version: 0.1.0+1
version: 0.2.0+1
homepage: https://github.com/fluttercuba/apklis-dart-flutter

environment:
Expand Down
21 changes: 21 additions & 0 deletions packages/apklis_web_api/test/apklis_web_api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';

import 'package:apklis_web_api/apklis_api_result.dart';
import 'package:apklis_web_api/apklis_web_api.dart';
import 'package:apklis_web_api/models/apklis_error_model.dart';
import 'package:apklis_web_api/models/apklis_model.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -39,4 +40,24 @@ void main() {
},
);
});

test('check error', () async {
final api = MockApklisWebApi();
when(() => api.get(['club.postdata.covid19cuba'])).thenAnswer(
(_) => Future.value(const ApklisApiResult.failure(ApklisErrorModel(
statusCode: -1,
statusMessage: 'Error',
))),
);
final model = await api.get(['club.postdata.covid19cuba']);
model.when(
success: (result) {
throw Exception('Result should be failure.');
},
failure: (error) {
expect(error.statusCode, isNot(200));
expect(error.statusMessage.isNotEmpty, true);
},
);
});
}

0 comments on commit c1914e6

Please sign in to comment.