Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/muhrifqii/parserss

A cup of library to Parse RSS for android. Also available as a ConverterFactory for Retrofit & Fuel
https://github.com/muhrifqii/parserss

android android-library feed fuel hacktoberfest kotlin retrofit2 retrofit2-converter rss rss-downloader rss-feed-parser rss-parser rssfeed

Last synced: 18 days ago
JSON representation

A cup of library to Parse RSS for android. Also available as a ConverterFactory for Retrofit & Fuel

Awesome Lists containing this project

README

        

ParseRSS


















CodeFactor
codebeat badge


RSS Parser for android





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/
- [x] [Atom](https://xml2rfc.tools.ietf.org/public/rfc/html/rfc4287.html)
- [x] [RSS V1](https://validator.w3.org/feed/docs/rss1.html#s5.2)
- [x] [RSS V0.91](https://www.rssboard.org/rss-specification)
- [x] [RSS V0.92](https://www.rssboard.org/rss-specification)
- [x] [RSS V2](https://www.rssboard.org/rss-specification)
- [x] Specific Version Handling
- RSS Namespace Checking
- [x] Atom
- [ ] DC
- [x] Media
- [x] RDF
- [ ] SY
- [ ] Specific namespaces
- Channel
- [x] Title ``
- [x] Description ``
- [x] Link ``
- [x] Publication Date ``
- [x] Image ``
- [x] Language ``
- [x] Copyright ``
- [x] Rights ``
- [x] Last Build Date ``
- [x] Atom Link ``
- [ ] TimeToLive ``
- [ ] SkipHours ``
- [ ] SkipDays ``
- [ ] Managing Editor ``
- [x] Description ``
- [x] Link ``
- [x] Item GUId ``
- [x] Media Content _(NYT)_ ``
- [x] Media Credit _(NYT)_ ``
- [x] Media Description _(NYT)_ ``
- [x] Publication Date ``
- [x] Author ``
- [x] Categories ``
- [ ] Source ``
- [ ] Enclosure ``
- [x] Atom Link ``
- [ ] DC Creator _(NYT)_ ``
- [x] Comments ``

`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.

```kotlin
ParseRSS.init(XmlPullParserFactory.newInstance())
```

Be aware that XmlPullParser could throw an exception even in initialization step.

Next, feed the RSS string into ParseRSS

```kotlin
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](https://square.github.io/retrofit/), and [Fuel](https://github.com/kittinunf/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.

```kotlin
Fuel.get(URL).responseRss { result ->
result.fold({ feed ->
feed.items.forEach {
print(it.title)
}
}, { error ->
print(error)
})
}
```

#### Retrofit

Convert Retrofit Response into RSSFeed by using `ParseRSSConverterFactory`

```kotlin
interface MyRssService {
@GET("rss")
fun rss(): Call
}
```

```kotlin
val retrofit = Retrofit.Builder()
.addConverterFactory(ParseRSSConverterFactory.create())
.baseUrl(BASE_URL)
.build()

val rssService = retrofit.create(MyRssService::class.java)
rssService.rss().enqueue(object : Callback {
override fun onFailure(call: Call, t: Throwable) {
}
override fun onResponse(call: Call, response: Response) {
}
})
```

## Gradle Dependency

Add jitpack repository in your **root** `build.gradle` at the end of repositories:

```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

### Used on Fuel

```gradle
// ParseRSS as Fuel Converter Factory
implementation "com.github.muhrifqii.ParseRSS:parserss:$version"
implementation "com.github.muhrifqii.ParseRSS:fuel:$version"
```

### Used on Retrofit

```gradle
// ParseRSS as Retrofit Converter Factory
implementation "com.github.muhrifqii.ParseRSS:parserss:$version"
implementation "com.github.muhrifqii.ParseRSS:retrofit:$version"
```

## License

```text
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.
```