Пример #1
0
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
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
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
}
Пример #5
0
func (r *Request) OperatorInfo() (*Response, string, error) {
	p := &r.Params
	client := util.HttpClient{}
	client.Path = "/operators/" + string(p.OperatorId)
	client.XSoracomApiKey = p.XSoracomApiKey
	client.XSoracomToken = p.XSoracomToken

	resp, err := client.Get()
	if err != nil {
		return nil, "", err
	}

	if resp.StatusCode == http.StatusBadRequest {
		err = errors.New("Invalid Operator Id.")
		return nil, "", err
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()

	or := Response{}

	err = json.Unmarshal(body, &or)
	if err != nil {
		return nil, "", err
	}

	return &or, string(body), nil
}
Пример #6
0
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
}
Пример #7
0
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
}
Пример #8
0
func (r *Request) OperatorSupportToken() (*Response, string, error) {
	p := &r.Params
	client := util.HttpClient{}
	client.Path = "/operators/" + string(p.OperatorId) + "/support/token"
	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("Invald OperatorId")
		return nil, "", err
	case http.StatusForbidden:
		err = errors.New("Invalid token for SORACOM")
		return nil, "", err
	}

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, "", err
	}
	defer resp.Body.Close()

	ar := Response{}

	err = json.Unmarshal(body, &ar)
	if err != nil {
		return nil, "", err
	}

	return &ar, string(body), nil
}