Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.guillaume.movies.Constants
- import okhttp3.OkHttpClient
- import okhttp3.Request
- import org.json.JSONArray
- /**
- * Function that tries to call an API
- * @param apiParams API Call GET parameters
- */
- fun callApi(apiParams: String): JSONArray {
- // Creates Http Client
- val client = OkHttpClient()
- // Build request with the url from the params
- val request = Request.Builder()
- .url(Constants.API_URL + '/' + apiParams)
- .build()
- // Executes request
- val response = client.newCall(request).execute()
- // Format response to JSON
- return JSONArray(response.body()?.string())
- }
- /**
- * Changes API Key
- * @param newApiKey new API Key
- */
- fun changeApiKey(newApiKey: String) {
- Constants.API_KEY = newApiKey
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement