示例#1
0
func (a *APIAuthenticator) Authenticate(u domain.User) (string, error) {
	a.user = u
	if !a.user.HasCredentials() {
		return "", errors.New("Given domain.User does not have Username and Password")
	}

	response := responses.Me{}
	strategy := &request.BasicAuthStrategy{
		Username: a.user.Username,
		Password: a.user.Password,
	}
	requester := request.New(a.Resolver.AuthenticateRequestURL(), strategy)
	responseBody, err := requester.Execute()
	handleError(err)

	err = response.Parse(responseBody)
	if err != nil {
		return "", err
	}
	return response.User().APIToken, nil
}
示例#2
0
文件: client.go 项目: pivotal/gumshoe
func (c *Client) Me() fmt.Stringer {
	response := responses.Me{}
	responseBody := c.executeRequest(c.resolver.MeRequestURL())
	response.Parse(responseBody)
	return presenters.User{response.User()}
}
示例#3
0
package responses_test

import (
	. "github.com/pivotal/gumshoe/repos/ginkgo"
	. "github.com/pivotal/gumshoe/repos/gomega"
	"github.com/pivotal/gumshoe/trackerapi/responses"
)

var _ = Describe("Me Response", func() {
	var (
		response responses.Me
	)

	BeforeEach(func() {
		response = responses.Me{}
		responseBody := `{
            "api_token": "abcde90792f3898ab464cd3412345",
            "name": "Mister Tee",
            "kind": "me",
            "id": 123,
            "email": "*****@*****.**",
            "initials": "MT",
            "username": "******",
            "time_zone": {
                "kind": "time_zone",
                "offset": "-08:00",
                "olson_name": "America/Los_Angeles"
            }
        }`
		response.Parse([]byte(responseBody))
	})