aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala
diff options
context:
space:
mode:
authorSergey Nastich <nastich@users.noreply.github.com>2018-09-19 13:57:53 -0400
committerGitHub <noreply@github.com>2018-09-19 13:57:53 -0400
commit1b979318d85ea6035084253596cf076151cef309 (patch)
treed5f64a3893b2581807020a88c8c2b28f277fbd53 /src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala
parent60ad2abd17a50c8bd73bfe75084984b4de27bd79 (diff)
downloaddriver-core-1b979318d85ea6035084253596cf076151cef309.tar.gz
driver-core-1b979318d85ea6035084253596cf076151cef309.tar.bz2
driver-core-1b979318d85ea6035084253596cf076151cef309.zip
Improve PhoneNumber (#222)
* Add support for extensions * Add PathMatcher and allow parsing JSON from string * Add a number of convenience methods which are to be used instead of `toString`
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala')
-rw-r--r--src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala b/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala
index 183ad9a..218c9ae 100644
--- a/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala
+++ b/src/main/scala/xyz/driver/core/rest/directives/PathMatchers.scala
@@ -10,6 +10,7 @@ import akka.http.scaladsl.server.PathMatcher.{Matched, Unmatched}
import akka.http.scaladsl.server.{PathMatcher, PathMatcher1, PathMatchers => AkkaPathMatchers}
import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.refineV
+import xyz.driver.core.domain.PhoneNumber
import xyz.driver.core.time.Time
import scala.util.control.NonFatal
@@ -70,4 +71,15 @@ trait PathMatchers {
Some(Revision[T](string))
}
+ def PhoneInPath: PathMatcher1[PhoneNumber] = new PathMatcher1[PhoneNumber] {
+ def apply(path: Path) = path match {
+ case Path.Segment(segment, tail) =>
+ PhoneNumber
+ .parse(segment)
+ .map(parsed => Matched(tail, Tuple1(parsed)))
+ .getOrElse(Unmatched)
+ case _ => Unmatched
+ }
+ }
+
}