Skip to content

Commit

Permalink
Feature/cn region depr (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmpay authored Jun 17, 2024
2 parents 7ec5acc + afce0be commit 2879973
Show file tree
Hide file tree
Showing 27 changed files with 476 additions and 83 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: CI
name: Quality check

# Controls when the action will run.
on:
Expand All @@ -13,10 +13,18 @@ on:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Reusable workflow call
workflow_call:
secrets:
CLIENT_ID:
required: true
CLIENT_SECRET:
required: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
check:
# The type of runner that the job will run on
runs-on: ubuntu-latest

Expand Down Expand Up @@ -56,4 +64,12 @@ jobs:
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
run: dart test

# The pub.dev site uses the analysis tool pana to calculate pub points.
# This is run automatically on the pub.dev site whenever you publish a new package,
# or a new version of an existing package.
- name: Calculating pub points prior to publishing
run: |
dart pub global activate pana
dart pub global run pana --exit-code-threshold 0 --json
33 changes: 4 additions & 29 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,12 @@ on:

# Publish using the reusable workflow from dart-lang.
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: dart-lang/setup-dart@v1

- name: Install dependencies
run: dart pub get

- name: Verify formatting
run: dart format -o none --set-exit-if-changed .

- name: Analyze project source
run: dart analyze --fatal-infos

- name: Make shell script write_credentials.sh executable
run: chmod +x .github/workflows/write_credentials.sh

- name: Write down test credentials
run: ./.github/workflows/write_credentials.sh
env:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}

- name: Run tests
run: dart test
check:
uses: ./.github/workflows/main.yml
secrets: inherit

publish:
needs: build
needs: check
permissions:
id-token: write # Required for authentication using OIDC
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
## 0.2.0

* Remove CN region (breaking change)
* Update documentation

## 0.1.3+2

* Connection timeout parameter
*

## 0.1.3+1

* battle_net_scope.dart exported
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ Locale support is limited to locations supported on Blizzard community game site
| EU | Battle.net, WoW, D3, SC2 |
| KR | Battle.net, WoW, D3, SC2 |
| TW | Battle.net, WoW, D3, SC2 |
| CN | Battle.net, WoW, D3, SC2 |

For example,
```dart
Expand All @@ -148,7 +147,6 @@ locales vary from region to region and align with those supported on Blizzard co
| Europe | https://eu.api.blizzard.com/ | en_GB, es_ES, fr_FR, ru_RU, de_DE, pt_PT, it_IT |
| Korea | https://kr.api.blizzard.com/ | ko_KR |
| Taiwan | https://tw.api.blizzard.com/ | zh_TW |
| China | https://gateway.battlenet.com.cn/ | zh_CN |

For example,
```dart
Expand Down
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ linter:
- always_declare_return_types
- always_put_control_body_on_new_line
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
- always_require_non_null_named_parameters
- always_specify_types
# - always_use_package_imports # we do this commonly
- annotate_overrides
Expand Down
4 changes: 1 addition & 3 deletions lib/src/battle_net.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ class BattleNet {
'Authorization': 'Bearer $accessToken',
'Battlenet-Namespace': '${namespace.name}-${region.slug}'
};
final String baseUrl = region == BattleNetRegion.cn
? 'gateway.battlenet.com.cn'
: '${region.slug}.api.blizzard.com';
final String baseUrl = '${region.slug}.api.blizzard.com';
final http.Request request = http.Request('GET',
Uri.parse('https://$baseUrl/data/wow/token/?locale=${locale.name}'));
request.headers.addAll(headers);
Expand Down
3 changes: 0 additions & 3 deletions lib/src/constants/battle_net_locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ enum BattleNetLocale {
ruRU,
koKR,
zhTW,
zhCN,
}

/// [BattleNetLocale] query parameter mapper
Expand Down Expand Up @@ -42,8 +41,6 @@ extension BattleNetLocaleExtension on BattleNetLocale {
return 'ko_KR';
case BattleNetLocale.zhTW:
return 'zh_TW';
case BattleNetLocale.zhCN:
return 'zh_CN';
}
}
}
5 changes: 0 additions & 5 deletions lib/src/constants/battle_net_region.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ enum BattleNetRegion {
eu,
kr,
tw,
cn,
}

/// [BattleNetRegion] query and title parameters mapper
Expand All @@ -21,8 +20,6 @@ extension BattleNetRegionExtension on BattleNetRegion {
return 'kr';
case BattleNetRegion.tw:
return 'tw';
case BattleNetRegion.cn:
return 'cn';
}
}

