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