melon-love/elm-gab-api/1.0.0

NOTE: the latest version is 11.0.0

Gab

Client for the Gab.com API, documented at developers.gab.com.

This does NOT do authentication. You'll need to use billstclair/elm-oauth-middleware for that. See the example directory.

The requests all come in two flavors, one which has the decoder built in, and returns an Http.Request, and one for which you provide your own decoder, and returns RequestParts. E.g.:

getTorbaRequest : OAuth.Token -> Http.Request User
getTorbaRequest token =
    userProfile token "a"


getTorbaParts : OAuth.Token -> RequestParts Json.Decode.Value
getTorbaParts token =
    userProfileParts Json.Decode.value token "a"


getTorbaRequestFromParts : OAuth.Token -> Http.Request Json.Decode.Value
getTorbaRequestFromParts token =
    getTorbaParts token
        |> request

Users

me : Token -> Request User

Return the logged-in user's profile information as a User record.

meParts : Decoder a -> Token -> RequestParts a

Return the logged-in user's profile information, using a custom decoder.

userProfile : Token -> String -> Request User

Return the logged-in user's profile information as a User record.

userProfileParts : Decoder a -> Token -> String -> RequestParts a

Return the logged-in user's profile information, using a custom decoder.

userFollowers : Token -> String -> Int -> Request UserList

Return the logged-in user's followers as a UserList record.

userFollowers token username before

before is the number of following users to skip before the listing starts. This enables scrolling through a long list.

userFollowersParts : Decoder a -> Token -> String -> Int -> RequestParts a

Return the logged-in user's followers, using a custom decoder.

userFollowersParts decoder token username before

before is the number of following users to skip before the listing starts. This enables scrolling through a long list.

userFollowing : Token -> String -> Int -> Request UserList

Return a list of users following the logged-in user, as a UserList record.

userFollowing token username before

before is the number of followers to skip before the listing starts. This enables scrolling through a long list.

userFollowingParts : Decoder a -> Token -> String -> Int -> RequestParts a

Return a list of users following the logged-in user, using a custom decoder.

userFollowingParts decoder token username before

before is the number of followers to skip before the listing starts. This enables scrolling through a long list.

User modification

followUser : Token -> String -> Bool -> Request Value

Follow or unfollow a user. Return value not interesting.

followUser token username unfollow
followUserParts : Decoder a -> Token -> String -> Bool -> RequestParts a

Follow or unfollow a user, with a custom decoder.

followUserParts decoder token username unfollow
muteUser : Token -> String -> Bool -> Request Value

Mute or unmute a user. Return value not interesting.

muteUser token username unmute

This isn't currently implemented by the API, but I expect that to change.

muteUserParts : Decoder a -> Token -> String -> Bool -> RequestParts a

Mute or unmute a user, with a custom decoder.

muteUserParts decoder token username unmute

This isn't currently implemented by the API, but I expect that to change.

Feeds

homeFeed : Token -> String -> Request ActivityLogList

Return posts in the home feed.

homeFeed token before

The posts returned will have dates before before. Pass the empty string for either to not limit that end.

homeFeedParts : Decoder a -> Token -> String -> RequestParts a

Return posts in the home feed, using a custom encoder.

homeFeedParts decoder token before

The posts returned will have dates before before. Pass the empty string for either to not limit that end.

userFeed : Token -> String -> String -> Request ActivityLogList

Return posts for a user feed.

userFeed token user before

The posts returned will have dates before before. Pass the empty string for either to not limit that end.

userFeedParts : Decoder a -> Token -> String -> String -> RequestParts a

Return posts for a user feed, using a custom decoder.

userFeedParts decoder user token before

The posts returned will have dates before before. Pass the empty string for either to not limit that end.

groupFeed : Token -> String -> String -> Request ActivityLogList

Return posts for a group feed.

groupFeed token group before

The posts returned will have dates before before. Pass the empty string for either to not limit that end.

This is a guess at what this API command will look like. It doesn't yet exist.

groupFeedParts : Decoder a -> Token -> String -> String -> RequestParts a

Return posts for a group feed, using a custom decoder.

groupFeedParts decoder group token before

