Skip to content

Commit

Permalink
internal function name cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
James Lawrence authored and james-lawrence committed Jul 21, 2018
1 parent 9ba46fc commit 2e06c71
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 104 deletions.
2 changes: 1 addition & 1 deletion bots.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type botResponseFull struct {

func botRequest(ctx context.Context, client HTTPRequester, path string, values url.Values, debug bool) (*botResponseFull, error) {
response := &botResponseFull{}
err := post(ctx, client, path, values, response, debug)
err := postPath(ctx, client, path, values, response, debug)
if err != nil {
return nil, err
}
Expand Down
8 changes: 6 additions & 2 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (api *Client) SendMessageContext(ctx context.Context, channelID string, opt
return "", "", "", err
}

if err = post(ctx, api.httpclient, string(config.mode), config.values, &response, api.debug); err != nil {
if err = postPath(ctx, api.httpclient, string(config.mode), config.values, &response, api.debug); err != nil {
return "", "", "", err
}

Expand Down Expand Up @@ -373,7 +373,11 @@ func MsgOptionCompose(options ...MsgOption) MsgOption {
func MsgOptionParse(b bool) MsgOption {
return func(c *sendConfig) error {
var v string
if b { v = "1" } else { v = "0" }
if b {
v = "1"
} else {
v = "0"
}
c.values.Set("parse", v)
return nil
}
Expand Down
28 changes: 14 additions & 14 deletions conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (api *Client) GetUsersInConversationContext(ctx context.Context, params *Ge
ResponseMetaData responseMetaData `json:"response_metadata"`
SlackResponse
}{}
err := post(ctx, api.httpclient, "conversations.members", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.members", values, &response, api.debug)
if err != nil {
return nil, "", err
}
Expand All @@ -112,7 +112,7 @@ func (api *Client) ArchiveConversationContext(ctx context.Context, channelID str
"channel": {channelID},
}
response := SlackResponse{}
err := post(ctx, api.httpclient, "conversations.archive", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.archive", values, &response, api.debug)
if err != nil {
return err
}
Expand All @@ -132,7 +132,7 @@ func (api *Client) UnArchiveConversationContext(ctx context.Context, channelID s
"channel": {channelID},
}
response := SlackResponse{}
err := post(ctx, api.httpclient, "conversations.unarchive", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.unarchive", values, &response, api.debug)
if err != nil {
return err
}
Expand All @@ -156,7 +156,7 @@ func (api *Client) SetTopicOfConversationContext(ctx context.Context, channelID,
SlackResponse
Channel *Channel `json:"channel"`
}{}
err := post(ctx, api.httpclient, "conversations.setTopic", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.setTopic", values, &response, api.debug)
if err != nil {
return nil, err
}
Expand All @@ -180,7 +180,7 @@ func (api *Client) SetPurposeOfConversationContext(ctx context.Context, channelI
SlackResponse
Channel *Channel `json:"channel"`
}{}
err := post(ctx, api.httpclient, "conversations.setPurpose", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.setPurpose", values, &response, api.debug)
if err != nil {
return nil, err
}
Expand All @@ -204,7 +204,7 @@ func (api *Client) RenameConversationContext(ctx context.Context, channelID, cha
SlackResponse
Channel *Channel `json:"channel"`
}{}
err := post(ctx, api.httpclient, "conversations.rename", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.rename", values, &response, api.debug)
if err != nil {
return nil, err
}
Expand All @@ -228,7 +228,7 @@ func (api *Client) InviteUsersToConversationContext(ctx context.Context, channel
SlackResponse
Channel *Channel `json:"channel"`
}{}
err := post(ctx, api.httpclient, "conversations.invite", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.invite", values, &response, api.debug)
if err != nil {
return nil, err
}
Expand All @@ -249,7 +249,7 @@ func (api *Client) KickUserFromConversationContext(ctx context.Context, channelI
"user": {user},
}
response := SlackResponse{}
err := post(ctx, api.httpclient, "conversations.kick", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.kick", values, &response, api.debug)
if err != nil {
return err
}
Expand All @@ -274,7 +274,7 @@ func (api *Client) CloseConversationContext(ctx context.Context, channelID strin
AlreadyClosed bool `json:"already_closed"`
}{}

err = post(ctx, api.httpclient, "conversations.close", values, &response, api.debug)
err = postPath(ctx, api.httpclient, "conversations.close", values, &response, api.debug)
if err != nil {
return false, false, err
}
Expand Down Expand Up @@ -388,7 +388,7 @@ func (api *Client) GetConversationRepliesContext(ctx context.Context, params *Ge
Messages []Message `json:"messages"`
}{}

err = post(ctx, api.httpclient, "conversations.replies", values, &response, api.debug)
err = postPath(ctx, api.httpclient, "conversations.replies", values, &response, api.debug)
if err != nil {
return nil, false, "", err
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func (api *Client) GetConversationsContext(ctx context.Context, params *GetConve
ResponseMetaData responseMetaData `json:"response_metadata"`
SlackResponse
}{}
err = post(ctx, api.httpclient, "conversations.list", values, &response, api.debug)
err = postPath(ctx, api.httpclient, "conversations.list", values, &response, api.debug)
if err != nil {
return nil, "", err
}
Expand Down Expand Up @@ -465,7 +465,7 @@ func (api *Client) OpenConversationContext(ctx context.Context, params *OpenConv
AlreadyOpen bool `json:"already_open"`
SlackResponse
}{}
err := post(ctx, api.httpclient, "conversations.open", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.open", values, &response, api.debug)
if err != nil {
return nil, false, false, err
}
Expand All @@ -489,7 +489,7 @@ func (api *Client) JoinConversationContext(ctx context.Context, channelID string
} `json:"response_metadata"`
SlackResponse
}{}
err := post(ctx, api.httpclient, "conversations.join", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.join", values, &response, api.debug)
if err != nil {
return nil, "", nil, err
}
Expand Down Expand Up @@ -551,7 +551,7 @@ func (api *Client) GetConversationHistoryContext(ctx context.Context, params *Ge

response := GetConversationHistoryResponse{}

err := post(ctx, api.httpclient, "conversations.history", values, &response, api.debug)
err := postPath(ctx, api.httpclient, "conversations.history", values, &response, api.debug)
if err != nil {
return nil, err
}
Expand Down
108 changes: 54 additions & 54 deletions dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,80 @@ package slack

import (
"context"
"errors"
"encoding/json"
"errors"
)

type DialogTrigger struct {
TriggerId string `json:"trigger_id"` //Required. Must respond within 3 seconds.
Dialog Dialog `json:"dialog"` //Required.
TriggerId string `json:"trigger_id"` //Required. Must respond within 3 seconds.
Dialog Dialog `json:"dialog"` //Required.
}

type Dialog struct {
CallbackId string `json:"callback_id"` //Required.
Title string `json:"title"` //Required.
SubmitLabel string `json:"submit_label,omitempty"` //Optional. Default value is 'Submit'
NotifyOnCancel bool `json:"notify_on_cancel,omitempty"` //Optional. Default value is false
Elements []DialogElement `json:"elements"` //Required.
CallbackId string `json:"callback_id"` //Required.
Title string `json:"title"` //Required.
SubmitLabel string `json:"submit_label,omitempty"` //Optional. Default value is 'Submit'
NotifyOnCancel bool `json:"notify_on_cancel,omitempty"` //Optional. Default value is false
Elements []DialogElement `json:"elements"` //Required.
}

type DialogElement interface {}
type DialogElement interface{}

type DialogTextElement struct {
Label string `json:"label"` //Required.
Name string `json:"name"` //Required.
Type string `json:"type"` //Required. Allowed values: "text", "textarea", "select".
Placeholder string `json:"placeholder,omitempty"` //Optional.
Optional bool `json:"optional,omitempty"` //Optional. Default value is false
Value string `json:"value,omitempty"` //Optional.
MaxLength int `json:"max_length,omitempty"` //Optional.
MinLength int `json:"min_length,omitempty"` //Optional,. Default value is 0
Hint string `json:"hint,omitempty"` //Optional.
Subtype string `json:"subtype,omitempty"` //Optional. Allowed values: "email", "number", "tel", "url".
Label string `json:"label"` //Required.
Name string `json:"name"` //Required.
Type string `json:"type"` //Required. Allowed values: "text", "textarea", "select".
Placeholder string `json:"placeholder,omitempty"` //Optional.
Optional bool `json:"optional,omitempty"` //Optional. Default value is false
Value string `json:"value,omitempty"` //Optional.
MaxLength int `json:"max_length,omitempty"` //Optional.
MinLength int `json:"min_length,omitempty"` //Optional,. Default value is 0
Hint string `json:"hint,omitempty"` //Optional.
Subtype string `json:"subtype,omitempty"` //Optional. Allowed values: "email", "number", "tel", "url".
}

type DialogSelectElement struct {
Label string `json:"label"` //Required.
Name string `json:"name"` //Required.
Type string `json:"type"` //Required. Allowed values: "text", "textarea", "select".
Placeholder string `json:"placeholder,omitempty"` //Optional.
Optional bool `json:"optional,omitempty"` //Optional. Default value is false
Value string `json:"value,omitempty"` //Optional.
DataSource string `json:"data_source,omitempty"` //Optional. Allowed values: "users", "channels", "conversations", "external".
SelectedOptions string `json:"selected_options,omitempty"` //Optional. Default value for "external" only
Options []DialogElementOption `json:"options,omitempty"` //One of options or option_groups is required.
OptionGroups []DialogElementOption `json:"option_groups,omitempty"` //Provide up to 100 options.
Label string `json:"label"` //Required.
Name string `json:"name"` //Required.
Type string `json:"type"` //Required. Allowed values: "text", "textarea", "select".
Placeholder string `json:"placeholder,omitempty"` //Optional.
Optional bool `json:"optional,omitempty"` //Optional. Default value is false
Value string `json:"value,omitempty"` //Optional.
DataSource string `json:"data_source,omitempty"` //Optional. Allowed values: "users", "channels", "conversations", "external".
SelectedOptions string `json:"selected_options,omitempty"` //Optional. Default value for "external" only
Options []DialogElementOption `json:"options,omitempty"` //One of options or option_groups is required.
OptionGroups []DialogElementOption `json:"option_groups,omitempty"` //Provide up to 100 options.
}

type DialogElementOption struct {
Label string `json:"label"` //Required.
Value string `json:"value"` //Required.
Label string `json:"label"` //Required.
Value string `json:"value"` //Required.
}

// DialogCallback is sent from Slack when a user submits a form from within a dialog
type DialogCallback struct {
Type string `json:"type"`
CallbackID string `json:"callback_id"`
Team Team `json:"team"`
Channel Channel `json:"channel"`
User User `json:"user"`
ActionTs string `json:"action_ts"`
Token string `json:"token"`
ResponseURL string `json:"response_url"`
Submission map[string]string `json:"submission"`
Type string `json:"type"`
CallbackID string `json:"callback_id"`
Team Team `json:"team"`
Channel Channel `json:"channel"`
User User `json:"user"`
ActionTs string `json:"action_ts"`
Token string `json:"token"`
ResponseURL string `json:"response_url"`
Submission map[string]string `json:"submission"`
}

// DialogSuggestionCallback is sent from Slack when a user types in a select field with an external data source
type DialogSuggestionCallback struct {
Type string `json:"type"`
Token string `json:"token"`
ActionTs string `json:"action_ts"`
Team Team `json:"team"`
User User `json:"user"`
Channel Channel `json:"channel"`
ElementName string `json:"name"`
Value string `json:"value"`
CallbackID string `json:"callback_id"`
Type string `json:"type"`
Token string `json:"token"`
ActionTs string `json:"action_ts"`
Team Team `json:"team"`
User User `json:"user"`
Channel Channel `json:"channel"`
ElementName string `json:"name"`
Value string `json:"value"`
CallbackID string `json:"callback_id"`
}

// OpenDialog opens a dialog window where the triggerId originated from
Expand All @@ -90,18 +90,18 @@ func (api *Client) OpenDialogContext(ctx context.Context, triggerId string, dial
}

resp := DialogTrigger{
TriggerId: triggerId,
Dialog: dialog,
TriggerId: triggerId,
Dialog: dialog,
}
jsonResp, err := json.Marshal(resp)
if err != nil {
return err
}
response := &SlackResponse{}
endpoint := SLACK_API+"dialog.open"
if err := postJson(ctx, api.httpclient, endpoint, api.token, jsonResp, response, api.debug); err != nil {
endpoint := SLACK_API + "dialog.open"
if err := postJSON(ctx, api.httpclient, endpoint, api.token, jsonResp, response, api.debug); err != nil {
return err
}

return response.Err()
}
}
6 changes: 3 additions & 3 deletions dnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type dndTeamInfoResponse struct {

func dndRequest(ctx context.Context, client HTTPRequester, path string, values url.Values, debug bool) (*dndResponseFull, error) {
response := &dndResponseFull{}
err := post(ctx, client, path, values, response, debug)
err := postPath(ctx, client, path, values, response, debug)
if err != nil {
return nil, err
}
Expand All @@ -61,7 +61,7 @@ func (api *Client) EndDNDContext(ctx context.Context) error {

response := &SlackResponse{}

if err := post(ctx, api.httpclient, "dnd.endDnd", values, response, api.debug); err != nil {
if err := postPath(ctx, api.httpclient, "dnd.endDnd", values, response, api.debug); err != nil {
return err
}

Expand Down Expand Up @@ -120,7 +120,7 @@ func (api *Client) GetDNDTeamInfoContext(ctx context.Context, users []string) (m
}
response := &dndTeamInfoResponse{}

if err := post(ctx, api.httpclient, "dnd.teamInfo", values, response, api.debug); err != nil {
if err := postPath(ctx, api.httpclient, "dnd.teamInfo", values, response, api.debug); err != nil {
return nil, err
}
if !response.Ok {
Expand Down
2 changes: 1 addition & 1 deletion emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (api *Client) GetEmojiContext(ctx context.Context) (map[string]string, erro
}
response := &emojiResponseFull{}

err := post(ctx, api.httpclient, "emoji.list", values, response, api.debug)
err := postPath(ctx, api.httpclient, "emoji.list", values, response, api.debug)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion im.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type IM struct {

func imRequest(ctx context.Context, client HTTPRequester, path string, values url.Values, debug bool) (*imResponseFull, error) {
response := &imResponseFull{}
err := post(ctx, client, path, values, response, debug)
err := postPath(ctx, client, path, values, response, debug)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func doPost(ctx context.Context, client HTTPRequester, req *http.Request, intf i
return parseResponseBody(resp.Body, intf, debug)
}

func postJson(ctx context.Context, client HTTPRequester, endpoint, token string, json []byte, intf interface{}, debug bool) error {
func postJSON(ctx context.Context, client HTTPRequester, endpoint, token string, json []byte, intf interface{}, debug bool) error {
reqBody := bytes.NewBuffer(json)
req, err := http.NewRequest("POST", endpoint, reqBody)
if err != nil {
Expand All @@ -192,7 +192,7 @@ func postForm(ctx context.Context, client HTTPRequester, endpoint string, values
return doPost(ctx, client, req, intf, debug)
}

func post(ctx context.Context, client HTTPRequester, path string, values url.Values, intf interface{}, debug bool) error {
func postPath(ctx context.Context, client HTTPRequester, path string, values url.Values, intf interface{}, debug bool) error {
return postForm(ctx, client, SLACK_API+path, values, intf, debug)
}

Expand Down
Loading

0 comments on commit 2e06c71

Please sign in to comment.