Awesome
<h1 align="center">ParseRSS</h1> <p align="center"> <a href="https://jitpack.io/#muhrifqii/ParseRSS"> <img src="https://jitpack.io/v/muhrifqii/ParseRSS.svg" /> </a> <a href="http://kotlinlang.org"> <img src="https://img.shields.io/badge/kotlin-1.9.21-yellow"/> </a> <a href="https://travis-ci.org/muhrifqii/ParseRSS"> <img src="https://travis-ci.org/muhrifqii/ParseRSS.svg?branch=master" /> </a> <a href="https://github.com/muhrifqii/ParseRSS/blob/master/LICENSE"> <img src="https://img.shields.io/badge/license-MIT-blue" /> </a> <a href="https://www.codacy.com/gh/muhrifqii/ParseRSS/dashboard?utm_source=github.com&utm_medium=referral&utm_content=muhrifqii/ParseRSS&utm_campaign=Badge_Grade"> <img src="https://app.codacy.com/project/badge/Grade/78c8325c65d649719dc627c1e803e647"/> </a> <a href="https://www.codefactor.io/repository/github/muhrifqii/parserss/overview/master"><img src="https://www.codefactor.io/repository/github/muhrifqii/parserss/badge/master" alt="CodeFactor" /></a> <a href="https://codebeat.co/projects/github-com-muhrifqii-parserss-master"><img alt="codebeat badge" src="https://codebeat.co/badges/b4cf5384-6139-4256-90c0-fe432ad648a4" /></a> </p> <p align="center"><sup>RSS Parser for android</sup></p> <br/> <br/>Simple, concise, and extensible RSS Parser in the entire coffee shop. It can capture these information from the RSS article:
-
RSS Version based on https://validator.w3.org/feed/docs/
-
RSS Namespace Checking
- Atom
- DC
- Media
- RDF
- SY
- Specific namespaces
-
Channel
- Title
<title>
- Description
<description>
- Link
<link>
- Publication Date
<pubDate>
- Image
<image>
- Language
<language>
- Copyright
<copyright>
- Rights
<rights>
- Last Build Date
<lastBuildDate>
- Atom Link
<atom:link>
- TimeToLive
<ttl>
- SkipHours
<skipHours>
- SkipDays
<skipDays>
- Managing Editor
<managingEditor
- Title
-
Items Element
- Title
<title>
- Description
<description>
- Link
<link>
- Item GUId
<guid>
- Media Content (NYT)
<media:content>
- Media Credit (NYT)
<media:credit>
- Media Description (NYT)
<media:description>
- Publication Date
<pubDate>
- Author
<author>
- Categories
<category>
- Source
<source>
- Enclosure
<enclosure>
- Atom Link
<atom:link>
- DC Creator (NYT)
<dc:creator>
- Comments
<comments>
- Title
ParseRSS
mainly has two main objects. RSSFeedObject
and RSSItemObject
. You can create your own parsing strategy by
implementing RSSFeed
and RSSItem
.
Usage
ParseRSS depends on XmlPullParser
, so feed it at least once in a lifetime. First thing first, the initialization part.
You can put it on your Application onCreate function.
ParseRSS.init(XmlPullParserFactory.newInstance())
Be aware that XmlPullParser could throw an exception even in initialization step.
Next, feed the RSS string into ParseRSS
val feed: RSSFeedObject = ParseRSS.parse(xml)
feed.items.forEach {
print(it.title)
}
ParseRSS as a Converter
ParseRSS does not have its own networking mechanism. Instead, it benefits from infamous networking library such as Retrofit, and Fuel. By using ConverterFactory, ParseRSS is ready to ship without breaking your project design pattern.
Fuel
Convert Fuel Response into RSSFeed by using responseRss
function.
Fuel.get(URL).responseRss<RSSFeedObject> { result ->
result.fold({ feed ->
feed.items.forEach {
print(it.title)
}
}, { error ->
print(error)
})
}
Retrofit
Convert Retrofit Response into RSSFeed by using ParseRSSConverterFactory
interface MyRssService {
@GET("rss")
fun rss(): Call<RSSFeedObject>
}
val retrofit = Retrofit.Builder()
.addConverterFactory(ParseRSSConverterFactory.create<RSSFeedObject>())
.baseUrl(BASE_URL)
.build()
val rssService = retrofit.create(MyRssService::class.java)
rssService.rss().enqueue(object : Callback<RSSFeedObject> {
override fun onFailure(call: Call<RSSFeedObject>, t: Throwable) {
}
override fun onResponse(call: Call<RSSFeedObject>, response: Response<RSSFeedObject>) {
}
})
Gradle Dependency
Add jitpack repository in your root build.gradle
at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Used on Fuel
// ParseRSS as Fuel Converter Factory
implementation "com.github.muhrifqii.ParseRSS:parserss:$version"
implementation "com.github.muhrifqii.ParseRSS:fuel:$version"
Used on Retrofit
// ParseRSS as Retrofit Converter Factory
implementation "com.github.muhrifqii.ParseRSS:parserss:$version"
implementation "com.github.muhrifqii.ParseRSS:retrofit:$version"
License
Copyright (c) 2019 Muhammad Rifqi Fatchurrahman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.