-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fcf508
commit 8e654be
Showing
15 changed files
with
329 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
func (c *IdentifiedClient) AdminGetUserByID(ctx context.Context, userID int) (res *User, err error) { | ||
path := fmt.Sprintf("/admin/users/%d", userID) | ||
return res, c.client.Do(ctx, "GET", path, nil, nil, &res) | ||
} | ||
|
||
func (c *IdentifiedClient) AdminAnonymizeUser(ctx context.Context, userID int) error { | ||
path := fmt.Sprintf("/admin/users/%d/anonymize", userID) | ||
return c.client.Do(ctx, "PUT", path, nil, nil, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"net/url" | ||
) | ||
|
||
type ListCategoriesOptions struct { | ||
IncludeSubcategories bool | ||
} | ||
|
||
func (c *IdentifiedClient) ListCategories(ctx context.Context, options *ListCategoriesOptions) (res *CategoryListResult, err error) { | ||
params := url.Values{} | ||
if options != nil && options.IncludeSubcategories { | ||
params.Set("include_subcategories", "true") | ||
} | ||
return res, c.client.Do(ctx, "GET", "/categories", params, nil, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
func (c *IdentifiedClient) CreatePost(ctx context.Context, req *PostNew) (res *Post, err error) { | ||
return res, c.client.Do(ctx, "POST", "/posts", nil, req, &res) | ||
} | ||
|
||
func (c *IdentifiedClient) GetPostByID(ctx context.Context, postID int) (res *Post, err error) { | ||
path := fmt.Sprintf("/posts/%d.json", postID) | ||
return res, c.client.Do(ctx, "GET", path, nil, nil, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
|
||
"github.com/wearemojo/mojo-public-go/lib/slicefn" | ||
) | ||
|
||
type GetTopicOptions struct { | ||
Print bool | ||
} | ||
|
||
func (c *IdentifiedClient) GetTopic(ctx context.Context, topicID int, options *GetTopicOptions) (res *PostStreamResult, err error) { | ||
path := fmt.Sprintf("/t/%d", topicID) | ||
params := url.Values{} | ||
if options != nil && options.Print { | ||
params.Set("print", "true") | ||
} | ||
return res, c.client.Do(ctx, "GET", path, params, nil, &res) | ||
} | ||
|
||
func (c *IdentifiedClient) ListTopicPostIDs(ctx context.Context, topicID int) (res *PostIDsResult, err error) { | ||
path := fmt.Sprintf("/t/%d/posts_ids", topicID) | ||
params := url.Values{"post_number": {"0"}} | ||
return res, c.client.Do(ctx, "GET", path, params, nil, &res) | ||
} | ||
|
||
func (c *IdentifiedClient) ListTopicPostsByIDs(ctx context.Context, topicID int, postIDs []int) (res *PostStreamResult, err error) { | ||
path := fmt.Sprintf("/t/%d/posts", topicID) | ||
params := url.Values{"post_ids[]": slicefn.Map(postIDs, strconv.Itoa)} | ||
return res, c.client.Do(ctx, "GET", path, params, nil, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/wearemojo/mojo-public-go/lib/merr" | ||
) | ||
|
||
func (c *IdentifiedClient) GetUserByUsername(ctx context.Context, username string) (res *UserResult, err error) { | ||
if username == "" { | ||
return nil, merr.New(ctx, ErrEmptyParam, merr.M{"param": "username"}) | ||
} | ||
|
||
path := fmt.Sprintf("/users/%s", url.PathEscape(username)) | ||
return res, c.client.Do(ctx, "GET", path, nil, nil, &res) | ||
} | ||
|
||
func (c *IdentifiedClient) GetUserByExternalID(ctx context.Context, externalID string) (res *UserResult, err error) { | ||
if externalID == "" { | ||
return nil, merr.New(ctx, ErrEmptyParam, merr.M{"param": "externalID"}) | ||
} | ||
|
||
path := fmt.Sprintf("/users/by-external/%s", url.PathEscape(externalID)) | ||
return res, c.client.Do(ctx, "GET", path, nil, nil, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// https://github.com/discourse/discourse-data-explorer | ||
|
||
type PluginDataExplorerRunQueryOptions struct { | ||
// https://meta.discourse.org/t/120063 | ||
// https://github.com/discourse/discourse-data-explorer/blob/2f1044820c479424d29d94df389360b1d9dee871/app/controllers/discourse_data_explorer/query_controller.rb#L137 | ||
|
||
Params map[string]any | ||
Explain bool | ||
Download bool | ||
LimitAll bool | ||
} | ||
|
||
type PluginDataExplorerQueryResult struct { | ||
// Errors indicates what went wrong with the query. | ||
// | ||
// At the time of writing, it is always empty when the request is successful. | ||
// | ||
// https://github.com/discourse/discourse-data-explorer/blob/2f1044820c479424d29d94df389360b1d9dee871/app/controllers/discourse_data_explorer/query_controller.rb#L193 | ||
Errors []string `json:"errors"` | ||
|
||
Duration float64 `json:"duration"` | ||
ResultCount int `json:"result_count"` | ||
Params map[string]any `json:"params"` | ||
Columns []string `json:"columns"` | ||
DefaultLimit int `json:"default_limit"` | ||
Explain *string `json:"explain"` | ||
Relations map[string][]map[string]any `json:"relations"` | ||
ColRender map[string]string `json:"col_render"` | ||
Rows [][]any `json:"rows"` | ||
} | ||
|
||
func (c *IdentifiedClient) PluginDataExplorerRunQuery(ctx context.Context, queryID int, options *PluginDataExplorerRunQueryOptions) (res *PluginDataExplorerQueryResult, err error) { | ||
path := fmt.Sprintf("/admin/plugins/explorer/queries/%d/run", queryID) | ||
body := map[string]any{} | ||
if options != nil { | ||
body["params"] = options.Params | ||
body["explain"] = options.Explain | ||
body["download"] = options.Download | ||
if options.LimitAll { | ||
body["limit"] = "ALL" | ||
} | ||
} | ||
return res, c.client.Do(ctx, "POST", path, nil, body, &res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package discourse | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/wearemojo/mojo-public-go/lib/merr" | ||
) | ||
|
||
// https://github.com/discourse/discourse-reactions | ||
|
||
type PluginDiscourseReactionsReactionType string | ||
|
||
const ( | ||
PluginDiscourseReactionsReactionTypeEmoji PluginDiscourseReactionsReactionType = "emoji" | ||
) | ||
|
||
type PluginDiscourseReactionsPostReaction struct { | ||
ID string `json:"id"` | ||
Type PluginDiscourseReactionsReactionType `json:"type"` | ||
Count int `json:"count"` | ||
} | ||
|
||
type PluginDiscourseReactionsPostReactionCurrentUser struct { | ||
ID string `json:"id"` | ||
Type PluginDiscourseReactionsReactionType `json:"type"` | ||
} | ||
|
||
func (c *IdentifiedClient) PluginDiscourseReactionsToggleReaction(ctx context.Context, postID int, reactionID string) (res *Post, err error) { | ||
if reactionID == "" { | ||
return nil, merr.New(ctx, ErrEmptyParam, merr.M{"param": "reactionID"}) | ||
} | ||
|
||
path := fmt.Sprintf("/discourse-reactions/posts/%d/custom-reactions/%s/toggle", postID, url.PathEscape(reactionID)) | ||
return res, c.client.Do(ctx, "GET", path, nil, nil, &res) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package discourse | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// these are the actual types | ||
|
||
// name as `FooNew` if it's a type that's used to create a new `Foo` | ||
|
||
type User struct { | ||
ID int `json:"id"` | ||
Username string `json:"username"` | ||
AvatarTemplate *string `json:"avatar_template"` | ||
SingleSignOnRecord *UserSingleSignOnRecord `json:"single_sign_on_record"` | ||
} | ||
|
||
type UserSingleSignOnRecord struct { | ||
ExternalID string `json:"external_id"` | ||
} | ||
|
||
type Category struct { | ||
ID int `json:"id"` | ||
Name string `json:"name"` | ||
Slug string `json:"slug"` | ||
ReadRestricted bool `json:"read_restricted"` | ||
SubcategoryIDs []int `json:"subcategory_ids"` | ||
SubcategoryList []Category `json:"subcategory_list"` | ||
} | ||
|
||
type PostNew struct { | ||
Title *string `json:"title"` | ||
Raw string `json:"raw"` | ||
TopicID *int `json:"topic_id"` | ||
Category *int `json:"category"` | ||
ReplyToPostNumber *int `json:"reply_to_post_number"` | ||
} | ||
|
||
type Post struct { | ||
ID int `json:"id"` | ||
Username string `json:"username"` | ||
AvatarTemplate string `json:"avatar_template"` | ||
CreatedAt time.Time `json:"created_at"` | ||
Raw string `json:"raw"` | ||
Cooked string `json:"cooked"` | ||
PostNumber int `json:"post_number"` | ||
PostType PostType `json:"post_type"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
ReplyToPostNumber *int `json:"reply_to_post_number"` | ||
TopicID int `json:"topic_id"` | ||
Version int `json:"version"` | ||
UserID int `json:"user_id"` | ||
Hidden bool `json:"hidden"` | ||
DeletedAt *time.Time `json:"deleted_at"` | ||
Wiki bool `json:"wiki"` | ||
|
||
// Discourse Reactions plugin | ||
Reactions []PluginDiscourseReactionsPostReaction `json:"reactions"` | ||
CurrentUserReaction *PluginDiscourseReactionsPostReactionCurrentUser `json:"current_user_reaction"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package discourse | ||
|
||
type PostType int | ||
|
||
const ( | ||
// https://github.com/discourse/discourse/blob/ce3f592275295f201f1332c0c5069897341d5f47/app/models/post.rb#L172 | ||
|
||
PostTypeRegular PostType = 1 | ||
PostTypeModeratorAction PostType = 2 | ||
PostTypeSmallAction PostType = 3 | ||
PostTypeWhisper PostType = 4 | ||
) |
Oops, something went wrong.