A most easily usable Duolingo API wrapper in Dart. Duolingo4D is an open-sourced Dart library.

Overview

A most easily usable Duolingo API wrapper in Dart!

pub package Dart

1. About Duolingo4D

Duolingo4D is an open-sourced Dart library.
With Duolingo4D, you can easily integrate your application with the Duolingo API.

Duolingo4D is an unofficial library.

1.1. Supported Duolingo API

Name Auth Required Remarks
Version Info You can fetch metadata about the various configurations of services in Duolingo.
Authentication Authenticate user by using Duolingo registered username or email address and password.
User You can fetch detailed user information.
Overview You can fetch information on all the words user have learned in Duolingo.
Word Hint You can fetch hint information about words and sentences.
Switch Language You can switch the learning language.

1.2. Introduction

1.2.1. Install Library

With Dart:

 dart pub add duolingo4d

With Flutter:

 flutter pub add duolingo4d

1.2.2. Import It

import 'package:duolingo4d/duolingo4d.dart';

1.2.3. Use Duolingo4D

The easiest way to use it is to get a singleton instance from Duolingo and call each method.

All response entities returned from the methods of Duolingo contain status codes and header information when HTTP communication is performed in internal processing.

For example, when performing the authentication process for a user, it will look like this:

void main() async {
  final duolingo = Duolingo.instance;

  final authResponse = await duolingo.authenticate(
    username: 'test_username',
    password: 'test_password',
  );

  if (authResponse.status.isNotOk) {
    // Client or Server error or something.
    authResponse.status.reasonPhrase;
    authResponse.headers;
    return;
  }

  if (authResponse.hasError) {
    // When there is an error on authentication.
    final authError = authResponse.error!;
    print(authError.code);
    print(authError.reason);

    authError.isInvalidUser; // Returns true if user is invalid.
    authError.isInvalidPassword; // Returns true if password is invalid.
    return;
  }

  // Do something if user is authenticated.
}

1.3. Using

1.3.1. Version Info API

Auth Required Snippet JSON
final response = await Duolingo.instance.versionInfo(); Check!

The Version Info API allows you to fetch metadata about the configuration of Duolingo services.
This metadata includes the TTS data used to play back the audio of the words, as well as mapping information for the languages supported by Duolingo.

void main() async {
  final duolingo = Duolingo.instance;

  final versionInfoResponse = await duolingo.versionInfo();
  final ttsVoiceConfiguration = versionInfoResponse.ttsVoiceConfiguration;

  for (final voiceDirections in ttsVoiceConfiguration.voiceDirections) {
    print(voiceDirections.language);
    print(voiceDirections.voice);
  }
}

1.3.2. Authentication API

Auth Required Snippet JSON
final response = await Duolingo.instance.authenticate(username: 'test_username', password: 'test_password',); Check!

You can use username and password to authenticate user registered with Duolingo. The registered e-mail address can be used for authentication in addition to the username.

In order to fetch the response you expect from each API that requires authentication, at first you need to use this authentication API to authenticate that the username and password entered are valid.

Note:
When a user is authenticated, the cookie information and session information for the Duolingo service is managed internally by Duolingo4D, so there is no need to be aware of this information after calling the API.

void main() async {
  final duolingo = Duolingo.instance;

  final authResponse = await duolingo.authenticate(
    username: 'test_username',
    password: 'test_password',
  );

  if (authResponse.status.isNotOk) {
    // Client or Server error or something.
    authResponse.status.reasonPhrase;
    authResponse.headers;
    return;
  }

  if (authResponse.hasError) {
    // When there is an error on authentication.
    final authError = authResponse.error!;
    print(authError.code);
    print(authError.reason);

    authError.isInvalidUser; // Returns true if user is invalid.
    authError.isInvalidPassword; // Returns true if password is invalid.
    return;
  }

  // Do something if user is authenticated.
}

Note:
If you try to authenticate again using information from an account that has already been authenticated, the Duolingo API will return an invalid password response.

