Skip to content

Commit

Permalink
Connection timeout parameter (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmpay committed Dec 10, 2023
2 parents 1c656e6 + 90592c9 commit 7ec5acc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.3+2

* Connection timeout parameter
*
## 0.1.3+1

* battle_net_scope.dart exported
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ analyzer:
# Ignore analyzer hints for updating pubspecs when using Future or
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
sdk_version_async_exported_from_core: ignore
# sdk_version_async_exported_from_core: ignore
exclude:
- "bin/cache/**"
# the following two are relative to the stocks example and the flutter package respectively
Expand Down
23 changes: 16 additions & 7 deletions lib/src/battle_net.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import 'models/token/token_index_response.dart';
class BattleNet {
final String _auth;
final String _clientId;
final int connectionTimeout;

BattleNet({
required String clientId,
required String clientSecret,
LogLevel logLevel = LogLevel.BASIC,
bool enableReleaseLogging = false,
this.connectionTimeout = 10000,
}) : _clientId = clientId,
_auth = base64.encode(utf8.encode('$clientId:$clientSecret')) {
Logger.init(logLevel: logLevel, enableReleaseLogging: enableReleaseLogging);
Expand All @@ -48,7 +50,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand Down Expand Up @@ -101,7 +104,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand Down Expand Up @@ -131,7 +135,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand All @@ -158,7 +163,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand Down Expand Up @@ -192,7 +198,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand Down Expand Up @@ -225,7 +232,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand Down Expand Up @@ -264,7 +272,8 @@ class BattleNet {

Logger.logRequest(request: request);

final http.StreamedResponse response = await request.send();
final http.StreamedResponse response =
await request.send().timeout(Duration(milliseconds: connectionTimeout));

if (response.statusCode == 200) {
final String body = await response.stream.bytesToString();
Expand Down
18 changes: 13 additions & 5 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ packages:
dependency: "direct main"
description:
name: http
sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525"
sha256: d4872660c46d929f6b8a9ef4e7a7eff7e49bbf0c4ec3f385ee32df5119175139
url: "https://pub.dev"
source: hosted
version: "1.1.0"
version: "1.1.2"
http_multi_server:
dependency: transitive
description:
Expand Down Expand Up @@ -157,10 +157,10 @@ packages:
dependency: "direct main"
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.11.0"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -345,6 +345,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: edc8a9573dd8c5a83a183dae1af2b6fd4131377404706ca4e5420474784906fa
url: "https://pub.dev"
source: hosted
version: "0.4.0"
web_socket_channel:
dependency: transitive
description:
Expand All @@ -370,4 +378,4 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.1.0 <4.0.0"
dart: ">=3.2.0 <4.0.0"
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: battle_net
description: Dart wrapper client for Battle.Net API https://develop.battle.net/documentation
version: 0.1.3+1
version: 0.1.3+2
repository: https://github.com/vmpay/battle_net_dart
issue_tracker: https://github.com/vmpay/battle_net_dart/issues

environment:
sdk: '>=3.1.0 <4.0.0'

dependencies:
http: ^1.1.0
meta: ^1.9.1
collection: ^1.17.2
http: ^1.1.2
meta: ^1.10.0
collection: ^1.18.0

dev_dependencies:
test: ^1.22.2
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void main() {
realmsIsTournament: false,
));
expect(result.page, 1);
expect(result.results.first.data.id, 4474);
expect(result.results.first.data.id, 4467);
});

test('get connected realm search eu', () async {
Expand Down Expand Up @@ -252,7 +252,7 @@ void main() {
realmsIsTournament: false,
));
expect(result.page, 1);
expect(result.results.first.data.id, 4485);
expect(result.results.first.data.id, 4488);
});

test('get connected realm tw', () async {
Expand Down

0 comments on commit 7ec5acc

Please sign in to comment.