-
Notifications
You must be signed in to change notification settings - Fork 3
/
Device.go
113 lines (84 loc) · 2.62 KB
/
Device.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
107
108
109
110
111
112
113
package HologramGo
import (
"fmt"
"os"
"strconv"
)
// Device object returned in the response.
type Device map[string]interface{}
// Devices is just a list of Device(s).
type Devices []interface{}
// GetDevices returns device details.
func GetDevices() Devices {
req := createGetRequest("/devices")
resp, err := sendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
return unmarshallIntoArrayObject(resp)
}
// GetDevice returns a device detail based on the given deviceid.
func GetDevice(deviceid int) Device {
req := createGetRequest("/devices/" + strconv.Itoa(deviceid))
resp, err := sendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
return unmarshallIntoObject(resp)
}
// ClaimOwnershipAndActivateDevice claims ownership and activate the given device.
func ClaimOwnershipAndActivateDevice(simnumber int) Device {
var params Parameters
req := createPostRequest("/cellular/sim_"+strconv.Itoa(simnumber)+"/claim", params)
resp, err := sendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
return unmarshallIntoObject(resp)
}
// PurchaseAndAssignPhoneNumberToDevice purchases and assigns a phone number to the device.
func PurchaseAndAssignPhoneNumberToDevice(deviceid int) Device {
var params Parameters
req := createPostRequest("/devices/"+strconv.Itoa(deviceid)+"/addnumber", params)
resp, err := sendRequest(req)
if err != nil {
fmt.Printf("Could not send request: %v\n", err)
os.Exit(1)
}
return unmarshallIntoObject(resp)
}
///////////////////////////////////////////////////
// GENERIC DEVICE GETTER FUNCTIONS
///////////////////////////////////////////////////
// GetDeviceId returns the id.
func (device Device) GetDeviceId() float64 {
return device["id"].(float64)
}
// GetDeviceUserId returns the user id.
func (device Device) GetDeviceUserId() float64 {
return device["userid"].(float64)
}
// GetDeviceName returns the device name.
func (device Device) GetDeviceName() string {
return device["name"].(string)
}
// GetDeviceType returns the device type.
func (device Device) GetDeviceType() string {
return device["type"].(string)
}
// GetWhenCreated returns a UNIX timestamp of the creation time.
func (device Device) GetWhenCreated() string {
return device["whencreated"].(string)
}
// GetPhoneNumber returns a phone number.
func (device Device) GetPhoneNumber() string {
return device["phonenumber"].(string)
}
// GetTunnelable returns true if it is tunnelable.
func (device Device) GetTunnelable() bool {
return device["tunnelable"].(bool)
}
// TODO: links/cellular