packages feed

google-maps-geocoding 0.7.0.2 → 0.7.0.3

raw patch · 4 files changed

+236/−224 lines, 4 filesdep ~aesondep ~basedep ~servantPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: aeson, base, servant, servant-client, text

API changes (from Hackage documentation)

- Web.Google.Geocoding: data Language
+ Web.Google.Geocoding: data () => Language
- Web.Google.Geocoding: data LatLng
+ Web.Google.Geocoding: data () => LatLng
- Web.Google.Geocoding: data Location
+ Web.Google.Geocoding: data () => Location
- Web.Google.Geocoding: data Region
+ Web.Google.Geocoding: data () => Region
- Web.Google.Geocoding: newtype Address
+ Web.Google.Geocoding: newtype () => Address
- Web.Google.Geocoding: newtype Key
+ Web.Google.Geocoding: newtype () => Key

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright Mike Pilgrem (c) 2017-2023
+Copyright Mike Pilgrem (c) 2017-2024
 
 All rights reserved.
 
google-maps-geocoding.cabal view
@@ -1,9 +1,9 @@ name:                google-maps-geocoding
-version:             0.7.0.2
+version:             0.7.0.3
 synopsis:            Bindings to the Google Geocoding API (formerly Maps
                      Geocoding API)
 description:         The
-                     <https://developers.google.com/maps/documentation/geocoding/intro Google Geocoding API>
+                     <https://developers.google.com/maps/documentation/geocoding Google 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.
@@ -35,13 +35,13 @@ library
   hs-source-dirs:      src
   exposed-modules:     Web.Google.Geocoding
-  build-depends:       base >= 4.8 && < 4.17
-                     , aeson >= 1.1 && < 2.2
+  build-depends:       base >= 4.8 && < 4.20
+                     , aeson >= 1.1 && < 2.3
                      , google-static-maps >= 0.7 && < 0.8
                      , http-client >= 0.5 && < 0.8
-                     , servant >= 0.16 && < 0.20
-                     , servant-client >= 0.16 && < 0.20
-                     , text >= 1.2 && < 2.1
+                     , servant >= 0.16 && < 0.21
+                     , servant-client >= 0.16 && < 0.21
+                     , text >= 1.2 && < 2.2
   default-language:    Haskell2010
   ghc-options:         -Wall
 
src/Web/Google/Geocoding.hs view
@@ -10,13 +10,13 @@ -- Module      : Web.Google.Geocoding
 -- Description : Bindings to the Google Geocoding API (formerly Maps Geocoding
 --               API)
--- Copyright   : (c) Mike Pilgrem 2017, 2018
+-- Copyright   : (c) Mike Pilgrem 2017, 2018, 2024
 -- Maintainer  : public@pilgrem.com
 -- Stability   : experimental
 --
 -- This package has no connection with Google Inc. or its affiliates.
 --
--- The <https://developers.google.com/maps/documentation/geocoding/intro Google Geocoding API>
+-- The <https://developers.google.com/maps/documentation/geocoding Google Geocoding API>
 -- provides a direct way to access geocoding and reverse geocoding services via
 -- an HTTP request. This library provides bindings in Haskell to that API.
 --
@@ -88,244 +88,253 @@ -- >       display window white picture
 -- >     Left err -> putStrLn $ "Error while displaying map: " ++ show err
 module Web.Google.Geocoding
-    ( -- * Functions
-      geocode
-    , backGeocode
-      -- * API
-    , GoogleGeocodingAPI
-    , api
-      -- * Types
-    , Key                  (..)
-    , Address              (..)
-    , FilterComponent      (..)
-    , Viewport             (..)
-    , Language             (..)
-    , Region               (..)
-    , GeocodingResponse    (..)
-    , Status               (..)
-    , Result               (..)
-    , AddressType          (..)
-    , AddressComponent     (..)
-    , PostcodeLocality     (..)
-    , Geometry             (..)
-    , LatLng               (..)
-    , PlaceId              (..)
-    , Location             (..)
-    , LocationType         (..)
-    ) where
+  ( -- * Functions
+    geocode
+  , backGeocode
+    -- * API
+  , GoogleGeocodingAPI
+  , api
+    -- * Types
+  , Key                  (..)
+  , Address              (..)
+  , FilterComponent      (..)
+  , Viewport             (..)
+  , Language             (..)
+  , Region               (..)
+  , GeocodingResponse    (..)
+  , Status               (..)
+  , Result               (..)
+  , AddressType          (..)
+  , AddressComponent     (..)
+  , PostcodeLocality     (..)
+  , Geometry             (..)
+  , LatLng               (..)
+  , PlaceId              (..)
+  , Location             (..)
+  , LocationType         (..)
+  ) where
 
