update to external apis

This commit is contained in:
Mohamed Nouffer
2022-10-19 08:53:17 +05:30
parent 8e30ee6ba7
commit 2d9f7a9633
13 changed files with 209 additions and 50 deletions

View File

@ -0,0 +1,133 @@
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import '../utils/const.dart';
class ExternalService {
static final ExternalService _instance = ExternalService._internal();
factory ExternalService(){
return _instance;
}
ExternalService._internal();
Future<Map<String, dynamic>> StartRogaining(String teamname, String eventcode) async {
Map<String, dynamic> _res = {};
String url = 'https://natnats.mobilous.com/start_from_rogapp';
//print('---- toekn is ${token} -----');
final http.Response response = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'team_name': teamname,
'event_code': eventcode
}),
);
if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----');
}
return _res;
}
Future<Map<String, dynamic>> makeCheckpoint(String teamname, int cp, String eventcode) async {
Map<String, dynamic> _res = {};
String url = 'https://natnats.mobilous.com/checkin_from_rogapp';
//print('---- toekn is ${token} -----');
final http.Response response = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'team_name': teamname,
'cp_number': cp.toString(),
'event_code': eventcode
}),
);
if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----');
}
return _res;
}
Future<Map<String, dynamic>> makeGoal(int user_id, String token, String teamname, String image, String goal_time, String eventcode) async {
Map<String, dynamic> _res2 = {};
String server_url = ConstValues.currentServer();
String url1 = "${server_url}/api/goalimage/";
final im1Bytes = File(image!).readAsBytesSync();
String im1_64 = base64Encode(im1Bytes);
final http.Response response = await http.post(
Uri.parse(url1),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Token ${token}'
},
// 'id', 'user', 'goalimage', 'goaltime', 'team_name', 'event_code','cp_number'
body: jsonEncode(<String, String>{
'user' : user_id.toString(),
'team_name': teamname,
'event_code': eventcode,
'goaltime' : goal_time,
'goalimage' : im1_64,
'cp_number' : "-1"
}),
);
String url = 'https://natnats.mobilous.com/start_from_rogapp';
//print("---response is : ${response.statusCode}----");
if (response.statusCode == 201) {
Map<String, dynamic> _res = json.decode(utf8.decode(response.bodyBytes));
print('----_res : ${_res} ----');
print('---- image url ${_res["goalimage"]} ----');
final http.Response response2 = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'team_name': teamname,
'event_code': eventcode,
'goal_time' : goal_time,
'image' : _res["goalimage"]
}
),
);
print('----- response2 is ${response2} --------');
if (response2.statusCode == 200) {
_res2 = json.decode(utf8.decode(response2.bodyBytes));
}
}
return _res2;
}
static Future<Map<String, dynamic>> usersEventCode(String teamcode, String password) async {
Map<String, dynamic> _res = {};
String url = "https://natnats.mobilous.com/check_event_code?zekken_number=${teamcode}&password=${password}";
print("url is ------ ${url}");
final http.Response response = await http.get(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
}
);
if (response.statusCode == 200) {
_res = json.decode(utf8.decode(response.bodyBytes));
}
return _res;
}
}