forked from carlosdp/twiliogo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
incoming_phone_number.go
75 lines (60 loc) · 2.34 KB
/
incoming_phone_number.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
package twiliogo
import (
"encoding/json"
"net/url"
)
type Capabilites struct {
Voice bool `json:"voice"`
SMS bool `json:"SMS"`
MMS bool `json:"MMS"`
}
type IncomingPhoneNumber struct {
Sid string `json:"sid"`
AccountSid string `json:"account_sid"`
FriendlyName string `json:"friendly_name"`
PhoneNumber string `json:"phone_number"`
VoiceUrl string `json:"voice_url"`
VoiceMethod string `json:"voice_method"`
VoiceFallbackUrl string `json:"voice_fallback_url"`
VoiceFallbackMethod string `json:"voice_fallback_method"`
StatusCallback string `json:"status_callback"`
StatusCallbackMethod string `json:"status_callback_method"`
VoiceCallerIdLookup bool `json:"voice_caller_id_lookup"`
VoiceApplicationId string `json:"voice_application_id"`
DateCreated string `json:"date_created"`
DateUpdated string `json:"date_updated"`
SmsUrl string `json:"sms_url"`
SmsMethod string `json:"sms_method"`
SmsFallbackUrl string `json:"sms_fallback_url"`
SmsFallbackMethod string `json:"sms_fallback_method"`
SmsApplicationId string `json:"sms_application_id"`
Capabilities Capabilites `json:"capabilities"`
ApiVersion string `json:"api_version"`
Uri string `json:"uri"`
}
func GetIncomingPhoneNumber(client Client, sid string) (*IncomingPhoneNumber, error) {
var incomingPhoneNumber *IncomingPhoneNumber
res, err := client.get(url.Values{}, "/IncomingPhoneNumbers/"+sid+".json")
if err != nil {
return nil, err
}
incomingPhoneNumber = new(IncomingPhoneNumber)
err = json.Unmarshal(res, incomingPhoneNumber)
return incomingPhoneNumber, err
}
func BuyPhoneNumber(client Client, number Optional) (*IncomingPhoneNumber, error) {
var incomingPhoneNumber *IncomingPhoneNumber
if number == nil {
return nil, Error{"Must input PhoneNumber or AreaCode"}
}
params := url.Values{}
param, value := number.GetParam()
params.Set(param, value)
res, err := client.post(params, "/IncomingPhoneNumbers.json")
if err != nil {
return incomingPhoneNumber, err
}
incomingPhoneNumber = new(IncomingPhoneNumber)
err = json.Unmarshal(res, incomingPhoneNumber)
return incomingPhoneNumber, err
}