Skip to content

Commit

Permalink
Upgrade library
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoeudes7 committed Dec 4, 2024
1 parent 2314209 commit c61a07d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ plugins {

android {
namespace = "com.jedev.grpckthelper"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.jedev.grpckthelper"
minSdk = 24
targetSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"

Expand Down
20 changes: 10 additions & 10 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
agp = "8.2.0"
agp = "8.7.3"
kotlin = "1.9.20"
coreKtx = "1.13.1"
coreKtx = "1.15.0"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"

Expand All @@ -17,12 +17,12 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
material = { group = "com.google.android.material", name = "material", version.ref = "material" }

timberkt = "com.github.ajalt:timberkt:1.5.1"
protobuf-javalite = "com.google.protobuf:protobuf-javalite:3.22.3"
grpc-protobuf-lite = "io.grpc:grpc-protobuf-lite:1.57.0"
grpc-kotlin-stub = "io.grpc:grpc-kotlin-stub:1.3.0"
grpc-stub = "io.grpc:grpc-stub:1.57.0"
grpc-android = "io.grpc:grpc-android:1.52.1"
grpc-okhttp = "io.grpc:grpc-okhttp:1.52.1"
protobuf-javalite = "com.google.protobuf:protobuf-javalite:4.29.1"
grpc-protobuf-lite = "io.grpc:grpc-protobuf-lite:1.68.2"
grpc-kotlin-stub = "io.grpc:grpc-kotlin-stub:1.4.1"
grpc-stub = "io.grpc:grpc-stub:1.68.2"
grpc-android = "io.grpc:grpc-android:1.68.2"
grpc-okhttp = "io.grpc:grpc-okhttp:1.68.2"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri May 31 22:02:44 BRT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
4 changes: 2 additions & 2 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

android {
namespace = "com.github.joaoeudes7.grpc.android.helper"
compileSdk = 34
compileSdk = 35

defaultConfig {
minSdk = 24
Expand Down Expand Up @@ -39,7 +39,7 @@ afterEvaluate {
publications {
val organizationGroup = "com.github.joaoeudes7"
val artifactIdPkg = "grpc-android-helper"
val versionPkg = "1.0.5"
val versionPkg = "1.0.6"

create<MavenPublication>("maven") {
groupId = organizationGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,23 @@ object ChannelGrpcBaseBuilders {
target: String,
sslSocketFactory: SSLSocketFactory,
coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): OkHttpChannelBuilder = createDefaultChannelConfig(target, coroutineDispatcher)
): OkHttpChannelBuilder = createDefaultChannelConfig(
target,
coroutineDispatcher
)
.useTransportSecurity()
.sslSocketFactory(sslSocketFactory)


fun createChannelSecure(
target: String,
coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
): OkHttpChannelBuilder =
createDefaultChannelConfig(
target,
coroutineDispatcher
).useTransportSecurity()

fun createDefaultChannelPlainText(
context: Context,
target: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package com.github.joaoeudes7.grpc.android.helper
import com.github.joaoeudes7.grpc.android.helper.extensions.withAuthToken
import io.grpc.*
import io.grpc.kotlin.*
import io.grpc.okhttp.OkHttpChannelBuilder
import javax.net.ssl.SSLSocketFactory

sealed class GrpcClient<S : AbstractCoroutineStub<S>> {
Expand All @@ -14,19 +15,22 @@ sealed class GrpcClient<S : AbstractCoroutineStub<S>> {

open class Grpc<S : AbstractCoroutineStub<S>>(
targetUrl: String,
channelConfig: OkHttpChannelBuilder.() -> OkHttpChannelBuilder,
stubStart: (ManagedChannel) -> S
) : GrpcClient<S>() {

final override val defaultManagedChannel: ManagedChannel by lazy {
ChannelGrpcBaseBuilders.createDefaultChannelConfig(targetUrl).usePlaintext().build()
ChannelGrpcBaseBuilders.createDefaultChannelConfig(targetUrl)
.apply { channelConfig() }
.build()
}

final override val stub: S by lazy {
stubStart(defaultManagedChannel)
}
}

open class GrpcSecure<S : AbstractCoroutineStub<S>>(
open class GrpcSecureSSL<S : AbstractCoroutineStub<S>>(
targetUrl: String,
stubStart: (ManagedChannel) -> S,
sslCredentialsFiles: SSLSocketFactory
Expand All @@ -43,6 +47,21 @@ sealed class GrpcClient<S : AbstractCoroutineStub<S>> {
}
}

open class GrpcSecure<S : AbstractCoroutineStub<S>>(
targetUrl: String,
stubStart: (ManagedChannel) -> S,
) : GrpcClient<S>() {
final override val defaultManagedChannel: ManagedChannel by lazy {
ChannelGrpcBaseBuilders.createChannelSecure(
targetUrl,
).build()
}

final override val stub: S by lazy {
stubStart(defaultManagedChannel)
}
}

fun authenticate(token: String): S {
return stub.withAuthToken(token)
}
Expand Down

0 comments on commit c61a07d

Please sign in to comment.