Keywords: 
Greetings!

I have recently created an example integrate from the Go language to the Plantronics REST API.

It is still a work in progress but it is functional for receiving device, session and session manager events. (For further guidance on the REST Service API URLs you can use, check out the Java and JavaScript integration samples elsewhere on this site).

Obtain Go language (golang) from here: https://golang.org/

Obtain the sample code from here: http://developer.plantronics.com/system/files/plt%20go%20sample.zip
Note: you must login to this site to download that file.

Here is how you connect to Plantronics from Go (code snippet):
 
func httpGetJSON(url string) (map[string]interface{}) {
    var dat map[string]interface{}
    resp, err := http.Get(url)
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()
    if b, err2 := ioutil.ReadAll(resp.Body); err2 == nil {
        if err := json.Unmarshal(b, &dat); err != nil {
            log.Fatal(err)
        }
    }
    return dat
}

func connectToPlantronics() {
    fmt.Print("Connecting to Plantronics...\r\n")
    var jsondata map[string]interface{} = httpGetJSON("http://127.0.0.1:32017/Spokes/DeviceServices/Attach?uid=0123456789")
    fmt.Print("\r\nSession ID:\r\n\r\n"+jsondata["Result"].(string)+"\r\n\r\n")
    sessionId = jsondata["Result"].(string)
    
    var result string = httpGet("http://127.0.0.1:32017/Spokes/SessionManager/Register?name="+pluginName)
    fmt.Print("\r\nResult:\r\n\r\n"+result+"\r\n\r\n")
    pluginRegistered = true
    
    go eventsListenerThread(sessionId,pluginName)  // start monitoring events after connect to api
}

Below is a picture of the code in action, having received a "Don" event (when I put on the Plantronics headset)...
Have fun!
Lewis.

News Articles Classification: