Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ include ':sphinx:application:network:concepts:queries:concept-network-query-cryp
include ':sphinx:application:network:features:queries:feature-network-query-crypter'
include ':sphinx:application:network:concepts:queries:concept-network-query-discover-tribes'
include ':sphinx:application:network:features:queries:feature-network-query-discover-tribes'
include ':sphinx:application:network:concepts:queries:concept-network-query-hive'
include ':sphinx:application:network:features:queries:feature-network-query-hive'
include ':sphinx:application:network:concepts:queries:concept-network-query-feed-status'
include ':sphinx:application:network:features:queries:feature-network-query-feed-status'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins {
id 'java-library'
id 'kotlin'
id 'kotlin-kapt'
}

dependencies {
api project(path: ':sphinx:application:common:kotlin-response')

implementation deps.kotlin.coroutinesCore

// needed to override moshi's use of 1.4.31
implementation deps.kotlin.reflect
implementation deps.square.moshi
kapt kaptDeps.square.moshiCodegen
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package chat.sphinx.concept_network_query_hive

import chat.sphinx.concept_network_query_hive.model.HiveAuthenticationTokenDto
import chat.sphinx.kotlin_response.LoadResponse
import chat.sphinx.kotlin_response.ResponseError
import kotlinx.coroutines.flow.Flow

abstract class NetworkQueryHive {
abstract fun postHiveAuthentication(
token: String,
pubkey: String,
timestamp: String,
): Flow<LoadResponse<HiveAuthenticationTokenDto, ResponseError>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package chat.sphinx.concept_network_query_hive.model

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class HiveAuthenticationTokenDto(val token: String) {
init { require(token.isNotBlank()) { "Hive token must not be blank" } }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id 'app.cash.exhaustive'
id 'java-library'
id 'kotlin'
id 'kotlin-kapt'
}

dependencies {
api project(path: ':sphinx:application:network:concepts:queries:concept-network-query-hive')
api project(path: ':sphinx:application:network:concepts:calls:concept-network-call')

implementation deps.kotlin.coroutinesCore

// needed to override moshi's use of 1.4.31
implementation deps.kotlin.reflect
implementation deps.square.moshi
kapt kaptDeps.square.moshiCodegen
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package chat.sphinx.feature_network_query_hive

import chat.sphinx.concept_network_call.NetworkCall
import chat.sphinx.concept_network_query_hive.NetworkQueryHive
import chat.sphinx.concept_network_query_hive.model.HiveAuthenticationTokenDto
import chat.sphinx.feature_network_query_hive.model.HiveAuthenticationRequestDto
import chat.sphinx.kotlin_response.LoadResponse
import chat.sphinx.kotlin_response.ResponseError
import kotlinx.coroutines.flow.Flow

class NetworkQueryHiveImpl(private val networkCall: NetworkCall) : NetworkQueryHive() {

companion object {
private const val HIVE_BASE_URL = "https://hive.sphinx.chat/api"
private const val ENDPOINT_HIVE_AUTH = "$HIVE_BASE_URL/auth/sphinx/token"
}

override fun postHiveAuthentication(
token: String,
pubkey: String,
timestamp: String,
): Flow<LoadResponse<HiveAuthenticationTokenDto, ResponseError>> =
networkCall.post(
url = ENDPOINT_HIVE_AUTH,
responseJsonClass = HiveAuthenticationTokenDto::class.java,
requestBodyJsonClass = HiveAuthenticationRequestDto::class.java,
requestBody = HiveAuthenticationRequestDto(token, pubkey, timestamp),
headers = mapOf("Cache-Control" to "no-store, no-cache"),
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chat.sphinx.feature_network_query_hive.model

import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class HiveAuthenticationRequestDto(
val token: String,
val pubkey: String,
val timestamp: String,
)