SenseClient is an API to interact with Sen.se platform. Sen.se is the place where Humans, Machines, Objects, Environments, Information, Physical and Virtual spaces mix up, talk, intertwine, interact, enrich and empower each other.

Dependencies:   NetServicesProxy

Dependents:   SenseClientSample

Revision:
0:ed7287a3edbf
Child:
1:0249701444ee
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SenseClient.cpp	Tue Sep 06 13:31:10 2011 +0000
@@ -0,0 +1,78 @@
+/*
+   Copyright [2011] [mimilowns@gmail.com]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+#include "SenseClient.h"
+#include "HTTPClient.h"
+
+
+SenseClient::SenseClient(const string& senseKey, const string& httpproxy) :  _jsonContent("application/json"), _jsonRespContent("application/json") {
+    _key = senseKey;
+    _proxy = httpproxy; 
+}
+
+SenseClient::~SenseClient() {
+}
+
+void SenseClient::PostEvent(const string& feedID, const string& value) {
+    _jsonContent.set("{\"feed_id\":"+feedID+", \"value\":"+value+"}");
+    
+    string uri = "http://api.sen.se/event_api/events/";
+    HTTPClient _client;
+    _client.setRequestHeader("sense_key", _key);
+    if(!_proxy.empty()) {
+        _client.setProxy(_proxy.c_str());
+    }
+    
+    _result = _client.post(uri.c_str(), _jsonContent, &_jsonRespContent);
+    _response = _client.getHTTPResponseCode();
+}
+  
+void SenseClient::GetLastFeedEvent(const string& feedID) {
+    string uri = "http://api.sen.se/event_api/feeds/"+feedID+"/last_event/";
+
+    HTTPClient _client;
+    _client.setRequestHeader("sense_key", _key);
+    if(!_proxy.empty()) {
+        _client.setProxy(_proxy.c_str());
+    }
+    
+    _result = _client.get(uri.c_str(), &_jsonRespContent);
+    _response = _client.getHTTPResponseCode();
+}
+
+void SenseClient::GetDeviceLastEvent(const string& deviceID) {
+    string uri = "http://api.sen.se/devices/"+deviceID+"/last_event/";
+    
+    HTTPClient _client;
+    _client.setRequestHeader("sense_key", _key);
+    if(!_proxy.empty()) {
+        _client.setProxy(_proxy.c_str());
+    }
+    
+    _result = _client.get(uri.c_str(), &_jsonRespContent);
+    _response = _client.getHTTPResponseCode();
+}
+
+// http result and response
+HTTPResult SenseClient::Result() {
+    return _result;
+}
+int SenseClient::Response() {
+    return _response;
+}
+
+HTTPText SenseClient::ResponseContent() {
+    return _jsonRespContent;
+}