Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tonicebrian committed Jan 25, 2019
1 parent b474177 commit 943be9a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name := "scala-opencage-geocodm Rer"
name := "scala-opencage-geocoder"

version := "0.1"
scalaVersion := "2.12.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ object OpenCageClient {
val defaultPort = 443
val defaultHostname = "api.opencagedata.com"
val defaultBackend = AsyncHttpClientFutureBackend()
val defaultUserAgent = "opencage-scala-client"
val defaultUserAgent = "scala-opencage-geocoder"

object Scheme extends Enumeration {
type Scheme = Value
Expand All @@ -180,7 +180,7 @@ object OpenCageClient {
}

/**
* See https://geocoder.opencagedata.com/api#forward-opt.
* See https://opencagedata.com/api#forward-opt.
*/
case class OpenCageClientParams(abbreviate: Boolean = false,
addRequest: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.github.nmdguerreiro.opencage.geocoder

import java.time.Instant
import java.util.UUID
import com.softwaremill.sttp.HeaderNames

import com.softwaremill.sttp.{HeaderNames, StatusCodes}
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock._
Expand All @@ -18,7 +18,7 @@ class OpencageClientTest extends AsyncFlatSpec with Matchers with BeforeAndAfter
val host = "localhost"

val requestUrl = "/geocode/v1/json"
val validCoords = (52.51627f, 13.37769f)
val validCoords: (Float, Float) = (52.51627f, 13.37769f)
val validKey = "1234"
val invalidKey = "2345"

Expand Down Expand Up @@ -57,7 +57,7 @@ class OpencageClientTest extends AsyncFlatSpec with Matchers with BeforeAndAfter
.withQueryParam("q", equalTo(reverseQuery))
.withQueryParam("key", equalTo(validKey))
.withQueryParam("no_annotations", equalTo("1"))
.withHeader(HeaderNames.UserAgent, equalTo("opencage-scala-client")))
.withHeader(HeaderNames.UserAgent, equalTo("scala-opencage-geocoder")))

assert(wireMockServer.findAllUnmatchedRequests().size == 0)
}
Expand Down Expand Up @@ -178,23 +178,23 @@ class OpencageClientTest extends AsyncFlatSpec with Matchers with BeforeAndAfter
}

it should "support invalid request errors" in {
genericError[InvalidRequestError]("badrequest", 400, ResponseData.invalidRequestError)
genericError[InvalidRequestError]("badrequest", StatusCodes.BadRequest, ResponseData.invalidRequestError)
}

it should "support quota exceeded errors" in {
genericError[QuotaExceededError]("quotaexceeded", 402, ResponseData.quotaExceededError)
genericError[QuotaExceededError]("quotaexceeded", StatusCodes.PaymentRequired, ResponseData.quotaExceededError)
}

it should "support rate limit exceeded errors" in {
genericError[RateLimitExceededError]("ratelimit", 429, ResponseData.rateLimitExceededError)
genericError[RateLimitExceededError]("ratelimit", StatusCodes.TooManyRequests, ResponseData.rateLimitExceededError)
}

it should "support timeout errors" in {
genericError[TimeoutError]("timeout", 408, ResponseData.timeoutError)
genericError[TimeoutError]("timeout", StatusCodes.RequestTimeout, ResponseData.timeoutError)
}

it should "support request too long errors" in {
genericError[RequestTooLongError]("timeout", 410, ResponseData.requestTooLongError)
genericError[RequestTooLongError]("timeout", StatusCodes.Gone, ResponseData.requestTooLongError)
}

it should "support connection errors" in {
Expand Down Expand Up @@ -231,15 +231,15 @@ class OpencageClientTest extends AsyncFlatSpec with Matchers with BeforeAndAfter


object ResponseData {
val now = Instant.now().toEpochMilli / 1000
val nowFormatted = Instant.now().toString
val tomorrow = Instant.now().toEpochMilli / 1000 + 86400
val now: Long = Instant.now().toEpochMilli / 1000
val nowFormatted: String = Instant.now().toString
val tomorrow: Long = Instant.now().toEpochMilli / 1000 + 86400

/**
* Valid response data
*/

val validResponseString =
val validResponseString: String =
s"""
|{
| "documentation" : "https://geocoder.opencagedata.com/api",
Expand Down Expand Up @@ -368,12 +368,12 @@ object ResponseData {
/**
* Errors
*/
val invalidRequestError = genericErrorMessage(400, "Bad, bad request!")
val quotaExceededError = genericErrorMessage(402, "need more money")
val invalidKeyError = genericErrorMessage(403, "You shall not pass!")
val timeoutError = genericErrorMessage(408, "I'm all out of time")
val requestTooLongError = genericErrorMessage(410, "try typing less")
val rateLimitExceededError = genericErrorMessage(429, "hold your fire")
val invalidRequestError: String = genericErrorMessage(StatusCodes.BadRequest, "Bad Request")
val quotaExceededError: String = genericErrorMessage(StatusCodes.PaymentRequired, "Payment Required")
val invalidKeyError: String = genericErrorMessage(StatusCodes.Forbidden, "Forbidden")
val timeoutError: String = genericErrorMessage(StatusCodes.RequestTimeout, "Request Timeout")
val requestTooLongError: String = genericErrorMessage(StatusCodes.Gone, "Gone")
val rateLimitExceededError: String = genericErrorMessage(StatusCodes.TooManyRequests, "Too Many Requests")

private def genericErrorMessage(code: Int, message: String) = {
s"""
Expand Down

0 comments on commit 943be9a

Please sign in to comment.