B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Static Code
Version=9.9
@EndOfDesignText@
' APIModule - Utility for communicating with the PHP Backend
Sub Process_Globals
    Public ServerURL As String = "https://bustrack.merosee.com/api" ' For Emulator use 10.0.2.2 instead of localhost
End Sub

Sub GetToken As String
	If File.Exists(File.DirInternal, "parent_token.txt") Then
		Return File.ReadString(File.DirInternal, "parent_token.txt")
	End If
	Return ""
End Sub

Sub SaveToken(token As String)
	File.WriteString(File.DirInternal, "parent_token.txt", token)
End Sub

Sub SaveStudents(studentsJson As String)
	File.WriteString(File.DirInternal, "students.json", studentsJson)
End Sub

Sub GetStudents As String
	If File.Exists(File.DirInternal, "students.json") Then
		Return File.ReadString(File.DirInternal, "students.json")
	End If
	Return ""
End Sub

Sub RegisterFCMToken(Phone As String, Token As String)
	Dim data As Map
	data.Initialize
	data.Put("phone", Phone)
	data.Put("token", Token)
	
	Dim json As JSONGenerator
	json.Initialize(data)
	
	Dim job As HttpJob
	job.Initialize("register_fcm", Main)
	job.PostString(ServerURL & "/register_fcm.php", json.ToString)
	job.GetRequest.SetHeader("Content-Type", "application/json")
End Sub
