module Web.VKHS.Types where
import Data.List
import Data.Char
import Data.Data
import Data.Typeable
import Data.Text(Text)
import qualified Data.Text as Text
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as ByteString
import Data.Aeson (FromJSON(..), ToJSON(..), (.=), (.:))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Types as Aeson
import qualified Network.Shpider.Forms as Shpider
data AccessToken = AccessToken {
at_access_token :: String
, at_user_id :: String
, at_expires_in :: String
} deriving(Read, Show, Eq, Ord)
data AccessRight
= Notify
| Friends
| Photos
| Audio
| Video
| Docs
| Notes
| Pages
| Status
| Offers
| Questions
| Wall
| Groups
| Messages
| Notifications
| Stats
| Ads
| Offline
deriving(Show, Eq, Ord, Enum)
toUrlArg :: [AccessRight] -> String
toUrlArg = intercalate "," . map (map toLower . show)
allAccess :: [AccessRight]
allAccess =
[
Friends
, Photos
, Audio
, Video
, Docs
, Notes
, Status
, Offers
, Questions
, Wall
, Groups
, Messages
, Notifications
, Stats
]
newtype AppID = AppID { aid_string :: String }
deriving(Show, Eq, Ord)
data JSON = JSON { js_aeson :: Aeson.Value }
deriving(Show, Data, Typeable)
parseJSON :: (Aeson.FromJSON a) => JSON -> Either String a
parseJSON j = Aeson.parseEither Aeson.parseJSON (js_aeson j)
data Form = Form {
form_title :: String
, form :: Shpider.Form
} deriving(Show)
data FilledForm = FilledForm {
fform_title :: String
, fform :: Shpider.Form
} deriving(Show)
data GenericOptions = GenericOptions {
o_login_host :: String
, o_api_host :: String
, o_port :: Int
, o_verbose :: Bool
, o_use_https :: Bool
, o_max_request_rate_per_sec :: Rational
, o_allow_interactive :: Bool
, l_appid :: AppID
, l_username :: String
, l_password :: String
, l_access_token :: String
, l_access_token_file :: FilePath
} deriving(Show)
defaultOptions = GenericOptions {
o_login_host = "oauth.vk.com"
, o_api_host = "api.vk.com"
, o_port = 443
, o_verbose = False
, o_use_https = True
, o_max_request_rate_per_sec = 3
, o_allow_interactive = True
, l_appid = AppID "3128877"
, l_username = ""
, l_password = ""
, l_access_token = ""
, l_access_token_file = ""
}
class ToGenericOptions s where
toGenericOptions :: s -> GenericOptions
data Verbosity = Normal | Trace | Debug
deriving(Enum,Eq,Ord,Show)
data MusicOptions = MusicOptions {
m_list_music :: Bool
, m_search_string :: String
, m_name_format :: String
, m_output_format :: String
, m_out_dir :: Maybe String
, m_records_id :: [String]
, m_skip_existing :: Bool
} deriving(Show)
data UserOptions = UserOptions {
u_queryString :: String
} deriving(Show)
data WallOptions = WallOptions {
w_woid :: String
} deriving(Show)
data GroupOptions = GroupOptions {
g_search_string :: String
, g_output_format :: String
} deriving(Show)
type MethodName = String
type MethodArgs = [(String, Text)]