Last active
August 29, 2015 14:07
-
-
Save erikkaplun/5a1169f70870190eb3ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.io.Source | |
import scala.xml.XML | |
val ServiceUrl = "http://services.postcodeanywhere.co.uk/PostcodeAnywhereInternational/interactive/RetrieveByPostalCode/v2.20/xmla.ws" | |
val params = Map( | |
"key" -> "UP26-TZ93-TK96-PJ69", | |
"country" -> "United Kingdom".toUpperCase, | |
"postalcode" -> "11312".replaceAll(" ", "")) | |
val paramsStr = | |
params | |
.mapValues(java.net.URLEncoder.encode(_, "UTF-8")) | |
.map { case (k, v) => s"$k=$v" } | |
.mkString("&") | |
val url = ServiceUrl + "?" + paramsStr | |
val xml = Source.fromURL(url).getLines.mkString("\n") |> scala.xml.XML.loadString | |
// scala.xml.Elem = <Table> <Columns Items="4"> <Column Type="String" Name="Error"/> <Column Type="String" Name="Description"/> <Column Type="String" Name="Cause"/> <Column Type="String" Name="Resolution"/> </Columns> <Rows Items="1"> <Row Resolution="Please ensure that you supply the PostalCode parameter and try again." Cause="The PostalCode parameter was not supplied." Description="PostalCode Required" Error="1003"/> </Rows></Table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment