Skip to content

Commit

Permalink
Add custom HEADERS to the requests (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPicador committed Jul 13, 2016
1 parent b0a71f1 commit efcbe49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit efcbe49

Please sign in to comment.