Exemplo n.º 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
}
Exemplo n.º 2
0
func (c *Client) Me() fmt.Stringer {
	response := responses.Me{}
	responseBody := c.executeRequest(c.resolver.MeRequestURL())
	response.Parse(responseBody)
	return presenters.User{response.User()}
}
Exemplo n.º 3
0
	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))
	})

	It("can be used to unmarshal a response, returning a user domain object", func() {
		user := response.User()
		Expect(user.APIToken).To(Equal("abcde90792f3898ab464cd3412345"))
		Expect(user.Name).To(Equal("Mister Tee"))
		Expect(user.Email).To(Equal("*****@*****.**"))
		Expect(user.Initials).To(Equal("MT"))
		Expect(user.Username).To(Equal("mister_tee"))
		Expect(user.Timezone).To(Equal("America/Los_Angeles"))
	})
})