Skip to content

Commit

Permalink
remove globals
Browse files Browse the repository at this point in the history
  • Loading branch information
James Lawrence authored and james-lawrence committed Oct 6, 2018
1 parent b9033a7 commit 8b3b6ec
Show file tree
Hide file tree
Showing 47 changed files with 371 additions and 450 deletions.
20 changes: 10 additions & 10 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type adminResponse struct {
Error string `json:"error"`
}

func adminRequest(ctx context.Context, client HTTPRequester, method string, teamName string, values url.Values, debug bool) (*adminResponse, error) {
func adminRequest(ctx context.Context, client httpClient, method string, teamName string, values url.Values, d debug) (*adminResponse, error) {
adminResponse := &adminResponse{}
err := parseAdminResponse(ctx, client, method, teamName, values, adminResponse, debug)
err := parseAdminResponse(ctx, client, method, teamName, values, adminResponse, d)
if err != nil {
return nil, err
}
Expand All @@ -40,7 +40,7 @@ func (api *Client) DisableUserContext(ctx context.Context, teamName string, uid
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "setInactive", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "setInactive", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to disable user with id '%s': %s", uid, err)
}
Expand All @@ -67,7 +67,7 @@ func (api *Client) InviteGuestContext(ctx context.Context, teamName, channel, fi
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "invite", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "invite", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to invite single-channel guest: %s", err)
}
Expand All @@ -94,7 +94,7 @@ func (api *Client) InviteRestrictedContext(ctx context.Context, teamName, channe
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "invite", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "invite", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to restricted account: %s", err)
}
Expand All @@ -118,7 +118,7 @@ func (api *Client) InviteToTeamContext(ctx context.Context, teamName, firstName,
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "invite", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "invite", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to invite to team: %s", err)
}
Expand All @@ -140,7 +140,7 @@ func (api *Client) SetRegularContext(ctx context.Context, teamName, user string)
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "setRegular", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "setRegular", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to change the user (%s) to a regular user: %s", user, err)
}
Expand All @@ -162,7 +162,7 @@ func (api *Client) SendSSOBindingEmailContext(ctx context.Context, teamName, use
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "sendSSOBind", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "sendSSOBind", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to send SSO binding email for user (%s): %s", user, err)
}
Expand All @@ -185,7 +185,7 @@ func (api *Client) SetUltraRestrictedContext(ctx context.Context, teamName, uid,
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "setUltraRestricted", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "setUltraRestricted", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to ultra-restrict account: %s", err)
}
Expand All @@ -207,7 +207,7 @@ func (api *Client) SetRestrictedContext(ctx context.Context, teamName, uid strin
"_attempts": {"1"},
}

_, err := adminRequest(ctx, api.httpclient, "setRestricted", teamName, values, api.debug)
_, err := adminRequest(ctx, api.httpclient, "setRestricted", teamName, values, api)
if err != nil {
return fmt.Errorf("Failed to restrict account: %s", err)
}
Expand Down
6 changes: 3 additions & 3 deletions bots.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ type botResponseFull struct {
SlackResponse
}

func botRequest(ctx context.Context, client HTTPRequester, path string, values url.Values, debug bool) (*botResponseFull, error) {
func botRequest(ctx context.Context, client httpClient, path string, values url.Values, d debug) (*botResponseFull, error) {
response := &botResponseFull{}
err := postSlackMethod(ctx, client, path, values, response, debug)
err := postSlackMethod(ctx, client, path, values, response, d)
if err != nil {
return nil, err
}
Expand All @@ -43,7 +43,7 @@ func (api *Client) GetBotInfoContext(ctx context.Context, bot string) (*Bot, err
"bot": {bot},
}

response, err := botRequest(ctx, api.httpclient, "bots.info", values, api.debug)
response, err := botRequest(ctx, api.httpclient, "bots.info", values, api)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion bots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestGetBotInfo(t *testing.T) {
http.HandleFunc("/bots.info", getBotInfo)

once.Do(startServer)
SLACK_API = "http://" + serverAddr + "/"
APIURL = "http://" + serverAddr + "/"
api := New("testing-token")

bot, err := api.GetBotInfo("B02875YLA")
Expand Down
36 changes: 18 additions & 18 deletions channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type Channel struct {
Locale string `json:"locale"`
}

func channelRequest(ctx context.Context, client HTTPRequester, path string, values url.Values, debug bool) (*channelResponseFull, error) {
func channelRequest(ctx context.Context, client httpClient, path string, values url.Values, d debug) (*channelResponseFull, error) {
response := &channelResponseFull{}
err := postForm(ctx, client, SLACK_API+path, values, response, debug)
err := postForm(ctx, client, APIURL+path, values, response, d)
if err != nil {
return nil, err
}
Expand All @@ -52,7 +52,7 @@ func (api *Client) ArchiveChannelContext(ctx context.Context, channelID string)
"channel": {channelID},
}

_, err = channelRequest(ctx, api.httpclient, "channels.archive", values, api.debug)
_, err = channelRequest(ctx, api.httpclient, "channels.archive", values, api)
return err
}

Expand All @@ -70,7 +70,7 @@ func (api *Client) UnarchiveChannelContext(ctx context.Context, channelID string
"channel": {channelID},
}

_, err = channelRequest(ctx, api.httpclient, "channels.unarchive", values, api.debug)
_, err = channelRequest(ctx, api.httpclient, "channels.unarchive", values, api)
return err
}

Expand All @@ -88,7 +88,7 @@ func (api *Client) CreateChannelContext(ctx context.Context, channelName string)
"name": {channelName},
}

response, err := channelRequest(ctx, api.httpclient, "channels.create", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.create", values, api)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (api *Client) GetChannelHistoryContext(ctx context.Context, channelID strin
}
}

response, err := channelRequest(ctx, api.httpclient, "channels.history", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.history", values, api)
if err != nil {
return nil, err
}
Expand All @@ -154,7 +154,7 @@ func (api *Client) GetChannelInfoContext(ctx context.Context, channelID string)
"channel": {channelID},
}

response, err := channelRequest(ctx, api.httpclient, "channels.info", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.info", values, api)
if err != nil {
return nil, err
}
Expand All @@ -167,7 +167,7 @@ func (api *Client) InviteUserToChannel(channelID, user string) (*Channel, error)
return api.InviteUserToChannelContext(context.Background(), channelID, user)
}

// InviteUserToChannelCustom invites a user to a given channel and returns a *Channel with a custom context
// InviteUserToChannelContext invites a user to a given channel and returns a *Channel with a custom context
// see https://api.slack.com/methods/channels.invite
func (api *Client) InviteUserToChannelContext(ctx context.Context, channelID, user string) (*Channel, error) {
values := url.Values{
Expand All @@ -176,7 +176,7 @@ func (api *Client) InviteUserToChannelContext(ctx context.Context, channelID, us
"user": {user},
}

response, err := channelRequest(ctx, api.httpclient, "channels.invite", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.invite", values, api)
if err != nil {
return nil, err
}
Expand All @@ -197,7 +197,7 @@ func (api *Client) JoinChannelContext(ctx context.Context, channelName string) (
"name": {channelName},
}

response, err := channelRequest(ctx, api.httpclient, "channels.join", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.join", values, api)
if err != nil {
return nil, err
}
Expand All @@ -218,7 +218,7 @@ func (api *Client) LeaveChannelContext(ctx context.Context, channelID string) (b
"channel": {channelID},
}

response, err := channelRequest(ctx, api.httpclient, "channels.leave", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.leave", values, api)
if err != nil {
return false, err
}
Expand All @@ -241,7 +241,7 @@ func (api *Client) KickUserFromChannelContext(ctx context.Context, channelID, us
"user": {user},
}

_, err = channelRequest(ctx, api.httpclient, "channels.kick", values, api.debug)
_, err = channelRequest(ctx, api.httpclient, "channels.kick", values, api)
return err
}

Expand All @@ -261,7 +261,7 @@ func (api *Client) GetChannelsContext(ctx context.Context, excludeArchived bool)
values.Add("exclude_archived", "1")
}

response, err := channelRequest(ctx, api.httpclient, "channels.list", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.list", values, api)
if err != nil {
return nil, err
}
Expand All @@ -288,7 +288,7 @@ func (api *Client) SetChannelReadMarkContext(ctx context.Context, channelID, ts
"ts": {ts},
}

_, err = channelRequest(ctx, api.httpclient, "channels.mark", values, api.debug)
_, err = channelRequest(ctx, api.httpclient, "channels.mark", values, api)
return err
}

Expand All @@ -309,7 +309,7 @@ func (api *Client) RenameChannelContext(ctx context.Context, channelID, name str

// XXX: the created entry in this call returns a string instead of a number
// so I may have to do some workaround to solve it.
response, err := channelRequest(ctx, api.httpclient, "channels.rename", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.rename", values, api)
if err != nil {
return nil, err
}
Expand All @@ -331,7 +331,7 @@ func (api *Client) SetChannelPurposeContext(ctx context.Context, channelID, purp
"purpose": {purpose},
}

response, err := channelRequest(ctx, api.httpclient, "channels.setPurpose", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.setPurpose", values, api)
if err != nil {
return "", err
}
Expand All @@ -353,7 +353,7 @@ func (api *Client) SetChannelTopicContext(ctx context.Context, channelID, topic
"topic": {topic},
}

response, err := channelRequest(ctx, api.httpclient, "channels.setTopic", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.setTopic", values, api)
if err != nil {
return "", err
}
Expand All @@ -374,7 +374,7 @@ func (api *Client) GetChannelRepliesContext(ctx context.Context, channelID, thre
"channel": {channelID},
"thread_ts": {thread_ts},
}
response, err := channelRequest(ctx, api.httpclient, "channels.replies", values, api.debug)
response, err := channelRequest(ctx, api.httpclient, "channels.replies", values, api)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 8b3b6ec

Please sign in to comment.