-import Data.Aeson (FromJSON (parseJSON), Options (fieldLabelModifier),
-    defaultOptions, genericParseJSON, withText)
-import Data.List (intersperse)
-import Data.Proxy (Proxy (..))
-import Data.Text (Text)
-import qualified Data.Text as T (concat, unpack)
-import GHC.Generics (Generic)
-import Network.HTTP.Client (Manager)
-import Servant.API (type (:<|>) (..), type (:>), Get, JSON, QueryParam,
-    ToHttpApiData (toUrlPiece))
-import Servant.Client (ClientError, ClientEnv (ClientEnv), ClientM, client,
-    runClientM)
+import           Data.Aeson
+                   ( FromJSON (parseJSON), Options (fieldLabelModifier)
+                   , defaultOptions, genericParseJSON, withText
+                   )
+import           Data.List ( intersperse )
+import           Data.Proxy ( Proxy (..) )
+import           Data.Text ( Text )
+import qualified Data.Text as T ( concat, unpack )
+import           GHC.Generics ( Generic )
+import           Network.HTTP.Client ( Manager )
+import           Servant.API
+                   ( type (:<|>) (..), type (:>), Get, JSON, QueryParam
+                   , ToHttpApiData (toUrlPiece)
+                   )
+import           Servant.Client
+                   ( ClientError, ClientEnv (ClientEnv), ClientM, client
+                   , runClientM
+                   )
 #if MIN_VERSION_servant_client(0,17,0)
-import Servant.Client (defaultMakeClientRequest)
+import           Servant.Client ( defaultMakeClientRequest )
 #endif
-import Web.Google.Maps.Common (Address (..), Key (..), Language (..),
-    LatLng (..), Location (..), Region (..), googleMapsApis)
+import           Web.Google.Maps.Common
+                   ( Address (..), Key (..), Language (..), LatLng (..)
+                   , Location (..), Region (..), googleMapsApis
+                   )
 
 -- | Fliter component: a component that can be used to filter the results
 -- returned in a geocoding response.
 data FilterComponent
-    = Route Text
-    | Locality Text
-    | AdministrativeArea Text
-    | PostalCode Text
-    | Country Region
-    deriving (Eq, Show)
+  = Route Text
+  | Locality Text
+  | AdministrativeArea Text
+  | PostalCode Text
+  | Country Region
+  deriving (Eq, Show)
 
 instance ToHttpApiData FilterComponent where
-    toUrlPiece filterComponent
-        | Route route <- filterComponent
-          = T.concat ["route:", route]
-        | Locality locality <- filterComponent
-          = T.concat ["locality:", locality]
-        | AdministrativeArea adminArea <- filterComponent
-          = T.concat ["administrative_area:", adminArea]
-        | PostalCode postalCode <- filterComponent
-          = T.concat ["postal_code:", postalCode]
-        | Country country <- filterComponent
-          = T.concat ["country:", toUrlPiece country]
+  toUrlPiece filterComponent
+    | Route route <- filterComponent
+      = T.concat ["route:", route]
+    | Locality locality <- filterComponent
+      = T.concat ["locality:", locality]
+    | AdministrativeArea adminArea <- filterComponent
+      = T.concat ["administrative_area:", adminArea]
+    | PostalCode postalCode <- filterComponent
+      = T.concat ["postal_code:", postalCode]
+    | Country country <- filterComponent
+      = T.concat ["country:", toUrlPiece country]
 
 instance ToHttpApiData [FilterComponent] where
