Skip to content

Commit

Permalink
Merge pull request #9 from muhrifqii/feature/atom
Browse files Browse the repository at this point in the history
Enable Atom Feed
  • Loading branch information
muhrifqii authored Apr 25, 2022
2 parents 09a7bb5 + 78e0065 commit 0d985e1
Show file tree
Hide file tree
Showing 27 changed files with 597 additions and 98 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ jobs:
gradle:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
- uses: gradle/gradle-build-action@v2
with:
arguments: testDebugUnitTest debugCoverage allDebugCoverage
arguments: detekt testDebugUnitTest debugCoverage allDebugCoverage
- uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: build/reports/detekt/detekt.sarif
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ Simple, concise, and extensible RSS Parser in the entire coffee shop. It can cap
article:

- RSS Version based on https://validator.w3.org/feed/docs/
- [ ] [Atom](https://xml2rfc.tools.ietf.org/public/rfc/html/rfc4287.html)
- [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
- [ ] Atom
- [x] Atom
- [ ] DC
- [x] Media
- [x] RDF
Expand All @@ -51,7 +51,7 @@ article:
- [x] Copyright `<copyright>`
- [x] Rights `<rights>`
- [x] Last Build Date `<lastBuildDate>`
- [ ] Atom Link `<atom:link>`
- [x] Atom Link `<atom:link>`
- [ ] TimeToLive `<ttl>`
- [ ] SkipHours `<skipHours>`
- [ ] SkipDays `<skipDays>`
Expand All @@ -70,7 +70,7 @@ article:
- [x] Categories `<category>`
- [ ] Source `<source>`
- [ ] Enclosure `<enclosure>`
- [ ] Atom Link `<atom:link>`
- [x] Atom Link `<atom:link>`
- [ ] DC Creator _(NYT)_ `<dc:creator>`
- [x] Comments `<comments>`

Expand Down
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ task clean(type: Delete) {
}

detekt {
toolVersion = "1.19.0"
buildUponDefaultConfig = true
allRules = false
config = files("$projectDir/detekt-config.yml")
config = files("$projectDir/detekt.yml")
parallel = true
setSource(files(projectDir))
reports {
xml.required.set(true)
html.required.set(true)
txt.required.set(false)
sarif.required.set(true)
}
}

dependencies {
Expand Down
Empty file removed detekt-config.yml
Empty file.
95 changes: 95 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
build:
maxIssues: 0
excludeCorrectable: false
weights:
config:
validation: true
warningsAsErrors: false
# when writing own rules with new properties, exclude the property path e.g.: 'my_rule_set,.*>.*>[my_property]'
excludes: ''
comments:
active: true
UndocumentedPublicClass:
active: false
excludes: &excludedDirs
- '**/test/**'
- '**/androidTest/**'
- '**/sample/**'
searchInNestedClass: true
searchInInnerClass: true
searchInInnerObject: true
searchInInnerInterface: true
UndocumentedPublicFunction:
active: true
excludes: *excludedDirs
UndocumentedPublicProperty:
active: false
complexity:
TooManyFunctions:
active: true
excludes: *excludedDirs
thresholdInFiles: 25
thresholdInClasses: 25
thresholdInInterfaces: 25
thresholdInObjects: 50
thresholdInEnums: 25
ignoreDeprecated: true
ignorePrivate: false
ignoreOverridden: true
NestedBlockDepth:
active: true
threshold: 4
empty-blocks:
active: true
EmptyCatchBlock:
active: true
allowedExceptionNameRegex: '_|(ignore|expected).*'
EmptyClassBlock:
active: true
EmptyDefaultConstructor:
active: true
EmptyDoWhileBlock:
active: true
EmptyElseBlock:
active: true
EmptyFinallyBlock:
active: true
EmptyForBlock:
active: true
EmptyFunctionBlock:
active: true
ignoreOverridden: true
EmptyIfBlock:
active: true
EmptyInitBlock:
active: true
EmptyKtFile:
active: true
EmptySecondaryConstructor:
active: true
EmptyTryBlock:
active: true
EmptyWhenBlock:
active: true
EmptyWhileBlock:
active: true
exceptions:
active: true
SwallowedException:
active: false
style:
active: true
MaxLineLength:
active: true
excludes: *excludedDirs
maxLineLength: 120
excludePackageStatements: true
excludeImportStatements: true
excludeCommentStatements: true
ReturnCount:
active: true
max: 3
PreferToOverPairSyntax:
active: true
formatting:
excludes: *excludedDirs
2 changes: 1 addition & 1 deletion fuel/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.7.3'
testImplementation 'org.mockito:mockito-core:4.3.1'
testImplementation 'org.mockito:mockito-core:4.4.0'
testImplementation 'com.google.truth:truth:1.1.3'
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.github.muhrifqii.parserss.fuel

import com.github.kittinunf.fuel.core.*
import com.github.kittinunf.fuel.core.Request
import com.github.kittinunf.fuel.core.ResponseDeserializable
import com.github.kittinunf.fuel.core.ResponseHandler
import com.github.kittinunf.fuel.core.ResponseResultHandler
import com.github.kittinunf.fuel.core.ResultHandler
import com.github.kittinunf.fuel.core.response
import com.github.muhrifqii.parserss.ParseRSS
import com.github.muhrifqii.parserss.RSSFeed
import java.io.Reader
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ compilesdk_version=31
buildtools_version=30.0.2
minsdk_version=14
targetsdk_version=31
project_version=0.5.0
project_version_code=500
project_version=0.6.0
project_version_code=600
3 changes: 2 additions & 1 deletion parserss/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {

testImplementation 'junit:junit:4.13.2'
testImplementation 'org.robolectric:robolectric:4.7.3'
testImplementation 'org.mockito:mockito-core:4.3.1'
testImplementation 'org.mockito:mockito-core:4.4.0'
testImplementation 'com.google.truth:truth:1.1.3'
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1"
}
12 changes: 0 additions & 12 deletions parserss/src/main/java/com/github/muhrifqii/parserss/ParseRSS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ object ParseRSS : ParseRSSOperation {
factory = pullParserFactory
}

/**
* Release Parser Factory
*/
override fun release() {
factory = null
}
Expand All @@ -29,9 +26,6 @@ object ParseRSS : ParseRSSOperation {
@Deprecated("unused", ReplaceWith(""), DeprecationLevel.ERROR)
override var applyRSSFeedConstructor: (() -> RSSFeed) = { RSSFeedObject() }

/**
* Parse RSS from Reader Object
*/
@Suppress("UNCHECKED_CAST")
@Throws(XmlPullParserException::class, IOException::class, ParseRSSException::class)
override fun <R : RSSFeed> parse(xml: Reader): R {
Expand All @@ -40,9 +34,6 @@ object ParseRSS : ParseRSSOperation {
} as R
}

/**
* Parse RSS from xml String
*/
@Suppress("UNCHECKED_CAST")
@Throws(XmlPullParserException::class, IOException::class, ParseRSSException::class)
override fun <R : RSSFeed> parse(xml: String): R {
Expand All @@ -51,9 +42,6 @@ object ParseRSS : ParseRSSOperation {
} as R
}

/**
* Parse RSS customizable
*/
override fun <T : RSSFeed> parse(xml: Reader, strictlyNamespaceChecking: Boolean, feedSupplier: () -> T): T {
val unwrappedFactory =
factory ?: throw ParseRSSException("xmlPullParserFactory is null. Should call ParseRSS.init() once.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal object ParseRSSKeyword {
const val DEFAULT_NS = ""
const val MEDIA_NS = "media"
const val RDF_NS = "rdf"
const val ATOM_NS = "atom"
const val DC_NS = "dc"

const val CHANNEL = "channel"
Expand All @@ -27,34 +28,45 @@ internal object ParseRSSKeyword {
const val CREDIT = "credit"
const val COMMENTS = "comments"

const val FEED = "feed"
const val ENTRY = "entry"

const val RDF_SEQ = "$RDF_NS:seq"
const val RDF_SEQ_LIST = "$RDF_NS:li"
const val SUBTITLE = "subtitle"
const val NAME = "name"
const val URI = "uri"
const val EMAIL = "email"
const val ID = "id"
const val UPDATED = "updated"
const val PUBLISHED = "published"
const val CONTRIBUTOR = "contributor"
const val SUMMARY = "summary"

const val ATTR_PERMALINK = "isPermaLink"
const val ATTR_DOMAIN = "domain"
const val ATTR_MEDIUM = "medium"
const val ATTR_HEIGHT = "height"
const val ATTR_WIDTH = "width"
const val ATTR_URL = "url"
const val ATTR_URI = "uri"
const val ATTR_HREF = "href"
const val ATTR_REL = "rel"
}

enum class RSSVersion(val elementName: String) {
TBD(""), RSS_V1("rdf"), RSS_V2("rss");
enum class RSSVersion(val elementName: String, val xmlns: String) {
TBD("", ""),
RSS_V1("rdf", "http://purl.org/rss/1.0/"),
RSS_V2("rss", ""),
RSS_ATOM("feed", "http://www.w3.org/2005/Atom");

override fun toString(): String {
return "$name(elementName='$elementName')"
}
override fun toString(): String = "RSSVersion(elementName='$elementName', xmlns='$xmlns')"

companion object {
fun valueOfElement(elementName: String): RSSVersion {
return when (elementName) {
RSS_V1.elementName -> RSS_V1
RSS_V2.elementName -> RSS_V2
else -> throw IllegalArgumentException("$elementName is not a valid element")
}
/**
* Deduce version based from rss element
*/
fun valueOfElement(elementName: String): RSSVersion = when (elementName) {
RSS_V1.elementName -> RSS_V1
RSS_V2.elementName -> RSS_V2
RSS_ATOM.elementName -> RSS_ATOM
else -> throw IllegalArgumentException("$elementName is not a valid element")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@ import java.io.IOException
import java.io.Reader

interface ParseRSSOperation {
/**
* Release Parser Factory
*/
fun release()
var applyRSSFeedConstructor: (() -> RSSFeed)

/**
* Parse RSS from Reader Object
*/
@Throws(ParseRSSException::class, IOException::class)
fun <R : RSSFeed> parse(xml: Reader): R

/**
* Parse RSS from xml String
*/
@Throws(ParseRSSException::class)
fun <R : RSSFeed> parse(xml: String): R

/**
* Parse RSS customizable
*/
@Throws(ParseRSSException::class)
fun <T : RSSFeed> parse(xml: Reader, strictlyNamespaceChecking: Boolean, feedSupplier: () -> T): T
}
Loading

0 comments on commit 0d985e1

Please sign in to comment.