nityanandaz / PokemonKit

PokeAPI wrapper, written in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Header

PokemonKit

Documentation

PokemonKit is a Swift package wrapping PokeAPI. It uses Foundation's URLSession and Swift's Result type. Callbacks can easily be transformed into Combine Futures.

Installation

Add .package(url: "https://github.com/nityanandaz/PokemonKit.git", from: "5.0.0") to your dependencies.

Usage

Example: Fetch berry with id 1.

import PokemonKit

Berry.fetch(id: "1") { (result) in
    if case let .success(berry) = result {
        print(berry.name)
    }
}

Example: Create a Combine Future.

import Combine
import PokemonKit

let favoriteVersion = Future(Version.fetch(id: "alpha-sapphire"))
favoriteVersion.subscribe(...)

Configuration

Set PokemonKit.baseURL to another URL, e.g., if you want to host your own instance of PokeAPI.

Code Generation

Execute

swift run gyb > Sources/PokemonKit/Types+Resource.swift

to renew Types+Resource.swift.

Types+Resource.swift.stencil is a template to generate all protocol conformances to Resource that are listed in resource-conformance.csv with Stencil.

Testing

InternalTests.swift sets intentionally PokemonKit.baseURL to a localhost URL.

Contributing

If there are any errors decoding a Resource, let me know by creating an issue. I am happy to fix that.

Authors

About

PokeAPI wrapper, written in Swift.

License:MIT License


Languages

Language:Swift 99.6%Language:Shell 0.4%