gondole.go
author Mikael Berthe <mikael@lilotux.net>
Thu, 13 Apr 2017 23:43:10 +0200
changeset 115 0684ac8b6634
parent 107 f0db7634e540
child 120 579912e9d0ef
permissions -rw-r--r--
Add FollowRequestAuthorize()

package gondole

import (
	"errors"
	"fmt"

	"github.com/sendgrid/rest"
)

const (
	// GondoleVersion contains the version of the Gondole implementation
	GondoleVersion = "0.0"

	defaultInstanceURL = "https://mastodon.social"
	apiVersion         = "v1" // That is not overridable
	defaultAPIPath     = "/api/" + apiVersion

	// NoRedirect is the URI for no redirection in the App registration
	NoRedirect = "urn:ietf:wg:oauth:2.0:oob"
)

// Error codes
var (
	ErrAlreadyRegistered = errors.New("app already registered")
	ErrEntityNotFound    = errors.New("entity not found")
	ErrInvalidParameter  = errors.New("incorrect parameter")
	ErrInvalidID         = errors.New("incorrect entity ID")
)

// prepareRequest insert all pre-defined stuff
func (g *Client) prepareRequest(what string) (req rest.Request) {
	var endPoint string

	endPoint = g.APIBase + "/" + what
	// Add at least one option, the APIkey if present
	hdrs := make(map[string]string)
	opts := make(map[string]string)

	// Insert our sig
	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,
		QueryParams: opts,
	}
	return
}