Skip to content
Merged
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
1 change: 1 addition & 0 deletions library/src/main/java/io/constructor/core/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Constants {
const val NUM_RESULTS = "num_results_"
const val GROUP_ID = "group[group_id]"
const val GROUP_DISPLAY_NAME = "group[display_name]"
const val USER_ID = "ui"
}

object QueryValues {
Expand Down
6 changes: 6 additions & 0 deletions library/src/main/java/io/constructor/core/ConstructorIo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ object ConstructorIo {
private lateinit var context: Context
private var disposable = CompositeDisposable()

var userId: String?
get() = configMemoryHolder.userId
set(value) {
configMemoryHolder.userId = value
}

internal val component: AppComponent by lazy {
DaggerAppComponent.builder()
.appModule(AppModule(context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ class TokenInterceptor(val context: Context, private val preferencesHelper: Pref
builder.addQueryParameter(it.first, it.second)
}
}
configMemoryHolder.userId?.let {
builder.addQueryParameter(Constants.QueryConstants.USER_ID, it)
}
val url = builder.build()
request = request.newBuilder().url(url).build()
return chain.proceed(request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ class ConfigMemoryHolder @Inject constructor() {
}

var autocompleteResultCount: Map<String, Int>? = null

var userId: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class ConstructorIoTest {
every { pref.token } returns "123"
every { pref.id } returns "1"
every { configMemoryHolder.testCellParams = any() } just Runs
every { configMemoryHolder.userId } returns "uid"
every { configMemoryHolder.autocompleteResultCount } returns mapOf(Constants.QueryValues.SEARCH_SUGGESTIONS to 10, Constants.QueryValues.PRODUCTS to 0)
every { configMemoryHolder.testCellParams } returns listOf("ef-1" to "2", "ef-3" to "4")
mockServer.start()
Expand All @@ -220,6 +221,7 @@ class ConstructorIoTest {
client.newCall(Request.Builder().url(mockServer.url("/")).build()).execute()
var recordedRequest = mockServer.takeRequest()
assert(recordedRequest.path.contains("ef-1=2"))
assert(recordedRequest.path.contains("ui=uid"))
}

@Test
Expand Down
1 change: 1 addition & 0 deletions sample/src/main/java/io/constructor/sample/SampleApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ class SampleApp : Application() {
super.onCreate()
ConstructorIo.init(this, ConstructorIoConfig("key_OucJxxrfiTVUQx0C",
testCells = listOf("ab" to "cd", "11" to "22")))
ConstructorIo.userId = "uid"
}
}