Plantronics Developer Connection - REST https://developer.plantronics.com/blog/rest en HubRESTSample – a new C++ REST API Sample for PDC https://developer.plantronics.com/article/hubrestsample-new-c-rest-api-sample-pdc <div class="field field-name-field-keywords field-type-taxonomy-term-reference field-label-above"> <div class="field-label">Keywords:&nbsp;</div> <div class="field-items"> <span class="field-item even label label-default keyword-label"><a href="/blog/c-0" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">C++</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/rest" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">REST</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/api" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">API</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/hub" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Hub</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/manager-pro" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Manager Pro</a></span> </div> </div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded">This new sample code illustrates seamless consumption of Plantronics out-of-proc REST API from C++ code!<br /> <br /> <strong>Location of full sample code:</strong> <a href="https://github.com/pltdev/pdc/tree/master/C%2B%2B%20REST%20Sample" target="_blank">https://github.com/pltdev/pdc/tree/master/C%2B%2B%20REST%20Sample</a><br />   <h3>Key Benefits</h3> <ol> <li><strong>Supports Plantronics Manager Pro configuration</strong> <ul> <li>Works with Plantronics Hub via “out-of-proc” REST API</li> </ul> </li> <li><strong>Supports multi-softphone &amp; multi-device configurations</strong></li> <li><strong>Same code for both Windows and Mac environments</strong></li> <li><strong>Follows same model as the other PDC samples for C#, Java, JavaScript, etc</strong> <ul> <li>Providing clear illustrations of basic call control</li> </ul> </li> <li><strong>Illustrates support for resilience to Hub restarting and device changing</strong></li> </ol> <h3>Design Overview</h3> The design of the sample uses a threaded (active) object called HubRESTLib, that handles all the REST HTTP requests and resilience (reconnects). It allows Hub SDK commands to be issued and events from Hub SDK to be received via the callbacks of the IHubRestLib interface.<br /> <br /> <div class="media media-element-container media-default"><div id="file-173" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/hubrestsample-1png">HubRESTSample 1.png</a></h2> <div class="content"> <img height="477" width="1115" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/HubRESTSample%201.png" alt="" /> </div> </div> </div><br /> <br /> *POCO Libraries were used in this sample for HTTP requests and JSON parsing functionality, but any libraries could be used<br />   <h3>The sample code in action…</h3> Note: with this integration sample it is just 1 line of C++ code to connect to Plantronics REST API (instantiate HubSDKConnector object), and 1 line of code to cleanup (delete the object).<br /> <br /> Once instantiated you are then able to submit API commands (e.g. IncomingCall, etc) to this object using a HubSDKAction object, as shown below. Some of the actions take parameters, e.g. callid, etc:<br /> <br /> <strong>Note: you will need the full sample code to use this</strong>, obtain from here: <a href="https://github.com/pltdev/pdc/tree/master/C%2B%2B%20REST%20Sample" target="_blank">https://github.com/pltdev/pdc/tree/master/C%2B%2B%20REST%20Sample</a><br />   <pre class="brush: cpp"> #include &lt;iostream&gt; #include &lt;string&gt; #include "HubSDKConnector.h" using namespace std; void ShowMenu() { cout &lt;&lt; endl; cout &lt;&lt; "plt sample menu" &lt;&lt; endl; cout &lt;&lt; "--" &lt;&lt; endl; cout &lt;&lt; "1 - ring/incoming call" &lt;&lt; endl; cout &lt;&lt; "2 - outgoing call" &lt;&lt; endl; cout &lt;&lt; "3 - answer call" &lt;&lt; endl; cout &lt;&lt; "4 - hold call" &lt;&lt; endl; cout &lt;&lt; "5 - resume call" &lt;&lt; endl; cout &lt;&lt; "6 - mute call" &lt;&lt; endl; cout &lt;&lt; "7 - unmute call" &lt;&lt; endl; cout &lt;&lt; "8 - end call" &lt;&lt; endl; cout &lt;&lt; "0 - quit" &lt;&lt; endl; cout &lt;&lt; endl; cout &lt;&lt; "&gt; "; } int GetCommand() { string cmdstr; int cmd; getline(std::cin, cmdstr); if (cmdstr.empty()) cmd = -1; else { try { cmd = atoi(cmdstr.c_str()); } catch (exception const &amp; e) { cout &lt;&lt; "error : " &lt;&lt; e.what() &lt;&lt; endl; cmd = -1; } } return cmd; } int main() { cout &lt;&lt; "C++ Plantronics Hub REST Sample" &lt;&lt; endl; bool quit = false; int callid = 0; HubSDKConnector * hubSDK = new HubSDKConnector(); // Connect to the Plantronics REST API while (!quit) { ShowMenu(); int cmd = GetCommand(); HubSDKAction action; switch (cmd) { case 1: callid++; // inform Plantronics my app has an incoming (ringing) call cout &lt;&lt; "Performing incoming call, id = " &lt;&lt; callid &lt;&lt; endl; action.ActionType = HubSDKActionType_IncomingCall; action.callid = callid; // numeric id to uniquely identify each call action.contactname = "Bob%20Smith"; // optional contact name for display devices, e.g. Calisto 240, note: needs url encoding e.g. spaces are %20, etc. hubSDK-&gt;DoHubSDKAction(action); break; case 2: callid++; // inform Plantronics my app has an outgoing call cout &lt;&lt; "Performing outgoing call, id = " &lt;&lt; callid &lt;&lt; endl; action.ActionType = HubSDKActionType_OutgoingCall; action.callid = callid; action.contactname = "Bob%20Smith"; hubSDK-&gt;DoHubSDKAction(action); break; case 3: // inform Plantronics my app has now answered an incoming (ringing) call cout &lt;&lt; "Answering call, id = " &lt;&lt; callid &lt;&lt; endl; action.ActionType = HubSDKActionType_AnswerCall; action.callid = callid; hubSDK-&gt;DoHubSDKAction(action); break; case 4: // place call on hold cout &lt;&lt; "Holding call, id = " &lt;&lt; callid &lt;&lt; endl; action.ActionType = HubSDKActionType_HoldCall; action.callid = callid; hubSDK-&gt;DoHubSDKAction(action); break; case 5: // resume the call cout &lt;&lt; "Resuming call, id = " &lt;&lt; callid &lt;&lt; endl; action.ActionType = HubSDKActionType_ResumeCall; action.callid = callid; hubSDK-&gt;DoHubSDKAction(action); break; case 6: // mute the headset (note for wireless products, audio link must be active) cout &lt;&lt; "Setting headset mute = true"; action.ActionType = HubSDKActionType_SetMute; action.mutestate = true; hubSDK-&gt;DoHubSDKAction(action); break; case 7: // unmute the headset (note for wireless products, audio link must be active) cout &lt;&lt; "Setting headset mute = false"; action.ActionType = HubSDKActionType_SetMute; action.mutestate = false; hubSDK-&gt;DoHubSDKAction(action); break; case 8: // inform Plantronics my app has now terminated the call cout &lt;&lt; "Terminating call, id = " &lt;&lt; callid &lt;&lt; endl; action.ActionType = HubSDKActionType_TerminateCall; action.callid = callid; hubSDK-&gt;DoHubSDKAction(action); break; case 0: quit = true; break; default: cout &lt;&lt; "Unrecognised menu choice." &lt;&lt; endl; break; } } delete hubSDK; // Cleanup the Plantronics REST API return 0; } </pre>   <h4>View of the application running:</h4> It presents a menu allowing you to try out the basic call control commands, and see connection information and notifications from Plantronics Hub and the headset:<br /> <br /> <div class="media media-element-container media-default"><div id="file-179" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/hubrestsample-3png-2">HubRESTSample 3.png</a></h2> <div class="content"> <img height="745" width="917" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/HubRESTSample%203_2.png" alt="" /> </div> </div> </div><br />  </div></div></div> Tue, 06 Jun 2017 14:00:33 +0000 lcollins 546 at https://developer.plantronics.com https://developer.plantronics.com/article/hubrestsample-new-c-rest-api-sample-pdc#comments Integrate Plantronics REST API from Go https://developer.plantronics.com/article/integrate-plantronics-rest-api-go <div class="field field-name-field-keywords field-type-taxonomy-term-reference field-label-above"> <div class="field-label">Keywords:&nbsp;</div> <div class="field-items"> <span class="field-item even label label-default keyword-label"><a href="/blog/go" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">go</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/sdk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">SDK</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/api" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">API</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/rest" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">REST</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/plantronics" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">plantronics</a></span> </div> </div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded">Greetings!<br /> <br /> I have recently created an example integrate from the Go language to the Plantronics REST API.<br /> <br /> 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).<br /> <br /> Obtain Go language (golang) from here: <a href="https://golang.org/">https://golang.org/</a><br /> <br /> Obtain the sample code from here: <a href="/system/files/plt%20go%20sample.zip">http://developer.plantronics.com/system/files/plt%20go%20sample.zip</a><br /> <strong>Note: </strong>you must login to this site to download that file.<br /> <br /> Here is how you connect to Plantronics from Go (code snippet):<br />   <pre class="prettyprint"> 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, &amp;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 } </pre> <br /> Below is a picture of the code in action, having received a "Don" event (when I put on the Plantronics headset)...<br /> Have fun!<br /> Lewis.<br /> <br /> <div class="media media-element-container media-default"><div id="file-111" class="file file-image file-image-png"> <h2 class="element-invisible"><a href="/files/go-samplepng">go sample.png</a></h2> <div class="content"> <img height="798" width="915" class="media-element file-default img-responsive" typeof="foaf:Image" src="https://developer.plantronics.com/sites/default/files/go%20sample.png" alt="" /> </div> </div> </div></div></div></div> Thu, 01 Sep 2016 12:06:32 +0000 lcollins 384 at https://developer.plantronics.com https://developer.plantronics.com/article/integrate-plantronics-rest-api-go#comments Using Plantronics SDK from Java https://developer.plantronics.com/article/using-plantronics-sdk-java <div class="field field-name-field-keywords field-type-taxonomy-term-reference field-label-above"> <div class="field-label">Keywords:&nbsp;</div> <div class="field-items"> <span class="field-item even label label-default keyword-label"><a href="/blog/java" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Java</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/plantronics" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">plantronics</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/sdk" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">SDK</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/integration" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">integration</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/rest" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">REST</a></span> <span class="field-item odd label label-default keyword-label"><a href="/blog/service" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">Service</a></span> <span class="field-item even label label-default keyword-label"><a href="/blog/api" typeof="skos:Concept" property="rdfs:label skos:prefLabel" datatype="">API</a></span> </div> </div><div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><span style="color:#FF0000;">*Update 22nd Jan 2016*</span>: Since the SDK version 3.7.x, you can now optionally use https:// port <span style="color:#FF0000;"><strong>32018</strong></span> in addition to http:// on port <strong>32017</strong>! (however for https you may need to manually deploy the self-signed certificate if using Firefox or Java).<br /> <br /> <strong>Sample code:</strong><br /> <a href="/system/files/PlantronicsRESTDemo%20-%20Milestone%201%20full%20call%20control%20and%20events%20listening.zip">Download this sample code as a ZIP</a><br />   <pre class="brush: java"> String tmpResult =     RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/DeviceServices/Attach?uid=0123456789" );</pre> This code requires the convenience function SendRESTCommand (available <a href="/system/files/PlantronicsRESTDemo%20-%20Milestone%201%20full%20call%20control%20and%20events%20listening.zip">in the sample code ZIP</a>).<br /> <br /> 0123456789 is a magic uid which tells the REST Service API to attach to the "primary" Plantronics device (primary device is settable via the Plantronics Hub user interface, in the case you have more than one Plantroncis device attached to your PC).<br /> <br /> Now we can examine the tmpResult variable to see if the attach was a success. <pre class="brush: java"> int pos = tmpResult.indexOf("\"Result\":\""); if (pos&gt;-1) {     tmpResult = tmpResult.substring(pos+10);     pos = tmpResult.indexOf("\"");     if (pos&gt;-1)     {         tmpResult = tmpResult.substring(0, pos);         System.out.println("Session id is: " + tmpResult);         sessionid = tmpResult;     } }</pre> This code is extracting the sessionid from the HTTP response. We need that later for some of the other REST Service API commands. Note, the HTTP response is in fact JSON, so it would be better to parse with a JSON parser, but I haven't adopted a suitable JSON parser yet...<br /> <br /> After a short delay we can go ahead an register a REST Service API plugin. The plugin is needed for some of the call control commands. <pre class="brush: java"> try {     Thread.sleep(250); } catch (InterruptedException ex) {     Logger.getLogger(PlantronicsRESTDemo.class.getName()).log(Level.SEVERE, null, ex); }                                   if (sessionid.length()&gt;0) {     RESTConvenienceClass.SendRESTCommand(         "http://127.0.0.1:32017/Spokes/SessionManager/Register?name=My%20Java%20Plugin"     );                    pluginRegistered = true; }</pre> Now we are able to poll for device events using further REST Service API commands, like this:<br /> (Note: the sessid and plugin_name need to match what we registered earlier).<br /> The contents of the responses we get back tell us lots of information, such as when user has answered a call with headset, mutes a call, takes headset off, etc. <pre class="brush: java"> RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/DeviceServices/Events?sess="         + sessid         + "&amp;queue=0" ) RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/Events" ); RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/SessionManagerCallEvents?name="         + plugin_name );</pre> Finally we can control the headset by telling it when we are going on a call, for example:<br /> An incoming call (pass an integer callid, used to refer to this call during its lifecycle, and pass an optional caller name for Plantronics' display device products): <pre class="brush: java"> callid = callid + 1; caller_name = "Bob%20Smith"; RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/IncomingCall?name=My%20Java%20Plugin&amp;callID=%7B%22Id%22%3A%22"         + callid         + "%22%7D&amp;contact=%7B%22Name%22%3A%22"         + caller_name         + "%22%7D&amp;tones=Unknown&amp;route=ToHeadset" );</pre> End the call: <pre class="brush: java"> RESTConvenienceClass.SendRESTCommand(     "http://127.0.0.1:32017/Spokes/CallServices/TerminateCall?name=My%20Java%20Plugin&amp;callID=%7B%22Id%22%3A%22"         + callid         + "%22%7D" );</pre> For more examples and to see a complete Java implementation, <a href="/system/files/PlantronicsRESTDemo%20-%20Milestone%201%20full%20call%20control%20and%20events%20listening.zip">download the sample code ZIP</a>.<br /> <br /> Here is a screeshot of the sample code in action running under <a href="https://netbeans.org/" target="_blank">NetBeans IDE</a>:<br /> <br /> false<br /> <br /> Have fun!<br /> <br /> <br /> <br /> <br /> <br />  </div></div></div> Thu, 05 Nov 2015 12:40:30 +0000 lcollins 162 at https://developer.plantronics.com https://developer.plantronics.com/article/using-plantronics-sdk-java#comments