Added URL reader and encoder extension funtions.
This commit is contained in:
parent
25d7a74568
commit
0dd02d7039
8 changed files with 27 additions and 32 deletions
|
@ -32,6 +32,8 @@
|
|||
|
||||
package net.thauvin.erik.mobibot
|
||||
|
||||
import net.thauvin.erik.mobibot.Utils.encodeUrl
|
||||
import net.thauvin.erik.mobibot.Utils.reader
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
import org.testng.Assert.assertFalse
|
||||
import org.testng.Assert.assertTrue
|
||||
|
@ -66,12 +68,8 @@ class PinboardTest : LocalProperties() {
|
|||
}
|
||||
|
||||
private fun validatePin(apiToken: String, url: String, vararg matches: String): Boolean {
|
||||
val response = Utils.urlReader(
|
||||
URL(
|
||||
"https://api.pinboard.in/v1/posts/get?auth_token=${apiToken}&tag=test&"
|
||||
+ Utils.encodeUrl(url)
|
||||
)
|
||||
)
|
||||
val response =
|
||||
URL("https://api.pinboard.in/v1/posts/get?auth_token=${apiToken}&tag=test&" + url.encodeUrl()).reader()
|
||||
|
||||
matches.forEach {
|
||||
if (!response.contains(it)) {
|
||||
|
|
|
@ -49,6 +49,7 @@ import net.thauvin.erik.mobibot.Utils.helpFormat
|
|||
import net.thauvin.erik.mobibot.Utils.lastOrEmpty
|
||||
import net.thauvin.erik.mobibot.Utils.obfuscate
|
||||
import net.thauvin.erik.mobibot.Utils.plural
|
||||
import net.thauvin.erik.mobibot.Utils.reader
|
||||
import net.thauvin.erik.mobibot.Utils.red
|
||||
import net.thauvin.erik.mobibot.Utils.replaceEach
|
||||
import net.thauvin.erik.mobibot.Utils.reverseColor
|
||||
|
@ -153,7 +154,7 @@ class UtilsTest {
|
|||
|
||||
@Test
|
||||
fun testEncodeUrl() {
|
||||
assertThat(encodeUrl("Hello Günter")).isEqualTo("Hello+G%C3%BCnter")
|
||||
assertThat("Hello Günter".encodeUrl()).isEqualTo("Hello+G%C3%BCnter")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -274,7 +275,7 @@ class UtilsTest {
|
|||
@Test
|
||||
@Throws(IOException::class)
|
||||
fun testUrlReader() {
|
||||
assertThat(urlReader(URL("https://postman-echo.com/status/200")), "urlReader()")
|
||||
assertThat(URL("https://postman-echo.com/status/200").reader(), "urlReader()")
|
||||
.isEqualTo("{\"status\":200}")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue