Swiftpack.co -  Package - riley-williams/PiholeNetworking
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
riley-williams/PiholeNetworking
Robust networking API for interfacing with Pi-hole instances
.package(url: "https://github.com/riley-williams/PiholeNetworking.git", from: "0.2.2")

PiholeNetworking

Swift codecov

Open source networking library for interacting with Pi-hole DNS blocker instances

Getting Started

// Add PHInstance conformance to your existing Pi-hole model type

struct MyPiholeModel {
    var ip: String
    var port: Int
    var password: String?
}

extension MyPiholeModel: PHInstance { }
// Create a shared provider object and a model instance

let provider = PHProvider()

var pihole = MyPiholeModel(ip: "192.168.1.10", port: 80, password: nil)
// Make a request

let summaryCancellable = provider.getSummary(pihole)
    .sink { completion in
        // Handle failure or completion
    } receiveValue: { summary in
        print("Queries today: \(summary.queryCount)")
        print("Queries blocked today: \(summary.blockedQueryCount)")
    }
// Queries today: 49216
// Queries blocked today: 3872
// Many queries require authentication
pihole.password = "MyWebPassword"

// Disable the Pi-hole for 15 seconds
let disableCancellable = provider.disable(pihole, for: 15)
    .sink { completion in
        // Handle failure or completion
    } receiveValue: { state in
        print("Pi-hole is now \(state)")
    }
// Pi-hole is now disabled

GitHub

link
Stars: 0
Last commit: 37 minutes ago

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