Merge branch 'master' of git://github.com/mattn/go-mastodon

pull/10/head
Yasuhiro Matsumoto 2017-04-15 00:10:12 +09:00
commit aa99f8559a
5 changed files with 22 additions and 21 deletions

View File

@ -2,6 +2,7 @@ package mastodon
import ( import (
"fmt" "fmt"
"net/http"
"net/url" "net/url"
"time" "time"
) )
@ -28,7 +29,7 @@ type Account struct {
// GetAccount return Account. // GetAccount return Account.
func (c *Client) GetAccount(id int) (*Account, error) { func (c *Client) GetAccount(id int) (*Account, error) {
var account Account var account Account
err := c.doAPI("GET", fmt.Sprintf("/api/v1/accounts/%d", id), nil, &account) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d", id), nil, &account)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -38,7 +39,7 @@ func (c *Client) GetAccount(id int) (*Account, error) {
// GetAccountCurrentUser return Account of current user. // GetAccountCurrentUser return Account of current user.
func (c *Client) GetAccountCurrentUser() (*Account, error) { func (c *Client) GetAccountCurrentUser() (*Account, error) {
var account Account var account Account
err := c.doAPI("GET", "/api/v1/accounts/verify_credentials", nil, &account) err := c.doAPI(http.MethodGet, "/api/v1/accounts/verify_credentials", nil, &account)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -48,7 +49,7 @@ func (c *Client) GetAccountCurrentUser() (*Account, error) {
// GetAccountFollowers return followers list. // GetAccountFollowers return followers list.
func (c *Client) GetAccountFollowers(id int64) ([]*Account, error) { func (c *Client) GetAccountFollowers(id int64) ([]*Account, error) {
var accounts []*Account var accounts []*Account
err := c.doAPI("GET", fmt.Sprintf("/api/v1/accounts/%d/followers", id), nil, &accounts) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/followers", id), nil, &accounts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -58,7 +59,7 @@ func (c *Client) GetAccountFollowers(id int64) ([]*Account, error) {
// GetAccountFollowing return following list. // GetAccountFollowing return following list.
func (c *Client) GetAccountFollowing(id int64) ([]*Account, error) { func (c *Client) GetAccountFollowing(id int64) ([]*Account, error) {
var accounts []*Account var accounts []*Account
err := c.doAPI("GET", fmt.Sprintf("/api/v1/accounts/%d/following", id), nil, &accounts) err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/accounts/%d/following", id), nil, &accounts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -77,7 +78,7 @@ type Relationship struct {
// AccountFollow follow the account. // AccountFollow follow the account.
func (c *Client) AccountFollow(id int64) (*Relationship, error) { func (c *Client) AccountFollow(id int64) (*Relationship, error) {
var relationship Relationship var relationship Relationship
err := c.doAPI("POST", fmt.Sprintf("/api/v1/accounts/%d/follow", id), nil, &relationship) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/follow", id), nil, &relationship)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -87,7 +88,7 @@ func (c *Client) AccountFollow(id int64) (*Relationship, error) {
// AccountUnfollow unfollow the account. // AccountUnfollow unfollow the account.
func (c *Client) AccountUnfollow(id int64) (*Relationship, error) { func (c *Client) AccountUnfollow(id int64) (*Relationship, error) {
var relationship Relationship var relationship Relationship
err := c.doAPI("POST", fmt.Sprintf("/api/v1/accounts/%d/unfollow", id), nil, &relationship) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unfollow", id), nil, &relationship)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -97,7 +98,7 @@ func (c *Client) AccountUnfollow(id int64) (*Relationship, error) {
// AccountBlock block the account. // AccountBlock block the account.
func (c *Client) AccountBlock(id int64) (*Relationship, error) { func (c *Client) AccountBlock(id int64) (*Relationship, error) {
var relationship Relationship var relationship Relationship
err := c.doAPI("POST", fmt.Sprintf("/api/v1/accounts/%d/block", id), nil, &relationship) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/block", id), nil, &relationship)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -107,7 +108,7 @@ func (c *Client) AccountBlock(id int64) (*Relationship, error) {
// AccountUnblock unblock the account. // AccountUnblock unblock the account.
func (c *Client) AccountUnblock(id int64) (*Relationship, error) { func (c *Client) AccountUnblock(id int64) (*Relationship, error) {
var relationship Relationship var relationship Relationship
err := c.doAPI("POST", fmt.Sprintf("/api/v1/accounts/%d/unblock", id), nil, &relationship) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unblock", id), nil, &relationship)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -117,7 +118,7 @@ func (c *Client) AccountUnblock(id int64) (*Relationship, error) {
// AccountMute mute the account. // AccountMute mute the account.
func (c *Client) AccountMute(id int64) (*Relationship, error) { func (c *Client) AccountMute(id int64) (*Relationship, error) {
var relationship Relationship var relationship Relationship
err := c.doAPI("POST", fmt.Sprintf("/api/v1/accounts/%d/mute", id), nil, &relationship) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/mute", id), nil, &relationship)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -127,7 +128,7 @@ func (c *Client) AccountMute(id int64) (*Relationship, error) {
// AccountUnmute unmute the account. // AccountUnmute unmute the account.
func (c *Client) AccountUnmute(id int64) (*Relationship, error) { func (c *Client) AccountUnmute(id int64) (*Relationship, error) {
var relationship Relationship var relationship Relationship
err := c.doAPI("POST", fmt.Sprintf("/api/v1/accounts/%d/unmute", id), nil, &relationship) err := c.doAPI(http.MethodPost, fmt.Sprintf("/api/v1/accounts/%d/unmute", id), nil, &relationship)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -140,7 +141,7 @@ func (c *Client) GetAccountRelationship(id int64) ([]*Relationship, error) {
params.Set("id", fmt.Sprint(id)) params.Set("id", fmt.Sprint(id))
var relationships []*Relationship var relationships []*Relationship
err := c.doAPI("GET", "/api/v1/accounts/relationship", params, &relationships) err := c.doAPI(http.MethodGet, "/api/v1/accounts/relationship", params, &relationships)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -154,7 +155,7 @@ func (c *Client) AccountsSearch(q string, limit int64) ([]*Account, error) {
params.Set("limit", fmt.Sprint(limit)) params.Set("limit", fmt.Sprint(limit))
var accounts []*Account var accounts []*Account
err := c.doAPI("GET", "/api/v1/accounts/search", params, &accounts) err := c.doAPI(http.MethodGet, "/api/v1/accounts/search", params, &accounts)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -167,7 +168,7 @@ func (c *Client) Follow(uri string) (*Account, error) {
params.Set("uri", uri) params.Set("uri", uri)
var account Account var account Account
err := c.doAPI("POST", "/api/v1/follows", params, &account) err := c.doAPI(http.MethodPost, "/api/v1/follows", params, &account)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -180,7 +181,7 @@ func (c *Client) GetFollowRequests(uri string) ([]*Account, error) {
params.Set("uri", uri) params.Set("uri", uri)
var accounts []*Account var accounts []*Account
err := c.doAPI("GET", "/api/v1/follow_requests", params, &accounts) err := c.doAPI(http.MethodGet, "/api/v1/follow_requests", params, &accounts)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -51,7 +51,7 @@ func RegisterApp(appConfig *AppConfig) (*Application, error) {
} }
url.Path = path.Join(url.Path, "/api/v1/apps") url.Path = path.Join(url.Path, "/api/v1/apps")
req, err := http.NewRequest("POST", url.String(), strings.NewReader(params.Encode())) req, err := http.NewRequest(http.MethodPost, url.String(), strings.NewReader(params.Encode()))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -46,7 +46,7 @@ func (c *Client) doAPI(method string, uri string, params url.Values, res interfa
return nil return nil
} }
if method == "GET" && resp.StatusCode != http.StatusOK { if method == http.MethodGet && resp.StatusCode != http.StatusOK {
return fmt.Errorf("bad request: %v", resp.Status) return fmt.Errorf("bad request: %v", resp.Status)
} }
@ -77,7 +77,7 @@ func (c *Client) Authenticate(username, password string) error {
} }
url.Path = path.Join(url.Path, "/oauth/token") url.Path = path.Join(url.Path, "/oauth/token")
req, err := http.NewRequest("POST", url.String(), strings.NewReader(params.Encode())) req, err := http.NewRequest(http.MethodPost, url.String(), strings.NewReader(params.Encode()))
if err != nil { if err != nil {
return err return err
} }
@ -164,7 +164,7 @@ type Status struct {
// GetTimelineHome return statuses from home timeline. // GetTimelineHome return statuses from home timeline.
func (c *Client) GetTimelineHome() ([]*Status, error) { func (c *Client) GetTimelineHome() ([]*Status, error) {
var statuses []*Status var statuses []*Status
err := c.doAPI("GET", "/api/v1/timelines/home", nil, &statuses) err := c.doAPI(http.MethodGet, "/api/v1/timelines/home", nil, &statuses)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -182,7 +182,7 @@ func (c *Client) PostStatus(toot *Toot) (*Status, error) {
//params.Set("visibility", "public") //params.Set("visibility", "public")
var status Status var status Status
err := c.doAPI("POST", "/api/v1/statuses", params, &status) err := c.doAPI(http.MethodPost, "/api/v1/statuses", params, &status)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -195,7 +195,7 @@ func TestGetAccountFollowing(t *testing.T) {
func TestRegisterApp(t *testing.T) { func TestRegisterApp(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" { if r.Method != http.MethodPost {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return return
} }

View File

@ -82,7 +82,7 @@ func (c *Client) StreamingPublic(ctx context.Context) (chan Event, error) {
defer ctx.Done() defer ctx.Done()
for { for {
req, err := http.NewRequest("GET", url.String(), nil) req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err == nil { if err == nil {
req.Header.Set("Authorization", "Bearer "+c.config.AccessToken) req.Header.Set("Authorization", "Bearer "+c.config.AccessToken)
resp, err = c.Do(req) resp, err = c.Do(req)