melon-love/elm-gab-api/7.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 to get a Token. 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

Normal, Auto-Decoding Functions

You'll usually use these, not the Parts functions below.

Users

me : Token -> Request User

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

userProfile : Token -> String -> Request User

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

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.

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.

User Interaction

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

Follow or unfollow a user. Return value not interesting.

followUser token username unfollow
muteUser : Token -> String -> Bool -> Request Success

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.

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 to get the beginning of the list.

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 to get the beginning of the list.

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 to get the beginning of the list.

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
popularUsers : Token -> Request UserList

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

popularUsers token

Notifications

notifications : Token -> String -> Request NotificationsLog

Return notifications for the logged in user.

notifications token before

For notifications, the before parameter is a notification ID, not a date.

Posts

getPost : Token -> String -> Request Post

Get a single post.

getPost token postid
upvotePost : Token -> Int -> Bool -> Request Success

Upvote or unupvote a post. Return value not interesting.

upvotePost token postid unupvote
downvotePost : Token -> Int -> Bool -> Request Success

Downvote or undownvote a post. Return value not interesting.

downvotePost token postid undownvote

This will return an Http BadStatus error if you you're not authorized to downvote.

repost : Token -> Int -> Bool -> Request Success

Repost or unrepost. Return value not interesting.

repost 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.

postImage : Token -> File -> Request String

Posting an image.

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

Parts Functions The Return a Value

These are mostly for the example, but if you need to get your hands on the raw return Value from the API, use these intead of the auto-decoding versions.

Users

meParts : Decoder a -> Token -> RequestParts a

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

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

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

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.

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 Interaction

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

Follow or unfollow a user, with a custom decoder.

followUserParts decoder token username unfollow
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

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 to get the beginning of the list.

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 to get the beginning of the list.

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

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

groupFeedParts decoder token groupid before

The posts returned will have dates before before. Pass the empty string to get the beginning of the list.

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

popularFeedParts : Decoder a -> Token -> RequestParts a

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

popularFeedParts decoder token
popularUsersParts : Decoder a -> Token -> RequestParts a

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

popularUserParts decoder token

Notifications

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

Return notifications, using a custom decoder.

notificationsParts decoder token before

For notifications, the before parameter is a notification ID, not a date.

Posts

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

Get a single post, using a custom decoder.

getPostParts decoder token postid
upvotePostParts : Decoder a -> Token -> Int -> Bool -> RequestParts a

Upvote or unupvote a post, with a custom decoder.

upvotePostParts decoder token postid unupvote
downvotePostParts : Decoder a -> Token -> Int -> Bool -> RequestParts a

Downvote or undownvote a post, with a custom decoder.

downvotePostParts decoder token postid undownvote
repostParts : Decoder a -> Token -> Int -> Bool -> RequestParts a

Repost or unrepost, with a custom decoder.

repostParts decoder token postid unrepost

New Posts

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

Create a new post with a custom decoder.

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

Post an image with a custom decoder

Generic requests

These are low-level functions used to implement the others. You won't need them unless you need to implement new API functionality that isn't yet in this module.

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.