A wrapper for the Pindo API written in Dart.
Click here to learn more about Pindo.
To see the example app, open https://pindo-client.netlify.app
Add the dependency
dependendies:
pindo: ^1.0.2
You need a Pindo()
object to use all the functionalities offered by the API.
Pindo-Dart 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 Pindo()
.
// If you are working with `Dio` in your app, you can use
final dio = Dio();
final pindo = Pindo(dio:dio)
// If you are not using `Dio` or simply don't wanna use it in your Pindo object, use
final pindo = Pindo();
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/pindo.dart';
Future<void> main() async{
final pindo = Pindo();
await pindo.register(
username:'pindo',
email:'[email protected]',
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/pindo.dart';
Future<void> main() async{
final pindo = Pindo();
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/pindo.dart';
Future<void> main() async{
final pindo = Pindo();
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/pindo.dart';
Future<void> main() async{
final pindo = Pindo();
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 function sendSMS
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.
import 'package:pindo/pindo.dart';
Future<void> main() async{
final pindo = Pindo();
await pindo.sendSMS(
token:'<my-token>',
to: '<my-phone-number>',
from: 'Pindo',
text: 'Hello Pindo',
).then((balance)=>print('$balance')).onError((e,s)=>print('$e'));
}
To update a pindo organization, use the function organization
which takes four parameters: a token(String), the organization name(String), a webhook url(String) and the number of retries(int). This function returns the organization's URL.
import 'package:pindo/pindo.dart';
Future<void> main() async{
final pindo = Pindo();
await pindo.organization(
token: '<my-token>',
name: '<org-name>',
webHookURL: 'https://example.com/hook',
retriesCount: 7,
).then((url)=>print(url)).onError((e,s)=>print('$e'));
}
To send the user an email to reset their password, use the function forgotPassword
which takes one parameter: the user's email addrres.
import 'package:pindo/pindo.dart';
Future<void> main()async{
final pindo = Pindo();
await pindo.forgotPassword(email: '[email protected]').then(
(_)=>print('Email sent')).onError((e,s)=>print('$e'));
}
Please make sure your code is tested before pushing
Visit the website here; or check the Pindo on Github.