Hastodon 0.2.0 → 0.3.1
raw patch · 2 files changed
+39/−13 lines, 2 filesdep +http-clientdep +mime-typesPVP ok
version bump matches the API change (PVP)
Dependencies added: http-client, mime-types
API changes (from Hackage documentation)
+ Web.Hastodon: postMediaFile :: HastodonClient -> String -> String -> IO (Either JSONException Attachment)
+ Web.Hastodon: postStatusWithMediaIds :: HastodonClient -> String -> [HastodonId] -> IO (Either JSONException Status)
- Web.Hastodon: Account :: Int -> String -> String -> String -> Bool -> String -> Int -> Int -> Int -> String -> String -> String -> String -> String -> String -> Account
+ Web.Hastodon: Account :: HastodonId -> String -> String -> String -> Bool -> String -> Int -> Int -> Int -> String -> String -> String -> String -> String -> String -> Account
- Web.Hastodon: Attachment :: Int -> String -> String -> String -> String -> Maybe String -> Attachment
+ Web.Hastodon: Attachment :: HastodonId -> String -> String -> Maybe String -> String -> Maybe String -> Attachment
- Web.Hastodon: Mention :: String -> String -> String -> Int -> Mention
+ Web.Hastodon: Mention :: String -> String -> String -> HastodonId -> Mention
- Web.Hastodon: Notification :: Int -> String -> String -> Account -> Maybe Status -> Notification
+ Web.Hastodon: Notification :: HastodonId -> String -> String -> Account -> Maybe Status -> Notification
- Web.Hastodon: OAuthClient :: Int -> String -> String -> String -> OAuthClient
+ Web.Hastodon: OAuthClient :: HastodonId -> String -> String -> String -> OAuthClient
- Web.Hastodon: Relationship :: Int -> Bool -> Bool -> Bool -> Bool -> Bool -> Relationship
+ Web.Hastodon: Relationship :: HastodonId -> Bool -> Bool -> Bool -> Bool -> Bool -> Relationship
- Web.Hastodon: Report :: Int -> String -> Report
+ Web.Hastodon: Report :: HastodonId -> String -> Report
- 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: Status :: HastodonId -> 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: [accountId] :: Account -> Int
+ Web.Hastodon: [accountId] :: Account -> HastodonId
- Web.Hastodon: [attachmentId] :: Attachment -> Int
+ Web.Hastodon: [attachmentId] :: Attachment -> HastodonId
- Web.Hastodon: [attachmentRemoteUrl] :: Attachment -> String
+ Web.Hastodon: [attachmentRemoteUrl] :: Attachment -> Maybe String
- Web.Hastodon: [mentionId] :: Mention -> Int
+ Web.Hastodon: [mentionId] :: Mention -> HastodonId
- Web.Hastodon: [notificationId] :: Notification -> Int
+ Web.Hastodon: [notificationId] :: Notification -> HastodonId
- Web.Hastodon: [oauthClientId] :: OAuthClient -> Int
+ Web.Hastodon: [oauthClientId] :: OAuthClient -> HastodonId
- Web.Hastodon: [relationshipId] :: Relationship -> Int
+ Web.Hastodon: [relationshipId] :: Relationship -> HastodonId
- Web.Hastodon: [reportId] :: Report -> Int
+ Web.Hastodon: [reportId] :: Report -> HastodonId
- Web.Hastodon: [statusId] :: Status -> Int
+ Web.Hastodon: [statusId] :: Status -> HastodonId
Files
- Hastodon.cabal +3/−1
- Web/Hastodon.hs +36/−12
Hastodon.cabal view
@@ -1,5 +1,5 @@ Name: Hastodon-Version: 0.2.0+Version: 0.3.1 Synopsis: mastodon client module for Haskell Category: Web Description: mastodon client module for Haskell@@ -22,7 +22,9 @@ Build-Depends: base >= 4.5 && < 5, aeson, bytestring,+ mime-types, http-types,+ http-client, http-conduit, MissingH, text
Web/Hastodon.hs view
@@ -38,6 +38,7 @@ , postAuthorizeRequest , postRejectRequest , getInstance+ , postMediaFile , getMutes , getNotifications , getNotificationById@@ -50,6 +51,7 @@ , getRebloggedBy , getFavoritedBy , postStatus+ , postStatusWithMediaIds , postReblog , postUnreblog , postFavorite@@ -68,6 +70,8 @@ import Data.String.Utils import Network.HTTP.Simple import Network.HTTP.Types.Header+import Network.HTTP.Client.MultipartFormData+import Network.Mime -- -- Utility@@ -98,6 +102,7 @@ pAuthorizeRequest = "/api/v1/follow_requests/:id/authorize" pRejectRequest = "/api/v1/follow_requests/:id/reject" pInstance = "/api/v1/instance"+pMedia = "/api/v1/media" pMutes = "/api/v1/mutes" pNotifications = "/api/v1/notifications" pNotificationById = "/api/v1/notifications/:id"@@ -119,6 +124,8 @@ pUnfavorite = "/api/v1/statuses/:id/unfavourite" pTaggedTimeline = "/api/v1/timelines/tag/:hashtag" +type HastodonId = String+ data HastodonClient = HastodonClient { host :: String, token :: String@@ -133,7 +140,7 @@ OAuthResponse <$> (v .: T.pack "access_token") data Account = Account {- accountId :: Int,+ accountId :: HastodonId, accountUsername :: String, accountAcct :: String, accountDisplayName :: String,@@ -177,10 +184,10 @@ <*> (v .:? T.pack "website") data Attachment = Attachment {- attachmentId :: Int,+ attachmentId :: HastodonId, attachmentType :: String, attachmentUrl :: String,- attachmentRemoteUrl :: String,+ attachmentRemoteUrl :: Maybe String, attachmentPreviewUrl :: String, attachmentTextUrl :: Maybe String } deriving (Show)@@ -189,7 +196,7 @@ Attachment <$> (v .: T.pack "id") <*> (v .: T.pack "type") <*> (v .: T.pack "url")- <*> (v .: T.pack "remote_url")+ <*> (v .:? T.pack "remote_url") <*> (v .: T.pack "preview_url") <*> (v .:? T.pack "text_url") @@ -232,7 +239,7 @@ mentionUrl :: String, mentionUsername :: String, mentionAcct :: String,- mentionId :: Int+ mentionId :: HastodonId } deriving (Show) instance FromJSON Mention where parseJSON (Object v) =@@ -242,7 +249,7 @@ <*> (v .: T.pack "id") data Notification = Notification {- notificationId :: Int,+ notificationId :: HastodonId, notificationType :: String, notificationCreatedAt :: String, notificationAccount :: Account,@@ -257,7 +264,7 @@ <*> (v .:? T.pack "status") data OAuthClient = OAuthClient {- oauthClientId :: Int,+ oauthClientId :: HastodonId, oauthClientRedirectUri :: String, oauthClientClientId :: String, oauthClientClientSecret :: String@@ -270,7 +277,7 @@ <*> (v .: T.pack "client_secret") data Relationship = Relationship {- relationshipId :: Int,+ relationshipId :: HastodonId, relationshipFollowing :: Bool, relationshipFollowed_by :: Bool, relationshipBlocking :: Bool,@@ -287,7 +294,7 @@ <*> (v .: T.pack "requested") data Report = Report {- reportId :: Int,+ reportId :: HastodonId, reportActionToken :: String } deriving (Show) instance FromJSON Report where@@ -307,7 +314,7 @@ <*> (v .: T.pack "hashtags") data Status = Status {- statusId :: Int,+ statusId :: HastodonId, statusUri :: String, statusUrl :: String, statusAccount :: Account,@@ -332,7 +339,7 @@ parseJSON (Object v) = Status <$> (v .: T.pack "id") <*> (v .: T.pack "uri")- <*> (v .: T.pack "url")+ <*> (maybe "" id <$> (v .:? T.pack "url")) <*> (v .: T.pack "account") <*> (v .:? T.pack "in_reply_to_id") <*> (v .:? T.pack "in_reply_to_account_id")@@ -359,7 +366,6 @@ parseJSON (Object v) = Tag <$> (v .: T.pack "name") <*> (v .: T.pack "url")- -- -- helpers -- @@ -520,6 +526,17 @@ res <- getHastodonResponseJSON pInstance client return (getResponseBody res :: Either JSONException Instance) +postMediaFile :: HastodonClient -> String -> String -> IO (Either JSONException Attachment)+postMediaFile client filename description = do+ initReq <- mkHastodonRequest pMedia client+ let file = partFileSource (T.pack "file") filename+ let mimetype = defaultMimeLookup (T.pack filename)+ req <- formDataBody [file { partContentType = Just mimetype },+ partBS (T.pack "description") (utf8ToChar8 description)+ ] initReq+ res <- httpJSONEither req+ return (getResponseBody res :: Either JSONException Attachment)+ getMutes :: HastodonClient -> IO (Either JSONException [Account]) getMutes client = do res <- getHastodonResponseJSON pMutes client@@ -576,6 +593,13 @@ postStatus :: HastodonClient -> String -> IO (Either JSONException Status) postStatus client status = do res <- postAndGetHastodonResponseJSON pStatuses [(Char8.pack "status", utf8ToChar8 status)] client+ return (getResponseBody res :: Either JSONException Status)++postStatusWithMediaIds :: HastodonClient -> String -> [HastodonId] -> IO (Either JSONException Status)+postStatusWithMediaIds client status mediaIds = do+ let unpackedMediaIds = [(Char8.pack "media_ids[]",utf8ToChar8 media)|media <- mediaIds] -- Rails array parameter convention?+ let body = (Char8.pack "status",utf8ToChar8 status):unpackedMediaIds+ res <- postAndGetHastodonResponseJSON pStatuses body client return (getResponseBody res :: Either JSONException Status) postReblog :: HastodonClient -> Int -> IO (Either JSONException Status)