Skip to content

Network Layer

Anirudh Ramanan edited this page Jan 22, 2020 · 1 revision

The network layer is used to fetch the ad response from the given url. The default implementation uses the ok-http library to make network calls.

The fetch method takes in request which contains the required url and headers along with the result listener and cancellation signal.

Components:

  • Network Listener: It is a listener to provide success / error callbacks.

  • NetworkAdRequest: Request object which has the url.

  • Cancellation Signal: This is a ok-http's construct where in you can cancel the request if it's in queue. For cases such as when the request was initiated and the user pressed back, we can use the cancellation signal to cancel the request.

  • Back-off Policy: The back off policy is used to decide the behaviour in case of network failure. The library provides a default back-off policy which can be overridden as per need.

    • Max retry count: Indicates the maximum number of retries allowed before discarding the request.
    • Back off multiplier: A multiplier which is used to determine exponential time set to socket for every retry attempt.

    The default policy retries for maximum of 3 times.

API:

  • fetch(request: NetworkAdRequest, resultListener: NetworkListener, cancellationSignal: CancellationSignal)

    The fetch method takes in the request object, along with the result listener and cancellation signal. In case of success, onSuccess of listener is called with the response string, and in case of failure, onError of listener is called with the error code and error message.

Clone this wiki locally