Skip to content

Commit

Permalink
feat: Implement apklis_http_web_api
Browse files Browse the repository at this point in the history
  • Loading branch information
leynier committed May 30, 2021
1 parent 1621001 commit dd04d44
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/apklis_http_web_api/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 02c026b03cd31dd3f867e5faeb7e104cce174c5f
channel: stable

project_type: package
21 changes: 21 additions & 0 deletions packages/apklis_http_web_api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Flutter Cuba Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions packages/apklis_http_web_api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<h1 align="center">Apklis Http Web API</h1>

<p align="center">
<a href="https://opensource.org/licenses/MIT" target="_blank">
<img src="https://img.shields.io/badge/License-MIT-green.svg?label=license" alt="License: MIT"/>
</a>
<a href="https://github.com/fluttercuba/apklis-dart-flutter/actions/workflows/test.yml" target="_blank">
<img src="https://github.com/fluttercuba/apklis-dart-flutter/actions/workflows/test.yml/badge.svg" alt="Test"/>
</a>
<a href="https://pub.dev/packages/apklis_http_web_api" target="_blank">
<img src="https://img.shields.io/pub/v/apklis_http_web_api" alt="Version"/>
</a>
<a href="https://github.com/invertase/melos" target="_blank">
<img src="https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square" alt="Melos"/>
</a>
<a href="https://pub.dev/packages/lint" target="_blank">
<img src="https://img.shields.io/badge/style-lint-4BC0F5.svg" alt="Lint">
</a>
</p>

<p align="center">
<a href="https://github.com/fluttercuba/apklis-dart-flutter/commits" target="_blank">
<img src="https://img.shields.io/github/last-commit/fluttercuba/apklis-dart-flutter.svg?style=flat" alt="Last commit"/>
</a>
<a href="https://github.com/fluttercuba/apklis-dart-flutter/commits" target="_blank">
<img src="https://img.shields.io/github/commit-activity/m/fluttercuba/apklis-dart-flutter" alt="GitHub commit activity"/>
</a>
<a href="https://github.com/fluttercuba/apklis-dart-flutter/stargazers" target="_blank">
<img src="https://img.shields.io/github/stars/fluttercuba/apklis-dart-flutter?style=flat&logo=github" alt="Github Stars"/>
</a>
<a href="https://github.com/fluttercuba/apklis-dart-flutter/network/members" target="_blank">
<img src="https://img.shields.io/github/forks/fluttercuba/apklis-dart-flutter?style=flat&logo=github" alt="Github Forks"/>
</a>
<a href="https://github.com/fluttercuba/apklis-dart-flutter" target="_blank">
<img src="https://img.shields.io/github/watchers/fluttercuba/apklis-dart-flutter?style=flat&logo=github" alt="Github Watchers"/>
</a>
<a href="https://github.com/fluttercuba/apklis-dart-flutter/graphs/contributors" target="_blank">
<img src="https://img.shields.io/github/contributors/fluttercuba/apklis-dart-flutter" alt="GitHub contributors"/>
</a>
</p>

---

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 [http](https://pub.dev/packages/http).
180 changes: 180 additions & 0 deletions packages/apklis_http_web_api/assets/response_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
{
"count": 1,
"next": null,
"previous": null,
"facets": {},
"results": [
{
"icon": "https://archive.apklis.cu/application/icon/club.postdata.covid19cuba-v14.png",
"background": "",
"package_name": "club.postdata.covid19cuba",
"name": "Covid19 Cuba Data",
"video_url": "",
"video_img": "",
"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>",
"updated": "2020-07-20T14:03:06+00:00",
"sale_count": 0,
"download_count": 354838,
"price": 0.0,
"rating": 4.066666666666666,
"sponsored": 0,
"with_db": false,
"reviews_star_1": 24,
"reviews_star_2": 5,
"reviews_star_3": 6,
"reviews_star_4": 17,
"reviews_star_5": 98,
"releases_count": 14,
"reviews_count": 150,
"categories": [
{
"id": 3,
"name": "Utilidades",
"icon": "utils",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/Utilidades_b48JMjB.png"
},
{
"id": 50,
"name": "Internet",
"icon": "internet",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/Internet_feq0fhU.png"
},
{
"id": 46,
"name": "Medicina",
"icon": "medicine",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/Medicina.png"
},
{
"id": 44,
"name": "Mapas y navegación",
"icon": "maps",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/MapasNavegaci%C3%B3n.png"
},
{
"id": 6,
"name": "Noticias y revistas",
"icon": "news_magazines",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/NoticiasRevistas.png"
},
{
"id": 5,
"name": "Salud y bienestar",
"icon": "health",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/SaludBienestar.png"
},
{
"id": 1,
"name": "Cuba",
"icon": "cubans",
"group": "Applications",
"icon_url": "https://archive.apklis.cu/category/Aplicaciones_y_juegos_cubanos.png"
}
],
"size": 13842621,
"developer": {
"username": "leynier",
"first_name": "Leynier",
"last_name": "Gutiérrez González",
"fullname": "Leynier Gutiérrez González",
"avatar": "https://archive.apklis.cu/user/avatar/avatar_zF8cIFo.png",
"background": null,
"apps": 3,
"is_active": true,
"description": "leynier.github.io"
},
"last_release": {
"abi": [
{
"abi": "armeabi-v7a"
}
],
"no_abi": false,
"version_name": "v1.0.0",
"package_name": "club.postdata.covid19cuba",
"app_name": "Covid19 Cuba Data",
"version_sdk_name": "Jelly Bean 4.1.x",
"version_target_sdk_name": "Pie 9.0",
"permissions": [
{
"icon": "",
"description": "",
"name": "Get tasks"
},
{
"icon": "",
"description": "",
"name": "Internet"
},
{
"icon": "",
"description": "",
"name": "Receive boot completed"
},
{
"icon": "",
"description": "",
"name": "Vibrate"
},
{
"icon": "",
"description": "",
"name": "Wake lock"
}
],
"screenshots": [
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-37.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-42.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-47.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-50.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-52.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-55.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-39-58.jpg"
},
{
"description": "",
"img": "https://archive.apklis.cu/application/screenshot/photo_2020-07-20_05-40-01.jpg"
}
],
"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>",
"version_code": 14,
"published": "2020-07-20T14:03:06.180774Z",
"sha256": "ffbca10a07c2e0f922dc31d1470ec823df0b395fc0c79f3d4e06efd669288cf1",
"size": "13.20 MB",
"icon": "https://archive.apklis.cu/application/icon/club.postdata.covid19cuba-v14.png",
"public": true,
"beta": false,
"version_sdk": "Jelly Bean 4.1.x",
"version_target_sdk": "Pie 9.0",
"deleted": false
},
"announced": false
}
]
}
36 changes: 36 additions & 0 deletions packages/apklis_http_web_api/lib/apklis_http_web_api.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
library apklis_http_web_api;

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/models.dart';
import 'package:http/http.dart';

