|
9 | 9 | import Foundation
|
10 | 10 | import Combine
|
11 | 11 |
|
| 12 | +/// An enumeration of error states that can be returned from a `SwapiService` |
12 | 13 | public enum ServiceError: Error {
|
13 | 14 | case unknown
|
14 | 15 | case networkError(error: NetworkError)
|
15 | 16 | case parsingError(error: Error)
|
16 | 17 | }
|
17 | 18 |
|
| 19 | +/// Objects conforming to the `SwapiService` protocol may act as a data service for request resources from the Star Wars API (SWAPI) |
18 | 20 | public protocol SwapiService {
|
19 | 21 |
|
| 22 | + /// Call this function to request a `Film` resource with a resource ID |
| 23 | + /// - Parameter resourceId: The specified ID `String` for the `Film` being requested. |
20 | 24 | func film(withId resourceId: String) -> AnyPublisher<Film, ServiceError>
|
21 | 25 |
|
| 26 | + /// Call this function to request a `Person` resource with a resource ID. |
| 27 | + /// - Parameter resourceId: The specified ID `String` for the `Person` being requested. |
22 | 28 | func person(withId resourceId: String) -> AnyPublisher<Person, ServiceError>
|
23 | 29 |
|
| 30 | + /// Call this function to request a `Planet` resource with a resource ID. |
| 31 | + /// - Parameter resourceId: The specified ID `String` for the resource. |
24 | 32 | func planet(withId resourceId: String) -> AnyPublisher<Planet, ServiceError>
|
25 | 33 |
|
| 34 | + /// Call tis function to request a `Planet` resource with a resource URL. |
| 35 | + /// - Parameter url: The specified URL `String` for the resource. |
26 | 36 | func planet(withResourceUrl url: String?) -> AnyPublisher<Planet, ServiceError>
|
27 | 37 |
|
| 38 | + /// Call tis function to request a `Species` resource with a resource ID. |
| 39 | + /// - Parameter resourceId: The specified ID `String` for the resource. |
28 | 40 | func species(withId resourceId: String) -> AnyPublisher<Species, ServiceError>
|
29 | 41 |
|
| 42 | + /// Call this function to request a `Starship` resource with a resource ID. |
| 43 | + /// - Parameter resourceId: The specified ID `String` for the resource. |
30 | 44 | func starship(withId resourceId: String) -> AnyPublisher<Starship, ServiceError>
|
31 | 45 |
|
| 46 | + /// Call this function to request a `Vehicle` resource with a resource ID. |
| 47 | + /// - Parameter resourceId: The specified ID `String` for the resource. |
32 | 48 | func vehicle(withId resourceId: String) -> AnyPublisher<Vehicle, ServiceError>
|
33 | 49 |
|
| 50 | + /// Call this function to request a list of all the `Film` resources available from the API service. |
| 51 | + /// - Parameter page: An optional resource URL `String` specifying the page of results being requested. |
34 | 52 | func allFilms(page: String?) -> AnyPublisher<ResourceRoot<Film>, ServiceError>
|
35 | 53 |
|
| 54 | + /// Call this function to request a list of all the `Person` resources available from the API service. |
| 55 | + /// - Parameter page: An optional resource URL `String` specifying the page of results being requested. |
36 | 56 | func allPeople(page: String?) -> AnyPublisher<ResourceRoot<Person>, ServiceError>
|
37 | 57 |
|
| 58 | + /// Call this function to request a list of all the `Planet` resources available from the API service. |
| 59 | + /// - Parameter page: An optional resource URL `String` specifying the page of results being requested. |
38 | 60 | func allPlanets(page: String?) -> AnyPublisher<ResourceRoot<Planet>, ServiceError>
|
39 | 61 |
|
| 62 | + /// Call this function to request a list of all the `Species` resources available from the API service. |
| 63 | + /// - Parameter page: An optional resource URL `String` specifying the page of results being requested. |
40 | 64 | func allSpecies(page: String?) -> AnyPublisher<ResourceRoot<Species>, ServiceError>
|
41 | 65 |
|
| 66 | + /// Call this function to request a list of all the `Starship` resources available from the API service. |
| 67 | + /// - Parameter page: An optional resource URL `String` specifying the page of results being requested. |
42 | 68 | func allStarships(page: String?) -> AnyPublisher<ResourceRoot<Starship>, ServiceError>
|
43 | 69 |
|
| 70 | + /// Call this function to request a list of all the `Vehicle` resources available from the API service. |
| 71 | + /// - Parameter page: An optional resource URL `String` specifying the page of results being requested. |
44 | 72 | func allVehicles(page: String?) -> AnyPublisher<ResourceRoot<Vehicle>, ServiceError>
|
45 | 73 |
|
46 |
| - func people(fromResourceUrls urls: [String]) -> AnyPublisher<[Person], ServiceError> |
| 74 | + /// Call this function to perform multiple requests for `Film` resources using an array of resource URLs. |
| 75 | + /// - Parameter urls: The specified array of resource URLs for the resources being requested. |
| 76 | + func films(fromResourceUrls urls: [String]) -> AnyPublisher<[Film], ServiceError> |
47 | 77 |
|
48 |
| - func starships(fromResourceUrls urls: [String]) -> AnyPublisher<[Starship], ServiceError> |
| 78 | + /// Call this function to perform multiple requests for `Person` resources using an array of resource URLs. |
| 79 | + /// - Parameter urls: The specified array of resource URLs for the resources being requested. |
| 80 | + func people(fromResourceUrls urls: [String]) -> AnyPublisher<[Person], ServiceError> |
49 | 81 |
|
| 82 | + /// Call this function to perform multiple requests for `Planet` resources from an using of resource URLs. |
| 83 | + /// - Parameter urls: The specified array of resource URLs for the resources being requested. |
50 | 84 | func planets(fromResourceUrls urls: [String]) -> AnyPublisher<[Planet], ServiceError>
|
51 | 85 |
|
| 86 | + /// Call this function to perform multiple requests for `Species` resources using an array of resource URLs. |
| 87 | + /// - Parameter urls: The specified array of resource URLs for the resources being requested. |
52 | 88 | func species(fromResourceUrls urls: [String]) -> AnyPublisher<[Species], ServiceError>
|
53 | 89 |
|
54 |
| - func vehicles(fromResourceUrls urls: [String]) -> AnyPublisher<[Vehicle], ServiceError> |
| 90 | + /// Call this function to perform multiple requests for `Starship` resources using an array of resource URLs. |
| 91 | + /// - Parameter urls: The specified array of resource URLs for the resources being requested. |
| 92 | + func starships(fromResourceUrls urls: [String]) -> AnyPublisher<[Starship], ServiceError> |
55 | 93 |
|
56 |
| - func films(fromResourceUrls urls: [String]) -> AnyPublisher<[Film], ServiceError> |
| 94 | + /// Call this function to perform multiple requests for `Vehicle` resources using an array of resource URLs. |
| 95 | + /// - Parameter urls: The specified array of resource URLs for the resources being requested. |
| 96 | + func vehicles(fromResourceUrls urls: [String]) -> AnyPublisher<[Vehicle], ServiceError> |
57 | 97 |
|
58 | 98 | }
|
59 | 99 |
|
| 100 | +/// The default implementation of a data service conforming to the `SwapiService` protocol. |
60 | 101 | public struct DataService: SwapiService {
|
61 | 102 |
|
62 | 103 | private let dataFetcher = DataFetcher()
|
|
0 commit comments