http-api-data-ip (empty) → 0.1.0.0
raw patch · 4 files changed
+103/−0 lines, 4 filesdep +attoparsecdep +basedep +http-api-datasetup-changed
Dependencies added: attoparsec, base, http-api-data, ip, text
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- http-api-data-ip.cabal +28/−0
- src/Web/HttpApiData/Net.hs +43/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Andrew Martin (c) 2016++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 Andrew Martin 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
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ http-api-data-ip.cabal view
@@ -0,0 +1,28 @@+cabal-version: 2.4+name: http-api-data-ip+version: 0.1.0.0+synopsis: Code for using the ip package with http-api-data+homepage: https://github.com/andrewthad/http-api-data-ip+license: BSD-3-Clause+license-file: LICENSE+author: Andrew Martin+maintainer: andrew.thaddeus@gmail.com+copyright: 2021 Andrew Martin+category: web+build-type: Simple++library+ hs-source-dirs: src+ exposed-modules:+ Web.HttpApiData.Net+ build-depends:+ , base >= 4.7 && < 5+ , attoparsec >= 0.13.2 && < 0.15+ , http-api-data >= 0.3 && < 0.7+ , ip >= 1.4.1 && < 1.8+ , text >= 1.2+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/andrewthad/http-api-data-ip
+ src/Web/HttpApiData/Net.hs view
@@ -0,0 +1,43 @@+-- | This module provides orphan instances for 'ToHttpApiData'+-- and 'FromHttpApiData' for data types from the @ip@ package.++module Web.HttpApiData.Net () where++import Data.Monoid+import Data.Text (Text)+import Net.Types (IPv4,Mac)+import Web.HttpApiData (ToHttpApiData(..),FromHttpApiData(..))++import qualified Data.Text as Text+import qualified Net.IPv4 as IPv4+import qualified Net.Mac as Mac++instance ToHttpApiData Mac where+ toUrlPiece = Mac.encode+ toHeader = Mac.encodeUtf8+ toQueryParam = Mac.encode++instance FromHttpApiData Mac where+ parseUrlPiece = describeError mac . Mac.decode+ parseQueryParam = describeError mac . Mac.decode+ parseHeader = describeError mac . Mac.decodeUtf8++instance ToHttpApiData IPv4 where+ toUrlPiece = IPv4.encode+ toHeader = IPv4.encodeUtf8+ toQueryParam = IPv4.encode++instance FromHttpApiData IPv4 where+ parseUrlPiece = describeError ipv4 . IPv4.decode+ parseQueryParam = describeError ipv4 . IPv4.decode+ parseHeader = describeError ipv4 . IPv4.decodeUtf8++mac,ipv4 :: Text+mac = Text.pack "MAC Address"+ipv4 = Text.pack "IPv4 Address"++describeError :: Text -> Maybe a -> Either Text a+describeError name x = case x of+ Nothing -> Left (Text.pack "could not parse " <> name)+ Just a -> Right a+