-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse url query param from Google Alerts feeds
- Loading branch information
Showing
10 changed files
with
92 additions
and
14 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
3 changes: 0 additions & 3 deletions
3
capy/src/main/java/com/jocmp/capy/accounts/LocalOkHttpClient.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
27 changes: 27 additions & 0 deletions
27
capy/src/main/java/com/jocmp/capy/accounts/local/ArticleURL.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,27 @@ | ||
package com.jocmp.capy.accounts.local | ||
|
||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull | ||
import java.net.MalformedURLException | ||
import java.net.URL | ||
|
||
internal object ArticleURL { | ||
internal fun parse(url: URL): URL { | ||
return googleAlertURL(url) ?: url | ||
} | ||
|
||
private fun googleAlertURL(url: URL): URL? { | ||
if (url.host != GOOGLE_ALERTS_DOMAIN) { | ||
return null | ||
} | ||
|
||
val articleURLParam = url.toHttpUrlOrNull()?.queryParameter("url") ?: return null | ||
|
||
return try { | ||
URL(articleURLParam) | ||
} catch (e: MalformedURLException) { | ||
null | ||
} | ||
} | ||
|
||
private const val GOOGLE_ALERTS_DOMAIN = "www.google.com" | ||
} |
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
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
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
26 changes: 26 additions & 0 deletions
26
capy/src/test/java/com/jocmp/capy/accounts/local/ArticleURLTest.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,26 @@ | ||
package com.jocmp.capy.accounts.local | ||
|
||
import java.net.URL | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class ArticleURLTest { | ||
@Test | ||
fun `entry URL is the same as article URL`() { | ||
val entryURL = URL("https://www.theverge.com/2025/1/12/24340818/robot-vacuum-innovations-roborock-dreame-ecovacs-ces2025") | ||
|
||
val url = ArticleURL.parse(url = entryURL) | ||
|
||
assertEquals(expected = entryURL.toString(), actual = url.toString()) | ||
} | ||
|
||
@Test | ||
fun `with a Google Alert entry URL it returns the url param`() { | ||
val entryURL = URL("https://www.google.com/url?rct=j&sa=t&url=https://www.androidheadlines.com/2025/01/meta-sued-for-allegedly-training-ai-with-content-from-pirated-books.html&ct=ga&cd=CAIyGjQ2MjY4NTIwYjAzMGNkMzc6Y29tOmVuOlVT&usg=AOvVaw2Ez54Yz16bwLLLX_YLfwA2") | ||
val articleURL = URL("https://www.androidheadlines.com/2025/01/meta-sued-for-allegedly-training-ai-with-content-from-pirated-books.html") | ||
|
||
val url = ArticleURL.parse(url = entryURL) | ||
|
||
assertEquals(expected = articleURL.toString(), actual = url.toString()) | ||
} | ||
} |
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
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
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