Swiftpack.co - otaviocc/MicroPinboardAPI as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by otaviocc.
otaviocc/MicroPinboardAPI 2.1.4
MicroPinboard is a Pinboard API wrapper, written in Swift using async/await
⭐️ 5
🕓 1 year ago
iOS macOS
.package(url: "https://github.com/otaviocc/MicroPinboardAPI.git", from: "2.1.4")

MicroPinboard

MicroPinboard is a Pinboard API wrapper, written in Swift using async/await.

public protocol PinboardAPIFactoryProtocol {
    func makePinboardAPIClient(
        userToken: @escaping () -> String?
    ) -> NetworkClientProtocol
}

The network client takes a single parameter: userToken: @escaping () -> String?, where the user token is passed to the client and is dynamically evaluated when needed (useful in those case where the network client is initialized before the user is asked to provide the token).

let factory = PinboardAPIFactory()

let client = factory.makePinboardAPIClient {
    "A_VALID_TOKEN_GOES_HERE"
}

Network requests are also built by factories, returning strongly-typed request objects:

// NetworkRequest<VoidRequest, DatesResponse>
let recentsRequest = PostsAPIFactory.makeDatesRequest()

The network client takes a single parameter, the request, returning NetworkResponse

public protocol NetworkClientProtocol {
    func run<RequestModel, ResponseModel>(
        _ networkRequest: NetworkRequest<RequestModel, ResponseModel>
    ) async throws -> NetworkResponse<ResponseModel>
}

E.g.:

let recentsRequest = PostsAPIFactory.makeRecentRequest()
let recentsResponse = try await client.run(recentsRequest)

GitHub

link
Stars: 5
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

2.1.0
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics