-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGetDeviceInfo.go
39 lines (34 loc) · 1.13 KB
/
GetDeviceInfo.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
package netgear_client
import (
"encoding/xml"
"fmt"
)
// Implements the DeviceInfo/GetInfo SOAP message
func (client *NetgearClient) GetDeviceInfo() (map[string]string, error) {
const ACTION = "urn:NETGEAR-ROUTER:service:DeviceInfo:1#GetInfo"
const REQUEST = `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope
xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>%s</SessionID>
</SOAP-ENV:Header>
</SOAP-ENV:Envelope>`
response, err := client.send_request(ACTION, fmt.Sprintf(REQUEST, client.sessionid), true)
if err != nil {
return make(map[string]string), err
}
var inside Node
err = xml.Unmarshal(response, &inside)
if err != nil {
return make(map[string]string), fmt.Errorf("failed to unmarshal response from inside SOAP body: %v", err)
}
var info = make(map[string]string)
for _, node := range inside.Nodes {
name := node.XMLName.Local
info[name] = node.Content
}
return info, nil
}