mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2024-11-16 15:26:46 +01:00
37 lines
528 B
Go
37 lines
528 B
Go
|
package ussd
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
|
||
|
"github.com/carlmjohnson/requests"
|
||
|
)
|
||
|
|
||
|
type (
|
||
|
USSDClient struct {
|
||
|
endpoint string
|
||
|
}
|
||
|
|
||
|
USSDResponse struct {
|
||
|
Address string `json:"address"`
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func New(endpoint string) *USSDClient {
|
||
|
return &USSDClient{
|
||
|
endpoint: endpoint,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (uc *USSDClient) GetAddress(ctx context.Context, phone string) (string, error) {
|
||
|
var resp USSDResponse
|
||
|
|
||
|
if err := requests.
|
||
|
URL(uc.endpoint + phone).
|
||
|
ToJSON(&resp).
|
||
|
Fetch(ctx); err != nil {
|
||
|
return "", err
|
||
|
}
|
||
|
|
||
|
return resp.Address, nil
|
||
|
}
|