Class TheGuardianDataSource


  • public class TheGuardianDataSource
    extends DataSource<TheGuardianDataEntity,​Object>
    TheGuardianDataSource is the data source for The Guardian records. It contains the data source logic.
    • Field Detail

      • ENV_API_KEY

        private static final String ENV_API_KEY
        The ENV_API_KEY field is used to get the API key from the environment variables.
      • BASE_URL

        private static final String BASE_URL
        The BASE_URL field is used to build the URL of the request.
        See Also:
        Constant Field Values
      • SEARCH_ENDPOINT

        private static final String SEARCH_ENDPOINT
        The SEARCH_ENDPOINT field is used to build the URL of the request.
        See Also:
        Constant Field Values
      • RESPONSE_FORMAT

        private static final String RESPONSE_FORMAT
        The RESPONSE_FORMAT field is used to build the URL of the request.
        See Also:
        Constant Field Values
      • DATE_FORMAT

        private static final SimpleDateFormat DATE_FORMAT
        The dateFormat field is used to format the date.
      • MAX_PAGE_SIZE

        private static final int MAX_PAGE_SIZE
        The MAX_PAGE_SIZE field is used to limit the number of articles per page.
        See Also:
        Constant Field Values
      • httpClient

        private final okhttp3.OkHttpClient httpClient
        The httpClient field is used to send the HTTP request.
    • Constructor Detail

      • TheGuardianDataSource

        public TheGuardianDataSource()
        The TheGuardianDataSource constructor. It is used to create a new TheGuardianDataSource object.
    • Method Detail

      • getData

        public List<TheGuardianDataEntity> getData​(Context context)
        The get method is used to get the data from The Guardian API and deserialize it. Pagination is processed in an asynchronous way using multiple threads.
        Overrides:
        getData in class DataSource<TheGuardianDataEntity,​Object>
        Parameters:
        context - the context of the request
        Returns:
        the list of TheGuardianDataEntity objects