instance.go
changeset 120 579912e9d0ef
parent 112 467dd91bf1f9
child 130 c450bb73f59a
--- a/instance.go	Sat Apr 15 00:39:43 2017 +0200
+++ b/instance.go	Sat Apr 15 10:26:36 2017 +0200
@@ -1,34 +1,14 @@
 package gondole
 
 import (
-	"encoding/json"
-	"fmt"
-
 	"github.com/sendgrid/rest"
 )
 
 // GetCurrentInstance returns current instance information
 func (g *Client) GetCurrentInstance() (*Instance, error) {
-	req := g.prepareRequest("instance")
-	r, err := rest.API(req)
-	if err != nil {
-		return nil, fmt.Errorf("instance: %s", 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 nil, fmt.Errorf("%s", errorResult.Text)
-		}
-	}
-
-	// Not an error reply; let's unmarshal the data
 	var i Instance
-	err = json.Unmarshal([]byte(r.Body), &i)
-	if err != nil {
-		return nil, fmt.Errorf("instance API: %s", err.Error())
+	if err := g.apiCall("instance", rest.Get, nil, &i); err != nil {
+		return nil, err
 	}
 	return &i, nil
 }