338 lines
8.8 KiB
Dart
338 lines
8.8 KiB
Dart
import 'dart:convert';
|
|
import 'package:get/get.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:SEFER/env/env.dart';
|
|
|
|
import '../../constant/api_key.dart';
|
|
|
|
class CRUD {
|
|
Future<dynamic> get({
|
|
required String link,
|
|
Map<String, dynamic>? payload,
|
|
}) async {
|
|
// String? basicAuthCredentials =
|
|
// await storage.read(key: BoxName.basicAuthCredentials);
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var response = await http.post(
|
|
url,
|
|
body: payload,
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
'Authorization':
|
|
// 'Basic ${base64Encode(utf8.encode('hamzaayedphp:malDEV@2101'))}',
|
|
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials.toString()))}',
|
|
// 'Basic ${base64Encode(utf8.encode(basicAuthCredentials.toString()))}',
|
|
},
|
|
);
|
|
print("-----request----" + response.request.toString());
|
|
// print("-----headers-----" + response.headers.toString());
|
|
// print("-----payload-----" + payload.toString());
|
|
if (response.statusCode == 200) {
|
|
var jsonData = jsonDecode(response.body);
|
|
if (jsonData['status'] == 'success') {
|
|
// print(jsonData);
|
|
|
|
return response.body;
|
|
}
|
|
|
|
return jsonData['status'];
|
|
}
|
|
}
|
|
|
|
Future<dynamic> getAgora({
|
|
required String channelName,
|
|
}) async {
|
|
var res = await http
|
|
.get(Uri.parse('http://localhost:8080/token?channelName=$channelName'));
|
|
|
|
if (res.statusCode == 200) {
|
|
var response = jsonDecode(res.body);
|
|
print(await response.stream.bytesToString());
|
|
return response['token'];
|
|
} else {
|
|
print(res.reasonPhrase);
|
|
}
|
|
}
|
|
|
|
Future<dynamic> getLlama({
|
|
required String link,
|
|
required String payload,
|
|
}) async {
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var headers = {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': 'Bearer ${Env.llamaKey}'
|
|
};
|
|
var data = json.encode({
|
|
"model": "llama-13b-chat",
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content":
|
|
"Extract the desired information from the following passage as json decoded like vin,make,made,year,expiration_date,color,owner,registration_date just in this:\n\n$payload"
|
|
}
|
|
],
|
|
"temperature": 0.9
|
|
});
|
|
var response = await http.post(
|
|
url,
|
|
body: data,
|
|
headers: headers,
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
return response.body;
|
|
}
|
|
return response.statusCode;
|
|
}
|
|
|
|
Future<dynamic> getChatGPT({
|
|
required String link,
|
|
required String payload,
|
|
}) async {
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var headers = {
|
|
'Content-Type': 'application/json',
|
|
'Authorization':
|
|
'Bearer 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'
|
|
};
|
|
var data = json.encode({
|
|
"model": "gpt-3.5-turbo",
|
|
"messages": [
|
|
{
|
|
"role": "user",
|
|
"content":
|
|
"Extract the desired information from the following passage as json decoded like vin,make,made,year,expiration_date,color,owner,registration_date just in this:\n\n$payload"
|
|
}
|
|
],
|
|
"temperature": 0.9
|
|
});
|
|
var response = await http.post(
|
|
url,
|
|
body: data,
|
|
headers: headers,
|
|
);
|
|
|
|
if (response.statusCode == 200) {
|
|
return response.body;
|
|
}
|
|
return response.statusCode;
|
|
}
|
|
|
|
Future<dynamic> postStripe({
|
|
required String link,
|
|
Map<String, dynamic>? payload,
|
|
}) async {
|
|
// String? secretKey = await storage.read(key: BoxName.secretKey);
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var response = await http.post(
|
|
url,
|
|
body: payload,
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
'Authorization': 'Bearer ${AK.secretKey}',
|
|
},
|
|
);
|
|
if (response.statusCode == 200) {
|
|
print(response);
|
|
return response.body;
|
|
} else {
|
|
print('eeeeeeeeerrrrorrrr ${response.statusCode}');
|
|
print(response.body);
|
|
}
|
|
}
|
|
|
|
Future<dynamic> post({
|
|
required String link,
|
|
Map<String, dynamic>? payload,
|
|
}) async {
|
|
// String? basicAuthCredentials =
|
|
// await storage.read(key: BoxName.basicAuthCredentials);
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var response = await http.post(
|
|
url,
|
|
body: payload,
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
'Authorization':
|
|
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
|
},
|
|
);
|
|
print(response.request);
|
|
print(payload);
|
|
|
|
var jsonData = jsonDecode(response.body);
|
|
if (response.statusCode == 200) {
|
|
if (jsonData['status'] == 'success') {
|
|
// Get.snackbar(
|
|
// jsonData['status'],
|
|
// jsonData['message'],
|
|
// );
|
|
// print(response.body);
|
|
return response.body;
|
|
}
|
|
}
|
|
return (jsonData['status']);
|
|
}
|
|
|
|
Future<dynamic> postFromDialogue({
|
|
required String link,
|
|
Map<String, dynamic>? payload,
|
|
}) async {
|
|
// String? basicAuthCredentials =
|
|
// await storage.read(key: BoxName.basicAuthCredentials);
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var response = await http.post(
|
|
url,
|
|
body: payload,
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
'Authorization':
|
|
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
|
},
|
|
);
|
|
//print(response.request);
|
|
//print('body=========================');
|
|
//print(response.body);
|
|
|
|
if (response.body.isNotEmpty) {
|
|
var jsonData = jsonDecode(response.body);
|
|
if (response.statusCode == 200) {
|
|
if (jsonData['status'] == 'success') {
|
|
Get.back();
|
|
// Get.snackbar(
|
|
// jsonData['status'],
|
|
// jsonData['message'],
|
|
// );
|
|
|
|
return response.body;
|
|
}
|
|
}
|
|
return (jsonData['status']);
|
|
}
|
|
}
|
|
|
|
Future<void> sendVerificationRequest(String phoneNumber) async {
|
|
final accountSid = "ACb4ad857efe0903bfd6238a763a2ce4d1";
|
|
final authToken = "14f39ef4628bb8a4f18469f462f8af75";
|
|
final verifySid = "VAf6e6022a7e95186aa5b1da25411859bd";
|
|
|
|
final Uri verificationUri = Uri.parse(
|
|
'https://verify.twilio.com/v2/Services/$verifySid/Verifications');
|
|
|
|
// Send the verification request
|
|
final response = await http.post(
|
|
verificationUri,
|
|
headers: {
|
|
'Authorization':
|
|
'Basic ' + base64Encode(utf8.encode('$accountSid:$authToken')),
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
},
|
|
body: {
|
|
'To': phoneNumber,
|
|
'Channel': 'sms',
|
|
},
|
|
);
|
|
|
|
if (response.statusCode == 201) {
|
|
print('Verification request sent');
|
|
} else {
|
|
print('Failed to send verification request');
|
|
}
|
|
|
|
// Prompt the user to enter the OTP
|
|
final otpCode = "123456"; // Replace with user input
|
|
|
|
// Check the verification code
|
|
final checkUri = Uri.parse(
|
|
'https://verify.twilio.com/v2/Services/$verifySid/VerificationCheck');
|
|
|
|
final checkResponse = await http.post(
|
|
checkUri,
|
|
headers: {
|
|
'Authorization':
|
|
'Basic ' + base64Encode(utf8.encode('$accountSid:$authToken')),
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
},
|
|
body: {
|
|
'To': phoneNumber,
|
|
'Code': otpCode,
|
|
},
|
|
);
|
|
|
|
if (checkResponse.statusCode == 201) {
|
|
print('Verification successful');
|
|
} else {
|
|
print('Verification failed');
|
|
}
|
|
}
|
|
|
|
Future<dynamic> getGoogleApi({
|
|
required String link,
|
|
Map<String, dynamic>? payload,
|
|
}) async {
|
|
var url = Uri.parse(
|
|
link,
|
|
);
|
|
var response = await http.post(
|
|
url,
|
|
body: payload,
|
|
);
|
|
print(response.request);
|
|
var jsonData = jsonDecode(response.body);
|
|
// //print(jsonData);
|
|
if (jsonData['status'] == 'OK') {
|
|
return jsonData;
|
|
}
|
|
return (jsonData['status']);
|
|
}
|
|
|
|
Future<dynamic> update({
|
|
required String endpoint,
|
|
required Map<String, dynamic> data,
|
|
required String id,
|
|
}) async {
|
|
// String? basicAuthCredentials =
|
|
// await storage.read(key: BoxName.basicAuthCredentials);
|
|
var url = Uri.parse('$endpoint/$id');
|
|
var response = await http.put(
|
|
url,
|
|
body: json.encode(data),
|
|
headers: {
|
|
'Authorization':
|
|
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
|
},
|
|
);
|
|
return json.decode(response.body);
|
|
}
|
|
|
|
Future<dynamic> delete({
|
|
required String endpoint,
|
|
required String id,
|
|
}) async {
|
|
// String? basicAuthCredentials =
|
|
// await storage.read(key: BoxName.basicAuthCredentials);
|
|
var url = Uri.parse('$endpoint/$id');
|
|
var response = await http.delete(
|
|
url,
|
|
headers: {
|
|
'Authorization':
|
|
'Basic ${base64Encode(utf8.encode(AK.basicAuthCredentials))}',
|
|
},
|
|
);
|
|
return json.decode(response.body);
|
|
}
|
|
}
|