gondole.go
changeset 125 2bbb72b9ebf6
parent 123 9b566c020a17
child 130 c450bb73f59a
--- a/gondole.go	Sat Apr 15 21:08:34 2017 +0200
+++ b/gondole.go	Sat Apr 15 21:08:34 2017 +0200
@@ -1,11 +1,7 @@
 package gondole
 
 import (
-	"encoding/json"
 	"errors"
-	"fmt"
-
-	"github.com/sendgrid/rest"
 )
 
 // apiCallParams is a map with the parameters for an API call
@@ -30,51 +26,3 @@
 	ErrInvalidParameter  = errors.New("incorrect parameter")
 	ErrInvalidID         = errors.New("incorrect entity ID")
 )
-
-// prepareRequest inserts all pre-defined stuff
-func (g *Client) prepareRequest(target string, method rest.Method, params apiCallParams) (req rest.Request) {
-	endPoint := g.APIBase + "/" + target
-
-	// Request headers
-	hdrs := make(map[string]string)
-	hdrs["User-Agent"] = fmt.Sprintf("Gondole/%s", GondoleVersion)
-	if g.UserToken != nil {
-		hdrs["Authorization"] = fmt.Sprintf("Bearer %s", g.UserToken.AccessToken)
-	}
-
-	req = rest.Request{
-		BaseURL:     endPoint,
-		Headers:     hdrs,
-		Method:      method,
-		QueryParams: params,
-	}
-	return
-}
-
-// apiCall makes a call to the Mastodon API server
-func (g *Client) apiCall(endPoint string, method rest.Method, params apiCallParams, data interface{}) error {
-	// Prepare query
-	req := g.prepareRequest(endPoint, method, params)
-
-	// Make API call
-	r, err := rest.API(req)
-	if err != nil {
-		return fmt.Errorf("API query (%s) failed: %s", endPoint, err.Error())
-	}
-
-	// Check for error reply
-	var errorResult Error
-	if err := json.Unmarshal([]byte(r.Body), &errorResult); err == nil {
-		// The empty object is not an error
-		if errorResult.Text != "" {
-			return fmt.Errorf("%s", errorResult.Text)
-		}
-	}
-
-	// Not an error reply; let's unmarshal the data
-	err = json.Unmarshal([]byte(r.Body), &data)
-	if err != nil {
-		return fmt.Errorf("cannot decode API response (%s): %s", method, err.Error())
-	}
-	return nil
-}