MangerKit

8.0.0

Request podcasts via proxy
michaelnisi/manger-kit

What's New

📦 Mangekit 8

2020-11-22T09:40:36Z

Convert to Swift package.

MangerKit

Browse podcasts with MangerKit. The MangerKit Swift package provides a JSON HTTP client that lets you request combined ranges of podcast feeds from the manger-http service, a caching RSS feed proxy.

MangerKit is used in the Podest podcast app.

Example

Requesting all episodes of three podcasts. You can limit the time range with the since property.

import Foundation
import Patron
import MangerKit

let url = URL(string: "https://your.endpoint")!
let s = URLSession(configuration: .default)
let p = Patron(URL: url, session: s)
let svc = Manger(client: p)

struct Query: MangerQuery {
  let url: String
  let since: Date

  init(url: String, since: Date = Date(timeIntervalSince1970: 0)) {
    self.url = url
    self.since = since
  }
}

let queries: [MangerQuery] = [
  Query(url: "http://feeds.wnyc.org/newyorkerradiohour"),
  Query(url: "http://feed.thisamericanlife.org/talpodcast"),
  Query(url: "http://feeds.serialpodcast.org/serialpodcast")
]

try! svc.entries(queries) { result, error in
  print(error ?? result)
}

The result is an unprocessed array of dictionaries, [[String: AnyObject]]?, typed Any? because JSON. Please refer to manger-http for details.

Dependencies

Types

MangerError

The simple error type also covers invalid queries.

enum MangerError: Error {
  case unexpectedResult(result: Any?)
  case cancelledByUser
  case noQueries
  case invalidQuery
  case niy
}

MangerQuery

Today, I don’t see why queries shouldn’t be struct—why we should be critical of using protocols.

protocol MangerQuery {
  var url: String { get }
  var since: Date { get }
}

MangerService

protocol MangerService {
  var client: JSONService { get }

  @discardableResult func feeds(
    _ queries: [MangerQuery],
    cachePolicy: NSURLRequest.CachePolicy,
    cb: @escaping (_ error: Error?, _ payload: [[String : AnyObject]]?) -> Void
  ) throws -> URLSessionTask

  @discardableResult func feeds(
    _ queries: [MangerQuery],
    cb: @escaping (_ error: Error?, _ payload: [[String : AnyObject]]?) -> Void
  ) throws -> URLSessionTask

  @discardableResult func entries(
    _ queries: [MangerQuery],
    cachePolicy: NSURLRequest.CachePolicy,
    cb: @escaping (_ error: Error?, _ payload: [[String : AnyObject]]?) -> Void
  ) throws -> URLSessionTask

  @discardableResult func entries(
    _ queries: [MangerQuery],
    cb: @escaping (_ error: Error?, _ payload: [[String : AnyObject]]?) -> Void
  ) throws -> URLSessionTask

  @discardableResult func version(
    _ cb: @escaping (_ error: Error?, _ service: String?) -> Void
  ) throws -> URLSessionTask
}

client

var client: JSONService { get }

The client property gives access to the underlying Patron client, providing hostname and status of the remote service.

Test

With manger-http running, do:

$ swift test

Install

📦 Add https://github.com/michaelnisi/manger-kit to your package manifest.

License

MIT License

Description

  • Swift Tools 5.3.0
View More Packages from this Author

Dependencies

Last updated: Sat Oct 19 2024 00:18:18 GMT-0900 (Hawaii-Aleutian Daylight Time)