Swiftpack.co - readium/r2-opds-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by readium.
readium/r2-opds-swift 2.2.0
A Swift parser for OPDS 1.x and 2.0, based on the Readium-2 models
⭐️ 5
🕓 4 weeks ago
iOS
.package(url: "https://github.com/readium/r2-opds-swift.git", from: "2.2.0")

:warning: ᴛʜɪs ʀᴇᴘᴏsɪᴛᴏʀʏ ɪs ᴅᴇᴘʀᴇᴄᴀᴛᴇᴅ :warning:

We moved all the r2-*-swift modules to a single repository: swift-toolkit.

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: 5
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

2.2.0
4 weeks ago

Take a look at the migration guide

Nothing new for r2-opds-swift in Readium Swift 2.2.0.

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