2020-03-27 02:20:07 +13:00
|
|
|
|
2020-04-09 05:26:18 +12:00
|
|
|
|
2019-09-20 18:33:11 +12:00
|
|
|
import 'package:dio/dio.dart';
|
2020-03-27 02:20:07 +13:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
import "../client.dart";
|
2020-03-27 02:20:07 +13:00
|
|
|
import '../enums.dart';
|
2020-04-06 01:23:15 +12:00
|
|
|
import "../service.dart";
|
2019-09-20 18:33:11 +12:00
|
|
|
|
|
|
|
class Avatars extends Service {
|
2020-04-06 01:23:15 +12:00
|
|
|
Avatars(Client client): super(client);
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-11 22:02:21 +12:00
|
|
|
/// Get Browser Icon
|
|
|
|
///
|
2019-10-14 09:19:06 +13:00
|
|
|
/// You can use this endpoint to show different browser icons to your users.
|
|
|
|
/// The code argument receives the browser code as it appears in your user
|
2019-10-09 21:40:02 +13:00
|
|
|
/// /account/sessions endpoint. Use width, height and quality arguments to
|
|
|
|
/// change the output settings.
|
2020-04-11 22:02:21 +12:00
|
|
|
///
|
2020-04-06 01:23:15 +12:00
|
|
|
Future<Response> getBrowser({@required String code, int width = 100, int height = 100, int quality = 100}) {
|
|
|
|
final String path = '/avatars/browsers/{code}'.replaceAll(RegExp('{code}'), code);
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
final Map<String, dynamic> params = {
|
|
|
|
'width': width,
|
|
|
|
'height': height,
|
|
|
|
'quality': quality,
|
|
|
|
};
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-11 22:02:21 +12:00
|
|
|
final Map<String, String> headers = {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
};
|
|
|
|
|
|
|
|
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
2020-04-11 22:02:21 +12:00
|
|
|
|
|
|
|
/// Get Credit Card Icon
|
|
|
|
///
|
2019-10-14 09:19:06 +13:00
|
|
|
/// Need to display your users with your billing method or their payment
|
2019-10-09 21:40:02 +13:00
|
|
|
/// methods? The credit card endpoint will return you the icon of the credit
|
|
|
|
/// card provider you need. Use width, height and quality arguments to change
|
|
|
|
/// the output settings.
|
2020-04-11 22:02:21 +12:00
|
|
|
///
|
2020-05-18 17:55:27 +12:00
|
|
|
String getCreditCard({@required String code, int width = 100, int height = 100, int quality = 100}) {
|
2020-04-06 01:23:15 +12:00
|
|
|
final String path = '/avatars/credit-cards/{code}'.replaceAll(RegExp('{code}'), code);
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
final Map<String, dynamic> params = {
|
|
|
|
'width': width,
|
|
|
|
'height': height,
|
|
|
|
'quality': quality,
|
2020-05-18 17:55:27 +12:00
|
|
|
'project': client.config['project'],
|
2020-04-06 01:23:15 +12:00
|
|
|
};
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-05-18 17:55:27 +12:00
|
|
|
Uri endpoint = Uri.parse(client.endPoint);
|
2020-05-24 17:30:49 +12:00
|
|
|
Uri location = new Uri(scheme: endpoint.scheme,
|
2020-05-18 17:55:27 +12:00
|
|
|
host: endpoint.host,
|
|
|
|
port: endpoint.port,
|
|
|
|
path: endpoint.path + path,
|
|
|
|
queryParameters:params,
|
|
|
|
);
|
2020-04-11 22:02:21 +12:00
|
|
|
|
2020-05-24 17:30:49 +12:00
|
|
|
return location.toString();
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
2020-04-11 22:02:21 +12:00
|
|
|
|
|
|
|
/// Get Favicon
|
|
|
|
///
|
2019-10-09 21:40:02 +13:00
|
|
|
/// Use this endpoint to fetch the favorite icon (AKA favicon) of a any remote
|
|
|
|
/// website URL.
|
2020-04-11 22:02:21 +12:00
|
|
|
///
|
2020-05-18 17:55:27 +12:00
|
|
|
String getFavicon({@required String url}) {
|
2020-04-06 01:23:15 +12:00
|
|
|
final String path = '/avatars/favicon';
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
final Map<String, dynamic> params = {
|
|
|
|
'url': url,
|
2020-05-18 17:55:27 +12:00
|
|
|
'project': client.config['project'],
|
2020-04-06 01:23:15 +12:00
|
|
|
};
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-05-18 17:55:27 +12:00
|
|
|
Uri endpoint = Uri.parse(client.endPoint);
|
2020-05-24 17:30:49 +12:00
|
|
|
Uri location = new Uri(scheme: endpoint.scheme,
|
2020-05-18 17:55:27 +12:00
|
|
|
host: endpoint.host,
|
|
|
|
port: endpoint.port,
|
|
|
|
path: endpoint.path + path,
|
|
|
|
queryParameters:params,
|
|
|
|
);
|
2020-04-11 22:02:21 +12:00
|
|
|
|
2020-05-24 17:30:49 +12:00
|
|
|
return location.toString();
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
2020-04-11 22:02:21 +12:00
|
|
|
|
|
|
|
/// Get Country Flag
|
|
|
|
///
|
2019-10-09 21:40:02 +13:00
|
|
|
/// You can use this endpoint to show different country flags icons to your
|
2019-10-14 09:19:06 +13:00
|
|
|
/// users. The code argument receives the 2 letter country code. Use width,
|
2019-10-09 21:40:02 +13:00
|
|
|
/// height and quality arguments to change the output settings.
|
2020-04-11 22:02:21 +12:00
|
|
|
///
|
2020-05-18 17:55:27 +12:00
|
|
|
String getFlag({@required String code, int width = 100, int height = 100, int quality = 100}) {
|
2020-04-06 01:23:15 +12:00
|
|
|
final String path = '/avatars/flags/{code}'.replaceAll(RegExp('{code}'), code);
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
final Map<String, dynamic> params = {
|
|
|
|
'width': width,
|
|
|
|
'height': height,
|
|
|
|
'quality': quality,
|
2020-05-18 17:55:27 +12:00
|
|
|
'project': client.config['project'],
|
2020-04-06 01:23:15 +12:00
|
|
|
};
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-05-18 17:55:27 +12:00
|
|
|
Uri endpoint = Uri.parse(client.endPoint);
|
2020-05-24 17:30:49 +12:00
|
|
|
Uri location = new Uri(scheme: endpoint.scheme,
|
2020-05-18 17:55:27 +12:00
|
|
|
host: endpoint.host,
|
|
|
|
port: endpoint.port,
|
|
|
|
path: endpoint.path + path,
|
|
|
|
queryParameters:params,
|
|
|
|
);
|
2020-04-11 22:02:21 +12:00
|
|
|
|
2020-05-24 17:30:49 +12:00
|
|
|
return location.toString();
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
2020-04-11 22:02:21 +12:00
|
|
|
|
|
|
|
/// Get Image from URL
|
|
|
|
///
|
2019-10-09 21:40:02 +13:00
|
|
|
/// Use this endpoint to fetch a remote image URL and crop it to any image size
|
|
|
|
/// you want. This endpoint is very useful if you need to crop and display
|
2019-10-14 09:19:06 +13:00
|
|
|
/// remote images in your app or in case you want to make sure a 3rd party
|
2019-10-09 21:40:02 +13:00
|
|
|
/// image is properly served using a TLS protocol.
|
2020-04-11 22:02:21 +12:00
|
|
|
///
|
2020-05-18 17:55:27 +12:00
|
|
|
String getImage({@required String url, int width = 400, int height = 400}) {
|
2020-04-06 01:23:15 +12:00
|
|
|
final String path = '/avatars/image';
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
final Map<String, dynamic> params = {
|
|
|
|
'url': url,
|
|
|
|
'width': width,
|
|
|
|
'height': height,
|
2020-05-18 17:55:27 +12:00
|
|
|
'project': client.config['project'],
|
2020-04-06 01:23:15 +12:00
|
|
|
};
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-05-18 17:55:27 +12:00
|
|
|
Uri endpoint = Uri.parse(client.endPoint);
|
2020-05-24 17:30:49 +12:00
|
|
|
Uri location = new Uri(scheme: endpoint.scheme,
|
2020-05-18 17:55:27 +12:00
|
|
|
host: endpoint.host,
|
|
|
|
port: endpoint.port,
|
|
|
|
path: endpoint.path + path,
|
|
|
|
queryParameters:params,
|
|
|
|
);
|
2020-04-11 22:02:21 +12:00
|
|
|
|
2020-05-24 17:30:49 +12:00
|
|
|
return location.toString();
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
2020-04-11 22:02:21 +12:00
|
|
|
|
|
|
|
/// Get QR Code
|
|
|
|
///
|
2019-10-09 21:40:02 +13:00
|
|
|
/// Converts a given plain text to a QR code image. You can use the query
|
|
|
|
/// parameters to change the size and style of the resulting image.
|
2020-04-11 22:02:21 +12:00
|
|
|
///
|
2020-05-18 17:55:27 +12:00
|
|
|
String getQR({@required String text, int size = 400, int margin = 1, int download = 0}) {
|
2020-04-06 01:23:15 +12:00
|
|
|
final String path = '/avatars/qr';
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-04-06 01:23:15 +12:00
|
|
|
final Map<String, dynamic> params = {
|
|
|
|
'text': text,
|
|
|
|
'size': size,
|
|
|
|
'margin': margin,
|
|
|
|
'download': download,
|
2020-05-18 17:55:27 +12:00
|
|
|
'project': client.config['project'],
|
2020-04-06 01:23:15 +12:00
|
|
|
};
|
2019-09-20 18:33:11 +12:00
|
|
|
|
2020-05-18 17:55:27 +12:00
|
|
|
Uri endpoint = Uri.parse(client.endPoint);
|
2020-05-24 17:30:49 +12:00
|
|
|
Uri location = new Uri(scheme: endpoint.scheme,
|
2020-05-18 17:55:27 +12:00
|
|
|
host: endpoint.host,
|
|
|
|
port: endpoint.port,
|
|
|
|
path: endpoint.path + path,
|
|
|
|
queryParameters:params,
|
|
|
|
);
|
2020-04-11 22:02:21 +12:00
|
|
|
|
2020-05-24 17:30:49 +12:00
|
|
|
return location.toString();
|
2019-09-20 18:33:11 +12:00
|
|
|
}
|
|
|
|
}
|