-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...n/src/main/kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzDomains.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz | ||
|
||
internal class MyDealzDomains { | ||
companion object { | ||
internal val DOMAINS_REGEX = Regex( | ||
"www\\.mydealz\\.de|mydealz\\.de|" + | ||
"chollometro\\.com|dealabs\\.com|desidime\\.com|hotukdeals\\.com|nl\\.pepper\\.com|" + | ||
"pepper\\.it|pepper\\.pl|pepper\\.ru|promodescuentos\\.com|pelando\\.com\\.br|" + | ||
"preisjaeger\\.at", | ||
) | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...otlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanitizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Léon - The URL Cleaner | ||
* Copyright (C) 2024 Sven Jacobs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz | ||
|
||
import android.content.Context | ||
import com.svenjacobs.app.leon.core.common.regex.RegexFactory | ||
import com.svenjacobs.app.leon.core.domain.R | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.RegexSanitizer | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId | ||
|
||
class MyDealzParametersSanitizer : | ||
RegexSanitizer( | ||
RegexFactory.AllParameters, | ||
) { | ||
|
||
override val id = SanitizerId("mydealz_parameters") | ||
|
||
override fun getMetadata(context: Context) = Sanitizer.Metadata( | ||
name = context.getString(R.string.sanitizer_mydealz_paremeters_name), | ||
) | ||
|
||
override fun matchesDomain(input: String) = MyDealzDomains.DOMAINS_REGEX.containsMatchIn(input) | ||
} |
49 changes: 49 additions & 0 deletions
49
...kotlin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanitizer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Léon - The URL Cleaner | ||
* Copyright (C) 2022 Sven Jacobs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz | ||
|
||
import android.content.Context | ||
import com.svenjacobs.app.leon.core.domain.R | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.Sanitizer | ||
import com.svenjacobs.app.leon.core.domain.sanitizer.SanitizerId | ||
|
||
class MyDealzRedirectsSanitizer : Sanitizer { | ||
|
||
override val id = SanitizerId("mydealz_redirects") | ||
|
||
override fun getMetadata(context: Context) = Sanitizer.Metadata( | ||
name = context.getString(R.string.sanitizer_mydealz_redirects_name), | ||
) | ||
|
||
override fun matchesDomain(input: String) = MyDealzDomains.DOMAINS_REGEX.containsMatchIn(input) | ||
|
||
override fun invoke(input: String): String { | ||
val groupValues = DEAL_REGEX.matchEntire(input)?.groupValues | ||
?: return input // URL is not in redirect format, pass through | ||
val host = groupValues.getOrNull(1) | ||
?: throw IllegalArgumentException("Could not extract host from MyDealz URL") | ||
val deal = groupValues.getOrNull(2) | ||
?: throw IllegalArgumentException("Could not extract deal from MyDealz URL") | ||
return "https://$host/deals/a-$deal" | ||
} | ||
|
||
private companion object { | ||
private val DEAL_REGEX = Regex("https://([^/]+)/share-deal-from-app/(.+)\$") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...in/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzParametersSanizierTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Léon - The URL Cleaner | ||
* Copyright (C) 2023 Sven Jacobs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class MyDealzParametersSanizierTest : | ||
WordSpec( | ||
{ | ||
|
||
"invoke" should { | ||
|
||
"convert www.mydealz.de app URLs (with ad redirect) into base/direct URLs" { | ||
val sanitizer = MyDealzParametersSanitizer() | ||
val result = sanitizer("https://www.mydealz.de/diskussion/gratis-adidas-fussball-trikot-2383743?pprmrkntfctnsrd=123456789&UATypeId=18") | ||
result shouldBe "https://www.mydealz.de/diskussion/gratis-adidas-fussball-trikot-2383743" | ||
} | ||
} | ||
}, | ||
) |
49 changes: 49 additions & 0 deletions
49
...lin/com/svenjacobs/app/leon/core/domain/sanitizer/mydealz/MyDealzRedirectsSanizierTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Léon - The URL Cleaner | ||
* Copyright (C) 2023 Sven Jacobs | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.svenjacobs.app.leon.core.domain.sanitizer.mydealz | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
class MyDealzRedirectsSanizierTest : | ||
WordSpec( | ||
{ | ||
|
||
"invoke" should { | ||
|
||
"convert www.mydealz.de app URLs (with ad redirect) into base/direct URLs" { | ||
val sanitizer = MyDealzRedirectsSanitizer() | ||
val result = sanitizer("https://www.mydealz.de/share-deal-from-app/2117879") | ||
result shouldBe "https://www.mydealz.de/deals/a-2117879" | ||
} | ||
|
||
"convert mydealz.de app URLs (with ad redirect) into base/direct URLs" { | ||
val sanitizer = MyDealzRedirectsSanitizer() | ||
val result = sanitizer("https://mydealz.de/share-deal-from-app/2117879") | ||
result shouldBe "https://mydealz.de/deals/a-2117879" | ||
} | ||
|
||
"convert preisjaeger.at app URLs (with ad redirect) into base/direct URLs" { | ||
val sanitizer = MyDealzRedirectsSanitizer() | ||
val result = sanitizer("https://preisjaeger.at/share-deal-from-app/2117879") | ||
result shouldBe "https://preisjaeger.at/deals/a-2117879" | ||
} | ||
} | ||
}, | ||
) |