1.3.3. User API

Auth Required Snippet JSON
final response = await Duolingo.instance.user(userId: authResponse.userId); Check!

From the User API, you can get detailed user information associated with the user ID.

The user ID is included in the response returned when the user authentication is completed. Please refer to the following implementation for details.

The user information also includes all the course information and skill information user have learned.

If user authentication has not been completed, data cannot be fetched.

void main() async {
  final duolingo = Duolingo.instance;

  final authResponse = await duolingo.authenticate(
    username: 'test_username',
    password: 'test_password',
  );

  final userResponse = await duolingo.user(userId: authResponse.userId);

  print(userResponse.name);
  print(userResponse.lingots);

  for (final course in userResponse.courses) {
    print(course.title);
    print(course.xp);
  }

  for (final skill in userResponse.currentCourse.skills) {
    if (skill.isAccessible) {
      print(skill.name);
      print(skill.proficiency);
      print(skill.tipsAndNotes);
    }
  }
}

1.3.4. Overview API

Auth Required Snippet JSON
final response = await Duolingo.instance.overview(); Check!

From the Overview API, you can fetch information about all the words you have learned in the course you have selected. The details that can be retrieved about a word will vary depending on the course and word.

If user authentication has not been completed, data cannot be fetched.

void main() async {
  final duolingo = Duolingo.instance;

  final authResponse = await duolingo.authenticate(
    username: 'test_username',
    password: 'test_password',
  );

  final overviewResponse = await duolingo.overview();

  for (final vocabulary in overviewResponse.vocabularies) {
      print(vocabulary.word);
  }
}

1.3.5. Word Hint API

Auth Required Snippet JSON
final response = await Duolingo.instance.wordHint(fromLanguage: 'en', learningLanguage: 'es', sentence: 'boligrafos',); Check!

You can fetch hint information for any word or sentence from the Word Hint API. Since the hint information is hint data managed by Duolingo, the accuracy of the translation data cannot be guaranteed.

The argument learningLanguage should be the language code corresponding to the word, and fromLanguage should be the language code corresponding to the hint. The sentence can be sentences as well as single words.

void main() async {
  final duolingo = Duolingo.instance;

  final wordHintResponse = await duolingo.wordHint(
    fromLanguage: 'en',
    learningLanguage: 'es',
    sentence: 'boligrafos',
  );

  for (final token in wordHintResponse.tokens) {
    final headers = token.table.headers;
    for (final header in headers) {
      print(header.selected);
      print(header.token);
    }

    final rows = token.table.rows;
    for (final row in rows) {
      for (final cell in row.cells) {
        print(cell.hint);
      }
    }
  }
}

1.3.6. Switch Language API

Auth Required Snippet
final response = await Duolingo.instance.switchLanguage(fromLanguage: 'es', learningLanguage: 'en',);

The Switch Language API allows you to switch between the courses supported by Duolingo. The mapping information for the courses that can be switched using the Switch Language API can be obtained from the Version Info API.

For the argument learningLanguage, specify the language to be learned after switching. And for fromLanguage, specify the language to be used when learning that learningLanguage.

void main() async {
  final duolingo = Duolingo.instance;

  final authResponse = await duolingo.authenticate(
    username: 'test_username',
    password: 'test_password',
  );

  final switchLanguageResponse = await duolingo.switchLanguage(
    fromLanguage: 'es',
    learningLanguage: 'en',
  );

  print(switchLanguageResponse.statusCode);
  print(switchLanguageResponse.reasonPhrase);
}

1.4. License

Copyright (c) 2021, Kato Shinya. All rights reserved.
Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.

1.5. More Information

Duolingo4D was designed and implemented by Kato Shinya.

