luminus_api 0.1.18

A library for Dart developers who's in need of LumiNUS API.

Created from templates made available by Stagehand under a BSD-style license.

Usage #

A simple usage example:

import 'package:luminus_api/luminus_api.dart';
import 'package:dotenv/dotenv.dart' show load, env;

main(List<String> args) async {
  // Remember to load the env var for the main() of your own application!
  load();
  Future<Authentication> auth = Future.delayed(
      Duration(seconds: 3),
      () => Authentication(
          password: env['LUMINUS_PASSWORD'],
          username: env['LUMINUS_USERNAME']));
  var modules = await API.getModules(auth);
  for (Module mod in modules) {
    print(mod.courseName);
    print(mod.id);
    print(await API.getAnnouncements(auth, mod));
    var dirs = await API.getModuleDirectories(auth, mod);
    for (var dir in dirs) {
      var items = await API.getItemsFromDirectory(auth, dir);
      print(items);
      for (var item in items) {
        if (item is File) {
          print(await API.getDownloadUrl(auth, item));
        }
      }
    }
  }
  print(await API.getProfile(auth));
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.1.1 #

  • Initial version.

0.1.2 #

  • Update sample code.

0.1.3 #

  • Cache JWT (no expiry check though)
  • Update API link

0.1.4 #

  • Fixed a serious problem =)

0.1.5 #

  • Now all the provided APIs work properly =)

0.1.6 #

  • Hide files that are necessary and exported inside luminus_api.dart
  • Fixed the dependency issue.
  • Added documentation for luminus_api.dart, which is the entry of this package.
  • Implemented automatic management of JWT renewal as long as you stick to the same Authentication objected created.

0.1.7 #

  • Downgraded dependecy requirement of meta
  • Removed unnecessary imports.
  • Made the package description longer so that pub.dev doesn't complain.

0.1.8 #

  • Maybe LumiNUS internally has a shorter token expiry time, I manually set the _jwtExpiresIn as 10 minutes and _refreshTokenExpiresIn as an hour. Please send an issue if this doesn't solve your problem.
  • Provide exceptions for API call HTTP exceptions (as specified in LumiNUS API documentation).
  • Add timeouts for HTTP requests.
  • Add methods for enforced re-authentication: forcedRefresh method in Authorization.

0.1.9 #

  • Overriden == for data abstractions to resolve this issue.

0.1.10 - 0.1.15 #

  • Support FutureOr
  • Throw AuthorizationException when something goes wrong in _getJwt
  • Added RestartAuthException to deal with weird LumiNUS behavior
  • Overrode hashCode for File class

0.1.16-0.1.18 #

  • Support for notifictaions
  • Provide WrongCredentialsException
  • 10x timeout threshold

example/luminus_api_example.dart

import 'package:luminus_api/luminus_api.dart';
import 'package:dotenv/dotenv.dart' show load, env;
// import 'dart:io' as io;

main(List<String> args) async {
  // Remember to load the env var for the main() of your own application!
  load();
  Future<Authentication> auth = Future.delayed(
      Duration(seconds: 3),
      () => Authentication(
          password: env['LUMINUS_PASSWORD'],
          username: env['LUMINUS_USERNAME']));
  var modules = await API.getModules(auth);
  for (Module mod in modules) {
    print(mod.courseName);
    print(mod.id);
    print(await API.getAnnouncements(auth, mod));
    var dirs = await API.getModuleDirectories(auth, mod);
    for (var dir in dirs) {
      var items = await API.getItemsFromDirectory(auth, dir);
      print(items);
      for (var item in items) {
        if (item is File) {
          print(await API.getDownloadUrl(auth, item));
        }
      }
    }
  }
  print(await API.getProfile(auth));
  // var res = io.File('./res');
  // var sink = res.openWrite();
  // sink.write(await API.getActiveAnnouncements(auth));
  // await sink.flush();
  // await sink.close();
}

Use this package as a library

1. Depend on it

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


dependencies:
  luminus_api: ^0.1.18

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:luminus_api/luminus_api.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

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

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, other

Primary library: package:luminus_api/luminus_api.dart with components: io.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.0 <3.0.0
convert ^2.1.1 2.1.1
cookie_jar ^1.0.0 1.0.1
dio ^2.1.3 2.1.13
html ^0.14.0+2 0.14.0+2
http ^0.12.0+2 0.12.0+2
meta ^1.1.6 1.1.7
Transitive dependencies
async 2.2.0
charcode 1.1.2
collection 1.14.11
csslib 0.16.1
http_parser 3.1.3
path 1.6.2
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
dotenv ^1.0.0
pedantic ^1.0.0 1.8.0+1
test ^1.0.0

Admin