packages feed

Hastodon 0.0.1 → 0.0.2

raw patch · 2 files changed

+48/−7 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Web.Hastodon: Account :: Int -> String -> String -> String -> Bool -> String -> Int -> Int -> Int -> String -> String -> String -> String -> String -> String -> Account
+ Web.Hastodon: Application :: String -> Maybe String -> Application
+ Web.Hastodon: Attachment :: Int -> String -> String -> String -> String -> Maybe String -> Attachment
+ Web.Hastodon: Card :: String -> String -> String -> String -> Card
+ Web.Hastodon: Context :: [Status] -> [Status] -> Context
+ Web.Hastodon: Instance :: String -> String -> String -> String -> Instance
+ Web.Hastodon: Mention :: String -> String -> String -> Int -> Mention
+ Web.Hastodon: Notification :: Int -> String -> String -> Account -> Maybe Status -> Notification
+ Web.Hastodon: OAuthClient :: Int -> String -> String -> String -> OAuthClient
+ Web.Hastodon: Relationship :: Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Relationship
+ Web.Hastodon: Report :: Int -> String -> Report
+ Web.Hastodon: Results :: [Account] -> [Status] -> [String] -> Results
+ Web.Hastodon: Status :: Int -> String -> String -> Account -> Maybe Int -> Maybe Int -> Maybe Status -> String -> String -> Int -> Int -> Maybe Bool -> Maybe Bool -> Maybe Bool -> String -> String -> [Attachment] -> [Mention] -> [Tag] -> Maybe Application -> Status
+ Web.Hastodon: Tag :: String -> String -> Tag
+ Web.Hastodon: [accountAcct] :: Account -> String
+ Web.Hastodon: [accountAvatarStatic] :: Account -> String
+ Web.Hastodon: [accountAvatar] :: Account -> String
+ Web.Hastodon: [accountCreatedAt] :: Account -> String
+ Web.Hastodon: [accountDisplayName] :: Account -> String
+ Web.Hastodon: [accountFollowersCount] :: Account -> Int
+ Web.Hastodon: [accountFollowingCount] :: Account -> Int
+ Web.Hastodon: [accountHeaderStatic] :: Account -> String
+ Web.Hastodon: [accountHeader] :: Account -> String
+ Web.Hastodon: [accountId] :: Account -> Int
+ Web.Hastodon: [accountLocked] :: Account -> Bool
+ Web.Hastodon: [accountNote] :: Account -> String
+ Web.Hastodon: [accountStatusesCount] :: Account -> Int
+ Web.Hastodon: [accountUrl] :: Account -> String
+ Web.Hastodon: [accountUsername] :: Account -> String
+ Web.Hastodon: [applicationName] :: Application -> String
+ Web.Hastodon: [applicationWebsite] :: Application -> Maybe String
+ Web.Hastodon: [attachmentId] :: Attachment -> Int
+ Web.Hastodon: [attachmentPreviewUrl] :: Attachment -> String
+ Web.Hastodon: [attachmentRemoteUrl] :: Attachment -> String
+ Web.Hastodon: [attachmentTextUrl] :: Attachment -> Maybe String
+ Web.Hastodon: [attachmentType] :: Attachment -> String
+ Web.Hastodon: [attachmentUrl] :: Attachment -> String
+ Web.Hastodon: [cardDescription] :: Card -> String
+ Web.Hastodon: [cardImage] :: Card -> String
+ Web.Hastodon: [cardTitle] :: Card -> String
+ Web.Hastodon: [cardUrl] :: Card -> String
+ Web.Hastodon: [contextAncestors] :: Context -> [Status]
+ Web.Hastodon: [contextDescendants] :: Context -> [Status]
+ Web.Hastodon: [instanceDescription] :: Instance -> String
+ Web.Hastodon: [instanceEmail] :: Instance -> String
+ Web.Hastodon: [instanceTitle] :: Instance -> String
+ Web.Hastodon: [instanceUri] :: Instance -> String
+ Web.Hastodon: [mentionAcct] :: Mention -> String
+ Web.Hastodon: [mentionId] :: Mention -> Int
+ Web.Hastodon: [mentionUrl] :: Mention -> String
+ Web.Hastodon: [mentionUsername] :: Mention -> String
+ Web.Hastodon: [name] :: Tag -> String
+ Web.Hastodon: [notificationAccount] :: Notification -> Account
+ Web.Hastodon: [notificationCreatedAt] :: Notification -> String
+ Web.Hastodon: [notificationId] :: Notification -> Int
+ Web.Hastodon: [notificationStatus] :: Notification -> Maybe Status
+ Web.Hastodon: [notificationType] :: Notification -> String
+ Web.Hastodon: [oauthClientClientId] :: OAuthClient -> String
+ Web.Hastodon: [oauthClientClientSecret] :: OAuthClient -> String
+ Web.Hastodon: [oauthClientId] :: OAuthClient -> Int
+ Web.Hastodon: [oauthClientRedirectUri] :: OAuthClient -> String
+ Web.Hastodon: [relationshipBlocking] :: Relationship -> Bool
+ Web.Hastodon: [relationshipFollowed_by] :: Relationship -> Bool
+ Web.Hastodon: [relationshipFollowing] :: Relationship -> Bool
+ Web.Hastodon: [relationshipId] :: Relationship -> Int
+ Web.Hastodon: [relationshipMuting] :: Relationship -> Bool
+ Web.Hastodon: [relationshipRequested] :: Relationship -> Bool
+ Web.Hastodon: [reportActionToken] :: Report -> String
+ Web.Hastodon: [reportId] :: Report -> Int
+ Web.Hastodon: [resultAccounts] :: Results -> [Account]
+ Web.Hastodon: [resultHashtags] :: Results -> [String]
+ Web.Hastodon: [resultStatus] :: Results -> [Status]
+ Web.Hastodon: [statusAccount] :: Status -> Account
+ Web.Hastodon: [statusApplication] :: Status -> Maybe Application
+ Web.Hastodon: [statusContent] :: Status -> String
+ Web.Hastodon: [statusCreatedAt] :: Status -> String
+ Web.Hastodon: [statusFavourited] :: Status -> Maybe Bool
+ Web.Hastodon: [statusFavouritesCount] :: Status -> Int
+ Web.Hastodon: [statusId] :: Status -> Int
+ Web.Hastodon: [statusInReplyToAccountId] :: Status -> Maybe Int
+ Web.Hastodon: [statusInReplyToId] :: Status -> Maybe Int
+ Web.Hastodon: [statusMediaAttachments] :: Status -> [Attachment]
+ Web.Hastodon: [statusMentions] :: Status -> [Mention]
+ Web.Hastodon: [statusReblog] :: Status -> Maybe Status
+ Web.Hastodon: [statusReblogged] :: Status -> Maybe Bool
+ Web.Hastodon: [statusReblogsCount] :: Status -> Int
+ Web.Hastodon: [statusSensitive] :: Status -> Maybe Bool
+ Web.Hastodon: [statusSpoilerText] :: Status -> String
+ Web.Hastodon: [statusTags] :: Status -> [Tag]
+ Web.Hastodon: [statusUri] :: Status -> String
+ Web.Hastodon: [statusUrl] :: Status -> String
+ Web.Hastodon: [statusVisibility] :: Status -> String
+ Web.Hastodon: [url] :: Tag -> String
+ Web.Hastodon: data Account
+ Web.Hastodon: data Application
+ Web.Hastodon: data Attachment
+ Web.Hastodon: data Card
+ Web.Hastodon: data Context
+ Web.Hastodon: data Instance
+ Web.Hastodon: data Mention
+ Web.Hastodon: data Notification
+ Web.Hastodon: data OAuthClient
+ Web.Hastodon: data Relationship
+ Web.Hastodon: data Report
+ Web.Hastodon: data Results
+ Web.Hastodon: data Status
+ Web.Hastodon: data Tag
+ Web.Hastodon: instance Data.Aeson.Types.FromJSON.FromJSON Web.Hastodon.OAuthResponse
+ Web.Hastodon: instance GHC.Show.Show Web.Hastodon.OAuthResponse
- Web.Hastodon: mkHastodonClient :: String -> String -> HastodonClient
+ Web.Hastodon: mkHastodonClient :: String -> String -> String -> String -> String -> IO (Maybe HastodonClient)
- Web.Hastodon: postApps :: String -> HastodonClient -> IO (Either JSONException OAuthClient)
+ Web.Hastodon: postApps :: String -> String -> IO (Either JSONException OAuthClient)

