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 }
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 }
"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)) }) })