Compare commits

..

26 Commits

Author SHA1 Message Date
bcc36dbfb7 provide opportunity to get public properties from sauce nao api 2022-12-11 11:19:08 +06:00
cf8ec46513 fill changelog and improve RequestQoutaManager API 2022-12-11 11:17:28 +06:00
9c25b08296 add opportunity to subscribe on quota changes 2022-12-11 11:13:38 +06:00
962d079f46 Update build_and_publish.yml 2022-12-11 09:17:08 +06:00
a84f31f888 Update build_and_publish.yml 2022-12-11 09:10:12 +06:00
14006652ee Add files via upload 2022-12-11 09:08:39 +06:00
29aa1271a6 Update libs.versions.toml 2022-12-11 09:04:51 +06:00
d2edd43a09 Update gradle.properties 2022-12-11 09:03:34 +06:00
c31793ab38 Merge pull request #146 from InsanusMokrassar/0.12.2
0.12.2
2022-10-02 22:27:28 +06:00
d19bb48384 Update CHANGELOG.md 2022-10-02 22:24:25 +06:00
b21c3f1ac9 Update libs.versions.toml 2022-10-02 11:16:53 +06:00
5ddc13eca0 start 0.12.2 2022-10-02 11:15:31 +06:00
8b180850da Merge pull request #141 from InsanusMokrassar/0.12.1
0.12.1
2022-08-12 00:47:12 +06:00
e65a171e65 Update CHANGELOG.md 2022-08-12 00:39:29 +06:00
31f32a7069 Update libs.versions.toml 2022-08-12 00:38:22 +06:00
5b299fb1c1 start 0.12.1 2022-08-12 00:37:47 +06:00
5038fb4240 Merge pull request #139 from InsanusMokrassar/0.12.0
0.12.0
2022-08-06 10:00:46 +06:00
96f520700f Update libs.versions.toml 2022-08-06 08:48:50 +06:00
2a4296ff7d Update gradle-wrapper.properties 2022-08-06 08:47:55 +06:00
2f34ab7ad1 start 0.12.0 2022-08-06 08:47:18 +06:00
798c4097ed Update github_release.gradle 2022-07-22 20:04:50 +06:00
c1df04fd09 Merge pull request #136 from InsanusMokrassar/0.11.1
0.11.1
2022-07-22 19:44:20 +06:00
8cc0426dc5 Update CHANGELOG.md 2022-07-18 17:08:54 +06:00
9cc929adf6 Update dependencies 2022-07-18 17:06:31 +06:00
85567956ed Update gradle.properties 2022-07-18 17:05:41 +06:00
db154f4202 Merge pull request #131 from InsanusMokrassar/0.11.0
0.11.0
2022-05-14 13:47:39 +06:00
10 changed files with 96 additions and 17 deletions

View File

@@ -16,8 +16,13 @@ jobs:
mv gradle.properties.tmp gradle.properties
- name: Build
run: ./gradlew build
- name: Publish to Gitea
continue-on-error: true
run: ./gradlew publishAllPublicationsToGiteaRepository
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: Publish
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel -x signJsPublication -x signJvmPublication -x signKotlinMultiplatformPublication
run: ./gradlew publishAllPublicationsToGithubPackagesRepository --no-parallel
continue-on-error: true
env:
GITHUBPACKAGES_USER: ${{ github.actor }}

View File

@@ -1,5 +1,33 @@
# SauceNaoAPI Changelog
## 0.13.0
* Versions:
* `Kotlin`: `1.7.20` -> `1.7.22`
* `Serialization`: `1.4.0` -> `1.4.1`
* `Klock`: `3.2.0` -> `3.4.0`
* `Ktor`: `2.1.2` -> `2.2.1`
* Now it is possible to subscribe onto API limits changes
## 0.12.2
* Versions:
* `Kotlin`: `1.7.10` -> `1.7.20`
* `Serialization`: `1.4.0-RC` -> `1.4.0`
* `Klock`: `3.0.0` -> `3.2.0`
* `Ktor`: `2.1.0` -> `2.1.2`
## 0.12.1
* Versions:
* `Ktor`: `2.0.3` -> `2.1.0`
## 0.11.1
* Versions updates:
* `Ktor`: `2.0.1` -> `2.0.3`
* `Coroutines`: `1.6.1` -> `1.6.4`
## 0.11.0
* Versions updates:

