app/lib/api/api.dart

120 lines
2.8 KiB
Dart
Raw Normal View History

2022-04-22 22:08:59 +02:00
import 'package:dio/dio.dart';
2022-05-16 02:51:47 +02:00
2022-04-22 22:08:59 +02:00
import 'package:nekoya_flutter/api/config.dart';
Future<dynamic> getProducts() async {
2022-05-12 05:27:19 +02:00
var req = await Dio().get('$host/getproducts');
2022-04-22 22:08:59 +02:00
var res = req.data;
return res;
2022-04-25 08:48:14 +02:00
}
Future<dynamic> getProduct(id) async {
2022-05-12 05:27:19 +02:00
var req = await Dio().get('$host/getproduct', queryParameters: {'id': id});
2022-04-25 08:48:14 +02:00
var res = req.data;
return res;
2022-04-25 15:24:26 +02:00
}
Future<dynamic> registerPost(data) async {
2022-04-25 15:24:26 +02:00
Response req = await Dio().post(
2022-05-12 05:27:19 +02:00
('$host/register'),
data: data,
2022-04-25 15:24:26 +02:00
options: Options(
contentType: Headers.formUrlEncodedContentType,
validateStatus: (status) {
return status! < 500;
},
),
);
return req.statusCode;
}
2022-05-12 13:11:20 +02:00
Future<dynamic> loginPost(data) async {
Response req = await Dio().post(
2022-05-12 05:27:19 +02:00
('$host/login'),
2022-05-12 13:11:20 +02:00
data: data,
options: Options(
contentType: Headers.formUrlEncodedContentType,
validateStatus: (status) {
2022-05-17 08:31:03 +02:00
return status! < 500;
},
),
);
2022-05-12 13:11:20 +02:00
return {'statusCode': req.statusCode, 'data': req.data};
}
2022-04-27 08:20:01 +02:00
2022-05-22 20:05:13 +02:00
Future<dynamic> otpPost(data) async {
Response req = await Dio().post(
('$host/otp-submit'),
data: data,
options: Options(
contentType: Headers.formUrlEncodedContentType,
validateStatus: (status) {
return status! < 500;
},
),
);
return {'statusCode': req.statusCode, 'data': req.data};
}
2022-05-15 12:48:35 +02:00
Future<dynamic> resetPost(data) async {
Response req = await Dio().post(
('$host/request-reset-password'),
data: data,
options: Options(
contentType: Headers.formUrlEncodedContentType,
validateStatus: (status) {
2022-05-21 12:49:56 +02:00
return status! < 500;
2022-05-15 12:48:35 +02:00
},
),
);
return {'statusCode': req.statusCode, 'data': req.data};
}
2022-05-12 16:46:13 +02:00
Future<dynamic> getSessions(session) async {
2022-05-22 20:17:40 +02:00
var req = await Dio().post(
'$host/sessions',
queryParameters: {'session_token': session},
options: Options(
validateStatus: (status) {
return status! < 500;
},
),
);
2022-05-12 16:46:13 +02:00
return {'statusCode': req.statusCode, 'data': req.data};
2022-04-30 18:47:48 +02:00
}
2022-05-12 16:46:13 +02:00
Future<dynamic> getTransactions(session) async {
var req = await Dio().post(
'$host/transaction',
queryParameters: {'session_token': session},
options: Options(
validateStatus: (status) {
return status! < 500;
},
),
);
2022-04-27 08:20:01 +02:00
var res = req.data;
return res;
2022-04-28 06:27:37 +02:00
}
2022-05-12 16:46:13 +02:00
Future<dynamic> checkoutPost(session, data) async {
2022-04-28 06:27:37 +02:00
Response req = await Dio().post(
2022-05-12 05:27:19 +02:00
('$host/checkout'),
2022-05-12 16:46:13 +02:00
queryParameters: {'session_token': session},
2022-04-28 06:27:37 +02:00
data: data,
options: Options(
contentType: Headers.formUrlEncodedContentType,
validateStatus: (status) {
return status! < 500;
},
),
);
return req.statusCode;
}
2022-05-16 15:55:38 +02:00
Future<dynamic> subscribe(email) async {
2022-05-17 08:31:03 +02:00
var req =
await Dio().get('$host/subscribe', queryParameters: {'email': email});
2022-05-16 15:55:38 +02:00
return req.statusCode;
2022-05-17 08:31:03 +02:00
}