Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

PokeAPI wrapper, written in Swift.

License

Notifications You must be signed in to change notification settings

nityanandaz/PokemonKit

 
 

Repository files navigation

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.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.6%
  • Shell 0.4%