Api wrapper to communicate with EVRYTHNG's Engine.
Dependencies: EthernetInterface mbed-rtos
Dependents: EvrythngApiExample
EvrythngApi.h
00001 /* 00002 * (c) Copyright 2012 EVRYTHNG Ltd London / Zurich 00003 * www.evrythng.com 00004 * 00005 * --- DISCLAIMER --- 00006 * 00007 * EVRYTHNG provides this source code "as is" and without warranty of any kind, 00008 * and hereby disclaims all express or implied warranties, including without 00009 * limitation warranties of merchantability, fitness for a particular purpose, 00010 * performance, accuracy, reliability, and non-infringement. 00011 * 00012 * Author: Michel Yerly 00013 * 00014 */ 00015 #ifndef EVRYTHNGAPI_H 00016 #define EVRYTHNGAPI_H 00017 00018 #include "EthernetInterface.h" 00019 #include <string> 00020 00021 #include <stdint.h> 00022 00023 enum HttpMethod { 00024 GET, PUT, POST, DELETE 00025 }; 00026 00027 00028 /* 00029 * Class to communicate with EVRYTHNG engine. 00030 */ 00031 class EvrythngApi 00032 { 00033 public: 00034 00035 /* 00036 * Constructor 00037 */ 00038 EvrythngApi(const std::string& token, const std::string& host = "api.evrythng.com", int port = 80); 00039 00040 /* 00041 * Destructor 00042 */ 00043 virtual ~EvrythngApi(); 00044 00045 /* 00046 * Reads the current value of a thng's property. The value read is put 00047 * in the value parameter. 00048 * Returns 0 on success, or an error code on error. Error codes are 00049 * described in evry_error.h. 00050 */ 00051 int getThngPropertyValue(const std::string& thngId, const std::string& key, std::string& value); 00052 00053 /* 00054 * Sets the value of a thng's property. 00055 * Returns 0 on success, or an error code on error. Error codes are 00056 * described in evry_error.h. 00057 */ 00058 int setThngPropertyValue(const std::string& thngId, const std::string& key, const std::string& value, int64_t timestamp); 00059 00060 private: 00061 std::string token; 00062 std::string host; 00063 int port; 00064 00065 int httpRequest(HttpMethod method, const std::string& path, const std::string& content, std::string& out, int& codeOut); 00066 00067 int httpPut(const std::string& path, const std::string& json, std::string& out, int& codeOut); 00068 int httpGet(const std::string& path, std::string& out, int& codeOut); 00069 int httpPost(const std::string& path, const std::string& json, std::string& out, int& codeOut); 00070 int httpDelete(const std::string& path, std::string& out, int& codeOut); 00071 }; 00072 00073 #endif
Generated on Tue Jul 12 2022 16:31:38 by 1.7.2