-    toUrlPiece [] = ""
-    toUrlPiece cs = T.concat $ intersperse "|" $ map toUrlPiece cs
+  toUrlPiece [] = ""
+  toUrlPiece cs = T.concat $ intersperse "|" $ map toUrlPiece cs
 
 -- | Geocoding Reponse
 data GeocodingResponse = GeocodingResponse
-    { status        :: Status
-    , error_message :: Maybe Text
-    , results       :: [Result]
-    } deriving (Eq, Show, Generic)
+  { status        :: Status
+  , error_message :: Maybe Text
+  , results       :: [Result]
+  } deriving (Eq, Show, Generic)
 
 instance FromJSON GeocodingResponse
 
 -- | Contains the status of the request and may contain debugging information to
 --  help you track down why geocoding is not working.
 data Status
-    = OK              -- ^ Indicates that no errors occurred; the address was
-                      -- successfully parsed and at least one geocode was
-                      -- returned.
-    | ZeroResults     -- ^ Indicates that the geocode was successful but
-                      -- returned no results. This may occur if the geocoder was
-                      -- passed a non-existent address.
-    | OverQueryLimit
-    | RequestDenied
-    | InvalidRequest  -- ^ Generally indicates that the query (address,
-                      -- components or latlng) is missing.
-    | UnknownError
-    deriving (Eq, Show)
+  = OK
+    -- ^ Indicates that no errors occurred; the address was successfully parsed
+    -- and at least one geocode was returned.
+  | ZeroResults
+    -- ^ Indicates that the geocode was successful but returned no results. This
+    -- may occur if the geocoder was passed a non-existent address.
+  | OverQueryLimit
+  | RequestDenied
+  | InvalidRequest
+    -- ^ Generally indicates that the query (address, components or latlng) is
+    -- missing.
+  | UnknownError
+  deriving (Eq, Show)
 
 instance FromJSON Status where
-    parseJSON = withText "Status" $ \t -> case t of
-        "OK"               -> return OK
-        "ZERO_RESULTS"     -> return ZeroResults
-        "OVER_QUERY_LIMIT" -> return OverQueryLimit
-        "REQUEST_DENIED"   -> return RequestDenied
-        "INVALID_REQUEST"  -> return InvalidRequest
-        "UNKNOWN_ERROR"    -> return UnknownError
-        _                  -> fail $ "Unrecognised status type, namely: " ++
-                                  T.unpack t
+  parseJSON = withText "Status" $ \t -> case t of
+    "OK"               -> return OK
+    "ZERO_RESULTS"     -> return ZeroResults
+    "OVER_QUERY_LIMIT" -> return OverQueryLimit
+    "REQUEST_DENIED"   -> return RequestDenied
+    "INVALID_REQUEST"  -> return InvalidRequest
+    "UNKNOWN_ERROR"    -> return UnknownError
+    _                  -> fail $ "Unrecognised status type, namely: " ++
+                            T.unpack t
 
 -- | A result of the geocoder.
 data Result = Result
-    { types :: [AddressType]
-    , formatted_address :: Text
-    , address_components :: [AddressComponent]
-    , postcode_localities :: Maybe [PostcodeLocality]
-    , geometry :: Geometry
-    , partial_match :: Maybe Bool
-    , place_id :: PlaceId
-    } deriving (Eq, Show, Generic)
+  { types :: [AddressType]
+  , formatted_address :: Text
+  , address_components :: [AddressComponent]
+  , postcode_localities :: Maybe [PostcodeLocality]
+  , geometry :: Geometry
+  , partial_match :: Maybe Bool
+  , place_id :: PlaceId
+  } deriving (Eq, Show, Generic)
 
 instance FromJSON Result
 
 -- | Address (and address component) type: The list of types provided by Google
 -- (as at 4 March 2017) is incomplete.
 newtype AddressType = AddressType Text
-    deriving (Eq, Show, Generic, ToHttpApiData)
+  deriving (Eq, Show, Generic, ToHttpApiData)
 
 instance FromJSON AddressType
 
 -- | Address component
 data AddressComponent = AddressComponent
