示例#1
0
文件: client.go 项目: pivotal/gumshoe
func (c *Client) executeRequest(url string) []byte {
	strategy := &request.APITokenStrategy{
		APIToken: c.user.APIToken,
	}
	requester := request.New(url, strategy)
	responseBody, err := requester.Execute()
	handleError(err)
	return responseBody
}
示例#2
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
}
示例#3
0
            "time_zone": {
                "kind": "time_zone",
                "offset": "-08:00",
                "olson_name": "America/Los_Angeles"
            }
        }`
		ts = &TestServer{
			apiToken: token,
		}
		ts.Boot()
		ts.SetResponse("/me", json)
		resolver = &request.Resolver{
			TrackerDomain: ts.URL,
		}
	})

	AfterEach(func() {
		ts.Close()
	})

	It("makes a request, returning the response body", func() {
		strategy := &request.APITokenStrategy{
			APIToken: token,
		}
		requester := request.New(resolver.MeRequestURL(), strategy)
		responseBody, _ := requester.Execute()
		actual := strings.TrimSpace(string(responseBody))
		Expect(actual).To(Equal(json))
	})
})