Comments
  • Leaderboard APIを参照する機能の追加

    Leaderboard APIを参照する機能の追加

    以下のURLを参照する機能を追加する。

    https://duolingo-leaderboards-prod.duolingo.com/leaderboards/7d9f5dd1-8423-491a-91f2-2532052038ce/users/557897808?client_unlocked=true

    Type: design Type: new feature 
    opened by myConsciousness 1
  • Stories APIに参照できる機能を追加

    Stories APIに参照できる機能を追加

    以下のURLに参照することができる機能を追加する。

    https://stories.duolingo.com/api2/stories?fromLanguage=en&learningLanguage=ja&illustrationFormat=png

    illustrationFormat はsvg, png, pdfに対応している。

    Type: design Type: new feature 
    opened by myConsciousness 1
  • Forum / Forum Comment APIを参照する機能の追加

    Forum / Forum Comment APIを参照する機能の追加

    以下のURLを参照する機能を追加する。

    https://forum-api.duolingo.com/comments?sort_by=new&topic_id=null

    topic_id が null の場合はForumのコメントリストが返却され、 特定の topic_id が指定された場合はそのトピックのコメントリストを返却する。

    sort_by は hot, new, 'followed' がある。

    Type: design Type: new feature 
    opened by myConsciousness 1
  • Type string is not a subtype of type bool

    Type string is not a subtype of type bool

    In json_impl.dart is this code: @override bool getBool({ required String key, bool defaultValue = false, }) => _resource[key] ?? defaultValue; but if _resource[key] is not type bool, it shows error

    opened by samuelvasecka 1
  • ディスカッションをフォロー / アンフォローする機能の追加

    ディスカッションをフォロー / アンフォローする機能の追加

    以下のURLを使用してディスカッションをフォロー / アンフォローすることができる機能を追加する。 どちらもPOST送信で正常に処理される。

    https://forum-api.duolingo.com/comments/{commentId (like 54867020)}/watch https://forum-api.duolingo.com/comments/{commentId (like 54867020)}/unwatch

    Type: design Type: new feature 
    opened by myConsciousness 0
  • Events APIを参照できる機能の追加

    Events APIを参照できる機能の追加

    以下のURLを参照できる機能を追加する。

    https://events-login.duolingo.com/api/2/events?available_only=true&end_range=2022-01-15T16:14:36.942Z&fields=hosts&is_featured_only=false&language_ids=ja&must_start_within_range=false&start_range=2021-12-16T16:14:36.942Z

    Type: design Type: new feature 
    opened by myConsciousness 0
Releases(1.3.0)
  • 1.3.0(Jan 24, 2022)

  • 1.2.0(Jan 17, 2022)

  • 1.1.1(Jan 12, 2022)

  • 1.1.0(Jan 12, 2022)

  • 1.0.0(Jan 11, 2022)

  • 0.4.1(Jan 5, 2022)

  • 0.4.0(Jan 5, 2022)

  • 0.3.0(Dec 28, 2021)

  • 0.2.0(Dec 26, 2021)

  • 0.1.4(Dec 22, 2021)

  • 0.1.3(Dec 14, 2021)

  • 0.1.0(Dec 13, 2021)

  • 0.0.5(Dec 5, 2021)

  • 0.0.4(Dec 4, 2021)

  • 0.0.3(Dec 4, 2021)

  • 0.0.2(Dec 3, 2021)

  • 0.0.1(Dec 2, 2021)

Owner
Kato Shinya
Freelance software developer. Web and Batch development in Java. Also mobile development in Flutter.
Kato Shinya
A most easily usable JSON wrapper library in Dart

A most easily usable JSON response wrapper library in Dart! 1. About 1.1. Introd

Kato Shinya 2 Jan 4, 2022
A most easily usable cookie management library in Dart. With SweetCookieJar, you can easily manage cookie on your application.

A most easily usable cookie management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use SweetCookieJar 1

Kato Shinya 9 Oct 27, 2022
A most easily usable cache management library in Dart. With CacheStorage, you can easily manage cache on your application.

A most easily usable cache management library in Dart! 1. About 1.1. Introduction 1.1.1. Install Library 1.1.2. Import It 1.1.3. Use CacheStorage 1.2.

