ParseRSS
Simple, concise, and extensible RSS Parser in the entire coffee shop. It can capture these information from the RSS article:
- Title
- Description
- Link
- Publication Date
- Image
- Item GUId
- Language
- Media
- Author
- Categories
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.