func (r *Request) OperatorPassword() (*Response, string, error) { p := &r.Params rp := RequestPassword{p.CurrentPassword, p.NewPassword} mJson, err := json.Marshal(rp) if err != nil { return nil, "", err } client := util.HttpClient{} client.Path = "/operators/" + string(p.OperatorId) + "/password" client.Body = mJson client.XSoracomApiKey = p.XSoracomApiKey client.XSoracomToken = p.XSoracomToken resp, err := client.Post() if err != nil { return nil, "", err } switch resp.StatusCode { case http.StatusBadRequest: err = errors.New("Invalid password") return nil, "", err case http.StatusOK: return nil, "OK", err } err = errors.New("Unknown Error.") return nil, "", err }
func (r *Request) PassWordResetTokenTheIssue() (*Response, string, error) { p := &r.Params ir := IssueRequest{p.Email} mJson, err := json.Marshal(ir) if err != nil { return nil, "", err } client := util.HttpClient{} client.Path = "/auth/password_reset_token/issue" client.Body = mJson resp, err := client.Post() if err != nil { return nil, "", err } if resp.StatusCode == http.StatusBadRequest { err = errors.New("Email is not valid.") return nil, "", err } if resp.StatusCode == http.StatusOK { return nil, "OK", nil } err = errors.New("Undefined error.") return nil, "", err }
func (r *Request) PassWordResetTokenTheVerify() (*Response, string, error) { p := &r.Params vr := VerifyRequest{p.NewPassword, p.VerifyToken} mJson, err := json.Marshal(vr) if err != nil { return nil, "", err } client := util.HttpClient{} client.Path = "/auth/password_reset_token/verify" client.Body = mJson resp, err := client.Post() if err != nil { return nil, "", err } switch resp.StatusCode { case http.StatusBadRequest: err = errors.New("Invalid token.") return nil, "", err case http.StatusNotFound: err = errors.New("Token timeout.") return nil, "", err case http.StatusOK: return nil, "OK", nil } err = errors.New("Unknown Error.") return nil, "", err }
func (r *Request) Operators() (*Response, string, error) { p := &r.Params ro := RequestOperators{p.Email, p.Password} mJson, err := json.Marshal(ro) if err != nil { return nil, "", err } client := util.HttpClient{} client.Path = "/operators" client.Body = mJson client.XSoracomApiKey = p.XSoracomApiKey client.XSoracomToken = p.XSoracomToken resp, err := client.Post() if err != nil { return nil, "", err } switch resp.StatusCode { case http.StatusCreated: return nil, "OK", nil case http.StatusBadRequest: err = errors.New("This email is already registered") return nil, "", err } err = errors.New("Unknown error.") return nil, "", err }
func (r *Request) Auth() (*Response, string, error) { p := &r.Params ar := AuthRequest{p.Email, p.Password, p.TokenTimeoutSeconds} mJson, err := json.Marshal(ar) if err != nil { return nil, "", err } client := util.HttpClient{} client.Path = "/auth" client.Body = mJson resp, err := client.Post() if err != nil { return nil, "", err } if resp.StatusCode == http.StatusForbidden { err = errors.New("Email or password is not valid.") return nil, "", err } body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, "", err } defer resp.Body.Close() aResp := Response{} err = json.Unmarshal(body, &aResp) if err != nil { return nil, "", err } return &aResp, string(body), nil }
func (r *Request) OperatorVerify() (*Response, string, error) { p := &r.Params rv := RequestVerify{p.VerifyToken} mJson, err := json.Marshal(rv) if err != nil { return nil, "", err } client := util.HttpClient{} client.Path = "/operators/verify" client.Body = mJson client.XSoracomApiKey = p.XSoracomApiKey client.XSoracomToken = p.XSoracomToken resp, err := client.Post() if err != nil { return nil, "", err } switch resp.StatusCode { case http.StatusBadRequest: err = errors.New("Invalid token") return nil, "", err case http.StatusNotFound: err = errors.New("Token is expired") return nil, "", err case http.StatusOK: return nil, "OK", nil } println(resp.StatusCode) err = errors.New("Unknown error.") return nil, "", err }