factual-api 0.6.0 → 0.6.1
raw patch · 5 files changed
+78/−11 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Factual.Write.Clear: Clear :: Table -> String -> [String] -> String -> Clear
+ Data.Factual.Write.Clear: data Clear
+ Data.Factual.Write.Clear: factualId :: Clear -> String
+ Data.Factual.Write.Clear: fields :: Clear -> [String]
+ Data.Factual.Write.Clear: instance Eq Clear
+ Data.Factual.Write.Clear: instance Show Clear
+ Data.Factual.Write.Clear: instance Write Clear
+ Data.Factual.Write.Clear: table :: Clear -> Table
+ Data.Factual.Write.Clear: user :: Clear -> String
Files
- Data/Factual/Write/Clear.hs +31/−0
- Network/Factual/API.hs +1/−1
- README.md +13/−6
- factual-api.cabal +3/−2
- test/Tests.hs +30/−2
+ Data/Factual/Write/Clear.hs view
@@ -0,0 +1,31 @@+-- | This module exports the types used to clear fields.+module Data.Factual.Write.Clear+ (+ -- * Clear type+ Clear(..)+ -- * Required modules+ , module Data.Factual.Shared.Table+ ) where++import Data.Factual.Write+import Data.Factual.Shared.Table+import Data.List.Utils (join)+import qualified Data.Map as M++-- | The Clear type represents a Write to be made to the API which will clear+-- certain fields from an entry. The table and factualId identify the row to+-- be changed, and the fields list indicates which fields to clear out. A user+-- must be specified as well.+data Clear = Clear { table :: Table+ , factualId :: String+ , fields :: [String]+ , user :: String+ } deriving (Eq, Show)++-- The Clear type is a member of the Write typeclass so it can be sent as a post+-- request to the API.+instance Write Clear where+ path clear = (show $ table clear) ++ "/" ++ (factualId clear) ++ "/clear"+ params _ = M.empty+ body clear = M.fromList [ ("user", user clear)+ , ("fields", join "," $ fields clear) ]
Network/Factual/API.hs view
@@ -176,7 +176,7 @@ urlEncode = U.encode . S.encode headersList :: [(String, String)]-headersList = [("X-Factual-Lib", "factual-haskell-driver-0.6.0")]+headersList = [("X-Factual-Lib", "factual-haskell-driver-0.6.1")] basePath :: String basePath = "http://api.v3.factual.com"
README.md view
@@ -33,8 +33,8 @@ ## Prerequisites -This driver targets [ghc 7.4.1](http://www.haskell.org/ghc/)-and [The Haskell Platform 2012.2.0.0](http://hackage.haskell.org/platform/).+This driver targets [ghc 7.4.2](http://www.haskell.org/ghc/)+and [The Haskell Platform 2012.4.0.0](http://hackage.haskell.org/platform/). Please follow the installation instructions for your specific platform to install ghc and The Haskell Platform. @@ -68,11 +68,11 @@ tests respectively: *Main> runUnitTests- Cases: 53 Tried: 53 Errors: 0 Failures: 0- Counts {cases = 53, tried = 53, errors = 0, failures = 0}+ Cases: 55 Tried: 55 Errors: 0 Failures: 0+ Counts {cases = 55, tried = 55, errors = 0, failures = 0} *Main> runIntegrationTests- Cases: 14 Tried: 14 Errors: 0 Failures: 0- Counts {cases = 14, tried = 14, errors = 0, failures = 0}+ Cases: 15 Tried: 15 Errors: 0 Failures: 0+ Counts {cases = 15, tried = 15, errors = 0, failures = 0} # Documentation @@ -92,3 +92,10 @@ In this example replace mykey with your key and mysecret with your secret. Note that compiling the source code generates .o and .hi files in the source directories.++# Locale issues++If you're using Linux and experience character encoding issues add the+following line to your bashrc before using the code:++ export LC_ALL="en_US.UTF-8"
factual-api.cabal view
@@ -1,5 +1,5 @@ name: factual-api-version: 0.6.0+version: 0.6.1 license: BSD3 license-file: LICENSE.txt category: API, Web@@ -7,7 +7,7 @@ author: Rudiger Lippert <rudy@factual.com> maintainer: Rudiger Lippert <rudy@factual.com> stability: stable-tested-with: GHC == 7.4.1+tested-with: GHC == 7.4.2 synopsis: A driver for the Factual API cabal-version: >= 1.8 homepage: https://github.com/rudyl313/factual-haskell-driver@@ -36,6 +36,7 @@ Data.Factual.Query.ResolveQuery Data.Factual.Query.SchemaQuery Data.Factual.Write+ Data.Factual.Write.Clear Data.Factual.Write.Flag Data.Factual.Write.Submit Data.Factual.Write.Insert
test/Tests.hs view
@@ -18,6 +18,7 @@ import qualified Data.Factual.Write.Submit as S import qualified Data.Factual.Write.Insert as I import qualified Data.Factual.Write.Flag as L+import qualified Data.Factual.Write.Clear as C runUnitTests = runTestTT unitTests @@ -88,7 +89,9 @@ , TestLabel "Insert path test" insertPathTest , TestLabel "Insert body test" insertBodyTest , TestLabel "Flag path test" flagPathTest- , TestLabel "Flag body test" flagBodyTest ]+ , TestLabel "Flag body test" flagBodyTest+ , TestLabel "Clear path test" clearPathTest+ , TestLabel "Clear body test" clearBodyTest ] integrationTests token = TestList [ TestLabel "Read test" (readIntegrationTest token) , TestLabel "Unicode test" (unicodeIntegrationTest token)@@ -104,6 +107,7 @@ , TestLabel "Submit test" (submitIntegrationTest token) , TestLabel "Insert test" (insertIntegrationTest token) , TestLabel "Flag test" (flagIntegrationTest token)+ , TestLabel "Clear test" (clearIntegrationTest token) , TestLabel "Error test" (errorIntegrationTest token) ] placeTablePathTest = TestCase (do@@ -423,7 +427,16 @@ assertEqual "Correct user" (bodyParams M.! "user") "user123" assertEqual "Correct comment" (bodyParams M.! "comment") "There was a problem") +clearPathTest = TestCase (do+ let expected = "/t/places/foobar/clear"+ let path = W.path clearWrite+ assertEqual "Correct path for clear" expected path) +clearBodyTest = TestCase (do+ let bodyParams = W.body clearWrite+ assertEqual "Correct user" (bodyParams M.! "user") "user123"+ assertEqual "Correct fields" (bodyParams M.! "fields") "latitude,longitude")+ readIntegrationTest :: Token -> Test readIntegrationTest token = TestCase (do let query = ReadQuery { table = Places@@ -454,7 +467,7 @@ let dat = lookupValue "data" resp let row = (toList dat) !! 0 let loc = lookupString "locality" row- assertEqual "Correctly encoded locality" loc "בני ברק")+ assertEqual "Correctly encoded locality" "בני ברק" loc) schemaIntegrationTest :: Token -> Test schemaIntegrationTest token = TestCase (do@@ -567,6 +580,15 @@ result <- executeWrite (Options { token = token, timeout = Nothing }) write assertEqual "Valid flag" "ok" (status result)) +clearIntegrationTest :: Token -> Test+clearIntegrationTest token = TestCase (do+ let write = C.Clear { C.table = Custom "t7RSEV"+ , C.user = "drivertest"+ , C.factualId = "97a38c06-cde1-402d-ad5a-4ae408530386"+ , C.fields = ["country"] }+ result <- executeWrite (Options { token = token, timeout = Nothing }) write+ assertEqual "Valid clear" "ok" (status result))+ errorIntegrationTest :: Token -> Test errorIntegrationTest token = TestCase (do result <- get (Options { token = token, timeout = Nothing }) "/t/foobarbaz" (M.empty)@@ -606,3 +628,9 @@ , L.dataJSON = Nothing , L.fields = Nothing , L.reference = Nothing }++clearWrite :: C.Clear+clearWrite = C.Clear { C.table = Places+ , C.factualId = "foobar"+ , C.user = "user123"+ , C.fields = ["latitude", "longitude"] }