‫Let's continue with the repository.
‫I'll use this call.
‫And there are a lot of methods here.
‫In the call instance we have enqueue and execute.
‫Enqueue and execute are two methods provided by the call interface to send Http request to a web service
‫or API.
‫They are used to initiate the request and obtain the response from the server.
‫However, they differ in terms of how they handle the request and the response.
‫In our case, I'll use the ink.
‫Ink is an asynchronous method for making Http requests.
‫It's typically used when you want to perform the network request in the background thread and handle
‫the response on the main UI thread.
‫While execute method is a synchronous method for making Http requests is typically used when you want
‫to perform a network request on the current thread, which is often discouraged of Android Main UI thread
‫because it can lead to UI freezes or unresponsiveness if the network operation takes a long time.
‫So I'd advise you to use enqueue, not execute execute in the main thread.
‫Enqueue is in the background thread when you call enqueue retrofit internally manages the threading
‫for you, ensuring that the network request runs on the background thread and the response is delivered
‫on the main thread.
‫You pass a callback as an argument to the enqueue which will be invoked when the request completed.
‫So I'll pass new callback and we have two methods on response and on failure.
‫These callback methods use to handle the success and failure cases respectively.
‫If the response is succeeded, we need to get a result object so result result equal to response body.
‫And I'm going to store this response dot body inside the result object.
‫Again guys, I am getting this whole response in form of a result object and storing it inside a result
‫object.
‫So for that I'm getting the result equal response dot body method.
‫Then I need to check if result is not equal to null and result dot get results doesn't equal to null.
‫Then I'm going to create a nested response movies equal to result dot get results.
‫If we go to the result class, we can see this method get results that returns a list of movie.
‫And this is what I need.
‫I need to get a nested response of the other data classes again guys, just for notice that the result
‫here is an array and here how we handle the arrays in Json.
‫We have an array of 20 objects inside an object of the whole response here.
‫I need to cast it because it's an array list of movies.
‫Then the mutable live data variable that we created before I call it, and use the set value and pass
‫the movies array list that we created from this response and set it to this mutable live data set value.
‫This method can be called on the main UI thread and sets the new value immediately.
‫If called from a background thread, it will throw an exception post value method.
‫This method can be called from any thread and schedules.
‫The new value to be set on the main thread.
‫It's useful when you need to update the live data from the background thread.
‫Then I don't need to make anything on the failure.
‫And here I need to return the object of the mutable live data because this is the method that returns
‫the mutable live data and it's placed inside this movie repository.