{"action":"created","comment":{"url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/comments/133142282","pull_request_review_id":56289046,"id":133142282,"diff_hunk":"@@ -0,0 +1,103 @@\n+/*\n+ * Copyright 2017 HM Revenue & Customs\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package uk.gov.hmrc.helptosavefrontend.connectors\n+\n+import com.google.inject.{ImplementedBy, Inject, Singleton}\n+import org.joda.time.Period\n+import play.api.Configuration\n+import play.api.http.Status._\n+import play.api.libs.json.{JsValue, Json}\n+import uk.gov.hmrc.helptosavefrontend.models.VerifyEmailStatus._\n+import uk.gov.hmrc.helptosavefrontend.models.{EmailVerificationRequest, VerifyEmailStatus}\n+import uk.gov.hmrc.helptosavefrontend.util.Logging\n+import uk.gov.hmrc.play.config.ServicesConfig\n+import uk.gov.hmrc.play.http.{HeaderCarrier, HttpResponse}\n+import uk.gov.hmrc.play.http.ws.WSHttp\n+\n+import scala.concurrent.ExecutionContext.Implicits.global\n+import scala.concurrent.Future\n+\n+@ImplementedBy(classOf[EmailVerificationConnectorImpl])\n+trait EmailVerificationConnector {\n+\n+  def verifyEmail(nino: String, newEmail: String)(implicit hc: HeaderCarrier): Future[VerifyEmailStatus]\n+  def isVerified(email: String)(implicit hc: HeaderCarrier): Future[Either[VerifyEmailStatus, Boolean]]\n+}\n+\n+@Singleton\n+class EmailVerificationConnectorImpl @Inject() (http: WSHttp, conf: Configuration) extends EmailVerificationConnector with ServicesConfig with Logging {\n+\n+  val emailVerifyBaseURL = baseUrl(\"email-verification\")\n+  val verifyEmailURL = s\"$emailVerifyBaseURL/email-verification/verification-requests\"\n+  def isVerifiedURL(email: String) = s\"$emailVerifyBaseURL/email-verification/verified-email-addresses/$email\"\n+\n+  val continueURL = \"email-verification.continue.baseUrl\"\n+  //+ EmailVerificationController.showSuccess.\n+  val defaultTemplate = \"hts_email_verification\"\n+\n+  override def verifyEmail(nino: String, newEmail: String)(implicit hc: HeaderCarrier): Future[VerifyEmailStatus] = {\n+    conf.getInt(\"services.email-verification.linkTTLMinutes\") match {\n+      case Some(linkTTLMinutes) ⇒ verify(nino, newEmail, Period.minutes(linkTTLMinutes))\n+      case None ⇒ throw new RuntimeException(\"email-verification.link.ttlMinutes not present in configuration\")\n+    }\n+  }\n+\n+  private def verify(nino: String, newEmail: String, ttlPeriod: Period)(implicit hc: HeaderCarrier): Future[VerifyEmailStatus] = {\n+    val postURL = s\"\"\"$verifyEmailURL\"\"\"\n+    val json: JsValue = Json.toJson(EmailVerificationRequest(newEmail, nino, \"\", ttlPeriod.toString, ttlPeriod.toString, Map()))\n+\n+    http.POST(postURL, json).map { (response: HttpResponse) ⇒\n+      response.status match {\n+        case OK | CREATED =>\n+          logger.info(\"[EmailVerification] - Successful return of data\")\n+          Verifing(nino, newEmail)\n+        case BAD_REQUEST ⇒\n+          logger.warn(\"[EmailVerification] - Bad Request\")","path":"app/uk/gov/hmrc/helptosavefrontend/connectors/EmailVerificationConnector.scala","position":69,"original_position":69,"commit_id":"d271b31b69c5dd74bd3c1c6c59826f5477872a9b","original_commit_id":"d271b31b69c5dd74bd3c1c6c59826f5477872a9b","user":{"login":"AndyHWChung","id":26929776,"avatar_url":"https://avatars1.githubusercontent.com/u/26929776?v=4","gravatar_id":"","url":"https://api.github.com/users/AndyHWChung","html_url":"https://github.com/AndyHWChung","followers_url":"https://api.github.com/users/AndyHWChung/followers","following_url":"https://api.github.com/users/AndyHWChung/following{/other_user}","gists_url":"https://api.github.com/users/AndyHWChung/gists{/gist_id}","starred_url":"https://api.github.com/users/AndyHWChung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AndyHWChung/subscriptions","organizations_url":"https://api.github.com/users/AndyHWChung/orgs","repos_url":"https://api.github.com/users/AndyHWChung/repos","events_url":"https://api.github.com/users/AndyHWChung/events{/privacy}","received_events_url":"https://api.github.com/users/AndyHWChung/received_events","type":"User","site_admin":false},"body":"you'll never get a this status or a 500 in this block because the `POST` method on `http` will throw - use  `post` from `uk.gov.hmrc.helptosavefrontend.config.WSHttpExtension` instead to be able to handle these","created_at":"2017-08-15T08:38:37Z","updated_at":"2017-08-15T08:53:05Z","html_url":"https://github.com/hmrc/help-to-save-frontend/pull/159#discussion_r133142282","pull_request_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159","_links":{"self":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/comments/133142282"},"html":{"href":"https://github.com/hmrc/help-to-save-frontend/pull/159#discussion_r133142282"},"pull_request":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159"}}},"pull_request":{"url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159","id":135752730,"html_url":"https://github.com/hmrc/help-to-save-frontend/pull/159","diff_url":"https://github.com/hmrc/help-to-save-frontend/pull/159.diff","patch_url":"https://github.com/hmrc/help-to-save-frontend/pull/159.patch","issue_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/159","number":159,"state":"open","locked":false,"title":"Hts 402","user":{"login":"Jackie1988","id":19712939,"avatar_url":"https://avatars1.githubusercontent.com/u/19712939?v=4","gravatar_id":"","url":"https://api.github.com/users/Jackie1988","html_url":"https://github.com/Jackie1988","followers_url":"https://api.github.com/users/Jackie1988/followers","following_url":"https://api.github.com/users/Jackie1988/following{/other_user}","gists_url":"https://api.github.com/users/Jackie1988/gists{/gist_id}","starred_url":"https://api.github.com/users/Jackie1988/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jackie1988/subscriptions","organizations_url":"https://api.github.com/users/Jackie1988/orgs","repos_url":"https://api.github.com/users/Jackie1988/repos","events_url":"https://api.github.com/users/Jackie1988/events{/privacy}","received_events_url":"https://api.github.com/users/Jackie1988/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-08-15T08:04:51Z","updated_at":"2017-08-15T08:53:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9a3bd4289a807c0ef7f896cbae65759d5244aac7","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159/commits","review_comments_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159/comments","review_comment_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/159/comments","statuses_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/statuses/d271b31b69c5dd74bd3c1c6c59826f5477872a9b","head":{"label":"hmrc:HTS-402","ref":"HTS-402","sha":"d271b31b69c5dd74bd3c1c6c59826f5477872a9b","user":{"login":"hmrc","id":5755339,"avatar_url":"https://avatars1.githubusercontent.com/u/5755339?v=4","gravatar_id":"","url":"https://api.github.com/users/hmrc","html_url":"https://github.com/hmrc","followers_url":"https://api.github.com/users/hmrc/followers","following_url":"https://api.github.com/users/hmrc/following{/other_user}","gists_url":"https://api.github.com/users/hmrc/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrc/subscriptions","organizations_url":"https://api.github.com/users/hmrc/orgs","repos_url":"https://api.github.com/users/hmrc/repos","events_url":"https://api.github.com/users/hmrc/events{/privacy}","received_events_url":"https://api.github.com/users/hmrc/received_events","type":"Organization","site_admin":false},"repo":{"id":87419474,"name":"help-to-save-frontend","full_name":"hmrc/help-to-save-frontend","owner":{"login":"hmrc","id":5755339,"avatar_url":"https://avatars1.githubusercontent.com/u/5755339?v=4","gravatar_id":"","url":"https://api.github.com/users/hmrc","html_url":"https://github.com/hmrc","followers_url":"https://api.github.com/users/hmrc/followers","following_url":"https://api.github.com/users/hmrc/following{/other_user}","gists_url":"https://api.github.com/users/hmrc/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrc/subscriptions","organizations_url":"https://api.github.com/users/hmrc/orgs","repos_url":"https://api.github.com/users/hmrc/repos","events_url":"https://api.github.com/users/hmrc/events{/privacy}","received_events_url":"https://api.github.com/users/hmrc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hmrc/help-to-save-frontend","description":null,"fork":false,"url":"https://api.github.com/repos/hmrc/help-to-save-frontend","forks_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/forks","keys_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/teams","hooks_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/hooks","issue_events_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/events","assignees_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/tags","blobs_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/languages","stargazers_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/stargazers","contributors_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/contributors","subscribers_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/subscribers","subscription_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/subscription","commits_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/merges","archive_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/downloads","issues_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/labels{/name}","releases_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/releases{/id}","deployments_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/deployments","created_at":"2017-04-06T11:00:29Z","updated_at":"2017-04-06T11:00:48Z","pushed_at":"2017-08-15T08:04:51Z","git_url":"git://github.com/hmrc/help-to-save-frontend.git","ssh_url":"git@github.com:hmrc/help-to-save-frontend.git","clone_url":"https://github.com/hmrc/help-to-save-frontend.git","svn_url":"https://github.com/hmrc/help-to-save-frontend","homepage":"","size":89822,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"hmrc:master","ref":"master","sha":"71fa8a63cb12be2b044e1dff2adc668b6c3487e3","user":{"login":"hmrc","id":5755339,"avatar_url":"https://avatars1.githubusercontent.com/u/5755339?v=4","gravatar_id":"","url":"https://api.github.com/users/hmrc","html_url":"https://github.com/hmrc","followers_url":"https://api.github.com/users/hmrc/followers","following_url":"https://api.github.com/users/hmrc/following{/other_user}","gists_url":"https://api.github.com/users/hmrc/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrc/subscriptions","organizations_url":"https://api.github.com/users/hmrc/orgs","repos_url":"https://api.github.com/users/hmrc/repos","events_url":"https://api.github.com/users/hmrc/events{/privacy}","received_events_url":"https://api.github.com/users/hmrc/received_events","type":"Organization","site_admin":false},"repo":{"id":87419474,"name":"help-to-save-frontend","full_name":"hmrc/help-to-save-frontend","owner":{"login":"hmrc","id":5755339,"avatar_url":"https://avatars1.githubusercontent.com/u/5755339?v=4","gravatar_id":"","url":"https://api.github.com/users/hmrc","html_url":"https://github.com/hmrc","followers_url":"https://api.github.com/users/hmrc/followers","following_url":"https://api.github.com/users/hmrc/following{/other_user}","gists_url":"https://api.github.com/users/hmrc/gists{/gist_id}","starred_url":"https://api.github.com/users/hmrc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hmrc/subscriptions","organizations_url":"https://api.github.com/users/hmrc/orgs","repos_url":"https://api.github.com/users/hmrc/repos","events_url":"https://api.github.com/users/hmrc/events{/privacy}","received_events_url":"https://api.github.com/users/hmrc/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hmrc/help-to-save-frontend","description":null,"fork":false,"url":"https://api.github.com/repos/hmrc/help-to-save-frontend","forks_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/forks","keys_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/teams","hooks_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/hooks","issue_events_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/events","assignees_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/tags","blobs_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/languages","stargazers_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/stargazers","contributors_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/contributors","subscribers_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/subscribers","subscription_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/subscription","commits_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/merges","archive_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/downloads","issues_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/labels{/name}","releases_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/releases{/id}","deployments_url":"https://api.github.com/repos/hmrc/help-to-save-frontend/deployments","created_at":"2017-04-06T11:00:29Z","updated_at":"2017-04-06T11:00:48Z","pushed_at":"2017-08-15T08:04:51Z","git_url":"git://github.com/hmrc/help-to-save-frontend.git","ssh_url":"git@github.com:hmrc/help-to-save-frontend.git","clone_url":"https://github.com/hmrc/help-to-save-frontend.git","svn_url":"https://github.com/hmrc/help-to-save-frontend","homepage":"","size":89822,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159"},"html":{"href":"https://github.com/hmrc/help-to-save-frontend/pull/159"},"issue":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/159"},"comments":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/issues/159/comments"},"review_comments":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159/comments"},"review_comment":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/pulls/159/commits"},"statuses":{"href":"https://api.github.com/repos/hmrc/help-to-save-frontend/statuses/d271b31b69c5dd74bd3c1c6c59826f5477872a9b"}}}}
{"actor":{"display_login":"AndyHWChung"}}