From 78f03630c0a6789fba09426164dbae5526d706ec Mon Sep 17 00:00:00 2001 From: Carl J Nash Date: Thu, 11 May 2023 16:12:42 +0100 Subject: [PATCH] Rename `APIClient` to `PhotosAPIClient` to be more specific. --- .../Flickr API/FlickrAPIClient.swift | 4 ++-- .../Photo List Views/PhotoListPresenter.swift | 10 +++++----- .../PhotoListPresenterTests.swift | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Komoot Challenge Carl Nash/Flickr API/FlickrAPIClient.swift b/Komoot Challenge Carl Nash/Flickr API/FlickrAPIClient.swift index b82c579..51d3340 100644 --- a/Komoot Challenge Carl Nash/Flickr API/FlickrAPIClient.swift +++ b/Komoot Challenge Carl Nash/Flickr API/FlickrAPIClient.swift @@ -8,7 +8,7 @@ import Foundation import UIKit -protocol APIClient { +protocol PhotosAPIClient { /// Method for for searching for photos from the Flickr Photo Search API based on GPS coordinates. /// This response contains information such as the `imageId`, `server` and `secret` that are used for downloading the image. /// @@ -33,7 +33,7 @@ protocol APIClient { func downloadPhoto(serverId: String, id: String, secret: String, photoSize: FlickrPhotoSize, completion: @escaping (Result) -> Void) } -struct FlickrAPIClient: APIClient { +struct FlickrAPIClient: PhotosAPIClient { enum ResponseError: Error { case invalidPhotosSearchResponseData diff --git a/Komoot Challenge Carl Nash/Photo List Views/PhotoListPresenter.swift b/Komoot Challenge Carl Nash/Photo List Views/PhotoListPresenter.swift index 64155ca..ae4cdd3 100644 --- a/Komoot Challenge Carl Nash/Photo List Views/PhotoListPresenter.swift +++ b/Komoot Challenge Carl Nash/Photo List Views/PhotoListPresenter.swift @@ -23,7 +23,7 @@ class PhotoListPresenter: NSObject { // Reference to the MVP View (`unowned` as it should never be `nil` but we don't want to increase the reference counter for the view) unowned let view: PhotoListViewing - let apiClient: APIClient + let photosAPIClient: PhotosAPIClient // The next step would be to cache these locations on disk or on a server so they are persisted. /// An array of locations that the user has visited and downloaded a photo for. @@ -37,10 +37,10 @@ class PhotoListPresenter: NSObject { // MARK: - Lifecycle - init(view: PhotoListViewing, locationManager: LocationManaging, apiClient: APIClient) { + init(view: PhotoListViewing, locationManager: LocationManaging, apiClient: PhotosAPIClient) { self.view = view self.locationManager = locationManager - self.apiClient = apiClient + self.photosAPIClient = apiClient } // MARK: - Public Methods @@ -129,7 +129,7 @@ private extension PhotoListPresenter { } // Search for photos for this location - self.apiClient.searchForPhotosForLocation(lat: latestLocation.coordinate.latitude, lon: latestLocation.coordinate.longitude) { [weak self] result in + self.photosAPIClient.searchForPhotosForLocation(lat: latestLocation.coordinate.latitude, lon: latestLocation.coordinate.longitude) { [weak self] result in guard let self = self else { return } switch result { @@ -148,7 +148,7 @@ private extension PhotoListPresenter { } // Download the photo - self.apiClient.downloadPhoto(serverId: firstPhoto.server, id: firstPhoto.id, secret: firstPhoto.secret, photoSize: .medium_640) { [weak self] result in + self.photosAPIClient.downloadPhoto(serverId: firstPhoto.server, id: firstPhoto.id, secret: firstPhoto.secret, photoSize: .medium_640) { [weak self] result in guard let self = self else { return } switch result { diff --git a/Komoot Challenge Carl NashTests/PhotoListPresenterTests.swift b/Komoot Challenge Carl NashTests/PhotoListPresenterTests.swift index c6ad0df..98fe470 100644 --- a/Komoot Challenge Carl NashTests/PhotoListPresenterTests.swift +++ b/Komoot Challenge Carl NashTests/PhotoListPresenterTests.swift @@ -161,7 +161,7 @@ class MockLocationManager: LocationManaging { } } -class MockAPIClient: APIClient { +class MockAPIClient: PhotosAPIClient { init(searchPhotosCompletionResult: Result? = nil, downloadPhotosCompletionResult: Result? = nil) { self.searchPhotosCompletionResult = searchPhotosCompletionResult