The posts returned will have dates before before. Pass the empty string for either to not limit that end.

This is a guess at what this API command will look like. It doesn't yet exist.

popularFeed : Token -> Request ActivityLogList

Return the posts in the "popular" feed, as a ActivityLogList.

popularFeed token
popularFeedParts : Decoder a -> Token -> RequestParts a

Return the posts in the "popular" feed, using a custom decoder.

popularFeedParts decoder token
popularUsers : Token -> Request UserList

Return a list of popular users, as a UserList record.

popularUsers token
popularUsersParts : Decoder a -> Token -> RequestParts a

Return a list of popular users, using a custom decoder.

popularUserParts decoder token

Posts

getPost : Token -> String -> Request Post

Get a single post.

getPost token postid
getPostParts : Decoder a -> Token -> String -> RequestParts a

Get a single post, using a custom decoder.

getPostParts decoder token postid
upvotePost : Token -> String -> Bool -> Request Value

Upvote or unupvote a post. Return value not interesting.

upvotePost token postid unupvote
upvotePostParts : Decoder a -> Token -> String -> Bool -> RequestParts a

Upvote or unupvote a post, with a custom decoder.

upvotePostParts decoder token postid unupvote
downvotePost : Token -> String -> Bool -> Request Value

Downvote or undownvote a post. Return value not interesting.

downvotePost token postid undownvote
downvotePostParts : Decoder a -> Token -> String -> Bool -> RequestParts a

Downvote or undownvote a post, with a custom decoder.

downvotePostParts decoder token postid undownvote
repost : Token -> String -> Bool -> Request Value

Repost or unrepost. Return value not interesting.

repost token postid unrepost
repostParts : Decoder a -> Token -> String -> Bool -> RequestParts a

Repost or unrepost, with a custom decoder.

repostParts decoder token postid unrepost

New Posts

newPost : Token -> PostForm -> Request ActivityLog

Posting uses JSON, which is not in the spec, but is what the web client does.

newPostParts : Decoder a -> Token -> PostForm -> RequestParts a

Create a new post with a custom decoder.

postImage : Token -> File -> Request String

Posting an image.

The String that comes back is a media ID, to be used in PostForm.media_attachments.

postImageParts : Decoder a -> Token -> File -> RequestParts a

Post an image with a custom decoder

Generic requests

doParts : String -> String -> Decoder a -> Token -> String -> Bool -> RequestParts a

Shared by doUsersParts and doPostParts

doParts prefix operation decoder token identifier undo

prefix can be "users" or "posts".

If undo is True, does a DELETE. Otherwise, does a POST.

doUsersParts : String -> Decoder a -> Token -> String -> Bool -> RequestParts a

Shared by followUserParts and muteUserParts

doUsersParts operation decoder token username undo

operation can be "follow" or "mute".

doPostsParts : String -> Decoder a -> Token -> String -> Bool -> RequestParts a

Shared by upvotePostParts, downvotePostParts, repostParts

doPostsParts operation decoder token username undo

operation can be "upvote", "downvote" or "repost".

Persistent tokens

savedTokenFromResponseToken : Posix -> ResponseToken -> SavedToken

Convert an OAuthMiddleWare.ResponseToken to Gab.Types.SavedToken.

Use Gab.EncodeDecode.savedTokenEncoder and Gab.EncodeDecode.savedTokenDecoder to persist it.

Low-level Http interface

gabApiUri : String

The base URI for GAB API requests. Automatically prepended to path args.

request : RequestParts a -> Request a

Turn parts into a ready-to-send Http.Request.

getParts : Decoder a -> Token -> String -> RequestParts a

Simple HTTP GET request. Empty body, no custom headers.

get token path decoder
String
-> List Header
-> Decoder a
-> Token
-> String
-> RequestParts a

General-purpose Http.Request constructor.

request method headers token path body decoder

method is the Http method, e.g. "GET".

headers is a list of custom Http.Headers.

token is an OAuth token, often gotten with billstclair/elm-oauth-middleware.

path is the path to the API endpoint, with NO leading slash.

decoder is a JSON decoder for the result.

Debugging

bodyToString : Int -> HttpBody -> String

Debugging function for displaying a request body.