git.iko.soy/typeable/bloodhound
on master help sign in
fucking around with outer/inner parametric types in Aeson
commitbd8dc3e986f74131a37ba05074932daeb5b50d39 authorChris Allen <cma@bitemyapp.com> dateSat 29 Mar 2014, 04:23 (13 years ago) parente2e3fa5
4 files changed+125−11
.gitignore+1 DSL.org+44 Database/Bloodhound/Client.hs+65 bloodhound.cabal+15−11
.gitignore+1
@@ -1,2 +1,3 @@
11cabal.sandbox.config
22.cabal-sandbox/
3+dist/
DSL.orgnew file+44
@@ -0,0 +1,44 @@
1+* ElasticSearch DSL
2+
3+** Grouping
4+
5+bulk
6+
7+** Indexing
8+
9+create index
10+index
11+delete index
12+index status
13+add alias
14+remove alias
15+
16+** Search
17+
18+search
19+
20+** Document Management
21+
22+get
23+count
24+delete by id
25+delete by query
26+update
27+
28+** Multi-**
29+
30+multiget
31+multisearch
32+
33+** Meta/Status
34+
35+Get status (root URL)
36+optimize
37+explain
38+more like this
39+
40+** Register/percolate/validate
41+
42+register query
43+percolate doc
44+validate
Database/Bloodhound/Client.hs+65
@@ -0,0 +1,65 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+
4+module Database.Bloodhound.Client where
5+
6+import Control.Applicative
7+import Control.Monad (liftM)
8+import Data.Aeson
9+import Data.Aeson.TH (deriveJSON)
10+import qualified Data.ByteString.Lazy.Char8 as L
11+import qualified Data.Text as T
12+import Data.Time.Clock as DTC
13+import GHC.Generics (Generic)
14+import Network.HTTP.Conduit
15+
16+data Version = Version { number :: T.Text
17+ , build_hash :: T.Text
18+ , build_timestamp :: DTC.UTCTime
19+ , build_snapshot :: Bool
20+ , lucene_version :: T.Text } deriving (Show, Generic)
21+
22+data (FromJSON a, ToJSON a) => Status a =
23+ Status { ok :: Bool
24+ , status :: Int
25+ , name :: T.Text
26+ , version :: a
27+ , tagline :: T.Text } deriving (Show)
28+
29+instance ToJSON Version
30+instance FromJSON Version
31+
32+instance (FromJSON a, ToJSON a) => FromJSON (Status a) where
33+ parseJSON (Object v) = Status <$>
34+ v .: "ok" <*>
35+ v .: "status" <*>
36+ v .: "name" <*>
37+ v .: "version" <*>
38+ v .: "tagline"
39+ parseJSON _ = empty
40+
41+-- instance ToJSON (Status a)
42+-- instance FromJSON (Status a)
43+
44+muhServer = "http://localhost:9200"
45+
46+-- bloo <- (liftM responseBody $ parseUrl "http://localhost:9200/" >>= \r -> withManager (httpLbs r))
47+
48+rootPath :: String
49+rootPath = rollUp $ ["/"]
50+
51+-- Kinda hate this.
52+pathFromType :: String -> String -> String
53+pathFromType index docType = "/" ++ index ++ docType
54+
55+-- Kinda hate this too.
56+rollUp :: [String] -> String
57+rollUp = Prelude.concat
58+
59+getStatus :: String -> IO (Maybe (Status Version))
60+getStatus server = do
61+ request <- parseUrl $ server ++ rootPath
62+ response <- withManager $ httpLbs request
63+ return $ (decode $ responseBody response)
64+
65+main = simpleHttp "http://localhost:9200/events/event/_search?q=hostname:localhost&size=1" >>= L.putStrLn
bloodhound.cabal+15−11
@@ -17,15 +17,19 @@ cabal-version: >=1.10
1717
1818library
1919 exposed-modules: Database.Bloodhound.Client
20− build-depends: base >=4.6 && <4.7,
21− bytestring >= 0.10,
22− transformers >= 0.3,
23− free >= 4.5,
24− lens >= 4,
25− aeson >= 0.7,
26− conduit >= 1.0,
27− http-conduit >= 2.0,
28− io-streams >= 1.1,
29− http-streams >= 0.7,
30− HTTP >= 4000.2
20+ build-depends: base >=4.6 && <4.7,
21+ bytestring >= 0.10,
22+ transformers >= 0.3,
23+ free >= 4.5,
24+ lens >= 4,
25+ aeson >= 0.7,
26+ conduit >= 1.0,
27+ http-conduit >= 2.0,
28+ io-streams >= 1.1,
29+ http-streams >= 0.7,
30+ HTTP >= 4000.2,
31+ time >= 1.4,
32+ text >= 0.11,
33+ http-types >= 0.8,
34+ blaze-builder >= 0.3
3135 default-language: Haskell2010