-    { address_component_types      :: [AddressType]
-    , long_name  :: Text
-    , short_name :: Text
-    } deriving (Eq, Show, Generic)
+  { address_component_types      :: [AddressType]
+  , long_name  :: Text
+  , short_name :: Text
+  } deriving (Eq, Show, Generic)
 
 instance FromJSON AddressComponent where
-    parseJSON = genericParseJSON defaultOptions
-        { fieldLabelModifier = \l -> case l of
-            "address_component_types" -> "types"
-            _ -> l
-        }
+  parseJSON = genericParseJSON defaultOptions
+    { fieldLabelModifier = \l -> case l of
+        "address_component_types" -> "types"
+        _ -> l
+    }
 
 -- | Postcode locality: a locality contained in a postal code.
 newtype PostcodeLocality = PostcodeLocality Text
-    deriving (Eq, Show, Generic)
+  deriving (Eq, Show, Generic)
 
 instance FromJSON PostcodeLocality
 
 -- | Geometry
 data Geometry = Geometry
-    { location :: LatLng
-    , location_type :: LocationType
-    , viewport :: Viewport
-    , bounds :: Maybe Viewport
-    } deriving (Eq, Show, Generic)
+  { location :: LatLng
+  , location_type :: LocationType
+  , viewport :: Viewport
+  , bounds :: Maybe Viewport
+  } deriving (Eq, Show, Generic)
 
 instance FromJSON Geometry
 
 -- | Location type
 data LocationType
-    = Rooftop
-    | RangeInterpolated
-    | GeometricCenter
-    | Approximate
-    deriving (Eq, Show)
+  = Rooftop
+  | RangeInterpolated
+  | GeometricCenter
+  | Approximate
+  deriving (Eq, Show)
 
 instance ToHttpApiData LocationType where
-    toUrlPiece locationType = case locationType of
-        Rooftop           -> "ROOFTOP"
-        RangeInterpolated -> "RANGE_INTERPOLATED"
-        GeometricCenter   -> "GEOMETRIC_CENTER"
-        Approximate       -> "APPROXIMATE"
+  toUrlPiece locationType = case locationType of
+    Rooftop           -> "ROOFTOP"
+    RangeInterpolated -> "RANGE_INTERPOLATED"
+    GeometricCenter   -> "GEOMETRIC_CENTER"
+    Approximate       -> "APPROXIMATE"
 
 instance FromJSON LocationType where
-    parseJSON = withText "LocationType" $ \t -> case t of
-        "ROOFTOP"            -> return Rooftop
-        "RANGE_INTERPOLATED" -> return RangeInterpolated
-        "GEOMETRIC_CENTER"   -> return GeometricCenter
-        "APPROXIMATE"        -> return Approximate
-        _ -> fail $ "Unrecognised location type, namely: " ++ T.unpack t
+  parseJSON = withText "LocationType" $ \t -> case t of
+    "ROOFTOP"            -> return Rooftop
+    "RANGE_INTERPOLATED" -> return RangeInterpolated
+    "GEOMETRIC_CENTER"   -> return GeometricCenter
+    "APPROXIMATE"        -> return Approximate
+    _ -> fail $ "Unrecognised location type, namely: " ++ T.unpack t
 
 -- | Viewport
 data Viewport = Viewport
-    { southwest :: LatLng
-    , northeast :: LatLng
-    } deriving (Eq, Show, Generic)
+  { southwest :: LatLng
+  , northeast :: LatLng
+  } deriving (Eq, Show, Generic)
 
 instance ToHttpApiData Viewport where
-    toUrlPiece (Viewport sw ne) = T.concat [toUrlPiece sw, "|", toUrlPiece ne]
+  toUrlPiece (Viewport sw ne) = T.concat [toUrlPiece sw, "|", toUrlPiece ne]
 
 instance FromJSON Viewport
 
 -- | Place id
 newtype PlaceId = PlaceId Text
-    deriving (Eq, Show, Generic, ToHttpApiData)
+  deriving (Eq, Show, Generic, ToHttpApiData)
 
 instance FromJSON PlaceId
 
 -- | Google Geocoding API
 type GoogleGeocodingAPI
