packages feed

google-maps-geocoding 0.1.0.1 → 0.2.0.0

raw patch · 5 files changed

+126/−105 lines, 5 filesdep +google-static-mapssetup-changedPVP ok

version bump matches the API change (PVP)

Dependencies added: google-static-maps

API changes (from Hackage documentation)

- Web.Google.Maps.Geocoding: instance Data.Aeson.Types.FromJSON.FromJSON Web.Google.Maps.Geocoding.Location
- Web.Google.Maps.Geocoding: instance GHC.Classes.Eq Web.Google.Maps.Geocoding.Key
- Web.Google.Maps.Geocoding: instance GHC.Classes.Eq Web.Google.Maps.Geocoding.Location
- Web.Google.Maps.Geocoding: instance GHC.Generics.Generic Web.Google.Maps.Geocoding.Location
- Web.Google.Maps.Geocoding: instance GHC.Show.Show Web.Google.Maps.Geocoding.Key
- Web.Google.Maps.Geocoding: instance GHC.Show.Show Web.Google.Maps.Geocoding.Location
- Web.Google.Maps.Geocoding: instance Web.Internal.HttpApiData.ToHttpApiData Web.Google.Maps.Geocoding.Key
- Web.Google.Maps.Geocoding: data Location
+ Web.Google.Maps.Geocoding: data Location :: *
- Web.Google.Maps.Geocoding: newtype Key
+ Web.Google.Maps.Geocoding: newtype Key :: *
- Web.Google.Maps.Geocoding: type GoogleMapsGeocodingAPI = "json" :> (QueryParam "key" Key :> (QueryParam "address" Address :> Get '[JSON] GeocodingResponse))
+ Web.Google.Maps.Geocoding: type GoogleMapsGeocodingAPI = "geocode" :> ("json" :> (QueryParam "key" Key :> (QueryParam "address" Address :> Get '[JSON] GeocodingResponse)))

Files

LICENSE view
@@ -1,30 +1,30 @@-Copyright Mike Pilgrem (c) 2017
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-    * Redistributions of source code must retain the above copyright
-      notice, this list of conditions and the following disclaimer.
-
-    * Redistributions in binary form must reproduce the above
-      copyright notice, this list of conditions and the following
-      disclaimer in the documentation and/or other materials provided
-      with the distribution.
-
-    * Neither the name of Mike Pilgrem nor the names of other
-      contributors may be used to endorse or promote products derived
-      from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+Copyright Mike Pilgrem (c) 2017++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Mike Pilgrem nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Setup.hs view
@@ -1,2 +1,2 @@-import Distribution.Simple
-main = defaultMain
+import Distribution.Simple+main = defaultMain
changelog.md view
@@ -1,9 +1,16 @@+# 0.2.0.0
+
+* Move `geocode` from the end of the base URL to the start of the API type
+
+* Depend on package `google-static-maps` for common types `Key` and `Location`
+  and function `googleMapsApis`
+
 # 0.1.0.1
 
 * Changes to documentation only
 
 # 0.1.0.0
 
-* Launch implementation. The 'components' and optional parameters in a geocoding
+* Launch implementation. The `components` and optional parameters in a geocoding
   request are not yet implemented. The reverse geocoding request is not yet
-  implemented.
+  implemented
google-maps-geocoding.cabal view
@@ -1,13 +1,18 @@ name:                google-maps-geocoding
-version:             0.1.0.1
+version:             0.2.0.0
 synopsis:            Google Maps Geocoding API bindings
-description:         The Google Maps Geocoding API provides a direct way to
-                     access geocoding and reverse geocoding services via an HTTP
-                     request. This library package provides bindings in Haskell
-                     to that API. NB: The use of the API's services is subject
-                     to the Google Maps APIs Terms of Service, which terms
-                     restrict the use of content (eg no use without a Google
-                     map).
+description:         The <https://developers.google.com/maps/documentation/geocoding/intro Google Maps Geocoding API>
+                     provides a direct way to access geocoding and reverse
+                     geocoding services via an HTTP request. This library
+                     package provides bindings in Haskell to that API.
+                     .
+                     NB: The use of the API's services is subject to the
+                     <https://developers.google.com/maps/terms Google Maps APIs Terms of Service>,
+                     which terms restrict the use of content (eg no use without
+                     a Google map).
+                     .
+                     This package has no connection with Google Inc. or its
+                     affiliates.
 homepage:            https://github.com/mpilgrem/google-maps-geocoding#readme
 bug-reports:         https://github.com/mpilgrem/google-maps-geocoding/issues
 license:             BSD3
@@ -25,6 +30,7 @@   exposed-modules:     Web.Google.Maps.Geocoding
   build-depends:       base >= 4.7 && < 5
                      , aeson >= 1.0 && < 1.1
+                     , google-static-maps >= 0.3 && < 0.4
                      , http-client >= 0.5 && < 0.6
                      , servant >= 0.9 && < 0.10
                      , servant-client >= 0.9 && <0.10
src/Web/Google/Maps/Geocoding.hs view
@@ -31,72 +31,89 @@ -- >
 -- > module Main (main) where
 -- >
+-- > import Data.Maybe (fromJust)
 -- > import Data.Text (Text)
 -- > import Data.Text.IO as T (getLine, putStr)
--- > import Network.HTTP.Client (newManager)
+-- > import Graphics.Gloss (Display (..), display, white)
+-- > import Graphics.Gloss.Juicy (fromDynamicImage)
+-- > import Network.HTTP.Client (Manager, newManager)
 -- > import Network.HTTP.Client.TLS (tlsManagerSettings)
 -- > import Web.Google.Maps.Geocoding (Address (..), geocode, GeocodingResponse (..),
 -- >     Geometry (..), Key (..), Location (..), Result (..), Status (..))
+-- > import Web.Google.Static.Maps (Center (..), Size (..), staticmap, Zoom (..))  
 -- > import System.IO (hFlush, stdout)
 -- >
 -- > main :: IO ()
 -- > main = do
--- >   putStrLn "A test of the Google Maps Geocoding API.\nNB: The use of the \
--- >     \API services is subject to the Google Maps APIs Terms of Serivce at \
--- >     \https://developers.google.com/maps/terms.\n"
--- >   txt <- input "Enter ful address: "
--- >   mgr <- newManager tlsManagerSettings
--- >   let apiKey = Key "<REPLACE_THIS_WITH_YOUR_ACTUAL_GOOGLE_API_KEY>"
--- >   result <- geocode mgr apiKey (Address txt)
--- >   case result of
--- >     Right response -> do
--- >       let s = status response
--- >       case s of
--- >         OK -> do print $ location $ geometry $ head $ results response
--- >                  putStrLn "Display the location by visiting \
--- >                    \maps.google.com on the web and entering the latitude \
--- >                    \and longitude."
--- >         _  -> putStrLn $ "Error! Status: " ++ show s
--- >     _ -> putStrLn $ "Error! Result:\n" ++ show result
+-- >     putStrLn "A test of the Google Maps Geocoding API.\nNB: The use of the \
+-- >         \API services is subject to the Google Maps APIs Terms of Serivce at \
+-- >         \https://developers.google.com/maps/terms.\n"
+-- >     txt <- input "Enter full address: "
+-- >     mgr <- newManager tlsManagerSettings
+-- >     let apiKey = Key "<REPLACE_THIS_WITH_YOUR_ACTUAL_GOOGLE_API_KEY>"
+-- >     result <- geocode mgr apiKey (Address txt)
+-- >     case result of
+-- >         Right response -> do
+-- >             let s = status response
+-- >             case s of
+-- >                 OK -> do
+-- >                     let center = Center $ location $ geometry $ head $
+-- >                             results response
+-- >                     print center
+-- >                     displayMap mgr apiKey center
+-- >                 _  -> putStrLn $ "Error! Status: " ++ show s
+-- >         _ -> putStrLn $ "Error! Result:\n" ++ show result
 -- >
 -- > input :: Text -> IO Text
 -- > input msg = T.putStr msg >> hFlush stdout >> T.getLine
+-- >
+-- > displayMap :: Manager -> Key -> Center -> IO ()
+-- > displayMap mgr apiKey center = do
+-- >     let zoom = Just $ Zoom 17
+-- >         w    = 400
+-- >         h    = 400
+-- >         size = Size w h
+-- >     result <- staticmap mgr apiKey Nothing (Just center) zoom size Nothing
+-- >         Nothing [] Nothing [] [] Nothing
+-- >     case result of
+-- >         Right response -> do
+-- >             let picture = fromJust $ fromDynamicImage response
+-- >                 title   = "Test Google Maps Geocoding API"
+-- >                 window  = InWindow title (w, h) (10, 10)
+-- >             display window white picture
+-- >         Left err -> putStrLn $ "Error while displaying map: " ++ show err
 module Web.Google.Maps.Geocoding
-       ( -- * Functions
-         geocode
-         -- * API
-       , GoogleMapsGeocodingAPI
-       , api
-         -- * Types
-       , Key                  (..)
-       , Address              (..)
-       , GeocodingResponse    (..)
-       , Status               (..)
-       , Result               (..)
-       , AddressType          (..)
-       , AddressComponent     (..)
-       , PostcodeLocality     (..)
-       , Geometry             (..)
-       , PlaceId              (..)
-       , Location             (..)
-       , LocationType         (..)
-       , Viewport             (..)
-       ) where
+    ( -- * Functions
+      geocode
+      -- * API
+    , GoogleMapsGeocodingAPI
+    , api
+      -- * Types
+    , Key                  (..)
+    , Address              (..)
+    , GeocodingResponse    (..)
+    , Status               (..)
+    , Result               (..)
+    , AddressType          (..)
+    , AddressComponent     (..)
+    , PostcodeLocality     (..)
+    , Geometry             (..)
+    , PlaceId              (..)
+    , Location             (..)
+    , LocationType         (..)
+    , Viewport             (..)
+    ) where
 
-import           Data.Aeson hiding (Result)
-import           Data.Aeson.Types (Options (..))
-import           Data.Foldable (asum)
-import           Data.Proxy
-import           Data.Text (Text)
+import Data.Aeson hiding (Result)
+import Data.Aeson.Types (Options (..))
+import Data.Proxy
+import Data.Text (Text)
 import qualified Data.Text as T (unpack)
-import           GHC.Generics
-import           Network.HTTP.Client (Manager)
-import           Servant.API
-import           Servant.Client
-
--- | API key
-newtype Key = Key Text
-    deriving (Eq, Show, ToHttpApiData)
+import GHC.Generics (Generic)
+import Network.HTTP.Client (Manager)
+import Servant.API
+import Servant.Client
+import Web.Google.Maps.Common (googleMapsApis, Key (..), Location (..))
 
 -- | Address
 newtype Address = Address Text
@@ -188,14 +205,6 @@ 
 instance FromJSON Geometry
 
--- | Location
-data Location = Location
-    { lat :: Double
-    , lng :: Double
-    } deriving (Eq, Show, Generic)
-
-instance FromJSON Location
-
 -- | Location type
 data LocationType
     = Rooftop
@@ -228,7 +237,8 @@ 
 -- | Google Translate API
 type GoogleMapsGeocodingAPI
-    =  "json"
+    =  "geocode"
+    :> "json"
     :> QueryParam "key" Key
     :> QueryParam "address" Address
     :> Get '[JSON] GeocodingResponse
@@ -243,9 +253,6 @@     -> ClientM GeocodingResponse
 geocode' = client api
 
-googleApis :: BaseUrl
-googleApis = BaseUrl Https "maps.googleapis.com" 443 "/maps/api/geocode"
-
 -- | Geocode. NB: The use of the Google Maps Geocoding API services is subject
 -- to the <https://developers.google.com/maps/terms Google Maps APIs Terms of Service>.
 geocode
@@ -254,4 +261,5 @@     -> Address
     -> IO (Either ServantError GeocodingResponse)
 geocode mgr key address =
-    runClientM (geocode' (Just key) (Just address)) (ClientEnv mgr googleApis)
+    runClientM (geocode' (Just key) (Just address))
+               (ClientEnv mgr googleMapsApis)