Skip to content

Commit 3ad17d0

Browse files
committed
Added documentation for the SwapiService protocol
1 parent b9bac17 commit 3ad17d0

File tree

1 file changed

+45
-4
lines changed

1 file changed

+45
-4
lines changed

SwapiSwift/Services/SwapiService.swift

+45-4
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,95 @@
99
import Foundation
1010
import Combine
1111

12+
/// An enumeration of error states that can be returned from a `SwapiService`
1213
public enum ServiceError: Error {
1314
case unknown
1415
case networkError(error: NetworkError)
1516
case parsingError(error: Error)
1617
}
1718

19+
/// Objects conforming to the `SwapiService` protocol may act as a data service for request resources from the Star Wars API (SWAPI)
1820
public protocol SwapiService {
1921

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.
2024
func film(withId resourceId: String) -> AnyPublisher<Film, ServiceError>
2125

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.
2228
func person(withId resourceId: String) -> AnyPublisher<Person, ServiceError>
2329

30+
/// Call this function to request a `Planet` resource with a resource ID.
31+
/// - Parameter resourceId: The specified ID `String` for the resource.
2432
func planet(withId resourceId: String) -> AnyPublisher<Planet, ServiceError>
2533

34+
/// Call tis function to request a `Planet` resource with a resource URL.
35+
/// - Parameter url: The specified URL `String` for the resource.
2636
func planet(withResourceUrl url: String?) -> AnyPublisher<Planet, ServiceError>
2737

38+
/// Call tis function to request a `Species` resource with a resource ID.
39+
/// - Parameter resourceId: The specified ID `String` for the resource.
2840
func species(withId resourceId: String) -> AnyPublisher<Species, ServiceError>
2941

42+
/// Call this function to request a `Starship` resource with a resource ID.
43+
/// - Parameter resourceId: The specified ID `String` for the resource.
3044
func starship(withId resourceId: String) -> AnyPublisher<Starship, ServiceError>
3145

46+
/// Call this function to request a `Vehicle` resource with a resource ID.
47+
/// - Parameter resourceId: The specified ID `String` for the resource.
3248
func vehicle(withId resourceId: String) -> AnyPublisher<Vehicle, ServiceError>
3349

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.
3452
func allFilms(page: String?) -> AnyPublisher<ResourceRoot<Film>, ServiceError>
3553

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.
3656
func allPeople(page: String?) -> AnyPublisher<ResourceRoot<Person>, ServiceError>
3757

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.
3860
func allPlanets(page: String?) -> AnyPublisher<ResourceRoot<Planet>, ServiceError>
3961

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.
4064
func allSpecies(page: String?) -> AnyPublisher<ResourceRoot<Species>, ServiceError>
4165

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.
4268
func allStarships(page: String?) -> AnyPublisher<ResourceRoot<Starship>, ServiceError>
4369

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.
4472
func allVehicles(page: String?) -> AnyPublisher<ResourceRoot<Vehicle>, ServiceError>
4573

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>
4777

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>
4981

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.
5084
func planets(fromResourceUrls urls: [String]) -> AnyPublisher<[Planet], ServiceError>
5185

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.
5288
func species(fromResourceUrls urls: [String]) -> AnyPublisher<[Species], ServiceError>
5389

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>
5593

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>
5797

5898
}
5999

100+
/// The default implementation of a data service conforming to the `SwapiService` protocol.
60101
public struct DataService: SwapiService {
61102

62103
private let dataFetcher = DataFetcher()

0 commit comments

Comments
 (0)