Expand All @@ -36,8 +33,6 @@ extension BattleNetRegionExtension on BattleNetRegion {
return 'Korea';
case BattleNetRegion.tw:
return 'Taiwan';
case BattleNetRegion.cn:
return 'China';
}
}
}
13 changes: 12 additions & 1 deletion lib/src/models/common/enum_values.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
/// Class required to describe typed values
/// Utility class for mapping enum values to and from strings.
///
/// This class provides functionality to map between enum values [T] and their
/// corresponding string representations. It accepts a [map] containing mappings
/// from string keys to enum values [T].
class EnumValues<T> {
/// A map that associates string keys with enum values [T].
Map<String, T> map;

/// A late-initialized map that associates enum values [T] with their string keys.
late Map<T, String> reverseMap;

/// Constructs an [EnumValues] instance with a [map] of string keys to enum values [T].
EnumValues(this.map);

/// Returns a map that associates enum values [T] with their corresponding string keys.
///
/// The [reverseMap] is constructed lazily from the [map] provided during initialization.
Map<T, String> get reverse {
reverseMap = map.map((String k, T v) => MapEntry<T, String>(v, k));
return reverseMap;
Expand Down
25 changes: 24 additions & 1 deletion lib/src/models/common/links.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
import 'dart:convert';

import 'package:meta/meta.dart';

import 'self.dart';

/// Request url confirmation holder data model
/// Represents the data model for holding request URL confirmations.
///
/// This class is immutable and encapsulates a [self] instance of [Self] class
/// which represents a self-reference URL.
@immutable
class Links {
/// Constructs a [Links] instance.
///
/// The [self] parameter is required and represents a self-reference URL instance.
const Links({
required this.self,
});

/// The self-reference URL instance.
final Self self;

/// Creates a [Links] instance from a raw JSON string [str].
///
/// Converts the JSON string into a map using [json.decode], and then constructs
/// a [Links] instance using [fromJson].
factory Links.fromRawJson(String str) => Links.fromJson(json.decode(str));

/// Converts this [Links] instance to a raw JSON string representation.
///
/// Converts the instance to a map using [toJson], and then encodes it to a JSON
/// string using [json.encode].
String toRawJson() => json.encode(toJson());

/// Creates a [Links] instance from a JSON map [json].
///
/// Constructs a [Links] instance from a map retrieved from JSON,
/// extracting the [self] as a [Self] instance.
factory Links.fromJson(Map<String, dynamic> json) => Links(
self: Self.fromJson(json['self']),
);

/// Converts this [Links] instance to a JSON map.
///
/// Converts the instance's [self] to a JSON-compatible format.
Map<String, dynamic> toJson() => <String, dynamic>{
'self': self.toJson(),
};
Expand Down
25 changes: 24 additions & 1 deletion lib/src/models/common/self.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
import 'dart:convert';

import 'package:meta/meta.dart';

/// Request url confirmation data model
/// Represents the data model for a self-reference URL.
///
/// This class is immutable and encapsulates a single string [href] representing
/// a URL that references itself.
@immutable
class Self {
/// Constructs a [Self] instance.
///
/// The [href] parameter is required and represents the URL string.
const Self({
required this.href,
});

/// The URL string that references itself.
final String href;

/// Creates a [Self] instance from a raw JSON string [str].
///
/// Converts the JSON string into a map using [json.decode], and then constructs
/// a [Self] instance using [fromJson].
factory Self.fromRawJson(String str) => Self.fromJson(json.decode(str));

/// Converts this [Self] instance to a raw JSON string representation.
///
/// Converts the instance to a map using [toJson], and then encodes it to a JSON
/// string using [json.encode].
String toRawJson() => json.encode(toJson());

/// Creates a [Self] instance from a JSON map [json].
///
/// Constructs a [Self] instance from a map retrieved from JSON,
/// extracting the [href] as a string.
factory Self.fromJson(Map<String, dynamic> json) => Self(
href: json['href'],
);

/// Converts this [Self] instance to a JSON map.
///
/// Converts the instance's [href] directly to a JSON-compatible format.
Map<String, dynamic> toJson() => <String, dynamic>{
'href': href,
};
Expand Down
22 changes: 22 additions & 0 deletions lib/src/models/oauth/authorization_code_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@ import 'package:meta/meta.dart';
/// the Authorization Code flow
@immutable
class AuthorizationCodeResponse {
/// The access token issued by the authorization server.
final String accessToken;

/// The type of the token issued, typically "Bearer".
final String tokenType;

/// The duration in seconds for which the access token is valid.
final int expiresIn;

/// A list of scopes that the access token is valid for.
final List<BattleNetScope> scope;

/// The subject (sub) identifier, representing the user.
final String sub;

/// The ID token issued by the authorization server.
final String idToken;

/// Creates an instance of [AuthorizationCodeResponse].
///
/// All fields are required.
const AuthorizationCodeResponse({
required this.accessToken,
required this.tokenType,
Expand All @@ -24,6 +38,10 @@ class AuthorizationCodeResponse {
required this.idToken,
});

/// Returns a copy of this instance with the given fields replaced
/// by new values.
///
/// If a field is not provided, the existing value is retained.
AuthorizationCodeResponse copyWith({
String? accessToken,
String? tokenType,
Expand All @@ -41,11 +59,14 @@ class AuthorizationCodeResponse {
idToken: idToken ?? this.idToken,
);

/// Creates an instance of [AuthorizationCodeResponse] from a JSON string.
factory AuthorizationCodeResponse.fromRawJson(String str) =>
AuthorizationCodeResponse.fromJson(json.decode(str));

/// Converts this instance to a JSON string.
String toRawJson() => json.encode(toJson());

/// Creates an instance of [AuthorizationCodeResponse] from a JSON map.
factory AuthorizationCodeResponse.fromJson(Map<String, dynamic> json) =>
AuthorizationCodeResponse(
accessToken: json['access_token'],
Expand All @@ -60,6 +81,7 @@ class AuthorizationCodeResponse {
idToken: json['id_token'],
);

/// Converts this instance to a JSON map.
Map<String, dynamic> toJson() => <String, dynamic>{
'access_token': accessToken,
'token_type': tokenType,
Expand Down
Loading

0 comments on commit 2879973

Please sign in to comment.