Skip to content

Commit

Permalink
🐛 fix #31
Browse files Browse the repository at this point in the history
  • Loading branch information
theapache64 committed Nov 27, 2024
1 parent 47af05d commit aa1eb68
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import com.github.theapache64.retrosheet.utils.MoshiUtils
import com.squareup.moshi.Types
import java.io.IOException
import java.net.HttpURLConnection
import okhttp3.FormBody
import okhttp3.Interceptor
import okhttp3.MediaType
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response
import okhttp3.ResponseBody
import retrofit2.Invocation
Expand Down Expand Up @@ -84,18 +84,16 @@ class GoogleFormHelper(
// Sending post to google forms
val lastSlashIndex = formUrl.lastIndexOf('/')
val submitUrl = formUrl.substring(0, lastSlashIndex) + "/formResponse"

val mediaType: MediaType? = MediaType.parse("application/x-www-form-urlencoded")
val submitData = submitMap.map { it.key + "=" + it.value }.joinToString("&")

val body = RequestBody.create(
mediaType,
submitData
)
val formBody = FormBody.Builder()
.apply {
for ((key, value) in submitMap) {
add(key, value)
}
}.build()
val formSubmitRequest = Request.Builder()
.url(submitUrl)
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.method("POST", body)
.method("POST", formBody)
.build()

val formResp = chain.proceed(formSubmitRequest)
Expand All @@ -106,7 +104,8 @@ class GoogleFormHelper(
.body(ResponseBody.create(respType, requestJson))
.build()
} else {
throw IOException("Failed to submit '$formName' with data '$submitData'")
val debugData = submitMap.map { it.key + "=" + it.value }.joinToString("&")
throw IOException("Failed to submit '$formName' with data '$debugData'")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fun main() = runBlocking {

// Adding sample order
val addNote = notesApi.addNote(
AddNoteRequest("Dynamic Note 1", "Dynamic Desc 1: ${java.util.Date()}")
AddNoteRequest("Dynamic Note 1", "Dynámic Desc 1: ${java.util.Date()}")
)

println(addNote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ReadTest {
@Test
fun `Reads data`() = runBlockingTest {
notesApi.getNote("Do not delete this row").description.should
.equal("This is custom desc")
.equal("This is custóm desc")
Unit
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ class WriteTest {
@Test
fun `Writes data`() = runBlockingTest {
//Write data
val noteTitle = "Title - ${java.util.UUID.randomUUID()}"
notesApi.addNote(
AddNoteRequest(noteTitle, "Dynamic Desc 1: ${Date()}")
)
val request = AddNoteRequest("Titlé - ${java.util.UUID.randomUUID()}", "Dynámic Desc 1: ${Date()}")
notesApi.addNote(request)

// Read data
notesApi.getNote(noteTitle).should.not.`null`
val remoteNote = notesApi.getNote(request.title)
remoteNote.should.not.`null`
remoteNote.title.should.equal(request.title)
remoteNote.description.should.equal(request.description)
}

@Test(expected = IOException::class)
Expand Down

0 comments on commit aa1eb68

Please sign in to comment.