func (client *DNSPodClient) GetDomainInfo(domain string, info *DomainInfo) error { t, err := client.token(client.email, client.password) if err != nil { return err } data := url.Values{} data.Set("user_token", t) data.Set("domain", domain) data.Set("format", "json") var ret map[string]interface{} u := rpc.BuildHttpsURL(client.addr, "/Domain.Info", nil) if err := client.conn.PostForm(nil, u, data, &ret); err != nil { return err } var status Status if err := util.Convert(ret["status"], &status); err != nil { return err } if status.Code != "1" { return errors.New(status.Message) } if err := util.Convert(ret["domain"], info); err != nil { return err } return nil }
func (client *DNSPodClient) DelRecord(domainID string, recordID string) error { t, err := client.token(client.email, client.password) if err != nil { return err } data := url.Values{} data.Set("user_token", t) data.Set("domain_id", domainID) data.Set("record_id", recordID) data.Set("format", "json") var ret map[string]interface{} u := rpc.BuildHttpsURL(client.addr, "/Record.Remove", nil) if err := client.conn.PostForm(nil, u, data, &ret); err != nil { return err } var status Status if err := util.Convert(ret["status"], &status); err != nil { return err } if status.Code != "1" { return errors.New(status.Message) } return nil }
func (client *DNSPodClient) ModRecord(domainID string, info *RecordInfo) error { t, err := client.token(client.email, client.password) if err != nil { return err } data := url.Values{} data.Set("user_token", t) data.Set("domain_id", domainID) data.Set("sub_domain", info.Name) data.Set("record_type", info.Type) data.Set("record_line", info.Line) data.Set("value", info.Value) if info.MX != "" { data.Set("mx", info.MX) } if info.TTL != "" { data.Set("ttl", info.TTL) } data.Set("format", "json") var ret map[string]interface{} u := rpc.BuildHttpsURL(client.addr, "/Record.Modify", nil) if err := client.conn.PostForm(nil, u, data, &ret); err != nil { return err } var status Status if err := util.Convert(ret["status"], &status); err != nil { return err } if status.Code != "1" { return errors.New(status.Message) } if err := util.Convert(ret["record"], info); err != nil { return err } return nil }
func (client *DNSPodClient) token(login_email, login_password string) (string, error) { if client.cache != nil { if t, ok := client.cache.Get(DNSPODTOKEN); ok { return t.(string), nil } } data := url.Values{} data.Set("login_email", login_email) data.Set("login_password", login_password) data.Set("format", "json") var ret map[string]interface{} u := rpc.BuildHttpsURL(client.addr, "/Auth", nil) if err := client.conn.PostForm(nil, u, data, &ret); err != nil { return "", err } var status Status if err := util.Convert(ret["status"], &status); err != nil { return "", err } if status.Code != "1" { return "", errors.New(status.Message) } var token string if err := util.Convert(ret["user_token"], &token); err != nil { return "", err } if client.cache != nil { client.cache.Set(DNSPODTOKEN, token, time.Minute*10) } client.email = login_email client.password = login_password return token, nil }