diff options
-rw-r--r-- | src/Network/BitTorrent/Tracker.hs | 23 | ||||
-rw-r--r-- | tests/Main.hs | 2 |
2 files changed, 5 insertions, 20 deletions
diff --git a/src/Network/BitTorrent/Tracker.hs b/src/Network/BitTorrent/Tracker.hs index 56def0ed..ed3f1d78 100644 --- a/src/Network/BitTorrent/Tracker.hs +++ b/src/Network/BitTorrent/Tracker.hs | |||
@@ -15,7 +15,8 @@ | |||
15 | -- easily request scrape info for a particular torrent list. | 15 | -- easily request scrape info for a particular torrent list. |
16 | -- | 16 | -- |
17 | {-# LANGUAGE OverloadedStrings #-} | 17 | {-# LANGUAGE OverloadedStrings #-} |
18 | {-# LANGUAGE RecordWildCards #-} | 18 | {-# LANGUAGE RecordWildCards #-} |
19 | {-# LANGUAGE TemplateHaskell #-} | ||
19 | module Network.BitTorrent.Tracker | 20 | module Network.BitTorrent.Tracker |
20 | ( withTracker, completedReq | 21 | ( withTracker, completedReq |
21 | 22 | ||
@@ -43,11 +44,12 @@ import Control.Concurrent.STM | |||
43 | import Control.Exception | 44 | import Control.Exception |
44 | import Control.Monad | 45 | import Control.Monad |
45 | 46 | ||
46 | import Data.Aeson hiding (Result) | 47 | import Data.Aeson.TH |
47 | import Data.BEncode | 48 | import Data.BEncode |
48 | import Data.ByteString (ByteString) | 49 | import Data.ByteString (ByteString) |
49 | import qualified Data.ByteString as B | 50 | import qualified Data.ByteString as B |
50 | import qualified Data.ByteString.Char8 as BC | 51 | import qualified Data.ByteString.Char8 as BC |
52 | import Data.Char | ||
51 | import Data.List as L | 53 | import Data.List as L |
52 | import Data.Map (Map) | 54 | import Data.Map (Map) |
53 | import qualified Data.Map as M | 55 | import qualified Data.Map as M |
@@ -293,22 +295,7 @@ instance BEncodable ScrapeInfo where | |||
293 | <*> d >--? "name" | 295 | <*> d >--? "name" |
294 | fromBEncode _ = decodingError "ScrapeInfo" | 296 | fromBEncode _ = decodingError "ScrapeInfo" |
295 | 297 | ||
296 | instance ToJSON ScrapeInfo where | 298 | $(deriveJSON (L.map toLower . L.dropWhile isLower) ''ScrapeInfo) |
297 | toJSON ScrapeInfo {..} = object | ||
298 | [ "complete" .= siComplete | ||
299 | , "downloaded" .= siDownloaded | ||
300 | , "incomplete" .= siIncomplete | ||
301 | , "name" .= siName | ||
302 | ] | ||
303 | |||
304 | instance FromJSON ScrapeInfo where | ||
305 | parseJSON (Object obj) = do | ||
306 | ScrapeInfo <$> obj .: "complete" | ||
307 | <*> obj .: "downloaded" | ||
308 | <*> obj .: "incomplete" | ||
309 | <*> obj .:? "name" | ||
310 | |||
311 | parseJSON _ = fail "ScrapeInfo" | ||
312 | 299 | ||
313 | -- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL' | 300 | -- | Trying to convert /announce/ URL to /scrape/ URL. If 'scrapeURL' |
314 | -- gives 'Nothing' then tracker do not support scraping. The info hash | 301 | -- gives 'Nothing' then tracker do not support scraping. The info hash |
diff --git a/tests/Main.hs b/tests/Main.hs index 0288cad9..64db61b0 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -307,8 +307,6 @@ allTests = | |||
307 | ++ | 307 | ++ |
308 | [ testProperty "scrape bencode" $ | 308 | [ testProperty "scrape bencode" $ |
309 | prop_properBEncode (T :: T ScrapeInfo) | 309 | prop_properBEncode (T :: T ScrapeInfo) |
310 | , testProperty "scrape json" $ | ||
311 | prop_properJSON (T :: T ScrapeInfo) | ||
312 | ] | 310 | ] |
313 | 311 | ||
314 | main :: IO () | 312 | main :: IO () |