Giter Club home page Giter Club logo

syndikit's Introduction

SyndiKit

Swift Package built on top of XMLCoder for Decoding RSS Feeds. Check out the DocC-Built Site!

DocC

Twitter GitHub SyndiKit GitHub issues

Codecov CodeFactor codebeat badge Code Climate maintainability Code Climate technical debt Code Climate issues Reviewed by Hound

Table of Contents

Introduction

Built on top of XMLCoder, SyndiKit can be used to import and read site data whether from a WordPress site, RSS feeds, YouTube channel or podcast.

Features

  • Import of RSS 2.0, Atom, and JSONFeed formats
  • Extensions for iTunes-compatabile podcasts, YouTube channels, as well as WordPress export data
  • User-friendly errors
  • Abstractions for format-agnostic parsing

Installation

Requirements

Apple Platforms

  • Xcode 13.3 or later
  • Swift 5.5.2 or later
  • iOS 15.4 / watchOS 8.5 / tvOS 15.4 / macOS 12.3 or later deployment targets

Linux

  • Ubuntu 18.04 or later
  • Swift 5.5.2 or later

Swift Package Manager

Swift Package Manager is Apple's decentralized dependency manager to integrate libraries to your Swift projects. It is now fully integrated with Xcode 11.

To integrate SyndiKit into your project using SPM, specify it in your Package.swift file:

let package = Package(
  ...
  dependencies: [
    .package(url: "https://github.com/brightdigit/SyndiKit", from: "0.3.0")
  ],
  targets: [
      .target(
          name: "YourTarget",
          dependencies: ["SyndiKit", ...]),
      ...
  ]
)

If this is for an Xcode project simply import the repo at:

https://github.com/brightdigit/SyndiKit

Usage

SyndiKit provides models and utilities for decoding RSS feeds of various formats and extensions.

Decoding Your First Feed

You can get started decoding your feed by creating your first SynDecoder. Once you've created you decoder you can decode using SynDecoder/decode(_:):

let decoder = SynDecoder()
let empowerAppsData = Data(contentsOf: "empowerapps-show.xml")!
let empowerAppsRSSFeed = try decoder.decode(empowerAppsData)

Working with Abstractions

Rather than working directly with the various formats, SyndiKit abstracts many of the common properties of the various formats. This enables developers to be agnostic regarding the specific format.

let decoder = SynDecoder()

// decoding a RSS 2.0 feed
let empowerAppsData = Data(contentsOf: "empowerapps-show.xml")!
let empowerAppsRSSFeed = try decoder.decode(empowerAppsData)
print(empowerAppsRSSFeed.title) // Prints "Empower Apps"

// decoding a Atom feed from YouTube
let kiloLocoData = Data(contentsOf: "kilo.youtube.xml")!
let kiloLocoAtomFeed = try decoder.decode(kiloLocoData)
print(kiloLocoAtomFeed.title) // Prints "Kilo Loco"

Specifying Formats

If you wish to access properties of specific formats, you can attempt to cast the objects to see if they match:

let empowerAppsRSSFeed = try decoder.decode(empowerAppsData)
if let rssFeed = empowerAppsRSSFeed as? RSSFeed {
  print(rssFeed.channel.title) // Prints "Empower Apps"
}

let kiloLocoAtomFeed = try decoder.decode(kiloLocoData)
if let atomFeed = kiloLocoAtomFeed as? AtomFeed {
  print(atomFeed.title) // Prints "Empower Apps"
}

Accessing Extensions

In addition to supporting RSS, Atom, and JSONFeed, SyndiKit also supports various RSS extensions for specific media including: YouTube, iTunes, and WordPress.

You can access these properties via their specific feed formats or via the Entryable/media property on Entryable.

let empowerAppsRSSFeed = try decoder.decode(empowerAppsData)
switch empowerAppsRSSFeed.children.last?.media {
  case .podcast(let podcast):
    print(podcast.title) // print "WWDC 2018 - What Does It Mean For Businesses?"
  default:
    print("Not a Podcast! 🤷‍♂️")
}

let kiloLocoAtomFeed = try decoder.decode(kiloLocoData)
switch kiloLocoAtomFeed.children.last?.media {
  case .video(.youtube(let youtube):
    print(youtube.videoID) // print "SBJFl-3wqx8"
    print(youtube.channelID) // print "UCv75sKQFFIenWHrprnrR9aA"
  default:
    print("Not a Youtube Video! 🤷‍♂️")
}

Documentation

There are two formats for the source documentation:

The DocC official web site is at syndikit.dev. This includes tutorials, articles, code documentation and more.

For just markdown formatted documentation on GitHub using SourceDocs, you can read see the list of types here.

Roadmap

1.0.0

  • OPML Support
  • WordPress DocC Tutorial
  • RSS Import Tutorial (i.e. OrchardNest)

License

This code is distributed under the MIT license. See the LICENSE file for more info.

syndikit's People

Contributors

devahmedshendy avatar leogdion avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

syndikit's Issues

Problems with RSS from some major news cooperations

I tried out SyndiKit in my app, where I want to parse the RSS feed from CNN and the national Danish broadcasting company 'DR'. Both fail. When I try an RSS feed from the national Swedish broadcasting company 'SVT', it works fine.

I can't seem to figure out, what the difference is, that makes CNN and DR fail.

The failing RSS feeds:

The working RSS feed:

dataCorrupted for some feeds

When I try to parse https://feeds.npr.org/344098539/podcast.xml, I get this error. Tried with another RSS parser, and it was able to parse it, so I'm not sure what's wrong exactly.

dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "Failed to decode data with several decoders.", underlyingError: Optional((extension in SyndiKit):Swift.DecodingError.Dictionary(errors: ["RSS": Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "link", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "channel", intValue: nil), CodingKeys(stringValue: "item", intValue: nil), XMLKey(stringValue: "193", intValue: 193), XMLKey(stringValue: "193", intValue: 193), CodingKeys(stringValue: "link", intValue: nil)], debugDescription: "No attribute or element found for key CodingKeys(stringValue: \"link\", intValue: nil) (\"link\").", underlyingError: nil)), "Atom": Swift.DecodingError.keyNotFound(CodingKeys(stringValue: "id", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "id", intValue: nil)], debugDescription: "No attribute or element found for key CodingKeys(stringValue: \"id\", intValue: nil) (\"id\").", underlyingError: nil))]))))

Parse Other Podcast Elements

<podcast:transcript url="https://share.transistor.fm/s/336118a1/transcript.srt" type="text/srt" rel="captions"/>
<podcast:chapters url="https://share.transistor.fm/s/336118a1/chapters.json" type="application/json+chapters"/>

Make all `WordPressElements` as `Equatable`, and make their properties as public

To make following WordPressElements confirming to Equatable protocol, and their properties as public:

Reason:
We needed them part of ContributeWordPress testing, and their properties are inaccessible due to internal access modifier.

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.