Skip to content

Commit ab3aa89

Browse files
committed
feat: implement apklis_dio_web_api
1 parent bf3cb24 commit ab3aa89

9 files changed

+385
-0
lines changed

packages/apklis_dio_web_api/.metadata

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: 02c026b03cd31dd3f867e5faeb7e104cce174c5f
8+
channel: stable
9+
10+
project_type: package

packages/apklis_dio_web_api/CHANGELOG.md

Whitespace-only changes.

packages/apklis_dio_web_api/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Flutter Cuba Contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/apklis_dio_web_api/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<h1 align="center">Apklis Dio Web API</h1>
2+
3+
<p align="center">
4+
<a href="https://opensource.org/licenses/MIT" target="_blank">
5+
<img src="https://img.shields.io/badge/License-MIT-green.svg?label=license" alt="License: MIT"/>
6+
</a>
7+
<a href="https://pub.dev/packages/apklis_dio_web_api" target="_blank">
8+
<img src="https://img.shields.io/pub/v/apklis_dio_web_api" alt="Version"/>
9+
</a>
10+
<a href="https://github.com/invertase/melos" target="_blank">
11+
<img src="https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square" alt="Melos"/>
12+
</a>
13+
<a href="https://pub.dev/packages/lint" target="_blank">
14+
<img src="https://img.shields.io/badge/style-lint-4BC0F5.svg" alt="Lint">
15+
</a>
16+
</p>
17+
18+
<p align="center">
19+
<a href="https://github.com/fluttercuba/apklis-dart-flutter/commits" target="_blank">
20+
<img src="https://img.shields.io/github/last-commit/fluttercuba/apklis-dart-flutter.svg?style=flat" alt="Last commit"/>
21+
</a>
22+
<a href="https://github.com/fluttercuba/apklis-dart-flutter/commits" target="_blank">
23+
<img src="https://img.shields.io/github/commit-activity/m/fluttercuba/apklis-dart-flutter" alt="GitHub commit activity"/>
24+
</a>
25+
<a href="https://github.com/fluttercuba/apklis-dart-flutter/stargazers" target="_blank">
26+
<img src="https://img.shields.io/github/stars/fluttercuba/apklis-dart-flutter?style=flat&logo=github" alt="Github Stars"/>
27+
</a>
28+
<a href="https://github.com/fluttercuba/apklis-dart-flutter/network/members" target="_blank">
29+
<img src="https://img.shields.io/github/forks/fluttercuba/apklis-dart-flutter?style=flat&logo=github" alt="Github Forks"/>
30+
</a>
31+
<a href="https://github.com/fluttercuba/apklis-dart-flutter" target="_blank">
32+
<img src="https://img.shields.io/github/watchers/fluttercuba/apklis-dart-flutter?style=flat&logo=github" alt="Github Watchers"/>
33+
</a>
34+
<a href="https://github.com/fluttercuba/apklis-dart-flutter/graphs/contributors" target="_blank">
35+
<img src="https://img.shields.io/github/contributors/fluttercuba/apklis-dart-flutter" alt="GitHub contributors"/>
36+
</a>
37+
</p>
38+
39+
---
40+
41+
Implementación concreta del paquete [apklis_web_api](https://pub.dev/packages/apklis_web_api) para interactuar con la API de [Apklis](https://apklis.cu) utilizando el paquete [dio](https://pub.dev/packages/dio).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
{
2+
"count": 1,
3+
"next": null,
4+
"previous": null,
5+
"facets": {},
6+
"results": [
7+
{
8+
"icon": "https://archive.apklis.cu/application/icon/club.postdata.covid19cuba-v14.png",
9+
"background": "",
10+
"package_name": "club.postdata.covid19cuba",
11+
"name": "Covid19 Cuba Data",
12+
"video_url": "",
13+
"video_img": "",
14+
"description": "<p>Proyecto para conocer los reportes diarios, estadísticas, etc. respecto a la Covid-19 en Cuba.</p><p>Sitio Web: <a href=\"https://covid19cubadata.github.io\">https://covid19cubadata.github.io</a></p><p>Autores:</p><p>- MatCom: <a href=\"http://www.matcom.uh.cu\">http://www.matcom.uh.cu</a></p><p>- Postdata.club: <a href=\"https://www.postdata.club\">https://www.postdata.club</a></p><p>- Juventud Técnica: <a href=\"https://medium.com/juventud-técnica\">https://medium.com/juventud-técnica</a></p><p>Los datos se actualizan a partir de la información oficial del MINSAP informados por las autoridades al día siguiente.</p><p>Canal de Telegram: <a href=\"Aplicación para conocer los reportes diarios, estadísticas, etc respecto a la Covid-19 en Cuba. Los datos se actualizan a partir de la información oficial del MINSAP informados por las autoridades al día siguiente. Canal de Telegram: https://t.me/covid19cubadata Grupo de Telegram: https://t.me/covid19cubadata\">https://t.me/covid19cubadata</a></p><p>Grupo de Telegram: <a href=\"Aplicación para conocer los reportes diarios, estadísticas, etc respecto a la Covid-19 en Cuba. Los datos se actualizan a partir de la información oficial del MINSAP informados por las autoridades al día siguiente. Canal de Telegram: https://t.me/covid19cubadata Grupo de Telegram: https://t.me/covid19cubadatachat\">https://t.me/covid19cubadatachat</a></p>",
15+
"updated": "2020-07-20T14:03:06+00:00",
16+
"sale_count": 0,
17+
"download_count": 354838,
18+
"price": 0.0,
19+
"rating": 4.066666666666666,
20+
"sponsored": 0,
21+
"with_db": false,
22+
"reviews_star_1": 24,
23+
"reviews_star_2": 5,
24+
"reviews_star_3": 6,
25+
"reviews_star_4": 17,
26+
"reviews_star_5": 98,
27+
"releases_count": 14,
28+
"reviews_count": 150,
29+
"categories": [
30+
{
31+
"id": 3,
32+
"name": "Utilidades",
33+
"icon": "utils",
34+
"group": "Applications",
35+
"icon_url": "https://archive.apklis.cu/category/Utilidades_b48JMjB.png"
36+
},
37+
{
38+
"id": 50,
39+
"name": "Internet",
40+
"icon": "internet",
41+
"group": "Applications",
42+
"icon_url": "https://archive.apklis.cu/category/Internet_feq0fhU.png"
43+
},
44+
{
45+
"id": 46,
46+
"name": "Medicina",
47+
"icon": "medicine",
48+
"group": "Applications",
49+
"icon_url": "https://archive.apklis.cu/category/Medicina.png"
50+
},
51+
{
52+
"id": 44,
53+
"name": "Mapas y navegación",
54+
"icon": "maps",
55+
"group": "Applications",
56+
"icon_url": "https://archive.apklis.cu/category/MapasNavegaci%C3%B3n.png"
57+
},
58+
{
59+
"id": 6,
60+
"name": "Noticias y revistas",
61+
"icon": "news_magazines",
62+
"group": "Applications",
63+
"icon_url": "https://archive.apklis.cu/category/NoticiasRevistas.png"
64+
},
65+
{
66+
"id": 5,
67+
"name": "Salud y bienestar",
68+
"icon": "health",
69+
"group": "Applications",
70+
"icon_url": "https://archive.apklis.cu/category/SaludBienestar.png"
71+
},
72+
{
73+
"id": 1,
74+
"name": "Cuba",
75+
"icon": "cubans",
76+
"group": "Applications",
77+
"icon_url": "https://archive.apklis.cu/category/Aplicaciones_y_juegos_cubanos.png"
78+
}
79+
],
80+
"size": 13842621,
81+
"developer": {
82+
"username": "leynier",
83+
"first_name": "Leynier",
84+
"last_name": "Gutiérrez González",
85+
"fullname": "Leynier Gutiérrez González",
86+
"avatar": "https://archive.apklis.cu/user/avatar/avatar_zF8cIFo.png",
87+
"background": null,
88+
"apps": 3,
89+
"is_active": true,
90+
"description": "leynier.github.io"
91+
},
92+
"last_release": {
93+
"abi": [
94+
{
95+
"abi": "armeabi-v7a"
96+
}
97+
],
98+
"no_abi": false,
99+
"version_name": "v1.0.0",
100+
"package_name": "club.postdata.covid19cuba",
101+
"app_name": "Covid19 Cuba Data",
102+
"version_sdk_name": "Jelly Bean 4.1.x",
103+
"version_target_sdk_name": "Pie 9.0",
104+
"permissions": [
105+
{
106+
"icon": "",
107+
"description": "",
108+
"name": "Get tasks"
109+
},
110+
{
111+
"icon": "",
112+
"description": "",
113+
"name": "Internet"
114+
},
115+
{
116+
"icon": "",
117+
"description": "",
118+
"name": "Receive boot completed"
119+
},
120+
{
121+
"icon": "",
122+
"description": "",
123+
"name": "Vibrate"
124+
},
125+
{
126+
"icon": "",
127+
"description": "",
128+
"name": "Wake lock"
129+
}
130+
],
131+
"screenshots": [
132+
{
133+
"description": "",
134+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-37.jpg"
135+
},
136+
{
137+
"description": "",
138+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-42.jpg"
139+
},
140+
{
141+
"description": "",
142+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-47.jpg"
143+
},
144+
{
145+
"description": "",
146+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-50.jpg"
147+
},
148+
{
149+
"description": "",
150+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-52.jpg"
151+
},
152+
{
153+
"description": "",
154+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-55.jpg"
155+
},
156+
{
157+
"description": "",
158+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-58.jpg"
159+
},
160+
{
161+
"description": "",
162+
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-40-01.jpg"
163+
}
164+
],
165+
"changelog": "<p>1. Reducción del tamaño de la aplicación a la mitad del tamaño de la versión anterior.</p><p>2. Nuevas imágenes y descripciones al carrusel inicial de bienvenida.</p><p>3. Separación de hombres y mujeres en la gráfica de Distribución por rangos etarios en la sección de gráficas General de Cuba.</p><p>4. Gráficas de casos sintomáticos/asintomáticos en la sección de gráficas General de Cuba.</p><p>5. Gráficas de la evolución de las personas en vigilancia en la sección de gráficas General de Cuba.</p><p>6. Gráficas de la evolución de las personas hospitalizadas en la sección de gráficas General de Cuba.</p><p>7. Sección de gráficos de casos Fallecidos en Cuba.</p><p>8. Más fuentes de noticias como Juventud Técnica, la Agencia Cubana de Noticias, Cubadebate, entre otras.</p><p>9. Fráfica de radar de comparación de varios parámetros de Cuba con otros países en la sección de Mundo.</p><p>10. Sección de boletines del Centro de Estudios Demográficos (CEDEM) de la Universidad de La Habana enfocados en la temática de la COVID-19.</p><p>11. Sección con las medidas de cada fase de la etapa de recuperación post Covid-19, así como la fase en la que se encuentran las provincias</p><p>12. Sección de descargas con las bases de datos utilizadas en diferentes formatos.</p><p>13. Sección con los protocolos de actuación, con alcance nacional, que contribuyen a la prevención, control y manejo de los casos relacionados con la enfermedad de la Covid-19.</p><p>14. Registro manual de las personas con que tuvo contacto (además de la fecha y el lugar) para mejorar y ayudar la labor de las autoridades satinarías en la lucha contra la pandemia.</p><p>15. Sección de Atención a la Población con los números telefónicos de cada provincia para la Covid-19.</p><p>16. Configuración de proxy para los usuarios que utilizan una red corporativa, estudiantil, etc. en la que se necesite configurar un proxy.</p><p>17. Configuración de las notificaciones por tipo de notificación y por horario del día.</p>",
166+
"version_code": 14,
167+
"published": "2020-07-20T14:03:06.180774Z",
168+
"sha256": "ffbca10a07c2e0f922dc31d1470ec823df0b395fc0c79f3d4e06efd669288cf1",
169+
"size": "13.20 MB",
170+
"icon": "https://archive.apklis.cu/application/icon/club.postdata.covid19cuba-v14.png",
171+
"public": true,
172+
"beta": false,
173+
"version_sdk": "Jelly Bean 4.1.x",
174+
"version_target_sdk": "Pie 9.0",
175+
"deleted": false
176+
},
177+
"announced": false
178+
}
179+
]
180+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
library apklis_dio_web_api;
2+
3+
import 'package:apklis_web_api/apklis_api_result.dart';
4+
import 'package:apklis_web_api/apklis_web_api.dart';
5+
import 'package:apklis_web_api/models/models.dart';
6+
import 'package:dio/dio.dart';
7+
8+
class ApklisDioWebApi extends ApklisWebApi {
9+
final Dio dioClient;
10+
11+
ApklisDioWebApi(this.dioClient);
12+
13+
@override
14+
Future<ApklisApiResult> getByUri(Uri uri) async {
15+
try {
16+
final response = await dioClient.getUri(uri);
17+
if (response.statusCode == 200) {
18+
final json = response.data as Map<String, dynamic>;
19+
final model = ApklisModel.fromJson(json);
20+
return ApklisApiResult.success(model);
21+
} else {
22+
return ApklisApiResult.failure(response.statusMessage!);
23+
}
24+
} catch (e) {
25+
return ApklisApiResult.failure(e.toString());
26+
}
27+
}
28+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: apklis_dio_web_api
2+
description: Implementación concreta del paquete apklis_web_api para interactuar con la API de Apklis utilizando el paquete dio.
3+
version: 0.0.0
4+
homepage: https://github.com/fluttercuba/apklis-dart-flutter
5+
6+
environment:
7+
sdk: ">=2.12.0 <3.0.0"
8+
9+
dependencies:
10+
apklis_web_api: ^0.0.1
11+
dio: ^4.0.0
12+
13+
dev_dependencies:
14+
build_runner: ^2.0.4
15+
freezed: ^0.14.2
16+
json_serializable: ^4.1.3
17+
lint: ^1.5.3
18+
mocktail: ^0.1.4
19+
test: ^1.17.5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import 'dart:convert';
2+
3+
import 'package:apklis_dio_web_api/apklis_dio_web_api.dart';
4+
import 'package:apklis_web_api/apklis_web_api.dart';
5+
import 'package:dio/dio.dart';
6+
import 'package:mocktail/mocktail.dart';
7+
import 'package:test/test.dart';
8+
9+
import 'utils.dart';
10+
11+
class MockDio extends Mock implements Dio {}
12+
13+
void main() {
14+
test('check request success', () async {
15+
final apps = ['club.postdata.covid19cuba'];
16+
final dio = MockDio();
17+
final api = ApklisDioWebApi(dio);
18+
final uri = ApklisWebApi.buildUri(apps);
19+
final file = await getProjectFile('assets/response_example.json');
20+
final text = await file.readAsString();
21+
expect(text, isNotEmpty);
22+
final resp = jsonDecode(text) as Map<String, dynamic>;
23+
when(() => dio.getUri(uri)).thenAnswer(
24+
(_) => Future.value(
25+
Response(
26+
requestOptions: RequestOptions(
27+
path: uri.path,
28+
baseUrl: uri.origin,
29+
method: 'GET',
30+
),
31+
statusCode: 200,
32+
data: resp,
33+
),
34+
),
35+
);
36+
final model = await api.get(['club.postdata.covid19cuba']);
37+
model.when(
38+
success: (result) {
39+
expect(result.results.isNotEmpty, true);
40+
},
41+
failure: (error) {
42+
throw Exception('Result should be success.');
43+
},
44+
);
45+
});
46+
47+
test('check request failure', () async {
48+
final apps = ['club.postdata.covid19cuba'];
49+
final dio = MockDio();
50+
final api = ApklisDioWebApi(dio);
51+
final uri = ApklisWebApi.buildUri(apps);
52+
when(() => dio.getUri(uri)).thenAnswer(
53+
(_) => Future.value(
54+
Response(
55+
requestOptions: RequestOptions(
56+
path: uri.path,
57+
baseUrl: uri.origin,
58+
method: 'GET',
59+
),
60+
statusCode: 400,
61+
statusMessage: 'Invalid request',
62+
),
63+
),
64+
);
65+
final model = await api.get(['club.postdata.covid19cuba']);
66+
model.when(
67+
success: (result) {
68+
throw Exception('Result should be failure.');
69+
},
70+
failure: (error) {
71+
expect(error.isNotEmpty, true);
72+
},
73+
);
74+
});
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'dart:io';
2+
3+
/// Get a stable path to a test resource by scanning up to the project root.
4+
Future<File> getProjectFile(String path) async {
5+
var dir = Directory.current;
6+
while (
7+
!await dir.list().any((entity) => entity.path.endsWith('pubspec.yaml'))) {
8+
dir = dir.parent;
9+
}
10+
return File('${dir.path}/$path');
11+
}

0 commit comments

Comments
 (0)