-    =    "geocode"
-    :>   "json"
-    :>   QueryParam "key"           Key
-    :>   QueryParam "address"       Address
-    :>   QueryParam "components"    [FilterComponent]
-    :>   QueryParam "bounds"        Viewport
-    :>   QueryParam "language"      Language
-    :>   QueryParam "region"        Region
-    :>   Get '[JSON] GeocodingResponse
-    :<|> "geocode"
-    :>   "json"
-    :>   QueryParam "key"           Key
-    :>   QueryParam "latlng"        LatLng
-    :>   QueryParam "place_id"      PlaceId
-    :>   QueryParam "result_type"   AddressType
-    :>   QueryParam "location_type" LocationType
-    :>   QueryParam "language"      Language
-    :>   Get '[JSON] GeocodingResponse
+  =    "geocode"
+  :>   "json"
+  :>   QueryParam "key"           Key
+  :>   QueryParam "address"       Address
+  :>   QueryParam "components"    [FilterComponent]
+  :>   QueryParam "bounds"        Viewport
+  :>   QueryParam "language"      Language
+  :>   QueryParam "region"        Region
+  :>   Get '[JSON] GeocodingResponse
+  :<|> "geocode"
+  :>   "json"
+  :>   QueryParam "key"           Key
+  :>   QueryParam "latlng"        LatLng
+  :>   QueryParam "place_id"      PlaceId
+  :>   QueryParam "result_type"   AddressType
+  :>   QueryParam "location_type" LocationType
+  :>   QueryParam "language"      Language
+  :>   Get '[JSON] GeocodingResponse
 
 -- | API type
 api :: Proxy GoogleGeocodingAPI
 api = Proxy
 
-geocode'
-    :: Maybe Key
-    -> Maybe Address
-    -> Maybe [FilterComponent]
-    -> Maybe Viewport
-    -> Maybe Language
-    -> Maybe Region
-    -> ClientM GeocodingResponse
-backGeocode'
-    :: Maybe Key
-    -> Maybe LatLng
-    -> Maybe PlaceId
-    -> Maybe AddressType
-    -> Maybe LocationType
-    -> Maybe Language
-    -> ClientM GeocodingResponse
+geocode' ::
+     Maybe Key
+  -> Maybe Address
+  -> Maybe [FilterComponent]
+  -> Maybe Viewport
+  -> Maybe Language
+  -> Maybe Region
+  -> ClientM GeocodingResponse
+backGeocode' ::
+     Maybe Key
+  -> Maybe LatLng
+  -> Maybe PlaceId
+  -> Maybe AddressType
+  -> Maybe LocationType
+  -> Maybe Language
+  -> ClientM GeocodingResponse
 geocode' :<|> backGeocode' = client api
 
 -- | Geocode. NB: The use of the Google Geocoding API services is subject to the
@@ -334,33 +343,37 @@ -- Maps/Google Earth Additional Terms of Service at
 -- <https://maps.google.com/help/terms_maps.html> and Google Privacy Policy at
 -- <https://www.google.com/policies/privacy/>.
-geocode
-    :: Manager
-    -> Key
-    -> Maybe Address
-    -> Maybe [FilterComponent]
-    -> Maybe Viewport
-    -> Maybe Language
-    -> Maybe Region
-    -> IO (Either ClientError GeocodingResponse)
+geocode ::
+     Manager
+  -> Key
+  -> Maybe Address
+  -> Maybe [FilterComponent]
+  -> Maybe Viewport
+  -> Maybe Language
+  -> Maybe Region
+  -> IO (Either ClientError GeocodingResponse)
 geocode
