Copyright | (c) 2014 Jens Thomas |
---|---|
License | BSD-style |
Maintainer | jetho@gmx.de |
Stability | experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
Extensions | OverloadedStrings |
Haskell bindings for the Syncthing REST API.
The library is based on the Network.Wreq package and uses some of wreq's functionalities for client configuration. For example, to use authentication, you need to import the Network.Wreq module.
Example Usage:
{-# LANGUAGE OverloadedStrings #-} import qualified Network.Wreq as Wreq import Control.Monad (liftM2
) import Control.Lens ((&
), (.~
), (?~
)) import Network.Syncthing import qualified Network.Syncthing.Get as Get -- A single Syncthing request. single =syncthing
defaultConfig
Get.ping
-- Connection sharing for multiple Syncthing requests. multiple1 =withManager
$ \cfg ->syncthing
cfg $ do p <- Get.ping
v <- Get.version
return (p, v) -- Multiple Syncthing requests with connection sharing and customized configuration. multiple2 =withManager
$ \cfg -> do let cfg' = cfg&
pServer
.~
"192.168.0.10:8080"&
pHttps
.~
True&
pAuth
?~
Wreq.basicAuth
"user" "pass"syncthing
cfg' $liftM2
(,) Get.ping
Get.version
- type Server = Text
- type Device = Text
- type FolderName = Text
- type Path = Text
- type Host = Text
- type Port = Int
- type Addr = (Host, Maybe Port)
- type SyncResult a = Either SyncError a
- data SyncM m a
- syncthing :: SyncConfig -> SyncM IO a -> IO (SyncResult a)
- withManager :: (SyncConfig -> IO a) -> IO a
- withManagerNoVerify :: (SyncConfig -> IO a) -> IO a
- withManager' :: ManagerSettings -> (SyncConfig -> IO a) -> IO a
- data SyncConfig
- pServer :: Lens' SyncConfig Server
- pApiKey :: Lens' SyncConfig (Maybe Text)
- pAuth :: Lens' SyncConfig (Maybe Auth)
- pHttps :: Lens' SyncConfig Bool
- pManager :: Lens' SyncConfig (Either ManagerSettings Manager)
- defaultConfig :: SyncConfig
- defaultFolder :: FolderName
- defaultManagerSettings :: ManagerSettings
- noSSLVerifyManagerSettings :: ManagerSettings
- setResponseTimeout :: ManagerSettings -> Int -> ManagerSettings
- data DeviceError
- data SyncError
- data CacheEntry = CacheEntry {}
- data Config = Config {}
- data AddressType
- data FolderConfig = FolderConfig {}
- data DeviceConfig = DeviceConfig {}
- data VersioningConfig = VersioningConfig {}
- data GuiConfig = GuiConfig {
- getEnabled :: Bool
- getApiKey :: Maybe Text
- getGuiAddress :: Addr
- getUser :: Text
- getPassword :: Text
- getUseTLS :: Bool
- data OptionsConfig = OptionsConfig {
- getListenAddress :: [Addr]
- getGlobalAnnServers :: [Text]
- getGlobalAnnEnabled :: Bool
- getLocalAnnEnabled :: Bool
- getLocalAnnPort :: Int
- getLocalAnnMCAddr :: Text
- getMaxSendKbps :: Int
- getMaxRecvKbps :: Int
- getReconnectIntervalS :: Int
- getStartBrowser :: Bool
- getUPnPEnabled :: Bool
- getUPnPLease :: Int
- getUPnPRenewal :: Int
- getURAccepted :: Int
- getURUniqueID :: Text
- getRestartOnWakeup :: Bool
- getAutoUpgradeIntervalH :: Int
- getKeepTemporariesH :: Int
- getCacheIgnoredFiles :: Bool
- getProgressUpdateIntervalS :: Int
- getSymlinksEnabled :: Bool
- data Connection = Connection {}
- data DirTree
- data Error = Error {}
- data Ignore = Ignore {
- getIgnores :: Maybe [Text]
- getPatterns :: Maybe [Text]
- data Model = Model {
- getGlobalBytes :: Integer
- getGlobalDeleted :: Integer
- getGlobalFiles :: Integer
- getInSyncBytes :: Integer
- getInSyncFiles :: Integer
- getLocalBytes :: Integer
- getLocalDeleted :: Integer
- getLocalFiles :: Integer
- getNeedBytes :: Integer
- getNeedFiles :: Integer
- getState :: Maybe ModelState
- getStateChanged :: Maybe UTCTime
- getInvalid :: Maybe Text
- getModelVersion :: Int
- data ModelState
- data Need = Need {}
- data Progress = Progress {
- getName :: Text
- getFlags :: Int
- getModified :: Integer
- getProgressVersion :: Int
- getLocalVersion :: Int
- getNumBlocks :: Int
- getSize :: Integer
- data System = System {
- getAlloc :: Integer
- getCpuPercent :: Double
- getExtAnnounceOK :: Maybe (Map Server Bool)
- getGoRoutines :: Int
- getMyId :: Text
- getSys :: Integer
- data SystemMsg
- data Upgrade = Upgrade {}
- data Version = Version {
- getArch :: Text
- getLongVersion :: Text
- getOs :: Text
- getVersion :: Text
- parseAddr :: Server -> Addr
- encodeAddr :: Addr -> Server
- toUTC :: String -> Maybe UTCTime
- fromUTC :: UTCTime -> String
Types
type FolderName = Text Source
The Syncthing Monad
type SyncResult a = Either SyncError a Source
The result type of Syncthing requests.
The SyncM Monad represents one or multiple Syncthing requests.
syncthing :: SyncConfig -> SyncM IO a -> IO (SyncResult a) Source
Run Syncthing requests.
Connection sharing
withManager :: (SyncConfig -> IO a) -> IO a Source
Create a default configuration with a new manager for connection sharing. The manager is released after running the Syncthing actions(s). This is equivalent to:
withManager'
defaultManagerSettings
Examples:
withManager
$ \cfg ->syncthing
cfg $liftM2
(,) Get.ping
Get.version
withManager
$ \cfg -> do let cfg' = cfg&
pServer
.~
"192.168.0.10:8080"syncthing
cfg' $liftM2
(,) Get.ping
Get.version
withManagerNoVerify :: (SyncConfig -> IO a) -> IO a Source
Create a manager with disabled SSL certificate verification. This is equivalent to:
withManager'
noSSLVerifyManagerSettings
Example:
withManagerNoVerify
$ \cfg -> do let cfg' = cfg&
pHttps
.~
Truesyncthing
cfg' $liftM2
(,) Get.ping
Get.version
withManager' :: ManagerSettings -> (SyncConfig -> IO a) -> IO a Source
Create a manager by using the provided manager settings.
Example:
withManager'
noSSLVerifyManagerSettings
$ \cfg -> do let cfg' = cfg&
pHttps
.~
Truesyncthing
cfg' $liftM2
(,) Get.ping
Get.version
Configuration
data SyncConfig Source
The Syncthing configuration for specifying the Syncthing server, authentication, the API Key etc.
pManager :: Lens' SyncConfig (Either ManagerSettings Manager) Source
A lens for specifying your own ManagerSettings/Manager. For more information, please refer to the Network.HTTP.Client package.
Defaults
defaultConfig :: SyncConfig Source
The default Syncthing configuration. Customize it to your needs by using the SyncConfig lenses.
Example:
>>>
defaultConfig
SyncConfig { pServer = "127.0.0.1:8080", pApiKey = Nothing, pAuth = Nothing, pHttps = False, pManager = Left _ }>>>
defaultConfig & pServer .~ "192.168.0.10:8080" & pApiKey ?~ "XXXX"
SyncConfig { pServer = "192.168.0.10:8080", pApiKey = Just "XXXX", pAuth = Nothing, pHttps = False, pManager = Left _ }
defaultFolder :: FolderName Source
The default folder name.
Manager Settings
defaultManagerSettings :: ManagerSettings Source
The default manager settings used by defaultConfig
.
noSSLVerifyManagerSettings :: ManagerSettings Source
Alternative manager settings with disabled SSL certificate verification.
setResponseTimeout :: ManagerSettings -> Int -> ManagerSettings Source
Set the response timeout (in microseconds). Default is 300 seconds.
Error Handling
data DeviceError Source
Data Types
data CacheEntry Source
Represents an entry in the discovery cache.
The current configuration data structure.
data AddressType Source
An address can be dynamic or static.
data FolderConfig Source
The folder specific configuration.
FolderConfig | |
|
data DeviceConfig Source
Device specific configuration information.
DeviceConfig | |
|
data VersioningConfig Source
Information about versioning.
Gui settings.
GuiConfig | |
|
data OptionsConfig Source
Various config settings.
data Connection Source
Connection information and some associated metadata.
A directory tree contains files or subdirectories.
Dir | |
File | |
|
An error message and its timestamp.
Contains the ignores list and a list of all compiled ignore patterns.
Ignore | |
|
Information about the current status of a folder.
data ModelState Source
The current state of activity of a folder.
Contains lists of files which are needed by a device for becoming in sync.
A file that is currently downloading.
Progress | |
|
Information about the system status and resource usage.
System messages.
Information about the current software version and upgrade possibilities.
Current Syncthing version information.
Version | |
|
Utility functions
encodeAddr :: Addr -> Server Source
Generate server string.