-
Notifications
You must be signed in to change notification settings - Fork 0
/
sms.go
106 lines (94 loc) · 3.68 KB
/
sms.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package simpay
import (
"encoding/json"
"fmt"
)
type Sms struct {
restClient restClient
}
func NewSms(apiKey, simPassword string) *Sms {
return &Sms{
restClient: newRestClient(apiKey, simPassword),
}
}
func (s Sms) GetServiceList(page, limit uint) (SmsServiceListResponse, error) {
endpoint := fmt.Sprintf("/sms?page=%v&limit=%v", page, limit)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return SmsServiceListResponse{}, err
}
var serviceList SmsServiceListResponse
return serviceList, json.Unmarshal(response, &serviceList)
}
func (s Sms) GetServiceDetails(serviceId uint) (SmsServiceDetailsResponse, error) {
endpoint := fmt.Sprintf("/sms/%v", serviceId)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return SmsServiceDetailsResponse{}, err
}
var serviceDetails SmsServiceDetailsResponse
return serviceDetails, json.Unmarshal(response, &serviceDetails)
}
func (s Sms) GetTransactions(serviceId, page, limit uint) (SmsTransactionListResponse, error) {
endpoint := fmt.Sprintf("/sms/%v/transactions?page=%v&limit=%v", serviceId, page, limit)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return SmsTransactionListResponse{}, err
}
var transactionList SmsTransactionListResponse
return transactionList, json.Unmarshal(response, &transactionList)
}
func (s Sms) GetTransactionDetails(serviceId, transactionId uint) (SmsTransactionDetailsResponse, error) {
endpoint := fmt.Sprintf("/sms/%v/transactions/%v", serviceId, transactionId)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return SmsTransactionDetailsResponse{}, err
}
var transactionDetails SmsTransactionDetailsResponse
return transactionDetails, json.Unmarshal(response, &transactionDetails)
}
func (s Sms) GetServiceNumbers(serviceId, page, limit uint) (NumberListResponse, error) {
endpoint := fmt.Sprintf("/sms/%v/numbers?page=%v&limit=%v", serviceId, page, limit)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return NumberListResponse{}, err
}
var numberListResponse NumberListResponse
return numberListResponse, json.Unmarshal(response, &numberListResponse)
}
func (s Sms) GetServiceNumberDetails(serviceId uint, number int64) (NumberDetailsResponse, error) {
endpoint := fmt.Sprintf("/sms/%v/numbers/%v", serviceId, number)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return NumberDetailsResponse{}, err
}
var numberDetails NumberDetailsResponse
return numberDetails, json.Unmarshal(response, &numberDetails)
}
func (s Sms) GetNumbers(page, limit uint) (NumberListResponse, error) {
endpoint := fmt.Sprintf("/sms/numbers?page=%v&limit=%v", page, limit)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return NumberListResponse{}, err
}
var numberListResponse NumberListResponse
return numberListResponse, json.Unmarshal(response, &numberListResponse)
}
func (s Sms) GetNumberDetails(number int64) (NumberDetailsResponse, error) {
endpoint := fmt.Sprintf("/sms/numbers/%v", number)
response, err := s.restClient.sendGetRequest(endpoint)
if err != nil {
return NumberDetailsResponse{}, err
}
var numberDetails NumberDetailsResponse
return numberDetails, json.Unmarshal(response, &numberDetails)
}
func (s Sms) VerifyCode(serviceId uint, code string, number int64) (CodeVerificationResponse, error) {
endpoint := fmt.Sprintf("/sms/%v", serviceId)
response, err := s.restClient.sendPostRequest(endpoint, CodeVerifyRequest{Code: code, Number: number})
if err != nil {
return CodeVerificationResponse{}, err
}
var verificationResponse CodeVerificationResponse
return verificationResponse, json.Unmarshal(response, &verificationResponse)
}