Do not use a global API version
Mastodon uses an API version per endpoint (cf. search v2) so
we need to be able to specify the version for any API call.
--- a/account.go Thu Sep 06 00:34:44 2018 +0200
+++ b/account.go Thu Sep 06 01:07:40 2018 +0200
@@ -62,7 +62,7 @@
}
var rel Relationship
- if err := mc.apiCall(endPoint, method, params, nil, nil, &rel); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, method, params, nil, nil, &rel); err != nil {
return nil, err
}
return &rel, nil
@@ -92,7 +92,7 @@
}
var account Account
- if err := mc.apiCall(endPoint, method, nil, nil, nil, &account); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, method, nil, nil, nil, &account); err != nil {
return nil, err
}
return &account, nil
@@ -104,7 +104,7 @@
func (mc *Client) getMultipleAccounts(endPoint string, params apiCallParams, lopt *LimitParams) ([]Account, error) {
var accounts []Account
var links apiLinks
- if err := mc.apiCall(endPoint, rest.Get, params, lopt, &links, &accounts); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, params, lopt, &links, &accounts); err != nil {
return nil, err
}
if lopt != nil { // Fetch more pages to reach our limit
@@ -112,7 +112,7 @@
for (lopt.All || lopt.Limit > len(accounts)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
- if err := mc.apiCall(endPoint, rest.Get, params, newlopt, &links, &accountSlice); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, params, newlopt, &links, &accountSlice); err != nil {
return nil, err
}
accounts = append(accounts, accountSlice...)
@@ -253,7 +253,7 @@
params["uri"] = uri
var account Account
- if err := mc.apiCall("follows", rest.Post, params, nil, nil, &account); err != nil {
+ if err := mc.apiCall("v1/follows", rest.Post, params, nil, nil, &account); err != nil {
return nil, err
}
if account.ID == 0 {
@@ -367,7 +367,7 @@
}
var rl []Relationship
- if err := mc.apiCall("accounts/relationships", rest.Get, params, nil, nil, &rl); err != nil {
+ if err := mc.apiCall("v1/accounts/relationships", rest.Get, params, nil, nil, &rl); err != nil {
return nil, err
}
return rl, nil
--- a/domain.go Thu Sep 06 00:34:44 2018 +0200
+++ b/domain.go Thu Sep 06 01:07:40 2018 +0200
@@ -17,7 +17,7 @@
const endPoint = "domain_blocks"
var links apiLinks
var domains []DomainName
- if err := mc.apiCall(endPoint, rest.Get, nil, lopt, &links, &domains); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, lopt, &links, &domains); err != nil {
return nil, err
}
if lopt != nil { // Fetch more pages to reach our limit
@@ -25,7 +25,7 @@
for (lopt.All || lopt.Limit > len(domains)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
- if err := mc.apiCall(endPoint, rest.Get, nil, newlopt, &links, &domainSlice); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, newlopt, &links, &domainSlice); err != nil {
return nil, err
}
domains = append(domains, domainSlice...)
@@ -40,7 +40,7 @@
const endPoint = "domain_blocks"
params := make(apiCallParams)
params["domain"] = string(domain)
- return mc.apiCall(endPoint, rest.Post, params, nil, nil, nil)
+ return mc.apiCall("v1/"+endPoint, rest.Post, params, nil, nil, nil)
}
// UnblockDomain unblocks the specified domain
@@ -48,5 +48,5 @@
const endPoint = "domain_blocks"
params := make(apiCallParams)
params["domain"] = string(domain)
- return mc.apiCall(endPoint, rest.Delete, params, nil, nil, nil)
+ return mc.apiCall("v1/"+endPoint, rest.Delete, params, nil, nil, nil)
}
--- a/emoji.go Thu Sep 06 00:34:44 2018 +0200
+++ b/emoji.go Thu Sep 06 01:07:40 2018 +0200
@@ -13,7 +13,7 @@
// GetCustomEmojis returns a list with the server custom emojis
func (mc *Client) GetCustomEmojis(lopt *LimitParams) ([]Emoji, error) {
var emojiList []Emoji
- if err := mc.apiCall("custom_emojis", rest.Get, nil, lopt, nil, &emojiList); err != nil {
+ if err := mc.apiCall("v1/custom_emojis", rest.Get, nil, lopt, nil, &emojiList); err != nil {
return nil, err
}
return emojiList, nil
--- a/endorsements.go Thu Sep 06 00:34:44 2018 +0200
+++ b/endorsements.go Thu Sep 06 01:07:40 2018 +0200
@@ -15,7 +15,7 @@
endPoint := "endorsements"
method := rest.Get
var accountList []Account
- if err := mc.apiCall(endPoint, method, nil, lopt, nil, &accountList); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, method, nil, lopt, nil, &accountList); err != nil {
return nil, err
}
return accountList, nil
--- a/instance.go Thu Sep 06 00:34:44 2018 +0200
+++ b/instance.go Thu Sep 06 01:07:40 2018 +0200
@@ -18,7 +18,7 @@
// GetCurrentInstance returns current instance information
func (mc *Client) GetCurrentInstance() (*Instance, error) {
var i Instance
- if err := mc.apiCall("instance", rest.Get, nil, nil, nil, &i); err != nil {
+ if err := mc.apiCall("v1/instance", rest.Get, nil, nil, nil, &i); err != nil {
return nil, err
}
return &i, nil
@@ -29,16 +29,18 @@
// resolved.
func (mc *Client) GetInstancePeers() ([]InstancePeer, error) {
var peers []InstancePeer
- if err := mc.apiCall("instance/peers", rest.Get, nil, nil, nil, &peers); err != nil {
+ if err := mc.apiCall("v1/instance/peers", rest.Get, nil, nil, nil, &peers); err != nil {
return nil, err
}
return peers, nil
}
// GetInstanceActivity returns current instance activity
+// The activity contains the counts of active users, locally posted statuses,
+// and new registrations in weekly buckets.
func (mc *Client) GetInstanceActivity() ([]WeekActivity, error) {
var activity []WeekActivity
- if err := mc.apiCall("instance/activity", rest.Get, nil, nil, nil, &activity); err != nil {
+ if err := mc.apiCall("v1/instance/activity", rest.Get, nil, nil, nil, &activity); err != nil {
return nil, err
}
return activity, nil
--- a/lists.go Thu Sep 06 00:34:44 2018 +0200
+++ b/lists.go Thu Sep 06 01:07:40 2018 +0200
@@ -21,7 +21,7 @@
}
endPoint := "lists/" + strconv.FormatInt(listID, 10)
var list List
- if err := mc.apiCall(endPoint, rest.Get, nil, nil, nil, &list); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, nil, nil, &list); err != nil {
return nil, err
}
return &list, nil
@@ -40,7 +40,7 @@
var lists []List
var links apiLinks
- if err := mc.apiCall(endPoint, rest.Get, nil, lopt, &links, &lists); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, lopt, &links, &lists); err != nil {
return nil, err
}
if lopt != nil { // Fetch more pages to reach our limit
@@ -48,7 +48,7 @@
for (lopt.All || lopt.Limit > len(lists)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
- if err := mc.apiCall(endPoint, rest.Get, nil, newlopt, &links, &listSlice); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, newlopt, &links, &listSlice); err != nil {
return nil, err
}
lists = append(lists, listSlice...)
@@ -103,7 +103,7 @@
qID := fmt.Sprintf("account_ids[%d]", i)
params[qID] = strconv.FormatInt(id, 10)
}
- return mc.apiCall(endPoint, method, params, nil, nil, nil)
+ return mc.apiCall("v1/"+endPoint, method, params, nil, nil, nil)
}
// RemoveListAccounts removes the accounts from the given list
@@ -118,7 +118,7 @@
qID := fmt.Sprintf("account_ids[%d]", i)
params[qID] = strconv.FormatInt(id, 10)
}
- return mc.apiCall(endPoint, method, params, nil, nil, nil)
+ return mc.apiCall("v1/"+endPoint, method, params, nil, nil, nil)
}
func (mc *Client) setSingleList(method rest.Method, listID int64, params apiCallParams) (*List, error) {
@@ -129,7 +129,7 @@
endPoint = "lists"
}
var list List
- if err := mc.apiCall(endPoint, method, params, nil, nil, &list); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, method, params, nil, nil, &list); err != nil {
return nil, err
}
return &list, nil
--- a/madon.go Thu Sep 06 00:34:44 2018 +0200
+++ b/madon.go Thu Sep 06 01:07:40 2018 +0200
@@ -25,9 +25,7 @@
// MadonVersion contains the version of the Madon library
MadonVersion = "2.4.0-dev"
- // API version implemented in this library
- apiVersion = "v1"
- currentAPIPath = "/api/" + apiVersion
+ currentAPIPath = "/api"
// NoRedirect is the URI for no redirection in the App registration
NoRedirect = "urn:ietf:wg:oauth:2.0:oob"
--- a/media.go Thu Sep 06 00:34:44 2018 +0200
+++ b/media.go Thu Sep 06 01:07:40 2018 +0200
@@ -101,7 +101,7 @@
endPoint := "media/" + strconv.FormatInt(mediaID, 10)
var attachment Attachment
- if err := mc.apiCall(endPoint, rest.Put, params, nil, nil, &attachment); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Put, params, nil, nil, &attachment); err != nil {
return nil, err
}
return &attachment, nil
--- a/notifications.go Thu Sep 06 00:34:44 2018 +0200
+++ b/notifications.go Thu Sep 06 01:07:40 2018 +0200
@@ -33,7 +33,7 @@
}
}
- if err := mc.apiCall("notifications", rest.Get, params, lopt, &links, ¬ifications); err != nil {
+ if err := mc.apiCall("v1/notifications", rest.Get, params, lopt, &links, ¬ifications); err != nil {
return nil, err
}
if lopt != nil { // Fetch more pages to reach our limit
@@ -41,7 +41,7 @@
for (lopt.All || lopt.Limit > len(notifications)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
- if err := mc.apiCall("notifications", rest.Get, nil, newlopt, &links, ¬ifSlice); err != nil {
+ if err := mc.apiCall("v1/notifications", rest.Get, nil, newlopt, &links, ¬ifSlice); err != nil {
return nil, err
}
notifications = append(notifications, notifSlice...)
@@ -61,7 +61,7 @@
var endPoint = "notifications/" + strconv.FormatInt(notificationID, 10)
var notification Notification
- if err := mc.apiCall(endPoint, rest.Get, nil, nil, nil, ¬ification); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, nil, nil, nil, ¬ification); err != nil {
return nil, err
}
if notification.ID == 0 {
@@ -78,13 +78,13 @@
endPoint := "notifications/dismiss"
params := apiCallParams{"id": strconv.FormatInt(notificationID, 10)}
- err := mc.apiCall(endPoint, rest.Post, params, nil, nil, &Notification{})
+ err := mc.apiCall("v1/"+endPoint, rest.Post, params, nil, nil, &Notification{})
return err
}
// ClearNotifications deletes all notifications from the Mastodon server for
// the authenticated user
func (mc *Client) ClearNotifications() error {
- err := mc.apiCall("notifications/clear", rest.Post, nil, nil, nil, &Notification{})
+ err := mc.apiCall("v1/notifications/clear", rest.Post, nil, nil, nil, &Notification{})
return err
}
--- a/report.go Thu Sep 06 00:34:44 2018 +0200
+++ b/report.go Thu Sep 06 01:07:40 2018 +0200
@@ -17,7 +17,7 @@
// (I don't know if the limit options are used by the API server.)
func (mc *Client) GetReports(lopt *LimitParams) ([]Report, error) {
var reports []Report
- if err := mc.apiCall("reports", rest.Get, nil, lopt, nil, &reports); err != nil {
+ if err := mc.apiCall("v1/reports", rest.Get, nil, lopt, nil, &reports); err != nil {
return nil, err
}
return reports, nil
@@ -41,7 +41,7 @@
}
var report Report
- if err := mc.apiCall("reports", rest.Post, params, nil, nil, &report); err != nil {
+ if err := mc.apiCall("v1/reports", rest.Post, params, nil, nil, &report); err != nil {
return nil, err
}
return &report, nil
--- a/search.go Thu Sep 06 00:34:44 2018 +0200
+++ b/search.go Thu Sep 06 01:07:40 2018 +0200
@@ -26,7 +26,7 @@
Results
Hashtags []string `json:"hashtags"`
}
- if err := mc.apiCall("search", rest.Get, params, nil, nil, &resultsV1); err != nil {
+ if err := mc.apiCall("v1/"+"search", rest.Get, params, nil, nil, &resultsV1); err != nil {
return nil, err
}
--- a/status.go Thu Sep 06 00:34:44 2018 +0200
+++ b/status.go Thu Sep 06 01:07:40 2018 +0200
@@ -44,7 +44,7 @@
func (mc *Client) getMultipleStatuses(endPoint string, params apiCallParams, lopt *LimitParams) ([]Status, error) {
var statuses []Status
var links apiLinks
- if err := mc.apiCall(endPoint, rest.Get, params, lopt, &links, &statuses); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, params, lopt, &links, &statuses); err != nil {
return nil, err
}
if lopt != nil { // Fetch more pages to reach our limit
@@ -52,7 +52,7 @@
for (lopt.All || lopt.Limit > len(statuses)) && links.next != nil {
newlopt := links.next
links = apiLinks{}
- if err := mc.apiCall(endPoint, rest.Get, params, newlopt, &links, &statusSlice); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, rest.Get, params, newlopt, &links, &statusSlice); err != nil {
return nil, err
}
statuses = append(statuses, statusSlice...)
@@ -83,7 +83,7 @@
endPoint += "/" + op
}
- return mc.apiCall(endPoint, rest.Get, nil, nil, nil, data)
+ return mc.apiCall("v1/"+endPoint, rest.Get, nil, nil, nil, data)
}
// updateStatusData updates the statuses
@@ -155,7 +155,7 @@
}
}
- return mc.apiCall(endPoint, method, params, nil, nil, data)
+ return mc.apiCall("v1/"+endPoint, method, params, nil, nil, data)
}
// GetStatus returns a status
--- a/streams.go Thu Sep 06 00:34:44 2018 +0200
+++ b/streams.go Thu Sep 06 01:07:40 2018 +0200
@@ -52,7 +52,7 @@
}
// Build streaming websocket URL
- u, err := url.Parse("ws" + mc.APIBase[4:] + "/streaming/")
+ u, err := url.Parse("ws" + mc.APIBase[4:] + "/v1/streaming/")
if err != nil {
return nil, errors.Wrap(err, "cannot create Websocket URL")
}
--- a/suggestions.go Thu Sep 06 00:34:44 2018 +0200
+++ b/suggestions.go Thu Sep 06 01:07:40 2018 +0200
@@ -17,7 +17,7 @@
endPoint := "suggestions"
method := rest.Get
var accountList []Account
- if err := mc.apiCall(endPoint, method, nil, lopt, nil, &accountList); err != nil {
+ if err := mc.apiCall("v1/"+endPoint, method, nil, lopt, nil, &accountList); err != nil {
return nil, err
}
return accountList, nil
@@ -27,5 +27,5 @@
func (mc *Client) DeleteSuggestion(accountID int64) error {
endPoint := "suggestions/" + strconv.FormatInt(accountID, 10)
method := rest.Delete
- return mc.apiCall(endPoint, method, nil, nil, nil, nil)
+ return mc.apiCall("v1/"+endPoint, method, nil, nil, nil, nil)
}