Skip to content

Commit

Permalink
Rename APIClient to PhotosAPIClient to be more specific.
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlJNash committed May 11, 2023
1 parent 3327385 commit 78f0363
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Komoot Challenge Carl Nash/Flickr API/FlickrAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -33,7 +33,7 @@ protocol APIClient {
func downloadPhoto(serverId: String, id: String, secret: String, photoSize: FlickrPhotoSize, completion: @escaping (Result<UIImage, Error>) -> Void)
}

struct FlickrAPIClient: APIClient {
struct FlickrAPIClient: PhotosAPIClient {

enum ResponseError: Error {
case invalidPhotosSearchResponseData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class MockLocationManager: LocationManaging {
}
}

class MockAPIClient: APIClient {
class MockAPIClient: PhotosAPIClient {
init(searchPhotosCompletionResult: Result<APIPhotosSearchResponse, Error>? = nil,
downloadPhotosCompletionResult: Result<UIImage, Error>? = nil) {
self.searchPhotosCompletionResult = searchPhotosCompletionResult
Expand Down

0 comments on commit 78f0363

Please sign in to comment.