From 3e9af03dc0c913225661201ecb42d4cb5aa24527 Mon Sep 17 00:00:00 2001 From: "Marco A. Braghim" Date: Mon, 8 Mar 2021 19:06:43 -0300 Subject: [PATCH] User can opt by SSL on CalcPrecoPrazo call --- .vscode/launch.json | 8 +++++++- CHANGELOG.md | 10 ++++++++++ example/pubspec.lock | 19 +++++++++++++------ lib/src/core.dart | 30 +++++++++++++----------------- pubspec.yaml | 2 +- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1813507..0548675 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,6 +8,12 @@ "name": "Flutter", "request": "launch", "type": "dart" - } + }, + { + "name": "Dart: Run all Tests", + "request": "launch", + "type": "dart", + "program": "./test/" + } ] } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index bcea204..61d6509 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 1.0.8 + +* Usuário pode escolher se quer usar HTTP (default) ou HTTPS +na requisição a CalcPrecoPrazo. Para isso é necessário definir +na instanciação da classe `Sigepweb` o atributo `useSSL` + +# 1.0.7 + +* CORS policy para requisição via web + # 1.0.6 * Regras de acordo com package pedantic diff --git a/example/pubspec.lock b/example/pubspec.lock index 8ca3197..4febfd1 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: @@ -14,7 +21,7 @@ packages: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.12" + version: "1.15.0" convert: dependency: transitive description: @@ -54,7 +61,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: @@ -82,7 +89,7 @@ packages: path: ".." relative: true source: path - version: "1.0.5" + version: "1.0.6" sky_engine: dependency: transitive description: flutter @@ -115,14 +122,14 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0" xml: dependency: transitive description: @@ -138,4 +145,4 @@ packages: source: hosted version: "4.3.0" sdks: - dart: ">=2.7.0 <3.0.0" + dart: ">=2.12.0-0 <3.0.0" diff --git a/lib/src/core.dart b/lib/src/core.dart index 1b3d957..96f35ed 100644 --- a/lib/src/core.dart +++ b/lib/src/core.dart @@ -17,17 +17,16 @@ import 'models/contrato.dart'; class Sigepweb { /// /// Endpoint para caso de ambiente de testes - final _homEndpoint = - 'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'; + final _homEndpoint = 'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'; /// /// Endpoint para caso de ambiente de producao. /// /// Este endpoint será usado quando [isDebug] for falso e nesse caso é necessário /// informar o [contrato] - final _prodEndpoint = - 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'; + final _prodEndpoint = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl'; + final bool useSSL; final bool isDebug; final dio = Dio(); @@ -42,10 +41,10 @@ class Sigepweb { Sigepweb({ this.contrato, this.isDebug = false, + this.useSSL = false, }) { if (contrato == null && !isDebug) { - throw SigepwebRuntimeError( - 'Obrigatório informar o contrato ou estar em modo debug'); + throw SigepwebRuntimeError('Obrigatório informar o contrato ou estar em modo debug'); } if (isDebug) { @@ -80,11 +79,13 @@ class Sigepweb { // do you know a better way to do that? Tell us... final isWeb = !Platform.isAndroid && !Platform.isIOS; + // Vai definir se a base do endpoint deverá usar HTTPS ou apenas HTTP + final baseEndpoint = 'http${useSSL ? 's' : ''}://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx'; + // // O Endpoint para calculo de preco e prazo eh o unico diferente // (ate agora) - final endpoint = - '${isWeb ? "https://cors-anywhere.herokuapp.com/" : ""}http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx'; + final endpoint = '${isWeb ? "https://cors-anywhere.herokuapp.com/" : ""}$baseEndpoint'; var result = []; @@ -95,8 +96,7 @@ class Sigepweb { // Efetiva a consulta var resp = await dio.get('$endpoint/CalcPrecoPrazo', queryParameters: { - 'nCdEmpresa': - contrato.codAdmin.isEmpty ? '08082650' : contrato.codAdmin, + 'nCdEmpresa': contrato.codAdmin.isEmpty ? '08082650' : contrato.codAdmin, 'sDsSenha': contrato.senha.isEmpty ? '564321' : contrato.senha, 'nCdServico': servicosList.join(','), 'sCepOrigem': SgUtils.formataCEP(cepOrigem), @@ -131,17 +131,14 @@ class Sigepweb { if (apiResult['cResultado'] == null || apiResult['cResultado']['Servicos'] == null || apiResult['cResultado']['Servicos']['cServico'] == null) { - throw SigepwebRuntimeError( - 'Xml result format isn\'t with expected format'); + throw SigepwebRuntimeError('Xml result format isn\'t with expected format'); } // Guarda o retorno em uma variavel para facilitar var cServico = apiResult['cResultado']['Servicos']['cServico']; // Verifica se houve retorno com erro - if (cServico is Map && - cServico['Erro'] != null && - cServico['Erro'] != '0') { + if (cServico is Map && cServico['Erro'] != null && cServico['Erro'] != '0') { throw SigepwebRuntimeError(cServico['MsgErro']); } @@ -216,8 +213,7 @@ class Sigepweb { xml2json.parse(response.body); Map apiResult = json.decode(xml2json.toGData()); - var soapBodyEnvelope = - apiResult['soap\$Envelope']['soap\$Body']['ns2\$consultaCEPResponse']; + var soapBodyEnvelope = apiResult['soap\$Envelope']['soap\$Body']['ns2\$consultaCEPResponse']; if (soapBodyEnvelope['return'] == null) { return ConsultaCepModel(); diff --git a/pubspec.yaml b/pubspec.yaml index 460f88d..4ee71f1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: sigepweb description: Utilize serviços dos Correios no seu App como buscar CEP ou calcular preços e prazos de encomendas -version: 1.0.6 +version: 1.0.8 repository: https://github.com/marcobraghim/sigepweb issue_tracker: https://github.com/marcobraghim/sigepweb/issues