class ApklisHttpWebApi extends ApklisWebApi {
final BaseClient httpClient;

ApklisHttpWebApi(this.httpClient);

@override
Future<ApklisApiResult> getByUri(Uri uri) async {
try {
final response = await httpClient.get(uri);
if (response.statusCode == 200) {
var text = '';
try {
text = utf8.decode(response.bodyBytes);
} on FormatException {
text = response.body;
}
final json = jsonDecode(text) as Map<String, dynamic>;
final model = ApklisModel.fromJson(json);
return ApklisApiResult.success(model);
} else {
return ApklisApiResult.failure(response.reasonPhrase!);
}
} catch (e) {
return ApklisApiResult.failure(e.toString());
}
}
}
19 changes: 19 additions & 0 deletions packages/apklis_http_web_api/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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.0
homepage: https://github.com/fluttercuba/apklis-dart-flutter

environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
apklis_web_api: ^0.0.1+2
http: ^0.13.3

dev_dependencies:
build_runner: ^2.0.4
freezed: ^0.14.2
json_serializable: ^4.1.3
lint: ^1.5.3
mocktail: ^0.1.4
test: ^1.17.5
52 changes: 52 additions & 0 deletions packages/apklis_http_web_api/test/apklis_http_web_api_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:apklis_http_web_api/apklis_http_web_api.dart';
import 'package:apklis_web_api/apklis_web_api.dart';
import 'package:http/http.dart';
import 'package:mocktail/mocktail.dart';
import 'package:test/test.dart';

import 'utils.dart';

class MockHttpClient extends Mock implements BaseClient {}

void main() {
test('check request success', () async {
final apps = ['club.postdata.covid19cuba'];
final httpClient = MockHttpClient();
final api = ApklisHttpWebApi(httpClient);
final uri = ApklisWebApi.buildUri(apps);
final file = await getProjectFile('assets/response_example.json');
final text = await file.readAsString();
expect(text, isNotEmpty);
when(() => httpClient.get(uri)).thenAnswer(
(_) => Future.value(Response(text, 200)),
);
final model = await api.get(['club.postdata.covid19cuba']);
model.when(
success: (result) {
expect(result.results.isNotEmpty, true);
},
failure: (error) {
throw Exception('Result should be success. Error: $error');
},
);
});

test('check request failure', () async {
final apps = ['club.postdata.covid19cuba'];
final httpClient = MockHttpClient();
final api = ApklisHttpWebApi(httpClient);
final uri = ApklisWebApi.buildUri(apps);
when(() => httpClient.get(uri)).thenAnswer(
(_) => Future.value(Response('', 400, reasonPhrase: 'Invalid request')),
);
final model = await api.get(['club.postdata.covid19cuba']);
model.when(
success: (result) {
throw Exception('Result should be failure.');
},
failure: (error) {
expect(error.isNotEmpty, true);
},
);
});
}
11 changes: 11 additions & 0 deletions packages/apklis_http_web_api/test/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:io';

/// Get a stable path to a test resource by scanning up to the project root.
Future<File> getProjectFile(String path) async {
var dir = Directory.current;
while (
!await dir.list().any((entity) => entity.path.endsWith('pubspec.yaml'))) {
dir = dir.parent;
}
return File('${dir.path}/$path');
}

0 comments on commit dd04d44

Please sign in to comment.