Kato Shinya 1 Dec 13, 2021
A most easily usable improvement rate calculator library in Dart.

A most easily usable improvement rate calculator library in Dart. With ImprovementRate, you can easily calculate improvement rate on your application.

Kato Shinya 1 Dec 27, 2021
AuthorizationHeader is an open-sourced Dart library. With AuthorizationHeader, you can easily manage authorization header on your application.

A most easily usable authorization header management library in Dart! 1. About 1.1. Supported 1.1.1. Authorization Header 1.1.2. Authorization Type 1.

Kato Shinya 3 Dec 24, 2021
Federico 1 Feb 3, 2022
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Ionicfirebaseapp 3.7k Jan 1, 2023
Most popular and easy to use open source UI library with 1000+ Widgets to build flutter app.

GetWidget is a 100% free Flutter open-source UI Kit library built with Flutter SDK to make Flutter development easier and more joyful than ever. GetWi

Ionicfirebaseapp 3.7k Jan 3, 2023
A Dart wrapper of the SMHI Open Data API

SMHI Open Data for Dart This package is in early development and some features may not work as intended. If so, feel free to submit a pull request. A

Lukas 1 Sep 19, 2022
The lightweight and powerful wrapper library for Twitter Ads API written in Dart and Flutter 🐦

TODO: Put a short description of the package here that helps potential users know whether this package might be useful for them. Features TODO: List w

Twitter.dart 2 Aug 26, 2022
DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures!

dice_bear Flutter Package DiceBear API wrapper. DiceBear is an avatar library for designers and developers. Generate random avatar profile pictures! C

Zaif Senpai 8 Oct 31, 2022
Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight Node.js based Bhagavad Gita API [An open source rest api on indian Vedic Scripture Shrimad Bhagavad Gita].

Gita Bhagavad Gita flutter app. Download App - Playstore Web Application About Bhagavad Gita app using flutter & Bhagavad-Gita-API is A lightweight No

Ravi Kovind 7 Apr 5, 2022
A simple dart zeromq implementation/wrapper around the libzmq C++ library

dartzmq A simple dart zeromq implementation/wrapper around the libzmq C++ library Features Currently supported: Creating sockets (pair, pub, sub, req,

Moritz Wirger 18 Dec 29, 2022
A wrapper around our Cocoa and Java client library SDKs, providing iOS and Android support for those using Flutter and Dart.

Ably Flutter Plugin A Flutter plugin wrapping the ably-cocoa (iOS) and ably-java (Android) client library SDKs for Ably, the platform that powers sync

Ably Realtime - our client library SDKs and libraries 46 Dec 13, 2022
A MangaDex API wrapper for Dart/Flutter

A MangaDex API wrapper for Dart Usage A simple usage example: import 'package:mangadex_api/mangadex_api.dart'; main() { var client = MDClient();

Matyáš Caras 4 Dec 2, 2022
An api wrapper for FortniteApi.io in dart.

Fortnite An api wrapper for FortniteApi.io in dart. Installation Add this to your package's pubspec.yaml file: dependencies: fortnite_api_io: any

Vanxh 3 Jan 29, 2022
Dart wrapper for mpesa daraja api by safaricom

mpesa-daraja-plugin-flutter-dart dart wrapper for mpesa daraja api by safaricom Features [Done]Lipa na mpesa [x] [inprogress] C2B [inprogress] B2B [in

Anselmo.Jr 11 Nov 6, 2022
App HTTP Client is a wrapper around the HTTP library Dio to make network requests and error handling simpler, more predictable, and less verbose.

App HTTP Client App HTTP Client is a wrapper around the HTTP library Dio to make network requests and error handling simpler, more predictable, and le

Joanna May 44 Nov 1, 2022
Binding and high-level wrapper on top of libssh - The SSH library!

Dart Binding to libssh version 0.9.6 binding and high-level wrapper on top of libssh - The SSH library! libssh is a multiplatform C library implementi

Isaque Neves 2 Dec 20, 2021