Skip to content
This repository has been archived by the owner on Feb 17, 2020. It is now read-only.

Commit

Permalink
Move Algolia prefix to application.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rock3r committed Oct 23, 2018
1 parent fc4f151 commit e04abc7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Expand Up @@ -60,6 +60,7 @@ circle_ci_android_container_config: &circle_ci_android_container_config
FABRIC_API_KEY: 0000000000000000000000000000000000000000
ALGOLIA_APPLICATION_ID: ABCDEFGH12
ALGOLIA_API_KEY: 00000000000000000000000000000000
ALGOLIA_INDICES_PREFIX: squanchy_dev

attach_workspace: &attach_workspace
attach_workspace:
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Expand Up @@ -45,6 +45,7 @@ android {

resValueString 'algolia_application_id', applicationProps['algoliaId'].or(envVars['ALGOLIA_APPLICATION_ID'])
resValueString 'algolia_api_key', secretsProps['algoliaApiKey'].or(envVars['ALGOLIA_API_KEY'])
resValueString 'algolia_indices_prefix', applicationProps['algoliaIndicesPrefix'].or(envVars['ALGOLIA_INDICES_PREFIX'])

resValueString 'deeplink_scheme', applicationProps['deeplinkScheme'].or("squanchy")
}
Expand Down
21 changes: 16 additions & 5 deletions app/src/main/java/net/squanchy/search/algolia/AlgoliaModule.kt
@@ -1,6 +1,7 @@
package net.squanchy.search.algolia

import android.app.Application
import android.content.Context
import com.algolia.search.saas.Client
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
Expand All @@ -21,12 +22,22 @@ class AlgoliaModule {
@Provides
@ApplicationLifecycle
@Named(EVENT_INDEX)
fun algoliaEventIndex(client: Client, parser: ResponseParser<AlgoliaSearchResponse>) = AlgoliaIndex(client.getIndex(EVENT_INDEX), parser)
fun algoliaEventIndex(app: Application, client: Client, parser: ResponseParser<AlgoliaSearchResponse>): AlgoliaIndex {
val indexName = composeIndexName(app, EVENT_INDEX)
return AlgoliaIndex(client.getIndex(indexName), parser)
}

@Provides
@ApplicationLifecycle
@Named(SPEAKER_INDEX)
fun algoliaSpeakerIndex(client: Client, parser: ResponseParser<AlgoliaSearchResponse>) = AlgoliaIndex(client.getIndex(SPEAKER_INDEX), parser)
fun algoliaSpeakerIndex(app: Application, client: Client, parser: ResponseParser<AlgoliaSearchResponse>): AlgoliaIndex {
val indexName = composeIndexName(app, SPEAKER_INDEX)
return AlgoliaIndex(client.getIndex(indexName), parser)
}
private fun composeIndexName(app: Context, indexName: String): String {
val indexPrefix = app.getString(R.string.algolia_indices_prefix)
return "$indexPrefix-$indexName"
}

@Provides
@ApplicationLifecycle
Expand All @@ -39,7 +50,7 @@ class AlgoliaModule {

@Provides
@ApplicationLifecycle
fun moshi() = Moshi.Builder().build()
fun moshi(): Moshi = Moshi.Builder().build()

@Provides
@ApplicationLifecycle
Expand All @@ -49,7 +60,7 @@ class AlgoliaModule {
fun responseParser(adapter: JsonAdapter<AlgoliaSearchResponse>): ResponseParser<AlgoliaSearchResponse> = MoshiResponseParser(adapter)

companion object {
const val EVENT_INDEX = "squanchy_dev-events"
const val SPEAKER_INDEX = "squanchy_dev-speakers"
const val EVENT_INDEX = "events"
const val SPEAKER_INDEX = "speakers"
}
}
5 changes: 3 additions & 2 deletions team-props/application.properties.sample
Expand Up @@ -7,5 +7,6 @@ applicationName=Squanchy
# Scheme used for deeplinks into content
deeplinkScheme=squanchy

# Algolia App ID (used for search)
algoliaId=
# Algolia App ID and indices prefix (used for search)
algoliaId=ABCDEFGH12
algoliaIndicesPrefix=squanchy_dev

0 comments on commit e04abc7

Please sign in to comment.