Skip to content

Commit 3e9af03

Browse files
committed
User can opt by SSL on CalcPrecoPrazo call
1 parent 214f802 commit 3e9af03

File tree

5 files changed

+44
-25
lines changed

5 files changed

+44
-25
lines changed

.vscode/launch.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"name": "Flutter",
99
"request": "launch",
1010
"type": "dart"
11-
}
11+
},
12+
{
13+
"name": "Dart: Run all Tests",
14+
"request": "launch",
15+
"type": "dart",
16+
"program": "./test/"
17+
}
1218
]
1319
}

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.0.8
2+
3+
* Usuário pode escolher se quer usar HTTP (default) ou HTTPS
4+
na requisição a CalcPrecoPrazo. Para isso é necessário definir
5+
na instanciação da classe `Sigepweb` o atributo `useSSL`
6+
7+
# 1.0.7
8+
9+
* CORS policy para requisição via web
10+
111
# 1.0.6
212

313
* Regras de acordo com package pedantic

example/pubspec.lock

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Generated by pub
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
4+
characters:
5+
dependency: transitive
6+
description:
7+
name: characters
8+
url: "https://pub.dartlang.org"
9+
source: hosted
10+
version: "1.1.0"
411
charcode:
512
dependency: transitive
613
description:
@@ -14,7 +21,7 @@ packages:
1421
name: collection
1522
url: "https://pub.dartlang.org"
1623
source: hosted
17-
version: "1.14.12"
24+
version: "1.15.0"
1825
convert:
1926
dependency: transitive
2027
description:
@@ -54,7 +61,7 @@ packages:
5461
name: meta
5562
url: "https://pub.dartlang.org"
5663
source: hosted
57-
version: "1.1.8"
64+
version: "1.3.0"
5865
path:
5966
dependency: transitive
6067
description:
@@ -82,7 +89,7 @@ packages:
8289
path: ".."
8390
relative: true
8491
source: path
85-
version: "1.0.5"
92+
version: "1.0.6"
8693
sky_engine:
8794
dependency: transitive
8895
description: flutter
@@ -115,14 +122,14 @@ packages:
115122
name: typed_data
116123
url: "https://pub.dartlang.org"
117124
source: hosted
118-
version: "1.1.6"
125+
version: "1.3.0"
119126
vector_math:
120127
dependency: transitive
121128
description:
122129
name: vector_math
123130
url: "https://pub.dartlang.org"
124131
source: hosted
125-
version: "2.0.8"
132+
version: "2.1.0"
126133
xml:
127134
dependency: transitive
128135
description:
@@ -138,4 +145,4 @@ packages:
138145
source: hosted
139146
version: "4.3.0"
140147
sdks:
141-
dart: ">=2.7.0 <3.0.0"
148+
dart: ">=2.12.0-0 <3.0.0"

lib/src/core.dart

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ import 'models/contrato.dart';
1717
class Sigepweb {
1818
///
1919
/// Endpoint para caso de ambiente de testes
20-
final _homEndpoint =
21-
'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl';
20+
final _homEndpoint = 'https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl';
2221

2322
///
2423
/// Endpoint para caso de ambiente de producao.
2524
///
2625
/// Este endpoint será usado quando [isDebug] for falso e nesse caso é necessário
2726
/// informar o [contrato]
28-
final _prodEndpoint =
29-
'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl';
27+
final _prodEndpoint = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl';
3028

29+
final bool useSSL;
3130
final bool isDebug;
3231
final dio = Dio();
3332

@@ -42,10 +41,10 @@ class Sigepweb {
4241
Sigepweb({
4342
this.contrato,
4443
this.isDebug = false,
44+
this.useSSL = false,
4545
}) {
4646
if (contrato == null && !isDebug) {
47-
throw SigepwebRuntimeError(
48-
'Obrigatório informar o contrato ou estar em modo debug');
47+
throw SigepwebRuntimeError('Obrigatório informar o contrato ou estar em modo debug');
4948
}
5049

5150
if (isDebug) {
@@ -80,11 +79,13 @@ class Sigepweb {
8079
// do you know a better way to do that? Tell us...
8180
final isWeb = !Platform.isAndroid && !Platform.isIOS;
8281

82+
// Vai definir se a base do endpoint deverá usar HTTPS ou apenas HTTP
83+
final baseEndpoint = 'http${useSSL ? 's' : ''}://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx';
84+
8385
//
8486
// O Endpoint para calculo de preco e prazo eh o unico diferente
8587
// (ate agora)
86-
final endpoint =
87-
'${isWeb ? "https://cors-anywhere.herokuapp.com/" : ""}http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx';
88+
final endpoint = '${isWeb ? "https://cors-anywhere.herokuapp.com/" : ""}$baseEndpoint';
8889

8990
var result = <CalcPrecoPrazoItemModel>[];
9091

@@ -95,8 +96,7 @@ class Sigepweb {
9596

9697
// Efetiva a consulta
9798
var resp = await dio.get('$endpoint/CalcPrecoPrazo', queryParameters: {
98-
'nCdEmpresa':
99-
contrato.codAdmin.isEmpty ? '08082650' : contrato.codAdmin,
99+
'nCdEmpresa': contrato.codAdmin.isEmpty ? '08082650' : contrato.codAdmin,
100100
'sDsSenha': contrato.senha.isEmpty ? '564321' : contrato.senha,
101101
'nCdServico': servicosList.join(','),
102102
'sCepOrigem': SgUtils.formataCEP(cepOrigem),
@@ -131,17 +131,14 @@ class Sigepweb {
131131
if (apiResult['cResultado'] == null ||
132132
apiResult['cResultado']['Servicos'] == null ||
133133
apiResult['cResultado']['Servicos']['cServico'] == null) {
134-
throw SigepwebRuntimeError(
135-
'Xml result format isn\'t with expected format');
134+
throw SigepwebRuntimeError('Xml result format isn\'t with expected format');
136135
}
137136

138137
// Guarda o retorno em uma variavel para facilitar
139138
var cServico = apiResult['cResultado']['Servicos']['cServico'];
140139

141140
// Verifica se houve retorno com erro
142-
if (cServico is Map &&
143-
cServico['Erro'] != null &&
144-
cServico['Erro'] != '0') {
141+
if (cServico is Map && cServico['Erro'] != null && cServico['Erro'] != '0') {
145142
throw SigepwebRuntimeError(cServico['MsgErro']);
146143
}
147144

@@ -216,8 +213,7 @@ class Sigepweb {
216213
xml2json.parse(response.body);
217214
Map<String, dynamic> apiResult = json.decode(xml2json.toGData());
218215

219-
var soapBodyEnvelope =
220-
apiResult['soap\$Envelope']['soap\$Body']['ns2\$consultaCEPResponse'];
216+
var soapBodyEnvelope = apiResult['soap\$Envelope']['soap\$Body']['ns2\$consultaCEPResponse'];
221217

222218
if (soapBodyEnvelope['return'] == null) {
223219
return ConsultaCepModel();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: sigepweb
22
description: Utilize serviços dos Correios no seu App como buscar CEP ou calcular preços e prazos de encomendas
3-
version: 1.0.6
3+
version: 1.0.8
44
repository: https://github.com/marcobraghim/sigepweb
55
issue_tracker: https://github.com/marcobraghim/sigepweb/issues
66

0 commit comments

Comments
 (0)