-    mgr
-    key
-    addressOpt
-    filterComponentsOpt
-    viewportOpt
-    languageOpt
-    regionOpt
-    = runClientM (geocode' (Just key) addressOpt filterComponentsOpt viewportOpt
-          languageOpt regionOpt)
+  mgr
+  key
+  addressOpt
+  filterComponentsOpt
+  viewportOpt
+  languageOpt
+  regionOpt
+  = runClientM
+      (geocode' (Just key) addressOpt filterComponentsOpt viewportOpt
+        languageOpt regionOpt)
+-- Middleware supported from servant-client-0.20.2
+#if MIN_VERSION_servant_client(0,20,2)
+      (ClientEnv mgr googleMapsApis Nothing defaultMakeClientRequest id)
 -- makeClientRequest supported from servant-client-0.17
-#if MIN_VERSION_servant_client(0,17,0)
-          (ClientEnv mgr googleMapsApis Nothing defaultMakeClientRequest)
+#elif MIN_VERSION_servant_client(0,17,0)
+      (ClientEnv mgr googleMapsApis Nothing defaultMakeClientRequest)
 -- CookieJar supported from servant-client-0.13
 #elif MIN_VERSION_servant_client(0,13,0)
-          (ClientEnv mgr googleMapsApis Nothing)
+      (ClientEnv mgr googleMapsApis Nothing)
 #else
-          (ClientEnv mgr googleMapsApis)
+      (ClientEnv mgr googleMapsApis)
 #endif
 
 -- | Reverse (back) geocode. NB: The use of the Google Geocoding API services is
@@ -370,31 +383,35 @@ -- Maps/Google Earth Additional Terms of Service at
 -- <https://maps.google.com/help/terms_maps.html> and Google Privacy Policy at
 -- <https://www.google.com/policies/privacy/>.
-backGeocode
-    :: Manager
-    -> Key
-    -> Maybe LatLng
-    -> Maybe PlaceId
-    -> Maybe AddressType
-    -> Maybe LocationType
-    -> Maybe Language
-    -> IO (Either ClientError GeocodingResponse)
+backGeocode ::
+     Manager
+  -> Key
+  -> Maybe LatLng
+  -> Maybe PlaceId
+  -> Maybe AddressType
+  -> Maybe LocationType
+  -> Maybe Language
+  -> IO (Either ClientError GeocodingResponse)
 backGeocode
-    mgr
-    key
-    latLngOpt
-    placeIdOpt
-    addressTypeOpt
-    locationTypeOpt
-    languageOpt
-    = runClientM (backGeocode' (Just key) latLngOpt placeIdOpt addressTypeOpt
-          locationTypeOpt languageOpt)
+  mgr
+  key
+  latLngOpt
+  placeIdOpt
+  addressTypeOpt
+  locationTypeOpt
+  languageOpt
+  = runClientM
+      (backGeocode' (Just key) latLngOpt placeIdOpt addressTypeOpt
+        locationTypeOpt languageOpt)
+-- Middleware supported from servant-client-0.20.2
+#if MIN_VERSION_servant_client(0,20,2)
+      (ClientEnv mgr googleMapsApis Nothing defaultMakeClientRequest id)
 -- makeClientRequest supported from servant-client-0.17
-#if MIN_VERSION_servant_client(0,17,0)
-          (ClientEnv mgr googleMapsApis Nothing defaultMakeClientRequest)
+#elif MIN_VERSION_servant_client(0,17,0)
+      (ClientEnv mgr googleMapsApis Nothing defaultMakeClientRequest)
 -- CookieJar supported from servant-client-0.13
 #elif MIN_VERSION_servant_client(0,13,0)
-          (ClientEnv mgr googleMapsApis Nothing)
+      (ClientEnv mgr googleMapsApis Nothing)
 #else
-          (ClientEnv mgr googleMapsApis)
+      (ClientEnv mgr googleMapsApis)
 #endif
stack.yaml view
@@ -1,9 +1,4 @@-resolver: lts-20.23 # GHC 9.2.7
-compiler: ghc-9.2.8 # No Stackage snapshot as at 2023-06-03
+snapshot: nightly-2024-10-27 # GHC 9.8.3
 
 extra-deps:
-- google-static-maps-0.7.0.2@sha256:03e66dd0c26fac3baf50c38b41a050e8cba73ea26f08898c1263699b45758ada,2788
-
-flags:
-  ansi-terminal:
-    win32-2-13-1: false
+- google-static-maps-0.7.0.3