diff options
author | Wim <wim@42.be> | 2018-01-08 22:41:38 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-01-08 22:41:38 +0100 |
commit | 4a96a977c0e86e22edcda40730779279334685be (patch) | |
tree | fea5efa54d17af2d3cadb4d4d5a42f57e9bb7fbe /vendor/github.com/matterbridge/slack/search.go | |
parent | 9a95293bdf74a4d02827018649b6ea0ffdef74ba (diff) | |
download | matterbridge-msglm-4a96a977c0e86e22edcda40730779279334685be.tar.gz matterbridge-msglm-4a96a977c0e86e22edcda40730779279334685be.tar.bz2 matterbridge-msglm-4a96a977c0e86e22edcda40730779279334685be.zip |
Update vendor (slack)
Diffstat (limited to 'vendor/github.com/matterbridge/slack/search.go')
-rw-r--r-- | vendor/github.com/matterbridge/slack/search.go | 150 |
1 files changed, 0 insertions, 150 deletions
diff --git a/vendor/github.com/matterbridge/slack/search.go b/vendor/github.com/matterbridge/slack/search.go deleted file mode 100644 index 0e8d65e2..00000000 --- a/vendor/github.com/matterbridge/slack/search.go +++ /dev/null @@ -1,150 +0,0 @@ -package slack - -import ( - "context" - "errors" - "net/url" - "strconv" -) - -const ( - DEFAULT_SEARCH_SORT = "score" - DEFAULT_SEARCH_SORT_DIR = "desc" - DEFAULT_SEARCH_HIGHLIGHT = false - DEFAULT_SEARCH_COUNT = 100 - DEFAULT_SEARCH_PAGE = 1 -) - -type SearchParameters struct { - Sort string - SortDirection string - Highlight bool - Count int - Page int -} - -type CtxChannel struct { - ID string `json:"id"` - Name string `json:"name"` -} - -type CtxMessage struct { - User string `json:"user"` - Username string `json:"username"` - Text string `json:"text"` - Timestamp string `json:"ts"` - Type string `json:"type"` -} - -type SearchMessage struct { - Type string `json:"type"` - Channel CtxChannel `json:"channel"` - User string `json:"user"` - Username string `json:"username"` - Timestamp string `json:"ts"` - Text string `json:"text"` - Permalink string `json:"permalink"` - Previous CtxMessage `json:"previous"` - Previous2 CtxMessage `json:"previous_2"` - Next CtxMessage `json:"next"` - Next2 CtxMessage `json:"next_2"` -} - -type SearchMessages struct { - Matches []SearchMessage `json:"matches"` - Paging `json:"paging"` - Pagination `json:"pagination"` - Total int `json:"total"` -} - -type SearchFiles struct { - Matches []File `json:"matches"` - Paging `json:"paging"` - Pagination `json:"pagination"` - Total int `json:"total"` -} - -type searchResponseFull struct { - Query string `json:"query"` - SearchMessages `json:"messages"` - SearchFiles `json:"files"` - SlackResponse -} - -func NewSearchParameters() SearchParameters { - return SearchParameters{ - Sort: DEFAULT_SEARCH_SORT, - SortDirection: DEFAULT_SEARCH_SORT_DIR, - Highlight: DEFAULT_SEARCH_HIGHLIGHT, - Count: DEFAULT_SEARCH_COUNT, - Page: DEFAULT_SEARCH_PAGE, - } -} - -func (api *Client) _search(ctx context.Context, path, query string, params SearchParameters, files, messages bool) (response *searchResponseFull, error error) { - values := url.Values{ - "token": {api.config.token}, - "query": {query}, - } - if params.Sort != DEFAULT_SEARCH_SORT { - values.Add("sort", params.Sort) - } - if params.SortDirection != DEFAULT_SEARCH_SORT_DIR { - values.Add("sort_dir", params.SortDirection) - } - if params.Highlight != DEFAULT_SEARCH_HIGHLIGHT { - values.Add("highlight", strconv.Itoa(1)) - } - if params.Count != DEFAULT_SEARCH_COUNT { - values.Add("count", strconv.Itoa(params.Count)) - } - if params.Page != DEFAULT_SEARCH_PAGE { - values.Add("page", strconv.Itoa(params.Page)) - } - response = &searchResponseFull{} - err := post(ctx, path, values, response, api.debug) - if err != nil { - return nil, err - } - if !response.Ok { - return nil, errors.New(response.Error) - } - return response, nil - -} - -func (api *Client) Search(query string, params SearchParameters) (*SearchMessages, *SearchFiles, error) { - return api.SearchContext(context.Background(), query, params) -} - -func (api *Client) SearchContext(ctx context.Context, query string, params SearchParameters) (*SearchMessages, *SearchFiles, error) { - response, err := api._search(ctx, "search.all", query, params, true, true) - if err != nil { - return nil, nil, err - } - return &response.SearchMessages, &response.SearchFiles, nil -} - -func (api *Client) SearchFiles(query string, params SearchParameters) (*SearchFiles, error) { - return api.SearchFilesContext(context.Background(), query, params) -} - -func (api *Client) SearchFilesContext(ctx context.Context, query string, params SearchParameters) (*SearchFiles, error) { - response, err := api._search(ctx, "search.files", query, params, true, false) - if err != nil { - return nil, err - } - return &response.SearchFiles, nil -} - -func (api *Client) SearchMessages(query string, params SearchParameters) (*SearchMessages, error) { - return api.SearchMessagesContext(context.Background(), query, params) -} - -func (api *Client) SearchMessagesContext(ctx context.Context, query string, params SearchParameters) (*SearchMessages, error) { - response, err := api._search(ctx, "search.messages", query, params, false, true) - if err != nil { - return nil, err - } - return &response.SearchMessages, nil -} |