Skip to content

Commit

Permalink
Endpoint correction
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcinMoskala committed Mar 16, 2023
1 parent b52dd2b commit cea6dfd
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.marcinmoskala"
val libVersion = "0.0.26"
val libVersion = "0.0.28"
version = libVersion

repositories {
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/AnkiConnector.kt
Expand Up @@ -173,7 +173,7 @@ class HeaderConfig(
val articleFileName: String? = null,
val packageDestination: String? = null,
// val generalComment: String? = null,
// val resourcesFile:String? = null
// val resourcesFile: String? = null
)

@Suppress("ArrayInDataClass")
Expand Down
13 changes: 9 additions & 4 deletions src/commonMain/kotlin/api/AnkiApi.kt
Expand Up @@ -215,12 +215,18 @@ class AnkiApi : RepositoryApi {
override suspend fun storeMediaFile(fileName: String, fileContentBase64: String): Boolean {
val data = FileNameAndData(fileName, fileContentBase64)
return request<ResultWithString>("storeMediaFile", json.encodeToString(data))
.result == "false"
.result != "false"
}

override suspend fun retrieveMediaFile(fileName: String): String =
request<ResultWithString>("retrieveMediaFile", """{ "filename": "$fileName" }}""")
.result.orEmpty()
request<ResultWithString>("retrieveMediaFile", """{ "filename": "$fileName" }""")
.result
.orEmpty()

suspend fun getAllMediaFileNames(): List<String> =
request<ResultWithListOfString>("getMediaFilesNames", """{ "pattern": "*" }""")
.result
.orEmpty()

private suspend fun call(action: String, params: String) {
val resText = client.post(url) {
Expand All @@ -235,7 +241,6 @@ class AnkiApi : RepositoryApi {
val paramsBody = if (params != null) """, "params": $params""" else ""
setBody("""{"action": "$action", "version": 6 $paramsBody}""")
}.body<String>()
println(resText)
return json.decodeFromString(resText)
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/commonTest/kotlin/PushingTest.kt
Expand Up @@ -310,6 +310,48 @@ class PushingTest: E2ETest() {
""".trimIndent()
)

@Test
fun listMultilineComments() = testPush(
markdown = """
S: What are HTTP methods?
* GET - The GET method requests a representation of the specified resource.
Requests using GET should only retrieve data.
* HEAD - The HEAD method asks for a response identical to a GET request,
but without the response body.
* POST - The POST method submits an entity to the specified resource,
often causing a change in state or side effects on the server.
generalComment: Those are not all the methods, there are also...
""".trimIndent(),
expectedNotes = listOf(
Note.ListDeletion(
type = Note.ListDeletion.ListType.List,
title = "What is the alphabet?",
items = listOf(
Note.ListDeletion.Item("A"),
Note.ListDeletion.Item("B"),
Note.ListDeletion.Item("C"),
)
)
),
expectedApiNotes = listOf(
listApi(
title = "What is the alphabet?",
items = mapOf(
"A" to "",
"B" to "",
"C" to "",
)
)
),
expectedMarkdown = """
@0
L: What is the alphabet?
* A
* B
* C
""".trimIndent()
)

@Test
fun general() = testPush(
markdown = """
Expand Down
9 changes: 5 additions & 4 deletions src/jvmMain/kotlin/com.marcinmoskala.application/Sync.kt
@@ -1,15 +1,16 @@
package com.marcinmoskala.application

import deckmarkdown.AnkiConnector
import deckmarkdown.api.AnkiApi
import kotlinx.coroutines.coroutineScope
import java.io.File

suspend fun main() = coroutineScope<Unit> {
val ankiMarkup = AnkiConnectorJvm()
val ankiConnector = AnkiConnector()
// ankiMarkup.syncFolder("notes")
// ankiMarkup.writeNotesToFile("Aktywne::Baza_wiedzy::The-Four-Hour-Work-Week", File("notes/Aktywne::Baza_wiedzy::The-Four-Hour-Work-Week.md"))
// ankiMarkup.writeNotesToFile("Aktywne::Latin_phrases", File("notes/Aktywne::Latin_phrases.md"))
ankiMarkup.pushFile(File("notes/Aktywne::Latin_phrases.md"))
// ankiMarkup.pushFile(File("notes/Aktywne::Latin_phrases.md"))
// ankiMarkup.syncFile(File("notes/Aktywne::Stoic::Ego_to_twój_wróg.md"))
// ankiMarkup.syncFile(File("notes/Aktywne::Stoic::Stoic_tldr.md"))
print("Done")
print(AnkiApi().retrieveMediaFile("210px-Alexei_Jawlensky_-_Young_Girl_with_a_Flowered_Hat,_1910_-_Google_Art_Project.jpg"))
}

0 comments on commit cea6dfd

Please sign in to comment.