parent
8da6f5eff3
commit
6ba1c7e8e3
@ -0,0 +1,27 @@
|
|||||||
|
package uca.baptistearthur.geocaching.services
|
||||||
|
|
||||||
|
import java.net.HttpURLConnection
|
||||||
|
import java.net.URL
|
||||||
|
import java.io.BufferedReader
|
||||||
|
import java.io.InputStreamReader
|
||||||
|
|
||||||
|
class GeocacheAPIServices {
|
||||||
|
|
||||||
|
fun fetchGeocacheAPI(linkToApi: String): String{
|
||||||
|
val url = URL(linkToApi)
|
||||||
|
val connection = url.openConnection() as HttpURLConnection
|
||||||
|
connection.requestMethod = "GET"
|
||||||
|
val input = BufferedReader(InputStreamReader(connection.inputStream))
|
||||||
|
val response = StringBuilder()
|
||||||
|
var inputLine: String?
|
||||||
|
while (input.readLine().also { inputLine = it } != null) {
|
||||||
|
response.append(inputLine)
|
||||||
|
}
|
||||||
|
input.close()
|
||||||
|
connection.disconnect()
|
||||||
|
return response.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue