Swiftpack.co -  readium/r2-opds-swift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
readium/r2-opds-swift
A Swift parser for OPDS 1.x and 2.0, based on the Readium-2 models
.package(url: "https://github.com/readium/r2-opds-swift.git", from: "2.0.0")

OPDS Parser (Swift)

License

A parser for OPDS 1.x and 2.0 written in Swift using the Readium-2 shared model and Readium Web Publication Manifest.

Changes and releases are documented in the Changelog

Features

  • ☑ Abstract model
  • ☑ OPDS 1.x support
  • ☑ OPDS 2.0 support
  • ☑ Search
  • ☑ Full entries
  • ☑ Facets
  • ☑ Groups
  • ☑ Indirect acquisition
  • ☐ Library specific extensions

Getting started

Adding the library to your iOS project

Note: requires Swift 4.2 (and Xcode 10.1).

Carthage

Carthage is a simple, decentralized dependency manager for Cocoa. To install ReadiumOPDS with Carthage:

  1. Make sure Carthage is installed.

  2. Update your Cartfile to include the following:

    github "readium/r2-opds-swift" "develop"
    
  3. Run:

  4. Add the appropriate framework.

Import

In your Swift files:

// Swift source file

import ReadiumOPDS

Dependencies in this module

  • R2Shared : Custom types shared by several readium-2 Swift modules.
  • Fuzi : A fast & lightweight XML & HTML parser in Swift with XPath & CSS support.

Modifications needed in Xcode:

In Build Settings, find Search Paths, add $(SDKROOT)/usr/include/libxml2 to Header Search Paths.

Usage

Parsing an OPDS feed (v1.x or 2.x):

import ReadiumOPDS

let myURL = URL(string: "https://your/custom/url")
var parseData: ParseData?

override func viewDidLoad() {
    super.viewDidLoad()
    
    // Fetch and parse data from the specified URL
    OPDSParser.parseURL(url: myURL) { data, error in
        if let data = data {
            // parseData property holds the OPDS related data
            self.parseData = data
        }
    }
}

func refreshUI() {
  // Custom method
}

API

Version

/// List of OPDS versions compliant with the parser.
public enum Version {
    /// OPDS 1.x must be an XML ressource
    case OPDS1
    /// OPDS 2.x must be a JSON ressource
    case OPDS2
}

ParseData structure

/// An intermediate structure return when the generic helper method public static
/// func parseURL(url: URL, completion: (ParseData?, Error?) -> Void) from OPDSParser class is called.
public struct ParseData {
    /// The ressource URL
    public var url: URL
    
    /// The URLResponse got after fetching the ressource
    public var response: URLResponse
    
    /// The OPDS version
    public var version: Version
    
    /// The feed (nil if publication is not)
    public var feed: Feed?
    
    /// The publication (nil if feed is not)
    public var publication: Publication?
}

OPDSParser class

/// Parse an OPDS feed or publication.
/// Feed can be v1 (XML) or v2 (JSON).
/// - parameter url: The feed URL
public static func parseURL(url: URL, completion: (ParseData?, Error?) -> Void)

GitHub

link
Stars: 4
Last commit: 4 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

2.0.0
3 weeks ago

Take a look at the migration guide

Changed

  • Upgraded shared dependencies.

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