-
Notifications
You must be signed in to change notification settings - Fork 1
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
Данила Беляков
authored and
Данила Беляков
committed
Nov 19, 2024
1 parent
e33fa1d
commit 569926e
Showing
27 changed files
with
272 additions
and
85 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
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
61 changes: 61 additions & 0 deletions
61
alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/AudioPlayerHandler.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,61 @@ | ||
package com.github.alice.ktx.handlers.impl | ||
|
||
import com.github.alice.ktx.Dispatcher | ||
import com.github.alice.ktx.common.AliceDsl | ||
import com.github.alice.ktx.handlers.Handler | ||
import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment | ||
import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment | ||
import com.github.alice.ktx.models.request.content.RequestContentType | ||
import com.github.alice.ktx.models.response.MessageResponse | ||
|
||
@AliceDsl | ||
data class AudioPlayerShouldRequestEnvironment( | ||
private val request: ShouldRequestEnvironment | ||
) : ShouldRequestEnvironment by request { | ||
|
||
val type = message.request.type | ||
val error = message.request.error | ||
} | ||
|
||
@AliceDsl | ||
data class AudioPlayerProcessRequestEnvironment( | ||
private val request: ProcessRequestEnvironment | ||
) : ProcessRequestEnvironment by request { | ||
|
||
val type = message.request.type | ||
val error = message.request.error | ||
} | ||
|
||
@AliceDsl | ||
fun Dispatcher.audioPlayer( | ||
shouldHandle: suspend AudioPlayerShouldRequestEnvironment.() -> Boolean = { true }, | ||
processRequest: suspend AudioPlayerProcessRequestEnvironment.() -> MessageResponse | ||
) { | ||
addHandler( | ||
AudioPlayerHandler( | ||
shouldHandleBlock = shouldHandle, | ||
processRequestBlock = processRequest | ||
) | ||
) | ||
} | ||
|
||
internal class AudioPlayerHandler ( | ||
private val shouldHandleBlock: suspend AudioPlayerShouldRequestEnvironment.() -> Boolean, | ||
private val processRequestBlock: suspend AudioPlayerProcessRequestEnvironment.() -> MessageResponse | ||
): Handler { | ||
override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { | ||
val audioPlayerTypes = setOf( | ||
RequestContentType.AudioPlayerPlaybackStarted, | ||
RequestContentType.AudioPlayerPlaybackFinished, | ||
RequestContentType.AudioPlayerPlaybackNearlyFinished, | ||
RequestContentType.AudioPlayerPlaybackStopped, | ||
RequestContentType.AudioPlayerPlaybackFailed, | ||
) | ||
|
||
return request.message.request.type in audioPlayerTypes && shouldHandleBlock(AudioPlayerShouldRequestEnvironment(request)) | ||
} | ||
|
||
override suspend fun processRequest(request: ProcessRequestEnvironment): MessageResponse { | ||
return processRequestBlock(AudioPlayerProcessRequestEnvironment(request)) | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/PurchaseConfirmationHandler.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,64 @@ | ||
package com.github.alice.ktx.handlers.impl | ||
|
||
import com.github.alice.ktx.Dispatcher | ||
import com.github.alice.ktx.common.AliceDsl | ||
import com.github.alice.ktx.handlers.Handler | ||
import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment | ||
import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment | ||
import com.github.alice.ktx.models.request.content.RequestContentType | ||
import com.github.alice.ktx.models.response.MessageResponse | ||
|
||
@AliceDsl | ||
data class PurchaseConfirmationShouldRequestEnvironment( | ||
private val request: ShouldRequestEnvironment | ||
) : ShouldRequestEnvironment by request { | ||
|
||
val purchaseRequestId = message.request.purchaseRequestId | ||
val purchaseToken = message.request.purchaseToken | ||
val orderId = message.request.orderId | ||
val purchaseTimestamp = message.request.purchaseTimestamp | ||
val purchasePayload = message.request.purchasePayload | ||
val signedData = message.request.signedData | ||
val signature = message.request.signature | ||
} | ||
|
||
@AliceDsl | ||
data class PurchaseConfirmationProcessRequestEnvironment( | ||
private val request: ProcessRequestEnvironment | ||
) : ProcessRequestEnvironment by request { | ||
|
||
val purchaseRequestId = message.request.purchaseRequestId | ||
val purchaseToken = message.request.purchaseToken | ||
val orderId = message.request.orderId | ||
val purchaseTimestamp = message.request.purchaseTimestamp | ||
val purchasePayload = message.request.purchasePayload | ||
val signedData = message.request.signedData | ||
val signature = message.request.signature | ||
} | ||
|
||
@AliceDsl | ||
fun Dispatcher.purchaseConfirmation( | ||
shouldHandle: suspend PurchaseConfirmationShouldRequestEnvironment.() -> Boolean = { true }, | ||
processRequest: suspend PurchaseConfirmationProcessRequestEnvironment.() -> MessageResponse | ||
) { | ||
addHandler( | ||
PurchaseConfirmationHandler( | ||
shouldHandleBlock = shouldHandle, | ||
processRequestBlock = processRequest | ||
) | ||
) | ||
} | ||
|
||
internal class PurchaseConfirmationHandler( | ||
private val shouldHandleBlock: suspend PurchaseConfirmationShouldRequestEnvironment.() -> Boolean, | ||
private val processRequestBlock: suspend PurchaseConfirmationProcessRequestEnvironment.() -> MessageResponse | ||
): Handler { | ||
override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { | ||
return request.message.request.type == RequestContentType.PurchaseConfirmation | ||
&& shouldHandleBlock(PurchaseConfirmationShouldRequestEnvironment(request)) | ||
} | ||
|
||
override suspend fun processRequest(request: ProcessRequestEnvironment): MessageResponse { | ||
return processRequestBlock(PurchaseConfirmationProcessRequestEnvironment(request)) | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
alice-ktx/src/main/kotlin/com/github/alice/ktx/handlers/impl/ShowPullHandler.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,52 @@ | ||
package com.github.alice.ktx.handlers.impl | ||
|
||
import com.github.alice.ktx.Dispatcher | ||
import com.github.alice.ktx.common.AliceDsl | ||
import com.github.alice.ktx.handlers.Handler | ||
import com.github.alice.ktx.handlers.environments.ProcessRequestEnvironment | ||
import com.github.alice.ktx.handlers.environments.ShouldRequestEnvironment | ||
import com.github.alice.ktx.models.request.content.RequestContentType | ||
import com.github.alice.ktx.models.response.MessageResponse | ||
|
||
@AliceDsl | ||
data class ShowPullShouldRequestEnvironment( | ||
private val request: ShouldRequestEnvironment | ||
) : ShouldRequestEnvironment by request { | ||
|
||
val showType = checkNotNull(request.message.request.showType) | ||
} | ||
|
||
@AliceDsl | ||
data class ShowPullProcessRequestEnvironment( | ||
private val request: ProcessRequestEnvironment | ||
) : ProcessRequestEnvironment by request { | ||
|
||
val showType = checkNotNull(request.message.request.showType) | ||
} | ||
|
||
@AliceDsl | ||
fun Dispatcher.showPull( | ||
shouldHandle: suspend ShowPullShouldRequestEnvironment.() -> Boolean = { true }, | ||
processRequest: suspend ShowPullProcessRequestEnvironment.() -> MessageResponse | ||
) { | ||
addHandler( | ||
ShowPullHandler( | ||
shouldHandleBlock = shouldHandle, | ||
processRequestBlock = processRequest | ||
) | ||
) | ||
} | ||
|
||
internal class ShowPullHandler( | ||
private val shouldHandleBlock: suspend ShowPullShouldRequestEnvironment.() -> Boolean, | ||
private val processRequestBlock: suspend ShowPullProcessRequestEnvironment.() -> MessageResponse | ||
) : Handler { | ||
override suspend fun shouldHandle(request: ShouldRequestEnvironment): Boolean { | ||
return request.message.request.type == RequestContentType.ShowPull | ||
&& shouldHandleBlock(ShowPullShouldRequestEnvironment(request)) | ||
} | ||
|
||
override suspend fun processRequest(request: ProcessRequestEnvironment): MessageResponse { | ||
return processRequestBlock(ShowPullProcessRequestEnvironment(request)) | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
alice-ktx/src/main/kotlin/com/github/alice/ktx/server/WebServer.kt
This file was deleted.
Oops, something went wrong.
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
15 changes: 15 additions & 0 deletions
15
alice-ktx/src/main/kotlin/com/github/alice/ktx/webhook/WebhookServer.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,15 @@ | ||
package com.github.alice.ktx.webhook | ||
|
||
/** | ||
* Интерфейс `WebhookServer` определяет контракт для веб-сервера, который может быть запущен и обрабатывать запросы. | ||
*/ | ||
interface WebhookServer { | ||
|
||
/** | ||
* Запускает веб-сервер и начинает обработку запросов. | ||
* | ||
* @param listener Обработчик, который будет вызван при получении запроса. | ||
*/ | ||
fun run(listener: WebhookServerListener) | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
...hub/alice/ktx/server/WebServerListener.kt → ...lice/ktx/webhook/WebhookServerListener.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
Oops, something went wrong.