Skip to content

Instantly share code, notes, and snippets.

@yostane
Last active February 25, 2021 15:31
Show Gist options
  • Save yostane/752a457dd127df982a7f1ae2c56207e4 to your computer and use it in GitHub Desktop.
Save yostane/752a457dd127df982a7f1ae2c56207e4 to your computer and use it in GitHub Desktop.
authenticateButton.setOnClickListener {
val service = retrofit.create(TerminalService::class.java)
val loginCall = service.login(loginEditText.text.toString(), passwordEditText.text.toString())
loginCall.enqueue(object : Callback<ResponseBody>{
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
val token = response.body()?.string()
if (token != null){
Log.d("PPE_LOG", "The token is $token")
} else {
Log.w("PPE_LOG", "Login failed")
}
}
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
Log.e("PPE_LOG", "Login failed")
}
})
}
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query
interface TerminalService {
@GET("login.php")
fun login(@Query("login") login: String, @Query("mdp") password: String): Call<ResponseBody>
@GET("reservations.php")
fun reservations(@Query("token") token: String): Call<List<TerminalReservation>>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment