[Library] Feed library (#4)
This PR contains the work done to setup the library and also, the necessary protocols, model, structs, and error definitions to implement remote service clients. Reviewed-on: rock-n-code/app-reviews#4 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #4.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// EndpointError.swift
|
||||
// ReviewsFeedKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 17/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
public enum EndpointError: Error {
|
||||
case inputParametersEmpty
|
||||
case requestFailed(statusCode: Int)
|
||||
case responseNotFound
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// Review.swift
|
||||
// ReviewsFeedKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 17/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct Review {
|
||||
|
||||
// MARK: Constants
|
||||
public let author: String
|
||||
public let content: String
|
||||
public let id: Int
|
||||
public let rating: Int
|
||||
public let title: String
|
||||
public let updated: Date
|
||||
public let version: String
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
id: Int,
|
||||
author: String,
|
||||
title: String,
|
||||
content: String,
|
||||
rating: Int,
|
||||
version: String,
|
||||
updated: Date
|
||||
) {
|
||||
self.author = author
|
||||
self.content = content
|
||||
self.id = id
|
||||
self.rating = rating
|
||||
self.title = title
|
||||
self.updated = updated
|
||||
self.version = version
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// Endpoint.swift
|
||||
// ReviewsFeedKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 17/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol Endpoint {
|
||||
|
||||
// MARK: Associated types
|
||||
associatedtype Input: EndpointInput
|
||||
associatedtype Output: EndpointOutput
|
||||
|
||||
// MARK: Properties
|
||||
var host: URL { get }
|
||||
var decoder: JSONDecoder { get }
|
||||
var session: URLSession { get }
|
||||
|
||||
// MARK: Functions
|
||||
func callAsFunction(_ input: Input) async throws -> Output
|
||||
func makePath(with input: Input) throws -> String
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Input
|
||||
public protocol EndpointInput {}
|
||||
|
||||
// MARK: - Output
|
||||
public protocol EndpointOutput {}
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// GetReviewsEndpoint.swift
|
||||
// ReviewsFeedKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 17/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol GetReviewsEndpoint: Endpoint
|
||||
where Input == GetReviewsInput,
|
||||
Output == GetReviewsOutput {}
|
||||
|
||||
// MARK: - Input
|
||||
public struct GetReviewsInput: EndpointInput {
|
||||
|
||||
// MARK: Constants
|
||||
public let appID: String
|
||||
public let countryCode: String
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
appID: String,
|
||||
countryCode: String
|
||||
) {
|
||||
self.appID = appID
|
||||
self.countryCode = countryCode
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Output
|
||||
public struct GetReviewsOutput: EndpointOutput {
|
||||
|
||||
// MARK: Constants
|
||||
public let reviews: [Review]
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(reviews: [Review]) {
|
||||
self.reviews = reviews
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// Service.swift
|
||||
// ReviewsFeedKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 17/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol Service {
|
||||
|
||||
// MARK: Properties
|
||||
var configuration: ServiceConfiguration { get }
|
||||
var decoder: JSONDecoder { get }
|
||||
var session: URLSession { get }
|
||||
|
||||
// MARK: Functions
|
||||
func getReviews(_ input: GetReviewsInput) async throws -> GetReviewsOutput
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// ServiceConfiguration.swift
|
||||
// ReviewsiTunesKit
|
||||
//
|
||||
// Created by Javier Cicchelli on 17/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde VoF. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct ServiceConfiguration {
|
||||
|
||||
// MARK: Constants
|
||||
public let decoder: JSONDecoder
|
||||
public let host: URL
|
||||
public let session: URLSessionConfiguration
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
host: URL,
|
||||
session: URLSessionConfiguration = .ephemeral,
|
||||
decoder: JSONDecoder? = nil
|
||||
) {
|
||||
self.decoder = decoder ?? .init()
|
||||
self.host = host
|
||||
self.session = session
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user