devmaximilian / Statistics

A wrapper for Statistics Sweden's Open Data API in Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Statistics

Statistics is a Swift package for interacting with Statistics Sweden's Open Data API.

Swift


Installation

Statistics is available through Swift Package Manager. To install it, simply include it in your package dependency list:

dependencies: [
    .package(url: "https://github.com/devmaximilian/Statistics.git", from: "1.0.0"),
]

– alternatively using Xcode via File > Swift Packages > Add Package Dependency...

Usage

Fetch topics by subject area πŸ—ƒ

let client = Statistics.defaultClient

// Get root navigation structure
client.navigationPublisher(for: .root)
    .assertNoFailure()
    .map(\.text)
    .sink { links in {
        print(links) // -> ["Labour market", "Population", ...]
    }

Retrieve filtered statistics by a given subject πŸ“Š

// Get table (population by region, only total population)
client.tablePublisher(for: "BE0101A", subject: "BefolkningNy")
    .configureRequest { builder in
        builder.select("BE0101N1")
            .filter("Region", by: "00")
    }
    .assertNoFailure()
    .sink { table in {
        print(table) // -> Table...
    }

Only want/need data within a given interval? πŸ“…

// Get table (population by region, only total population between 1970 – 1980)
client.tablePublisher(for: "BE0101A", subject: "BefolkningNy")
    .configureRequest { builder in
        builder.select("BE0101N1")
            .filter("Region", by: "00")
            .between("1970", "1980")
    }
    .assertNoFailure()
    .sink { table in {
        print(table) // -> Table...
    }

Legal disclaimer

The developer and this package are not affiliated with or endorsed by Statistics Sweden. Any products and services provided through this package are not supported or warrantied by Statistics Sweden.

License

See LICENSE for license details concerning this package. Read more about using Statistics Sweden's Open Data API here for details concerning the data provided by their API and license information.

About

A wrapper for Statistics Sweden's Open Data API in Swift.

License:MIT License


Languages

Language:Swift 100.0%