aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-13 03:18:59 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-13 03:18:59 +0100
commit5dd267af24d709292ed7c48c213b7bfd0d7b9269 (patch)
tree10587c8efd87ab6533d7b9fff1327e8783e382bf /client.go
parentdbc27c3a29e6644688d015f36c689165e6d90168 (diff)
Combine messages
Diffstat (limited to 'client.go')
-rw-r--r--client.go46
1 files changed, 28 insertions, 18 deletions
diff --git a/client.go b/client.go
index e2d8492..a97279b 100644
--- a/client.go
+++ b/client.go
@@ -4,6 +4,8 @@ import (
"bytes"
"encoding/json"
"errors"
+ "fmt"
+ "io/ioutil"
"log"
"net/http"
"net/textproto"
@@ -68,8 +70,8 @@ func (c Client) Nonce() (string, error) {
// request is used for
// new-reg, new-authz, challenge, new-cert
-func (c *Client) request(url string, s Signer, rq, re interface{}) error {
- body, err := json.Marshal(rq)
+func (c *Client) post(url string, s Signer, v interface{}) error {
+ body, err := json.Marshal(v)
if err != nil {
return err
}
@@ -95,7 +97,14 @@ func (c *Client) request(url string, s Signer, rq, re interface{}) error {
c.Link = links(resp)
c.Location = location(resp)
- return json.NewDecoder(resp.Body).Decode(re)
+ body, err = ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return err
+ }
+ // DEBUG
+ log.Println("RESPONSE", string(body))
+ return json.Unmarshal(body, v)
+ //return json.NewDecoder(resp.Body).Decode(v)
}
func location(r *http.Response) string {
@@ -146,37 +155,38 @@ func replyNonce(r *http.Response) string {
challenge cert-chain
*/
-func (c *Client) Register(a *Account) (RegistrationResp, error) {
- rq := Registration{
+func (c *Client) Register(a *Account) (*Registration, error) {
+ r := &Registration{
Resource: ResNewReg,
Contact: a.Contact,
}
- re := RegistrationResp{}
- err := c.request(c.Dir.NewReg, a, rq, &re)
- return re, err
+ err := c.post(c.Dir.NewReg, a, r)
+ return r, err
}
// Agree to TOS
-func (c *Client) Agree(a *Account) (RegistrationResp, error) {
- rq := Registration{
+func (c *Client) Agree(a *Account) (*Registration, error) {
+ r := &Registration{
Resource: ResRegister,
Contact: a.Contact,
Agreement: c.Link["terms-of-service"],
}
- re := RegistrationResp{}
- err := c.request(c.Location, a, rq, &re)
- return re, err
+ err := c.post(c.Location, a, r)
+ return r, err
}
-func (c *Client) Authorize(a *Account, domain string) (AuthorizationResp, error) {
- rq := Authorization{
+func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
+ r := &Authorization{
Resource: ResNewAuthz,
Identifier: Identifier{
Type: IdentDNS,
Value: domain,
},
}
- re := AuthorizationResp{}
- err := c.request(c.Dir.NewAuthz, a, rq, &re)
- return re, err
+ err := c.post(c.Dir.NewAuthz, a, r)
+ return r, err
+}
+
+func (c Client) String() string {
+ return fmt.Sprintf("Link: %v, Location: %v", c.Link, c.Location)
}