This is a non-official wrapper for the Pindo API written in Dart.
Click here to learn more about Pindo.
Add the dependency
dependendies:
pindo_client: ^1.0.0
You need a PindoClient()
object to use all the functionalities offered by the API.
Pindo Client uses Dio under the hood to handle http requests. If you are using Dio in your app and already have a Dio object initialized, reusing it is recommended but not required while initializing a new PindoClient()
.
final pindo = PindoClient();
To create a new Pindo account, use the function register
that takes a username, an email and a password as parameters (all of them are as strings and required).
import 'package:pindo_client/pindo_client.dart';
Future<void> main() async{
final pindo = PindoClient();
await pindo.register(
username:'pindo',
email:'pindo@test.com',
password: 'awesome-password'
).then((_)=>print('Logged in')).onError((e,s)=>print(e));
}
To get the user's token, use the function getToken
that takes a username and a password (all as string and required); and returns the token(string).
import 'package:pindo_client/pindo_client.dart';
Future<void> main() async{
final pindo = PindoClient();
await pindo.getToken(
username:'pindo',
password:'awesome-password'
).then((token)=>print(token)).onError((e,s)=>print(e));
}
To refresh the user's token, use the function refreshToken
that takes a username and a password(all as string and required); and returns the refreshed token(string).
import 'package:pindo_client/pindo_client.dart';
Future<void> main() async{
final pindo = PindoClient();
await pindo.refreshToken(
username:'pindo',
password:'awesome-password'
).then((token)=>print(token)).onError((e,s)=>print(e));
}
To get the user's balance, use the function balance
that takes the user's token and returns their balance(double).
import 'package:pindo_client/pindo_client.dart';
Future<void> main() async{
final pindo = PindoClient();
await pindo.balance(
token:'awesomest-token-in-the-entire-world',
).then((balance)=>print('$balance')).onError((e,s)=>print(e));
}
To send an SMS, use the functionsendSMS
that takes the parameters: token(sender's token), to(the receiver's phone number), from(the sender's name), and text(the sms body) all of them as strings. This function returns the user's remaining balance after they have sent the SMS.
Note: Only works with Rwandan 🇷🇼 phone numbers
import 'package:pindo_client/pindo_client.dart';
Future<void> main() async{
final pindo = PindoClient();
await pindo.sendSMS(
token:'awesomest-token-in-the-entire-world',
to: '+250789159557', // Please don't spam me!
from: 'Pindo',
text: 'Hello Pindo',
).then((balance)=>print('$balance')).onError((e,s)=>print(e));
}
Please make sure your code is tested before pushing
Visit the website here; or check the Pindo on Github.