Use id from Gerrit response as project identifier

The 'id' in the Gerrit JSON response is a better identifier
for the projects. Furthermore it is already URL encoded compared
to the 'key' value.

Change-Id: If518d4ffec303664cf863f4655c3bc2feae279bf
diff --git a/src/main/scala/com/gerritforge/analytics/model/GerritProjects.scala b/src/main/scala/com/gerritforge/analytics/model/GerritProjects.scala
index 0e80468..bbfee35 100644
--- a/src/main/scala/com/gerritforge/analytics/model/GerritProjects.scala
+++ b/src/main/scala/com/gerritforge/analytics/model/GerritProjects.scala
@@ -14,24 +14,23 @@
 
 package com.gerritforge.analytics.model
 
-import org.json4s.JObject
-import org.json4s.native.JsonMethods.parse
-
 import scala.io.Source
+import org.json4s.native.JsonMethods.parse
 
 object GerritProjects {
 
   type GerritProjects = Seq[String]
 
-  val GERRIT_PREFIX_LEN = ")]}'\n".length
+  val GERRIT_PREFIX = ")]}'\n"
+  private val GERRIT_PREFIX_LEN = GERRIT_PREFIX.length
 
   def apply(jsonSource: Source) =
     parse(jsonSource.drop(GERRIT_PREFIX_LEN).mkString)
-      .asInstanceOf[JObject]
       .values
-      .keys
+      .asInstanceOf[Map[String,Map[String,String]]]
+      .values
+      .map(_("id"))
       .toSeq
 }
 
-case class ProjectContributionSource(name: String, contributorsUrl: String)
-
+case class ProjectContributionSource(name: String, contributorsUrl: String)
\ No newline at end of file
diff --git a/src/test/scala/com/gerritforge/analytics/model/GerritProjectsTest.scala b/src/test/scala/com/gerritforge/analytics/model/GerritProjectsTest.scala
new file mode 100644
index 0000000..ab71352
--- /dev/null
+++ b/src/test/scala/com/gerritforge/analytics/model/GerritProjectsTest.scala
@@ -0,0 +1,14 @@
+package com.gerritforge.analytics.model
+
+import org.scalatest.{FlatSpec, Matchers}
+
+import scala.io.Source
+
+class GerritProjectsTest extends FlatSpec with Matchers {
+
+  "GerritProjects" should "use the 'id' as identifier" in {
+    val projectId = "apps%2Freviewit" // URL_Encode(project_key) => project_id (i.e.: app/reviewit => apps%2Freviewit)
+    val source = Source.fromString(GerritProjects.GERRIT_PREFIX + s"""{"app/reviewit": {"id":"$projectId"}}""")
+    GerritProjects(source) shouldBe Seq(projectId)
+  }
+}
\ No newline at end of file