Categorygithub.com/lvoytek/discourse_client_go

# README

Discourse API Client for Go

Go

Library for interacting with a Discourse site via the Discourse API

Installation

Download the library to your project with go get:

go get github.com/lvoytek/discourse_client_go

Usage

Initialization

All interactions with a site using this library require a Client variable which can be created with either NewClient or NewAnonymousClient. An API key and username are needed to upload data or access admin data, which can be provided with NewClient:

discourseClient := discourse.NewClient("http://127.0.0.1:3000/", "714552c...", "system")

Most downloading can be done without an API key. If you would just like to get data from the Discourse site, then you can create an anonymous client:

discourseClient := discourse.NewAnonymousClient("https://discourse.ubuntu.com")

Access

Functions that access the Discourse site are meant to match Discourse API calls 1:1. The input will include the Client variable, an identifier variable if needed, and a variable with included fields that match the required data to upload if needed. The return will be either a success/fail, or a variable with fields matching the site's output.

FunctionAPI EndpointTypeInput BodyOutput Body
ListBadgesForUser/user-badges/{username}.jsonGETListBadgesForUserResponse
CreateBadge/admin/badges.jsonPOSTBadgeUpdatedBadgeData
UpdateBadgeByID/admin/badges/{id}.jsonPUTBadgeUpdatedBadgeData
CreateCategory/categories.jsonPOSTNewCategoryShowCategoryResponse
ListCategories/categories.json?include_subcategories={showSubcategories}GETListCategoriesResponse
UpdateCategoryByID/categories/{id}.jsonPUTNewCategoryShowCategoryResponse
GetCategoryContentsByID/c/{id}.json?page={page}GETCategoryContents
GetCategoryContentsBySlug/c/{slug}.json?page={page}GETCategoryContents
ShowCategory/c/{id}/show.jsonGETShowCategoryResponse
GetPersonalNotifications/notifications.jsonGETGetNotificationsResponse
GetLatestPosts/posts.jsonGETGetLatestPostsResponse
GetPostRevisionByID/posts/{id}/revisions/{revision}.jsonGETPostRevision
GetPostLatestRevisionByID/posts/{id}/revisions/latest.jsonGETPostRevision
CreatePost/posts.jsonPOSTNewPostPostData
GetPostByID/posts/{id}.jsonGETPostData
GetPostRepliesByID/posts/{id}/replies.jsonGET[]PostData
CreateTopic/posts.jsonPOSTNewPostPostData
GetTopicByID/t/{id}.jsonGETTopicData
BookmarkTopicByID/t/{id}/bookmark.jsonPUT
Search/search.jsonGETSee BelowSearchResult
GetSiteInfo/site.jsonGETSiteInfo
GetSiteBasicInfo/site/basic-info.jsonGETSiteBasicInfo
ListTagGroups/tag_groups.jsonGETListTagGroupsResponse
GetTagGroupByID/tag_groups/{id}.jsonGETTagGroup
GetGroupByID/groups/{id}.jsonGETGetGroupResponse
GetGroupByName/groups/{name}.jsonGETGetGroupResponse
GetGroupMembersByID/groups/{id}/members.json?offset={offset}GETGroupMemberList
GetGroupMembersByName/groups/{name}/members.json?offset={offset}GETGroupMemberList
CreateGroup/admin/groups.jsonPOSTCreateGroupRequestCreateGroupResponse
DeleteGroupByID/admin/groups/{id}.jsonDEL
ListTags/tags.jsonGETListTagsResponse
GetTagByName/tag/{name}.jsonGETTagData
CreateUser/users.jsonPOSTNewUserCreateUserResponse
GetUserByUsername/u/{username}.jsonGETGetUserResponse
GetUserByExternalID/u/by-external/{external_id}.jsonGETGetUserResponse
GetUserByExternalAuthID/u/by-external/{provider}/{external_id}.jsonGETGetUserResponse
ListUsersByStats/directory_items.jsonGETSee BelowUserDirectory
UpdateUserByUsername/u/{username}.jsonPUTNewUserUpdateUserResponse
UpdateUserAvatarByUsername/u/{username}/preferences/avatar/pick.jsonPUTUserAvatarChoice
UpdateUserEmailByUsername/u/{username}/preferences/email.jsonPUTstring
UpdateUserUsernameByUsername/u/{username}/preferences/username.jsonPUTstring
ActivateUserByID/admin/users/{id}/activate.jsonPUT
DeactivateUserByID/admin/users/{id}/deactivate.jsonPUT
DeleteUserByID/admin/users/{id}.jsonDELUserDeleteOptions

The Search Function

Discourse sites have the special /search.json endpoint that allows for custom queries. This can be accessed using Search() with a SearchQuery object. Fields represent the following:

FieldTypeInfo
TermstringText content to look for, can not start with # or @, can contain spaces
UsernamestringGet posts created by this user
CategorystringSlug of category to limit search to
Tags[]stringTags associated with each post
RequiresAllTagsboolWhen true, posts will only show if they have all the tags provided
BeforeTimeSearch for posts made before this date (not inclusive)
AfterTimeSearch for posts made on or after this date (inclusive)
OrderstringThe order to present data in, by default you can use OrderLatest, OrderLikes, OrderViews, or OrderLatestTopic
AssignedUsernamestringGet items assigned to this user
In[]stringWhere the search term is located, by default you can use InTitle, InLikes, InPersonal, InMessages, InSeen, InUnseen, InPosted, InCreated, InWatching, InTracking, InBookmarks, InAssigned, InUnassigned, InFirst, InPinned, or InWiki
With[]stringOnly get posts containing this type of data, by default you can use WithImages
Status[]stringThe post has at least one of the provided statuses, by default you can use StatusOpen, StatusClosed, StatusPublic, StatusArchived, StatusNoReplies, StatusSingleUser, StatusSolved, or StatusUnsolved
GroupstringGroup name or ID associated with an item
GroupMessagesstringGet messages associated with group name or ID
MinPostsintMinimum number of contained posts, > 0
MaxPostsintMaximum number of contained posts, > 0
MinViewsintMinimum views on a post, > 0
MaxViewsintMaximum views on a post, > 0
Custommap[string][]stringAny additional fields specific to a Discourse site, matches the Status format of key:val1,val2,val3

The User Directory Function

Discourse sites also have the /directory_items.json endpoint for searching through all users, ranked by a certain statistic. This can be accessed through the ListUsersByStats function using a UserDirectoryQuery object. Note that this query uses pages with a maximum of 50 entries per page. If logged in, the first result on page 0 will be your user statistics, followed by all other users in order. The query includes:

FieldTypeInfo
PeriodstringThe length of time that the included statistics represent, and are ranked by. By default you can use PeriodDaily, PeriodWeekly, PeriodMonthly, PeriodQuarterly, PeriodYearly, or PeriodAll. This library considers PeriodAll to be the default value.
OrderstringThe statistic to rank users by. By default this can be OrderLikesReceived, OrderLikesGiven, OrderTopicCount, OrderPostCount, OrderTopicsEntered, OrderPostsRead, or OrderDaysVisited.
AscendingboolWhen true, rank users from the lowest value to the greatest.
PageintThe page number to look at, starts at 0. The last page number can be determined by the output's Meta.TotalRowsDirectoryItems value divided by 50. All pages after will have no entries.

# Packages

No description provided by the author
No description provided by the author