| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package smsto |
||
| 2 | |||
| 3 | import ( |
||
| 4 | "context" |
||
| 5 | "encoding/json" |
||
| 6 | "net/http" |
||
| 7 | ) |
||
| 8 | |||
| 9 | // smsService is the API client for the `/sms` endpoint |
||
| 10 | type smsService service |
||
| 11 | |||
| 12 | // SendSingle Sends a single SMS message to a phone number |
||
| 13 | // |
||
| 14 | // API Docs: https://developers.sms.to/#0eff8134-6ad5-4b61-86f3-28ff18145bfc |
||
| 15 | func (service *smsService) SendSingle( |
||
| 16 | ctx context.Context, |
||
| 17 | params *SmsSendSingleRequest, |
||
| 18 | ) (*SmsSendSingleResponse, *Response, error) { |
||
| 19 | request, err := service.client.newRequest(ctx, http.MethodPost, "/sms/send", params) |
||
| 20 | if err != nil { |
||
| 21 | return nil, nil, err |
||
| 22 | } |
||
| 23 | |||
| 24 | response, err := service.client.do(request) |
||
| 25 | if err != nil { |
||
| 26 | return nil, response, err |
||
| 27 | } |
||
| 28 | |||
| 29 | status := new(SmsSendSingleResponse) |
||
| 30 | if err = json.Unmarshal(*response.Body, status); err != nil { |
||
| 31 | return nil, response, err |
||
| 32 | } |
||
| 33 | |||
| 34 | return status, response, nil |
||
| 35 | } |
||
| 36 |