thetale_api 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

The Tale API #

Build Status codecov pub package

This is an unofficial way to create a basic API for the ZPG https://the-tale.org

Usage #

There are two classes to use TheTaleApi and TheTaleApiWrapper. The only difference between these two are that TheTaleApiWrapper handles the session storing using SessionStorage.

If you don't want any code to handle the session stuff, just use TheTaleApi.

To create TheTaleApiWrapper use the WrapperBuilder.

final wrapper = WrapperBuilder().build(apiUrl, applicationId, appVersion);
wrapper.setStorage(LocalSessionStorage());

You have to set the SessionStorage to make sure the session with preserve between method calls. There is no SessionStorage implementations available, a basic in-memory example would look like this:

class LocalSessionStorage implements SessionStorage {
  SessionInfo _sessionInfo;

  @override
  Future<void> addSession(SessionInfo sessionInfo) async {
    _sessionInfo = sessionInfo;
  }

  @override
  Future<SessionInfo> readSession() async {
    return _sessionInfo;
  }

  @override
  Future<void> updateSession(SessionInfo sessionInfo) async {
    _sessionInfo = sessionInfo;
  }
}

Specifics #

Only a few methods will actually set the session: apiInfo() and authStatus(). This means that the session will be empty if you don't call apiInfo() before any other call.

Please, refer to the example for more details.

1.0.5 #

  • Adds receive-cards request to api and wrapper.

1.0.4 #

  • Fixes get-cards return type.

1.0.3 #

  • Adds get-cards request to api and wrapper.

1.0.2 #

  • Adds example. Makes auth params required. Readme updates.

1.0.1 #

  • More tests, CI and fixes.

1.0.0 #

example/thetale_api_example.dart

import 'dart:io';

import 'package:http/http.dart';
import 'package:thetale_api/thetale_api.dart';

const String apiUrl = "https://the-tale.org";
const String applicationId = "epic_tale_api_example";
const String appVersion = "0.0.1";

const String applicationName = "Название приложения";
const String applicationInfo = "Информация о приложении";
const String applicationDescription = "Описание приложения";

main() async {
  final wrapper = WrapperBuilder().build(apiUrl, applicationId, appVersion);
  wrapper.setStorage(LocalSessionStorage());

  final info = await wrapper.apiInfo();
  stdout.write("Session id: ${info.sessionInfo.sessionId}");

  final thirdPartyLink = await wrapper.auth(
      applicationName, applicationInfo, applicationDescription);
  stdout.writeln(
      "Authorize application by following the link: ${apiUrl}${thirdPartyLink.authorizationPage}");

  TaleResponse<ThirdPartyStatus> status;
  do {
    sleep(Duration(seconds: 25));
    status = await wrapper.authStatus();
  } while (!status.data.isAccepted);

  stdout.writeln("Ну привет, ${status.data.accountName}");
  final gameInfo = await wrapper.gameInfo();
  stdout.writeln("${gameInfo.account.hero.base.name} уже заждался.");
}

class LocalSessionStorage implements SessionStorage {
  SessionInfo _sessionInfo;

  @override
  Future<void> addSession(SessionInfo sessionInfo) async {
    _sessionInfo = sessionInfo;
  }

  @override
  Future<SessionInfo> readSession() async {
    return _sessionInfo;
  }

  @override
  Future<void> updateSession(SessionInfo sessionInfo) async {
    _sessionInfo = sessionInfo;
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  thetale_api: ^1.0.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:thetale_api/thetale_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
94
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

We analyzed this package on Oct 16, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:thetale_api/thetale_api.dart.

Health issues and suggestions

Document public APIs. (-0.82 points)

164 out of 165 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/api.dart.

Run dartfmt to format lib/src/api.dart.

Format lib/src/converters.dart.

Run dartfmt to format lib/src/converters.dart.

Format lib/src/models.dart.

Run dartfmt to format lib/src/models.dart.

Format lib/src/session.dart.

Run dartfmt to format lib/src/session.dart.

Format lib/thetale_api.dart.

Run dartfmt to format lib/thetale_api.dart.

Maintenance suggestions

The package description is too short. (-6 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
http ^0.12.0+2 0.12.0+2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
mockito ^3.0.1
pedantic ^1.0.0 1.8.0+1
test ^1.0.0
test_coverage ^0.2.0