Advertisement
Guest User

Untitled

a guest
Jul 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import com.guillaume.movies.Constants
  2. import okhttp3.OkHttpClient
  3. import okhttp3.Request
  4. import org.json.JSONArray
  5.  
  6. /**
  7. * Function that tries to call an API
  8. * @param apiParams API Call GET parameters
  9. */
  10. fun callApi(apiParams: String): JSONArray {
  11. // Creates Http Client
  12. val client = OkHttpClient()
  13.  
  14. // Build request with the url from the params
  15. val request = Request.Builder()
  16. .url(Constants.API_URL + '/' + apiParams)
  17. .build()
  18.  
  19. // Executes request
  20. val response = client.newCall(request).execute()
  21.  
  22. // Format response to JSON
  23. return JSONArray(response.body()?.string())
  24. }
  25.  
  26. /**
  27. * Changes API Key
  28. * @param newApiKey new API Key
  29. */
  30.  
  31. fun changeApiKey(newApiKey: String) {
  32. Constants.API_KEY = newApiKey
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement