aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-12 15:59:51 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-12 15:59:51 +0100
commit79caada10f801c4ef5c4a5554360cb15e566178c (patch)
tree216b3a8f90ac1b4b2001baf75adadd110238ef4e
parent6ccca7c4e8a6efa649a6b7d96463d30498406bdf (diff)
Split again
-rw-r--r--client.go20
-rw-r--r--cmd/x/main.go6
2 files changed, 18 insertions, 8 deletions
diff --git a/client.go b/client.go
index aef6ec0..8efa32c 100644
--- a/client.go
+++ b/client.go
@@ -93,9 +93,7 @@ func (c *Client) request(url string, s Signer, rq, re interface{}) error {
c.nonce <- replyNonce(resp)
c.Link = links(resp)
- if resp.StatusCode == http.StatusCreated {
- c.Location = location(resp)
- }
+ c.Location = location(resp)
return json.NewDecoder(resp.Body).Decode(re)
}
@@ -159,16 +157,22 @@ func (c *Client) Register(a *Account) error {
return err
}
log.Println(re)
+ return err
+}
- // Agree to TOS
- rq.Resource = ResRegister
- rq.Agreement = c.Link["terms-of-service"]
- err = c.request(c.Location, a, rq, &re)
+// Agree to TOS
+func (c *Client) Agree(a *Account) error {
+ rq := Registration{
+ Resource: ResRegister,
+ Contact: a.Contact,
+ Agreement: c.Link["terms-of-service"],
+ }
+ re := RegistrationResp{}
+ err := c.request(c.Location, a, rq, &re)
if err != nil {
return err
}
log.Println(re)
-
return err
}
diff --git a/cmd/x/main.go b/cmd/x/main.go
index 28a1b0c..0e6cf71 100644
--- a/cmd/x/main.go
+++ b/cmd/x/main.go
@@ -43,4 +43,10 @@ func main() {
log.Fatal(err)
}
log.Printf("%+v\n", c)
+
+ err = c.Agree(a)
+ if err != nil {
+ log.Fatal(err)
+ }
+ log.Printf("%+v\n", c)
}