Skip to content

Commit

Permalink
Release/0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyand authored Nov 21, 2019
2 parents fd01585 + c3c47e6 commit 7a2f995
Show file tree
Hide file tree
Showing 14 changed files with 468 additions and 178 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: scala
dist: trusty
scala:
- 2.11.12
- 2.12.5
- 2.12.8
jdk:
- oraclejdk8
script:
Expand All @@ -11,7 +11,7 @@ deploy:
provider: script
script: "./.travis/deploy.sh $TRAVIS_TAG"
on:
condition: '"${TRAVIS_SCALA_VERSION}" == "2.12.5"'
condition: '"${TRAVIS_SCALA_VERSION}" == "2.12.8"'
tags: true
after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
Version 0.6.0 (2019-11-21)
--------------------------
Add support for isInEuropeanUnion flag (#87)
Add support for continent and accuracyRadius to the model (#101)
Introduce tagless final encoding (#108)
Support cats.Id (#112)
Abstract over IpLookups creation (#113)
Add function to combine errors raised when processing a CityResponse (#120)
Add readme examples (#79)
Bump geoip2 to 2.12.0 (#93)
Bump cats-effect to 1.2.0 (#90)
Bump cats-core to 1.6.0 (#91)
Bump scala-lru-map to 0.3.0 (#105)
Bump specs2-core to 4.4.1 (#110)
Bump Scala to 2.12.8 and remove Scala 2.11 support (#89)
Bump SBT to 1.2.8 (#109)
Use sbt-tpolecat (#102)
Change Travis distribution to Trusty (#117)
Remove thread safety warning regarding LRU cache from readme file (#99)
Extend copyright to 2019 (#111)

Version 0.5.0 (2018-06-29)
--------------------------
Add Gitter badge (#57)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-2.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2012 Snowplow Analytics Ltd.
Copyright 2012-2019 Snowplow Analytics Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
86 changes: 56 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ can also configure an LRU (Least Recently Used) cache of variable size

## Installation

The latest version of scala-maxmind-iplookups is **0.5.0** and is compatible with Scala 2.11 and
2.12.
The latest version of scala-maxmind-iplookups is **0.6.0** and is compatible with Scala 2.12.

Add this to your SBT config:

```scala
val maxmindIpLookups = "com.snowplowanalytics" %% "scala-maxmind-iplookups" % "0.5.0"
val maxmindIpLookups = "com.snowplowanalytics" %% "scala-maxmind-iplookups" % "0.6.0"
```

Retrieve the `GeoLite2-City.mmdb` file from the [MaxMind downloads page][maxmind-downloads]
Expand All @@ -45,16 +44,15 @@ import cats.effect.IO
import com.snowplowanalytics.maxmind.iplookups.IpLookups

val result = (for {
ipLookups <- IpLookups.createFromFilenames[IO](
ipLookups <- CreateIpLookups[IO].createFromFilenames(
geoFile = Some("/opt/maxmind/GeoLite2-City.mmdb")
ispFile = None,
domainFile = None,
connectionTypeFile = None,
memCache = false,
lruCacheSize = 20000
)

lookup <- ipLookups.performLookups[IO]("175.16.199.0")
lookup <- ipLookups.performLookups("175.16.199.0")
} yield lookup).unsafeRunSync()

result.ipLocation match {
Expand All @@ -66,7 +64,37 @@ result.ipLocation match {
}
```

Note that `GeoLite2-City.mmdb` is updated by MaxMind each month..
`cats.Eval` and `cats.Id` are also supported:

```scala
import cats.{Eval, Id}

val evalResult: Eval[IpLookupResult] = for {
ipLookups <- CreateIpLookups[Eval].createFromFilenames(
geoFile = Some("/opt/maxmind/GeoLite2-City.mmdb")
ispFile = None,
domainFile = None,
connectionTypeFile = None,
memCache = false,
lruCacheSize = 20000
)
lookup <- ipLookups.performLookups("175.16.199.0")
} yield lookup

val idResult: IpLookupResult = {
val ipLookups = CreateIpLookups[Id].createFromFilenames(
geoFile = Some("/opt/maxmind/GeoLite2-City.mmdb")
ispFile = None,
domainFile = None,
connectionTypeFile = None,
memCache = false,
lruCacheSize = 20000
)
ipLookups.performLookups("175.16.199.0")
}
```

Note that `GeoLite2-City.mmdb` is updated by MaxMind each month.

For further usage examples for Scala MaxMind IP Lookups, please see the tests in
[`IpLookupsTest.scala`][iplookupstest-scala]. The test suite uses test databases provided by
Expand All @@ -79,7 +107,7 @@ MaxMind.
The signature is as follows:

```scala
case class IpLookups(
final case class IpLookups(
geoFile: Option[File],
ispFile: Option[File],
domainFile: Option[File],
Expand All @@ -89,11 +117,11 @@ case class IpLookups(
)
```

In the `IpLookups` companion object there is an alternative constructor which takes `Option[String]`
`CreateIpLookups` proposes an alternative constructor which takes `Option[String]`
as file paths to the databases instead:

```scala
def apply(
def createFromFilenames(
geoFile: Option[String],
ispFile: Option[String],
domainFile: Option[String],
Expand Down Expand Up @@ -121,7 +149,7 @@ cache, set its size to zero, i.e. `lruCache = 0`.
The `performLookups(ip)` method returns a:

```scala
case class IpLookupResult(
final case class IpLookupResult(
ipLocation: Option[Either[Throwable, IpLocation]],
isp: Option[Either[Throwable, String]],
organization: Option[Either[Throwable, String]],
Expand All @@ -143,7 +171,7 @@ Note that enabling providing an ISP database will return an `organization` in ad
The geographic lookup returns an `IpLocation` case class instance with the following structure:

```scala
case class IpLocation(
final case class IpLocation(
countryCode: String,
countryName: String,
region: Option[String],
Expand All @@ -153,7 +181,10 @@ case class IpLocation(
timezone: Option[String],
postalCode: Option[String],
metroCode: Option[Int],
regionName: Option[String]
regionName: Option[String],
isInEuropeanUnion: Boolean,
continent: String,
accuracyRadius: Int
)
```

Expand All @@ -164,16 +195,17 @@ This example shows how to do a lookup using all four databases.
```scala
import com.snowplowanalytics.maxmind.iplookups.IpLookups

val ipLookups = IpLookups(
geoFile = Some("/opt/maxmind/GeoLite2-City.mmdb"),
ispFile = Some("/opt/maxmind/GeoIP2-ISP.mmdb"),
domainFile = Some("/opt/maxmind/GeoIP2-Domain.mmdb"),
connectionType = Some("/opt/maxmind/GeoIP2-Connection-Type.mmdb"),
memCache = false,
lruCache = 10000
)

val lookupResult = ipLookups.performLookups("70.46.123.145")
val lookupResult = (for {
ipLookups <- CreateIpLookups[IO].createFromFilenames(
geoFile = Some("/opt/maxmind/GeoLite2-City.mmdb"),
ispFile = Some("/opt/maxmind/GeoIP2-ISP.mmdb"),
domainFile = Some("/opt/maxmind/GeoIP2-Domain.mmdb"),
connectionType = Some("/opt/maxmind/GeoIP2-Connection-Type.mmdb"),
memCache = false,
lruCache = 10000
)
lookupResult <- ipLookups.performLookups("70.46.123.145")
} yield lookupResult).unsafeRunSync()

// Geographic lookup
println(lookupResult.ipLocation).map(_.countryName) // => Some(Right("United States"))
Expand All @@ -196,10 +228,6 @@ println(lookupResult.connectionType) // => Some(Right("Dialup"))

We recommend trying different LRU cache sizes to see what works best for you.

Please note that the LRU cache is **not** thread-safe ([see this note][twitter-lru-cache]). Switch
it off if you are thinking about performing ip lookups with the same `IpLookups` instance across
threads.

## Building etc

Assuming you already have SBT installed:
Expand All @@ -225,7 +253,7 @@ As such we recommend upgrading to version 0.4.0 as soon as possible

## Copyright and license

Copyright 2012-2018 Snowplow Analytics Ltd.
Copyright 2012-2019 Snowplow Analytics Ltd.

Licensed under the [Apache License, Version 2.0][license] (the "License");
you may not use this software except in compliance with the License.
Expand All @@ -240,8 +268,6 @@ limitations under the License.

[iplookupstest-scala]: https://github.com/snowplow/scala-maxmind-iplookups/blob/master/src/test/scala/com.snowplowanalytics.maxmind.iplookups/IpLookupsTest.scala

[twitter-lru-cache]: https://twitter.github.com/commons/apidocs/com/twitter/common/util/caching/LRUCache.html

[maxmind-downloads]: https://dev.maxmind.com/geoip/geoip2/downloadable/#MaxMind_APIs
[maxmind-isp]: https://www.maxmind.com/en/geoip2-isp-database
[maxmind-domain]: https://www.maxmind.com/en/geoip2-domain-name-database
Expand Down
8 changes: 3 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Snowplow Analytics Ltd. All rights reserved.
* Copyright (c) 2012-2019 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
Expand All @@ -17,11 +17,9 @@ lazy val root = project
.settings(
organization := "com.snowplowanalytics",
name := "scala-maxmind-iplookups",
version := "0.5.0",
version := "0.6.0",
description := "Scala wrapper for MaxMind GeoIP2 library",
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.11.12", "2.12.5"),
scalacOptions := BuildSettings.compilerOptions,
scalaVersion := "2.12.8",
javacOptions := BuildSettings.javaCompilerOptions,
scalafmtOnCompile := true
)
Expand Down
18 changes: 1 addition & 17 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Snowplow Analytics Ltd. All rights reserved.
* Copyright (c) 2012-2019 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
Expand Down Expand Up @@ -27,22 +27,6 @@ import scoverage.ScoverageKeys._

object BuildSettings {

lazy val compilerOptions = Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Xfuture",
"-Xlint",
"-Ypartial-unification"
)

lazy val javaCompilerOptions = Seq(
"-source", "1.8",
"-target", "1.8"
Expand Down
14 changes: 7 additions & 7 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012-2018 Snowplow Analytics Ltd. All rights reserved.
* Copyright (c) 2012-2019 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
Expand All @@ -13,10 +13,10 @@
import sbt._

object Dependencies {
val maxmind = "com.maxmind.geoip2" % "geoip2" % "2.11.0"
val catsEffect = "org.typelevel" %% "cats-effect" % "0.10.1"
val cats = "org.typelevel" %% "cats-core" % "1.1.0"
val lruMap = "com.snowplowanalytics" %% "scala-lru-map" % "0.1.0"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.14.0" % "test"
val specs2 = "org.specs2" %% "specs2-core" % "4.0.3" % "test"
val maxmind = "com.maxmind.geoip2" % "geoip2" % "2.12.0"
val catsEffect = "org.typelevel" %% "cats-effect" % "1.2.0"
val cats = "org.typelevel" %% "cats-core" % "1.6.0"
val lruMap = "com.snowplowanalytics" %% "scala-lru-map" % "0.3.0"
val scalaCheck = "org.scalacheck" %% "scalacheck" % "1.14.0" % Test
val specs2 = "org.specs2" %% "specs2-core" % "4.4.1" % Test
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.1.1
sbt.version=1.2.8
3 changes: 2 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15")
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.3.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.5")
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2012-2019 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.maxmind.iplookups

import java.net.InetAddress

import cats.{Eval, Id}
import cats.effect.Sync
import cats.syntax.either._

/** Data type letting you resolve IP address */
sealed trait IpAddressResolver[F[_]] {
def resolve(ip: String): F[Either[Throwable, InetAddress]]

protected def getIpAddress(ip: String): Either[Throwable, InetAddress] =
Either.catchNonFatal(InetAddress.getByName(ip))
}

object IpAddressResolver {
implicit def syncIpAddressResolver[F[_]: Sync]: IpAddressResolver[F] = new IpAddressResolver[F] {
def resolve(ip: String): F[Either[Throwable, InetAddress]] =
Sync[F].delay { getIpAddress(ip) }
}

implicit def evalIpAddressResolver: IpAddressResolver[Eval] = new IpAddressResolver[Eval] {
def resolve(ip: String): Eval[Either[Throwable, InetAddress]] =
Eval.later { getIpAddress(ip) }
}

implicit def idIpAddressResolver: IpAddressResolver[Id] = new IpAddressResolver[Id] {
def resolve(ip: String): Id[Either[Throwable, InetAddress]] =
getIpAddress(ip)
}
}
Loading

0 comments on commit 7a2f995

Please sign in to comment.