Last updated:
0 purchases
rollapi
Roll-API Dart #
Dart library for Roll-API
This icon ↑ indicates if API is working right now
What the hell is Roll-API?? #
It's a super cool API that allows you to roll a real dice and get it's number!
Check it out: https://github.com/TheLastGimbus/Roll-API
How to use #
Import:
import 'package:rollapi/rollapi.dart' as roll;
copied to clipboard
Simple way - use getRandomNumber():
print("Rolling a dice...");
roll.getSimpleResult().then((result) => print("Number: $result"));
copied to clipboard
It returns pure Future<int>, and throws an exception if something failed
More advance way: use makeRequest():
It returns a Request object, which contains UUID and Stream of values:
var request = await roll.makeRequest();
request.stateStream.listen((event) {
switch (event.key) {
case roll.RequestState.queued:
print('Wating...');
// .queued value is an ETA DateTime - which can be null
if (event.value != null) {
var sec = (event.value as DateTime).difference(DateTime.now());
print('Time left: $sec seconds');
}
break;
case roll.RequestState.failed:
print('Request failed :(((');
// .failed value is an exception - you can throw it
throw event.value;
break;
case roll.RequestState.finished:
print('Finished!!! Number: ${event.value}');
break;
default:
break;
}
});
copied to clipboard
If you want to use another instance, because you want to test your own or official is currently down, you can:
import 'package:rollapi/rollapi.dart' as roll;
roll.API_BASE_URL = 'http://192.168.1.100:5000/api/';
copied to clipboard
CLI #
This package also offers really nice CLI, that can, for example, generate you a random password!
You can either get it with dart pub global activate rollapi, or from GitHub releases:
https://github.com/TheLastGimbus/rollapi_dart/releases/
Then, you can run:
$ rollapi roll
Rolling the dice...
1
copied to clipboard
$ rollapi pwd --numbers -l 6
Generating random password...
0%
8%
...
92%
DONE! Your password: cwgl0r
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.