def METHOD_NAME(self, endpoint, json_directory, page_size):
    url = "/api/next/{endpoint}/?page_size={page_size}&format=json".format(
        page_size=page_size, endpoint=endpoint
    )
    while url:
        page = page_from_url(url)
        output_filename = join(
            json_directory, page_filename(endpoint, page)
        )
        response = self.get(url)
        if response.status_code != 200:
            msg = "Unexpected response {0} from {1}"
            raise Exception(msg.format(response.status_code, url))
        data = json.loads(response.content.decode("utf-8"))
        original_next_url = data["next"]
        self.rewrite_next_and_previous_links(endpoint, data)
        json_page = json.dumps(data, indent=4, sort_keys=True).encode(
            "utf8"
        )
        if page == 1:
            self.first_page_json = json_page
        self.storage.save(output_filename, ContentFile(json_page))
        # Now make sure the next URL works with the test client:
        if original_next_url:
            url = path_and_query(original_next_url)
        else:
            url = None