Files

Hastodon.cabal view
@@ -1,5 +1,5 @@ Name: Hastodon-Version: 0.0.1+Version: 0.0.2 Synopsis: mastodon client module for Haskell Category: Web Description: mastodon client module for Haskell
Web/Hastodon.hs view
@@ -1,7 +1,21 @@ module Web.Hastodon   (-    mkHastodonClient+    Account(..)+  , Application(..)+  , Attachment(..)+  , Card(..)+  , Context(..)+  , Instance(..)+  , Mention(..)+  , Notification(..)+  , OAuthClient(..)+  , Relationship(..)+  , Report(..)+  , Results(..)+  , Status(..)+  , Tag(..) +  , mkHastodonClient   , getAccountById   , getCurrentAccount   , getFollowers@@ -101,6 +115,14 @@   token :: String } +data OAuthResponse = OAuthResponse {+  accessToken :: String+  -- NOTE currently ignore other fields.+} deriving (Show)+instance FromJSON OAuthResponse where+  parseJSON (Object v) =+    OAuthResponse <$> (v .: T.pack "access_token")+ data Account = Account {   accountId :: Int,   accountUsername :: String,@@ -333,6 +355,19 @@ -- helpers --  +getOAuthToken :: String -> String -> String -> String -> String -> IO (Either JSONException OAuthResponse)+getOAuthToken clientId clientSecret username password host = do+  initReq <- parseRequest $ "https://" ++ host ++ "/oauth/token"+  let reqBody = [(Char8.pack "client_id", Char8.pack clientId),+                 (Char8.pack "client_secret", Char8.pack clientSecret),+                 (Char8.pack "username", Char8.pack username),+                 (Char8.pack "password", Char8.pack password),+                 (Char8.pack "grant_type", Char8.pack "password"),+                 (Char8.pack "scope", Char8.pack "read write follow")]+  let req = setRequestBodyURLEncoded reqBody $ initReq+  res <- httpJSONEither req+  return $ (getResponseBody res :: Either JSONException OAuthResponse)+ mkHastodonHeader :: String -> Request -> Request mkHastodonHeader token =   addRequestHeader hAuthorization $ Char8.pack $ "Bearer " ++ token@@ -365,8 +400,12 @@ -- exported functions --  -mkHastodonClient :: String -> String -> HastodonClient-mkHastodonClient host token = HastodonClient host token+mkHastodonClient :: String -> String -> String -> String -> String -> IO (Maybe HastodonClient)+mkHastodonClient clientId clientSecret username password host = do+  oauthRes <- getOAuthToken clientId clientSecret username password host+  case oauthRes of+    Left err -> return $ Nothing+    Right oauthData -> return $ Just $ HastodonClient host (accessToken oauthData)  getAccountById :: Int -> HastodonClient -> IO (Either JSONException Account) getAccountById id client = do@@ -436,12 +475,14 @@   res <- postAndGetHastodonResponseJSON (replace ":id" (show id) pUnmute) [] client   return (getResponseBody res :: Either JSONException Relationship) -postApps :: String -> HastodonClient -> IO (Either JSONException OAuthClient)-postApps clientName client = do+postApps :: String -> String -> IO (Either JSONException OAuthClient)+postApps host clientName = do   let reqBody = [(Char8.pack "client_name", Char8.pack clientName),                  (Char8.pack "redirect_uris", Char8.pack "urn:ietf:wg:oauth:2.0:oob"),                  (Char8.pack "scopes", Char8.pack "read write follow")]-  res <- postAndGetHastodonResponseJSON pApps reqBody client+  initReq <- parseRequest $ "https://" ++ host ++ pApps+  let req = setRequestBodyURLEncoded reqBody $ initReq+  res <- httpJSONEither req   return (getResponseBody res :: Either JSONException OAuthClient)  getBlocks :: HastodonClient -> IO (Either JSONException [Account])