Git Product home page Git Product logo

swifthole's Introduction

SwiftHole

A Swift library to connect to your Pi-hole

Installation

You can follow Apple's documentation on how to install a SPM into your project

Authentication Token

Some methods like fetchSummary do not require authentication to work, but to interact with the Pi-hole server, for example, with disablePiHole or enablePiHole authentication is necessary.

There are two different ways to get your authentication token:

  • /etc/pihole/setupVars.conf under WEBPASSWORD
  • WebUI -> Settings -> API -> Show API Token

Examples

  • Getting Pi-hole summary:
SwiftHole(host: "192.168.1.123").fetchSummary { result in
    switch result {
        case .success(let summary):
            print("Status \(summary.status)")
                
        case .failure(let error):
            print("Error \(error)")
    }
}
  • Disable Pi-hole for 5 seconds:
SwiftHole.init(host: "192.168.1.123", apiToken: "klaatubaradanikto")
         .disablePiHole(seconds: 5) { result in
                
    switch result {
        case .success:
            print("disabled")
                    
        case .failure(let error):
            print("Error \(error)")
    }
}
  • Enable Pi-hole:
 SwiftHole.init(host: "192.168.1.123", apiToken: "klaatubaradanikto")
          .enablePiHole { result in
                
    switch result {
        case .success:
            print("enabled")
                
        case .failure(let error):
            print("Error \(error)")
    }
}

Interface

SwiftHole has the following public interface:

public var timeoutInterval: TimeInterval { get set }

public init(host: String, port: Int? = nil, apiToken: String? = nil, timeoutInterval: TimeInterval = 30, secure: Bool = false)

public func fetchSummary(completion: @escaping (Result<Summary, SwiftHoleError>) -> ())

public func enablePiHole(_ completion: @escaping (Result<Void, SwiftHoleError>) -> ())

public func disablePiHole(seconds: Int = 0, completion: @escaping (Result<Void, SwiftHoleError>) -> ())

public func fetchList(_ listType: ListType, completion: @escaping (Result<[ListItem], SwiftHoleError>) -> ())

public func fetchHistoricalQueries(completion: @escaping (Result<[DNSRequest], SwiftHoleError>) -> ())

public func add(domain: String, to list: ListType, completion: @escaping (Result<Void, SwiftHoleError>) -> ())

public func remove(domain: String, from list: ListType, completion: @escaping (Result<Void, SwiftHoleError>) -> ())

swifthole's People

Contributors

bunn avatar leafonthewind avatar subdigital avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.