Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom HEADERS to the requests #123

Merged
merged 2 commits into from
Jul 13, 2016
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
11 changes: 9 additions & 2 deletions src/main/scala/algolia/AlgoliaClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ import algolia.objects.Query

import scala.concurrent.{ExecutionContext, Future}

class AlgoliaClient(applicationId: String, apiKey: String) {
/**
* The AlgoliaClient to query Algolia
*
* @param applicationId The APP_ID of your Algolia account
* @param apiKey The API KEY of your Algolia account
* @param customHeader Custom headers to add to every requests
*/
class AlgoliaClient(applicationId: String, apiKey: String, customHeader: Map[String, String] = Map.empty) {

if (applicationId == null || applicationId.isEmpty) {
throw new AlgoliaClientException(s"'applicationId' is probably too short: '$applicationId'")
Expand Down Expand Up @@ -69,7 +76,7 @@ class AlgoliaClient(applicationId: String, apiKey: String) {
val random: AlgoliaRandom = AlgoliaRandom
val userAgent = s"Algolia for Scala ${BuildInfo.scalaVersion} API ${BuildInfo.version}"

val headers: Map[String, String] = Map(
val headers: Map[String, String] = customHeader ++ Map(
"Accept-Encoding" -> "gzip",
"X-Algolia-Application-Id" -> applicationId,
"X-Algolia-API-Key" -> apiKey,
Expand Down
5 changes: 5 additions & 0 deletions src/test/scala/algolia/AlgoliaClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class AlgoliaClientTest extends AlgoliaTest {
new AlgoliaClient("APP_ID", "APIKEY")
}

it("should add custom headers") {
val client = new AlgoliaClient("APP_ID", "APIKEY", Map("my" -> "header"))
client.headers should contain("my" -> "header")
}

}

describe("requests") {
Expand Down