View File

@@ -19,7 +19,7 @@ if (new File(projectDir, "secret.gradle").exists()) {
owner "InsanusMokrassar"
repo "${rootProject.name}"
tagName "${project.version}"
tagName "v${project.version}"
releaseName "${project.version}"
targetCommitish "${project.version}"

View File

@@ -1,3 +1,3 @@
kotlin.code.style=official
library_version=0.11.0
library_version=0.13.0

View File

@@ -1,13 +1,13 @@
[versions]
kt = "1.6.21"
kt-serialization = "1.3.3"
kt-coroutines = "1.6.1"
kt = "1.7.22"
kt-serialization = "1.4.1"
kt-coroutines = "1.6.4"
klock = "2.7.0"
ktor = "2.0.1"
klock = "3.4.0"
ktor = "2.2.1"
gh-release = "2.3.7"
gh-release = "2.4.1"
[libraries]

View File

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip

View File

@@ -42,20 +42,40 @@ publishing {
maven {
name = "GithubPackages"
url = uri("https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI")
credentials {
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
}
}
}
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
maven {
name = "Gitea"
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
maven {
name = "sonatype"
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
}
}
}
}

View File

@@ -1 +1 @@
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/SauceNaoAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"SauceNao API","description":"SauceNao API library","url":"https://insanusmokrassar.github.io/${project.name}","vcsUrl":"https://github.com/insanusmokrassar/${project.name}.git","developers":[{"id":"InsanusMokrassar","name":"Ovsyannikov Alexey","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/SauceNaoAPI/blob/master/LICENSE"}],"mavenConfig":{"name":"SauceNao API","description":"SauceNao API library","url":"https://insanusmokrassar.github.io/${project.name}","vcsUrl":"https://github.com/insanusmokrassar/${project.name}.git","developers":[{"id":"InsanusMokrassar","name":"Ovsyannikov Alexey","eMail":"ovsyannikov.alexey95@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/SauceNaoAPI"},{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}

View File

@@ -52,8 +52,12 @@ data class SauceNaoAPI(
private val timeManager = TimeManager(subscope)
private val quotaManager = RequestQuotaManager(subscope)
val limitsState: LimitsState
get() = quotaManager.limitsState
val limitsState: LimitsState by quotaManager::limitsState
val longQuotaFlow by quotaManager::longQuotaFlow
val shortQuotaFlow by quotaManager::shortQuotaFlow
val longMaxQuotaFlow by quotaManager::longMaxQuotaFlow
val shortMaxQuotaFlow by quotaManager::shortMaxQuotaFlow
val limitsStateFlow by quotaManager::limitsStateFlow
private val requestsJob = subscope.launch {
for ((callback, requestBuilder) in requestsChannel) {

View File

@@ -9,17 +9,39 @@ import dev.inmo.saucenaoapi.models.Header
import dev.inmo.saucenaoapi.models.LimitsState
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlin.math.max
import kotlin.math.min
internal class RequestQuotaManager (
scope: CoroutineScope
) {
private var longQuota = 1
private var shortQuota = 1
private var longMaxQuota = 1
private var shortMaxQuota = 1
private val _longQuotaFlow = MutableStateFlow(1)
private val _shortQuotaFlow = MutableStateFlow(1)
private val _longMaxQuotaFlow = MutableStateFlow(1)
private val _shortMaxQuotaFlow = MutableStateFlow(1)
private var longQuota by _longQuotaFlow::value
private var shortQuota by _shortQuotaFlow::value
private var longMaxQuota by _longMaxQuotaFlow::value
private var shortMaxQuota by _shortMaxQuotaFlow::value
val longQuotaFlow = _longQuotaFlow.asStateFlow()
val shortQuotaFlow = _shortQuotaFlow.asStateFlow()
val longMaxQuotaFlow = _longMaxQuotaFlow.asStateFlow()
val shortMaxQuotaFlow = _shortMaxQuotaFlow.asStateFlow()
val limitsStateFlow = merge(
longQuotaFlow, shortQuotaFlow, longMaxQuotaFlow, shortMaxQuotaFlow
).map { _ ->
LimitsState(
shortMaxQuota,
longMaxQuota,
shortQuota,
longQuota
)
}
val limitsState: LimitsState
get() = LimitsState(
shortMaxQuota,