github 0.1.1 → 0.1.2
raw patch · 4 files changed
+29/−22 lines, 4 filesdep +unordered-containersdep ~aesondep ~attoparsecdep ~http-enumerator
Dependencies added: unordered-containers
Dependency ranges changed: aeson, attoparsec, http-enumerator
Files
- Github/Data.hs +9/−3
- Github/Private.hs +12/−12
- LICENSE +2/−2
- github.cabal +6/−5
Github/Data.hs view
@@ -9,12 +9,12 @@ import Data.Time import Control.Applicative import Control.Monad-import qualified Data.Map as Map import qualified Data.Text as T import Data.Aeson.Types import System.Locale (defaultTimeLocale) import Data.Attoparsec.Number (Number(..)) import qualified Data.Vector as V+import qualified Data.HashMap.Lazy as Map import Github.Data.Definitions @@ -465,15 +465,21 @@ -- | Produce all values for the given key. obj `values` key =- let (Object children) = Map.findWithDefault (Object Map.empty) key obj in+ let (Object children) = findWithDefault (Object Map.empty) key obj in parseJSON $ Array $ V.fromList $ Map.elems children -- | Produce the value for the last key by traversing. obj <.:> [key] = obj .: key obj <.:> (key:keys) =- let (Object nextObj) = Map.findWithDefault (Object Map.empty) key obj in+ let (Object nextObj) = findWithDefault (Object Map.empty) key obj in nextObj <.:> keys -- | Produce the value for the given key, maybe. at :: Object -> T.Text -> Maybe Value obj `at` key = Map.lookup key obj++-- Taken from Data.Map:+findWithDefault def k m =+ case Map.lookup k m of+ Nothing -> def+ Just x -> x
Github/Private.hs view
@@ -3,7 +3,7 @@ import Github.Data import Data.Aeson-import Data.Attoparsec+import Data.Attoparsec.ByteString.Lazy import Control.Applicative import Data.List import qualified Data.ByteString.Char8 as BS@@ -34,20 +34,10 @@ githubAPI method url body = do result <- doHttps method url (Just encodedBody) return $ either (Left . HTTPConnectionError)- (parseJson . BS.pack . LBS.unpack . responseBody)+ (parseJson . responseBody) result where encodedBody = RequestBodyLBS $ encode $ toJSON body -parseJson :: (FromJSON b, Show b) => BS.ByteString -> Either Error b-parseJson jsonString =- let parsed = parse (fromJSON <$> json) jsonString in- case parsed of- Data.Attoparsec.Done _ jsonResult -> do- case jsonResult of- (Success s) -> Right s- (Error e) -> Left $ JsonError $ e ++ " on the JSON: " ++ BS.unpack jsonString- (Fail _ _ e) -> Left $ ParseError e- doHttps :: BS.ByteString -> String -> Maybe (RequestBody IO) -> IO (Either E.IOException Response) doHttps method url body = do let (Just uri) = parseURI url@@ -66,3 +56,13 @@ (getResponse request >>= return . Right) `catch` (return . Left) where getResponse request = withManager $ \manager -> httpLbs request manager++parseJson :: (FromJSON b, Show b) => LBS.ByteString -> Either Error b+parseJson jsonString =+ let parsed = parse (fromJSON <$> json) jsonString in+ case parsed of+ Data.Attoparsec.ByteString.Lazy.Done _ jsonResult -> do+ case jsonResult of+ (Success s) -> Right s+ (Error e) -> Left $ JsonError $ e ++ " on the JSON: " ++ LBS.unpack jsonString+ (Fail _ _ e) -> Left $ ParseError e
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c)2011, ???+Copyright (c)2011, Mike Burns All rights reserved. @@ -13,7 +13,7 @@ disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of ??? nor the names of other+ * Neither the name of Mike Burns nor the names of other contributors may be used to endorse or promote products derived from this software without specific prior written permission.
github.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.1.1+Version: 0.1.2 -- A short (one-line) description of the package. Synopsis: Access to the Github API, v3.@@ -144,19 +144,20 @@ -- Packages needed in order to build this package. Build-depends: base >= 4.0 && < 5.0, time,- aeson,- attoparsec,+ aeson == 0.5.0.0,+ attoparsec == 0.10.1.0, bytestring, containers, text, old-locale, HTTP, network,- http-enumerator,+ http-enumerator == 0.7.2.1, uri, failure, http-types,- vector+ vector,+ unordered-containers == 0.1.4.3 -- Modules not exported by this package. Other-modules: Github.Private