notfall/vendor/github.com/sms77io/go-client/sms77api/voice.go
kekskurse c9ab16b493
Some checks failed
continuous-integration/drone/push Build is failing
SMS
2022-01-16 13:30:48 +01:00

61 lines
1 KiB
Go

package sms77api
import (
"context"
"strconv"
"strings"
)
type Voice struct {
Code int
Cost float64
Id int
}
type VoiceParams struct {
Debug bool `json:"debug,omitempty"`
To string `json:"to"`
Text string `json:"text"`
Xml bool `json:"xml,omitempty"`
From string `json:"from,omitempty"`
}
type VoiceResource resource
func makeVoice(res string) Voice {
lines := strings.Split(res, "\n")
code, _ := strconv.Atoi(lines[0])
id, _ := strconv.Atoi(lines[1])
cost, _ := strconv.ParseFloat(lines[2], 64)
return Voice{
Code: code,
Cost: cost,
Id: id,
}
}
func (api *VoiceResource) Text(p VoiceParams) (*string, error) {
return api.TextContext(context.Background(), p)
}
func (api *VoiceResource) TextContext(ctx context.Context, p VoiceParams) (*string, error) {
res, err := api.client.request(ctx, "voice", "POST", p)
if err != nil {
return nil, err
}
return &res, nil
}
func (api *VoiceResource) Json(p VoiceParams) (o Voice, e error) {
r, e := api.Text(p)
if nil != e {
return
}
return makeVoice(*r), nil
}